From dfd58840d16a0a23850c21995e52418cd584c0de Mon Sep 17 00:00:00 2001 From: Narcis Beleuzu Date: Wed, 6 Dec 2017 00:27:11 +0200 Subject: [PATCH] Backed out changeset 8a4050c7e0fd (bug 1423114) for bustages on memory/mozalloc/mozalloc.cpp r=backout on a CLOSED TREE --- memory/mozalloc/mozalloc.cpp | 35 +++++++++++++++++++++++++++++++++-- memory/mozalloc/mozalloc.h | 16 ++++++++++++++++ memory/replace/dmd/dmd.py | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/memory/mozalloc/mozalloc.cpp b/memory/mozalloc/mozalloc.cpp index 985741e15cdc..db571ff2a348 100644 --- a/memory/mozalloc/mozalloc.cpp +++ b/memory/mozalloc/mozalloc.cpp @@ -40,18 +40,20 @@ MOZ_MEMORY_API char *strndup_impl(const char *, size_t); // we need not to use the suffixes. #if defined(MALLOC_H) -# include MALLOC_H // for memalign, malloc_size, malloc_us +# include MALLOC_H // for memalign, valloc, malloc_size, malloc_us #endif // if defined(MALLOC_H) #include // for malloc, free #if defined(XP_UNIX) -# include +# include // for valloc on *BSD #endif //if defined(XP_UNIX) #define malloc_impl malloc +#define posix_memalign_impl posix_memalign #define calloc_impl calloc #define realloc_impl realloc #define free_impl free #define memalign_impl memalign +#define valloc_impl valloc #define malloc_usable_size_impl malloc_usable_size #define strdup_impl strdup #define strndup_impl strndup @@ -133,6 +135,21 @@ moz_xstrndup(const char* str, size_t strsize) } #endif // if defined(HAVE_STRNDUP) +#if defined(HAVE_POSIX_MEMALIGN) +int +moz_xposix_memalign(void **ptr, size_t alignment, size_t size) +{ + int err = posix_memalign_impl(ptr, alignment, size); + if (UNLIKELY(err && ENOMEM == err)) { + mozalloc_handle_oom(size); + return moz_xposix_memalign(ptr, alignment, size); + } + // else: (0 == err) or (EINVAL == err) + return err; +} +#endif // if defined(HAVE_POSIX_MEMALIGN) + +#if defined(HAVE_MEMALIGN) void* moz_xmemalign(size_t boundary, size_t size) { @@ -144,6 +161,20 @@ moz_xmemalign(size_t boundary, size_t size) // non-NULL ptr or errno == EINVAL return ptr; } +#endif // if defined(HAVE_MEMALIGN) + +#if defined(HAVE_VALLOC) +void* +moz_xvalloc(size_t size) +{ + void* ptr = valloc_impl(size); + if (UNLIKELY(!ptr)) { + mozalloc_handle_oom(size); + return moz_xvalloc(size); + } + return ptr; +} +#endif // if defined(HAVE_VALLOC) #ifndef MOZ_STATIC_RUNTIME size_t diff --git a/memory/mozalloc/mozalloc.h b/memory/mozalloc/mozalloc.h index 0de28654c5cf..aefe63256bf2 100644 --- a/memory/mozalloc/mozalloc.h +++ b/memory/mozalloc/mozalloc.h @@ -97,8 +97,24 @@ MFBT_API char* moz_xstrndup(const char* str, size_t strsize) MOZ_ALLOCATOR; #endif /* if defined(HAVE_STRNDUP) */ + +#if defined(HAVE_POSIX_MEMALIGN) +MFBT_API MOZ_MUST_USE +int moz_xposix_memalign(void **ptr, size_t alignment, size_t size); +#endif /* if defined(HAVE_POSIX_MEMALIGN) */ + + +#if defined(HAVE_MEMALIGN) MFBT_API void* moz_xmemalign(size_t boundary, size_t size) MOZ_ALLOCATOR; +#endif /* if defined(HAVE_MEMALIGN) */ + + +#if defined(HAVE_VALLOC) +MFBT_API void* moz_xvalloc(size_t size) + MOZ_ALLOCATOR; +#endif /* if defined(HAVE_VALLOC) */ + MOZ_END_EXTERN_C diff --git a/memory/replace/dmd/dmd.py b/memory/replace/dmd/dmd.py index 73f6da421da1..37816ad11121 100755 --- a/memory/replace/dmd/dmd.py +++ b/memory/replace/dmd/dmd.py @@ -34,7 +34,7 @@ allocatorFns = [ 'calloc', # Matches realloc, replace_realloc, moz_xrealloc, vpx_realloc, js_realloc, pod_realloc, pod_reallocCanGC. 'realloc', - # Matches memalign, posix_memalign, replace_memalign, replace_posix_memalign, moz_xmemalign, vpx_memalign, malloc_zone_memalign. + # Matches memalign, posix_memalign, replace_memalign, replace_posix_memalign, moz_xmemalign, moz_xposix_memalign, vpx_memalign, malloc_zone_memalign. 'memalign', 'operator new(', 'operator new[](',