2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the w64 mingw-runtime package.
4 * No warranty is given; refer to the file DISCLAIMER within this package.
11 #pragma pack(push,_CRT_PACKING)
13 #ifndef _MM_MALLOC_H_INCLUDED
14 #define _MM_MALLOC_H_INCLUDED
22 #define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
24 #define _HEAP_MAXREQ 0xFFFFFFE0
27 #ifndef _STATIC_ASSERT
28 #define _STATIC_ASSERT(expr) extern char (*static_assert(void)) [(expr) ? 1 : -1]
31 /* Return codes for _heapwalk() */
32 #define _HEAPEMPTY (-1)
34 #define _HEAPBADBEGIN (-3)
35 #define _HEAPBADNODE (-4)
37 #define _HEAPBADPTR (-6)
39 /* Values for _heapinfo.useflag */
43 #ifndef _HEAPINFO_DEFINED
44 #define _HEAPINFO_DEFINED
45 /* The structure used to walk through the heap with _heapwalk. */
46 typedef struct _heapinfo
{
53 extern unsigned int _amblksiz
;
55 /* Make sure that X86intrin.h doesn't produce here collisions. */
56 #if (!defined (_XMMINTRIN_H_INCLUDED) && !defined (_MM_MALLOC_H_INCLUDED)) || defined(_aligned_malloc)
57 #define __DO_ALIGN_DEFINES
60 #ifdef __DO_ALIGN_DEFINES
61 #pragma push_macro("_aligned_free")
62 #pragma push_macro("_aligned_malloc")
64 #undef _aligned_malloc
67 #define _mm_free(a) _aligned_free(a)
68 #define _mm_malloc(a,b) _aligned_malloc(a,b)
70 #ifndef _CRT_ALLOCATION_DEFINED
71 #define _CRT_ALLOCATION_DEFINED
72 void *__cdecl
calloc(size_t _NumOfElements
,size_t _SizeOfElements
);
73 void __cdecl
free(void *_Memory
);
74 void *__cdecl
malloc(size_t _Size
);
75 void *__cdecl
realloc(void *_Memory
,size_t _NewSize
);
76 _CRTIMP
void *__cdecl
_recalloc(void *_Memory
,size_t _Count
,size_t _Size
);
78 #ifdef __DO_ALIGN_DEFINES
79 _CRTIMP
void __cdecl
_aligned_free(void *_Memory
);
80 _CRTIMP
void *__cdecl
_aligned_malloc(size_t _Size
,size_t _Alignment
);
83 _CRTIMP
void *__cdecl
_aligned_offset_malloc(size_t _Size
,size_t _Alignment
,size_t _Offset
);
84 _CRTIMP
void *__cdecl
_aligned_realloc(void *_Memory
,size_t _Size
,size_t _Alignment
);
85 _CRTIMP
void *__cdecl
_aligned_recalloc(void *_Memory
,size_t _Count
,size_t _Size
,size_t _Alignment
);
86 _CRTIMP
void *__cdecl
_aligned_offset_realloc(void *_Memory
,size_t _Size
,size_t _Alignment
,size_t _Offset
);
87 _CRTIMP
void *__cdecl
_aligned_offset_recalloc(void *_Memory
,size_t _Count
,size_t _Size
,size_t _Alignment
,size_t _Offset
);
90 #ifdef __DO_ALIGN_DEFINES
91 #undef __DO_ALIGN_DEFINES
93 #pragma pop_macro("_aligned_malloc")
94 #pragma pop_macro("_aligned_free")
98 #define _MAX_WAIT_MALLOC_CRT 60000
100 _CRTIMP
int __cdecl
_resetstkoflw (void);
101 _CRTIMP
unsigned long __cdecl
_set_malloc_crt_max_wait(unsigned long _NewValue
);
103 _CRTIMP
void *__cdecl
_expand(void *_Memory
,size_t _NewSize
);
104 _CRTIMP
size_t __cdecl
_msize(void *_Memory
);
107 #define _alloca(x) __builtin_alloca((x))
109 void *__cdecl
_alloca(size_t _Size
);
111 _CRTIMP
size_t __cdecl
_get_sbh_threshold(void);
112 _CRTIMP
int __cdecl
_set_sbh_threshold(size_t _NewValue
);
113 _CRTIMP errno_t __cdecl
_set_amblksiz(size_t _Value
);
114 _CRTIMP errno_t __cdecl
_get_amblksiz(size_t *_Value
);
115 _CRTIMP
int __cdecl
_heapadd(void *_Memory
,size_t _Size
);
116 _CRTIMP
int __cdecl
_heapchk(void);
117 _CRTIMP
int __cdecl
_heapmin(void);
118 _CRTIMP
int __cdecl
_heapset(unsigned int _Fill
);
119 _CRTIMP
int __cdecl
_heapwalk(_HEAPINFO
*_EntryInfo
);
120 _CRTIMP
size_t __cdecl
_heapused(size_t *_Used
,size_t *_Commit
);
121 _CRTIMP
intptr_t __cdecl
_get_heap_handle(void);
123 #define _ALLOCA_S_THRESHOLD 1024
124 #define _ALLOCA_S_STACK_MARKER 0xCCCC
125 #define _ALLOCA_S_HEAP_MARKER 0xDDDD
127 #if(defined(_X86_) && !defined(__x86_64))
128 #define _ALLOCA_S_MARKER_SIZE 8
129 #elif defined(__ia64__) || defined(__x86_64)
130 #define _ALLOCA_S_MARKER_SIZE 16
131 #elif defined(__arm__)
132 #define _ALLOCA_S_MARKER_SIZE 8
135 #if !defined(RC_INVOKED)
136 static __inline
void *_MarkAllocaS(void *_Ptr
,unsigned int _Marker
) {
138 *((unsigned int*)_Ptr
) = _Marker
;
139 _Ptr
= (char*)_Ptr
+ _ALLOCA_S_MARKER_SIZE
;
146 #define _malloca(size) \
147 ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \
148 _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \
149 _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER))
151 #define _FREEA_INLINE
155 static __inline
void __cdecl
_freea(void *_Memory
) {
156 unsigned int _Marker
;
158 _Memory
= (char*)_Memory
- _ALLOCA_S_MARKER_SIZE
;
159 _Marker
= *(unsigned int *)_Memory
;
160 if(_Marker
==_ALLOCA_S_HEAP_MARKER
) {
164 else if(_Marker
!=_ALLOCA_S_STACK_MARKER
) {
165 _ASSERTE(("Corrupted pointer passed to _freea",0));
170 #endif /* RC_INVOKED */
173 #define alloca _alloca
177 #ifndef _HEAPHOOK_DEFINED
178 #define _HEAPHOOK_DEFINED
179 typedef int (__cdecl
*_HEAPHOOK
)(int,size_t,void *,void **);
182 _CRTIMP _HEAPHOOK __cdecl
_setheaphook(_HEAPHOOK _NewHook
);
184 #define _HEAP_MALLOC 1
185 #define _HEAP_CALLOC 2
187 #define _HEAP_REALLOC 4
188 #define _HEAP_MSIZE 5
189 #define _HEAP_EXPAND 6
198 #endif /* _MALLOC_H_ */