| /** | |
| * This file has no copyright assigned and is placed in the Public Domain. | |
| * This file is part of the mingw-w64 runtime package. | |
| * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| */ | |
| #ifndef _MALLOC_H_ | |
| #define _MALLOC_H_ | |
| #include <crtdefs.h> | |
| #include <corecrt_malloc.h> | |
| _CRT_BEGIN_C_HEADER | |
| #ifdef _WIN64 | |
| #define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0 | |
| #else | |
| #define _HEAP_MAXREQ 0xFFFFFFE0 | |
| #endif | |
| /* Return codes for _heapwalk() */ | |
| #define _HEAPEMPTY (-1) | |
| #define _HEAPOK (-2) | |
| #define _HEAPBADBEGIN (-3) | |
| #define _HEAPBADNODE (-4) | |
| #define _HEAPEND (-5) | |
| #define _HEAPBADPTR (-6) | |
| /* Values for _heapinfo.useflag */ | |
| #define _FREEENTRY 0 | |
| #define _USEDENTRY 1 | |
| /* The structure used to walk through the heap with _heapwalk. */ | |
| typedef struct _heapinfo { | |
| int *_pentry; | |
| size_t _size; | |
| int _useflag; | |
| } _HEAPINFO; | |
| #define _amblksiz (*__p__amblksiz()) | |
| _CRTIMP unsigned int *__cdecl __p__amblksiz(void); | |
| /* Users should really use MS provided versions */ | |
| void * __mingw_aligned_malloc (size_t _Size, size_t _Alignment); | |
| void __mingw_aligned_free (void *_Memory); | |
| void * __mingw_aligned_offset_realloc (void *_Memory, size_t _Size, size_t _Alignment, size_t _Offset); | |
| void * __mingw_aligned_offset_malloc (size_t, size_t, size_t); | |
| void * __mingw_aligned_realloc (void *_Memory, size_t _Size, size_t _Offset); | |
| size_t __mingw_aligned_msize (void *memblock, size_t alignment, size_t offset); | |
| #if defined(__x86_64__) || defined(__i386__) | |
| /* Get the compiler's definition of _mm_malloc and _mm_free. */ | |
| #include <mm_malloc.h> | |
| #endif | |
| #define _MAX_WAIT_MALLOC_CRT 60000 | |
| #ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP | |
| _CRTIMP int __cdecl _resetstkoflw (void); | |
| #endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */ | |
| _CRTIMP unsigned long __cdecl _set_malloc_crt_max_wait(unsigned long _NewValue); | |
| #if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) | |
| #pragma push_macro("_expand") | |
| #undef _expand | |
| #pragma push_macro("_msize") | |
| #undef _msize | |
| #endif | |
| _CRTIMP void *__cdecl _expand(void *_Memory,size_t _NewSize); | |
| _CRTIMP size_t __cdecl _msize(void *_Memory); | |
| #if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) | |
| #pragma pop_macro("_expand") | |
| #pragma pop_macro("_msize") | |
| #endif | |
| #ifdef __GNUC__ | |
| #undef _alloca | |
| #define _alloca(x) __builtin_alloca((x)) | |
| #else | |
| void *__cdecl _alloca(size_t _Size) __MINGW_ATTRIB_DEPRECATED_SEC_WARN; | |
| #endif | |
| _CRTIMP size_t __cdecl _get_sbh_threshold(void); | |
| _CRTIMP int __cdecl _set_sbh_threshold(size_t _NewValue); | |
| _CRTIMP errno_t __cdecl _set_amblksiz(size_t _Value); | |
| _CRTIMP errno_t __cdecl _get_amblksiz(size_t *_Value); | |
| _CRTIMP int __cdecl _heapadd(void *_Memory,size_t _Size); | |
| _CRTIMP int __cdecl _heapchk(void); | |
| _CRTIMP int __cdecl _heapmin(void); | |
| _CRTIMP int __cdecl _heapset(unsigned int _Fill); | |
| _CRTIMP int __cdecl _heapwalk(_HEAPINFO *_EntryInfo); | |
| _CRTIMP size_t __cdecl _heapused(size_t *_Used,size_t *_Commit); | |
| _CRTIMP intptr_t __cdecl _get_heap_handle(void); | |
| #define _ALLOCA_S_THRESHOLD 1024 | |
| #define _ALLOCA_S_STACK_MARKER 0xCCCC | |
| #define _ALLOCA_S_HEAP_MARKER 0xDDDD | |
| #if defined(_ARM_) || (defined(_X86_) && !defined(__x86_64)) | |
| #define _ALLOCA_S_MARKER_SIZE 8 | |
| #elif defined(__ia64__) || defined(__x86_64) || defined(__aarch64__) | |
| #define _ALLOCA_S_MARKER_SIZE 16 | |
| #endif | |
| #if !defined(RC_INVOKED) | |
| static __inline void *_MarkAllocaS(void *_Ptr,unsigned int _Marker) { | |
| if(_Ptr) { | |
| *((unsigned int*)_Ptr) = _Marker; | |
| _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE; | |
| } | |
| return _Ptr; | |
| } | |
| #endif | |
| #ifdef _DEBUG | |
| #ifndef _CRTDBG_MAP_ALLOC | |
| #undef _malloca | |
| #define _malloca(size) \ | |
| _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE), _ALLOCA_S_HEAP_MARKER) | |
| #endif | |
| #else | |
| #undef _malloca | |
| #define _malloca(size) \ | |
| ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \ | |
| _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \ | |
| _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER)) | |
| #endif | |
| #undef _FREEA_INLINE | |
| #define _FREEA_INLINE | |
| #ifndef RC_INVOKED | |
| #undef _freea | |
| static __inline void __cdecl _freea(void *_Memory) { | |
| unsigned int _Marker; | |
| if(_Memory) { | |
| _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE; | |
| _Marker = *(unsigned int *)_Memory; | |
| if(_Marker==_ALLOCA_S_HEAP_MARKER) { | |
| free(_Memory); | |
| } | |
| #ifdef _ASSERTE | |
| else if(_Marker!=_ALLOCA_S_STACK_MARKER) { | |
| _ASSERTE(("Corrupted pointer passed to _freea",0)); | |
| } | |
| #endif | |
| } | |
| } | |
| #endif /* RC_INVOKED */ | |
| #ifndef NO_OLDNAMES | |
| #undef alloca | |
| #ifdef __GNUC__ | |
| #define alloca(x) __builtin_alloca((x)) | |
| #else | |
| #define alloca _alloca | |
| #endif | |
| #endif | |
| #ifdef HEAPHOOK | |
| typedef int (__cdecl *_HEAPHOOK)(int,size_t,void *,void **); | |
| _CRTIMP _HEAPHOOK __cdecl _setheaphook(_HEAPHOOK _NewHook); | |
| #define _HEAP_MALLOC 1 | |
| #define _HEAP_CALLOC 2 | |
| #define _HEAP_FREE 3 | |
| #define _HEAP_REALLOC 4 | |
| #define _HEAP_MSIZE 5 | |
| #define _HEAP_EXPAND 6 | |
| #endif | |
| _CRT_END_C_HEADER | |
| #endif /* _MALLOC_H_ */ |