Differential D3094 Diff 14018 ps/trunk/libraries/source/spidermonkey/include-win32-debug/mozilla/mozalloc.h
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/libraries/source/spidermonkey/include-win32-debug/mozilla/mozalloc.h
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- | ||||
* vim: sw=4 ts=4 et : | * vim: sw=4 ts=4 et : | ||||
*/ | */ | ||||
/* This Source Code Form is subject to the terms of the Mozilla Public | /* This Source Code Form is subject to the terms of the Mozilla Public | ||||
* License, v. 2.0. If a copy of the MPL was not distributed with this | * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||||
#ifndef mozilla_mozalloc_h | #ifndef mozilla_mozalloc_h | ||||
#define mozilla_mozalloc_h | #define mozilla_mozalloc_h | ||||
/* | /* | ||||
* https://bugzilla.mozilla.org/show_bug.cgi?id=427099 | * https://bugzilla.mozilla.org/show_bug.cgi?id=427099 | ||||
*/ | */ | ||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#if defined(__cplusplus) | #if defined(__cplusplus) | ||||
# include <new> | # include <new> | ||||
// Since libstdc++ 6, including the C headers (e.g. stdlib.h) instead of the | |||||
// corresponding C++ header (e.g. cstdlib) can cause confusion in C++ code | |||||
// using things defined there. Specifically, with stdlib.h, the use of abs() | |||||
// in gfx/graphite2/src/inc/UtfCodec.h somehow ends up picking the wrong abs() | |||||
# include <cstdlib> | |||||
# include <cstring> | |||||
#else | |||||
# include <stdlib.h> | |||||
# include <string.h> | |||||
#endif | #endif | ||||
#if defined(__cplusplus) | #if defined(__cplusplus) | ||||
#include "mozilla/fallible.h" | #include "mozilla/fallible.h" | ||||
#include "mozilla/mozalloc_abort.h" | |||||
#include "mozilla/TemplateLib.h" | #include "mozilla/TemplateLib.h" | ||||
#endif | #endif | ||||
#include "mozilla/Attributes.h" | #include "mozilla/Attributes.h" | ||||
#include "mozilla/Types.h" | #include "mozilla/Types.h" | ||||
#define MOZALLOC_HAVE_XMALLOC | #define MOZALLOC_HAVE_XMALLOC | ||||
#if defined(MOZ_ALWAYS_INLINE_EVEN_DEBUG) | #if defined(MOZ_ALWAYS_INLINE_EVEN_DEBUG) | ||||
# define MOZALLOC_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG | # define MOZALLOC_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG | ||||
#elif defined(HAVE_FORCEINLINE) | #elif defined(HAVE_FORCEINLINE) | ||||
# define MOZALLOC_INLINE __forceinline | # define MOZALLOC_INLINE __forceinline | ||||
#else | #else | ||||
# define MOZALLOC_INLINE inline | # define MOZALLOC_INLINE inline | ||||
#endif | #endif | ||||
/* Workaround build problem with Sun Studio 12 */ | /* Workaround build problem with Sun Studio 12 */ | ||||
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) | #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) | ||||
# undef MOZ_WARN_UNUSED_RESULT | # undef MOZ_MUST_USE | ||||
# define MOZ_WARN_UNUSED_RESULT | # define MOZ_MUST_USE | ||||
# undef MOZ_ALLOCATOR | # undef MOZ_ALLOCATOR | ||||
# define MOZ_ALLOCATOR | # define MOZ_ALLOCATOR | ||||
#endif | #endif | ||||
#if defined(__cplusplus) | #if defined(__cplusplus) | ||||
extern "C" { | extern "C" { | ||||
#endif /* ifdef __cplusplus */ | #endif /* ifdef __cplusplus */ | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#if defined(HAVE_STRNDUP) | #if defined(HAVE_STRNDUP) | ||||
MFBT_API char* moz_xstrndup(const char* str, size_t strsize) | MFBT_API char* moz_xstrndup(const char* str, size_t strsize) | ||||
MOZ_ALLOCATOR; | MOZ_ALLOCATOR; | ||||
#endif /* if defined(HAVE_STRNDUP) */ | #endif /* if defined(HAVE_STRNDUP) */ | ||||
#if defined(HAVE_POSIX_MEMALIGN) | #if defined(HAVE_POSIX_MEMALIGN) | ||||
MFBT_API MOZ_WARN_UNUSED_RESULT | MFBT_API MOZ_MUST_USE | ||||
int moz_xposix_memalign(void **ptr, size_t alignment, size_t size); | int moz_xposix_memalign(void **ptr, size_t alignment, size_t size); | ||||
MFBT_API MOZ_WARN_UNUSED_RESULT | MFBT_API MOZ_MUST_USE | ||||
int moz_posix_memalign(void **ptr, size_t alignment, size_t size); | int moz_posix_memalign(void **ptr, size_t alignment, size_t size); | ||||
#endif /* if defined(HAVE_POSIX_MEMALIGN) */ | #endif /* if defined(HAVE_POSIX_MEMALIGN) */ | ||||
#if defined(HAVE_MEMALIGN) | #if defined(HAVE_MEMALIGN) | ||||
MFBT_API void* moz_xmemalign(size_t boundary, size_t size) | MFBT_API void* moz_xmemalign(size_t boundary, size_t size) | ||||
MOZ_ALLOCATOR; | MOZ_ALLOCATOR; | ||||
#endif /* if defined(HAVE_MEMALIGN) */ | #endif /* if defined(HAVE_MEMALIGN) */ | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | |||||
* This policy is identical to MallocAllocPolicy, except it uses | * This policy is identical to MallocAllocPolicy, except it uses | ||||
* moz_xmalloc/moz_xcalloc/moz_xrealloc instead of | * moz_xmalloc/moz_xcalloc/moz_xrealloc instead of | ||||
* malloc/calloc/realloc. | * malloc/calloc/realloc. | ||||
*/ | */ | ||||
class InfallibleAllocPolicy | class InfallibleAllocPolicy | ||||
{ | { | ||||
public: | public: | ||||
template <typename T> | template <typename T> | ||||
T* maybe_pod_malloc(size_t aNumElems) | |||||
{ | |||||
return pod_malloc<T>(aNumElems); | |||||
} | |||||
template <typename T> | |||||
T* maybe_pod_calloc(size_t aNumElems) | |||||
{ | |||||
return pod_calloc<T>(aNumElems); | |||||
} | |||||
template <typename T> | |||||
T* maybe_pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize) | |||||
{ | |||||
return pod_realloc<T>(aPtr, aOldSize, aNewSize); | |||||
} | |||||
template <typename T> | |||||
T* pod_malloc(size_t aNumElems) | T* pod_malloc(size_t aNumElems) | ||||
{ | { | ||||
if (aNumElems & mozilla::tl::MulOverflowMask<sizeof(T)>::value) { | if (aNumElems & mozilla::tl::MulOverflowMask<sizeof(T)>::value) { | ||||
return nullptr; | reportAllocOverflow(); | ||||
} | } | ||||
return static_cast<T*>(moz_xmalloc(aNumElems * sizeof(T))); | return static_cast<T*>(moz_xmalloc(aNumElems * sizeof(T))); | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
T* pod_calloc(size_t aNumElems) | T* pod_calloc(size_t aNumElems) | ||||
{ | { | ||||
return static_cast<T*>(moz_xcalloc(aNumElems, sizeof(T))); | return static_cast<T*>(moz_xcalloc(aNumElems, sizeof(T))); | ||||
} | } | ||||
template <typename T> | template <typename T> | ||||
T* pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize) | T* pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize) | ||||
{ | { | ||||
if (aNewSize & mozilla::tl::MulOverflowMask<sizeof(T)>::value) { | if (aNewSize & mozilla::tl::MulOverflowMask<sizeof(T)>::value) { | ||||
return nullptr; | reportAllocOverflow(); | ||||
} | } | ||||
return static_cast<T*>(moz_xrealloc(aPtr, aNewSize * sizeof(T))); | return static_cast<T*>(moz_xrealloc(aPtr, aNewSize * sizeof(T))); | ||||
} | } | ||||
void free_(void* aPtr) | void free_(void* aPtr) | ||||
{ | { | ||||
free_impl(aPtr); | free_impl(aPtr); | ||||
} | } | ||||
void reportAllocOverflow() const | void reportAllocOverflow() const | ||||
{ | { | ||||
mozalloc_abort("alloc overflow"); | |||||
} | |||||
bool checkSimulatedOOM() const | |||||
{ | |||||
return true; | |||||
} | } | ||||
}; | }; | ||||
#endif /* ifdef __cplusplus */ | #endif /* ifdef __cplusplus */ | ||||
#ifdef malloc_impl_ | #ifdef malloc_impl_ | ||||
#undef malloc_impl_ | #undef malloc_impl_ | ||||
#undef malloc_impl | #undef malloc_impl | ||||
#endif | #endif | ||||
#ifdef free_impl_ | #ifdef free_impl_ | ||||
#undef free_impl_ | #undef free_impl_ | ||||
#undef free_impl | #undef free_impl | ||||
#endif | #endif | ||||
#endif /* ifndef mozilla_mozalloc_h */ | #endif /* ifndef mozilla_mozalloc_h */ |
Wildfire Games · Phabricator