diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp index 82a8c2514f57..a98fb1e96e29 100644 --- a/memory/build/mozjemalloc.cpp +++ b/memory/build/mozjemalloc.cpp @@ -1665,14 +1665,24 @@ static inline StallSpecs GetStallSpecs() { # endif } +} // namespace MozAllocRetries + +namespace mozilla { + +StallSpecs GetAllocatorStallSpecs() { + return ::MozAllocRetries::GetStallSpecs(); +} + // Drop-in wrapper around VirtualAlloc. When out of memory, may attempt to stall // and retry rather than returning immediately, in hopes that the page file is // about to be expanded by Windows. // // Ref: // https://docs.microsoft.com/en-us/troubleshoot/windows-client/performance/slow-page-file-growth-memory-allocation-errors -[[nodiscard]] void* MozVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, - DWORD flAllocationType, DWORD flProtect) { +void* MozVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, + DWORD flProtect) { + using namespace MozAllocRetries; + DWORD const lastError = ::GetLastError(); constexpr auto IsOOMError = [] { @@ -1727,14 +1737,7 @@ static inline StallSpecs GetStallSpecs() { return ret.value_or(nullptr); } -} // namespace MozAllocRetries -using MozAllocRetries::MozVirtualAlloc; - -namespace mozilla { -MOZ_JEMALLOC_API StallSpecs GetAllocatorStallSpecs() { - return ::MozAllocRetries::GetStallSpecs(); -} } // namespace mozilla #endif // XP_WIN diff --git a/memory/build/mozmemory_utils.h b/memory/build/mozmemory_utils.h index 3c0e23ecffbc..713c800d6b54 100644 --- a/memory/build/mozmemory_utils.h +++ b/memory/build/mozmemory_utils.h @@ -11,6 +11,7 @@ #include #if defined(MOZ_MEMORY) && defined(XP_WIN) +# include # include "mozmemory_wrap.h" #endif @@ -68,6 +69,10 @@ struct StallSpecs { #if defined(MOZ_MEMORY) && defined(XP_WIN) MOZ_JEMALLOC_API StallSpecs GetAllocatorStallSpecs(); +MOZ_JEMALLOC_API_NODISCARD void* MozVirtualAlloc(LPVOID lpAddress, + SIZE_T dwSize, + DWORD flAllocationType, + DWORD flProtect); #endif } // namespace mozilla diff --git a/memory/build/mozmemory_wrap.h b/memory/build/mozmemory_wrap.h index 92d0a1176a63..6d7fc33fd255 100644 --- a/memory/build/mozmemory_wrap.h +++ b/memory/build/mozmemory_wrap.h @@ -106,6 +106,7 @@ #ifdef MOZ_MEMORY_IMPL # define MOZ_JEMALLOC_API MOZ_EXTERN_C MFBT_API +# define MOZ_JEMALLOC_API_NODISCARD MOZ_EXTERN_C [[nodiscard]] MFBT_API # if defined(XP_WIN) # define mozmem_malloc_impl(a) je_##a # else @@ -119,6 +120,7 @@ #if !defined(MOZ_MEMORY_IMPL) # define MOZ_MEMORY_API MOZ_EXTERN_C MFBT_API # define MOZ_JEMALLOC_API MOZ_EXTERN_C MFBT_API +# define MOZ_JEMALLOC_API_NODISCARD MOZ_EXTERN_C [[nodiscard]] MFBT_API #endif #ifndef MOZ_MEMORY_API @@ -126,6 +128,7 @@ #endif #ifndef MOZ_JEMALLOC_API # define MOZ_JEMALLOC_API MOZ_EXTERN_C +# define MOZ_JEMALLOC_API_NODISCARD MOZ_EXTERN_C [[nodiscard]] #endif #ifndef mozmem_malloc_impl