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
75 _Post_writable_byte_size_(_NumOfElements
* _SizeOfElements
)
79 _In_
size_t _NumOfElements
,
80 _In_
size_t _SizeOfElements
);
85 _Pre_maybenull_ _Post_invalid_
void *_Memory
);
89 _Post_writable_byte_size_(_Size
)
97 _Post_writable_byte_size_(_NewSize
)
101 _Pre_maybenull_ _Post_invalid_
void *_Memory
,
102 _In_
size_t _NewSize
);
106 _Post_writable_byte_size_(_Count
* _Size
)
111 _Pre_maybenull_ _Post_invalid_
void *_Memory
,
115 #ifdef __DO_ALIGN_DEFINES
121 _Pre_maybenull_ _Post_invalid_
void *_Memory
);
125 _Post_writable_byte_size_(_Size
)
131 _In_
size_t _Alignment
);
133 #endif /* __DO_ALIGN_DEFINES */
137 _Post_writable_byte_size_(_Size
)
141 _aligned_offset_malloc(
143 _In_
size_t _Alignment
,
144 _In_
size_t _Offset
);
148 _Post_writable_byte_size_(_Size
)
153 _Pre_maybenull_ _Post_invalid_
void *_Memory
,
155 _In_
size_t _Alignment
);
159 _Post_writable_byte_size_(_Count
* _Size
)
164 _Pre_maybenull_ _Post_invalid_
void *_Memory
,
167 _In_
size_t _Alignment
);
171 _Post_writable_byte_size_(_Size
)
175 _aligned_offset_realloc(
176 _Pre_maybenull_ _Post_invalid_
void *_Memory
,
178 _In_
size_t _Alignment
,
179 _In_
size_t _Offset
);
183 _Post_writable_byte_size_(_Count
* _Size
)
187 _aligned_offset_recalloc(
188 _Pre_maybenull_ _Post_invalid_
void *_Memory
,
191 _In_
size_t _Alignment
,
192 _In_
size_t _Offset
);
194 #endif /* _CRT_ALLOCATION_DEFINED */
196 #ifdef __DO_ALIGN_DEFINES
197 #undef __DO_ALIGN_DEFINES
199 #pragma pop_macro("_aligned_malloc")
200 #pragma pop_macro("_aligned_free")
204 #define _MAX_WAIT_MALLOC_CRT 60000
206 _CRTIMP
int __cdecl
_resetstkoflw (void);
211 _set_malloc_crt_max_wait(
212 _In_
unsigned long _NewValue
);
216 _Post_writable_byte_size_(_NewSize
)
221 _In_opt_
void *_Memory
,
222 _In_
size_t _NewSize
);
233 #define _alloca(x) __builtin_alloca((x))
236 _Post_writable_byte_size_(_Size
)
247 _get_sbh_threshold(void);
253 _In_
size_t _NewValue
);
265 _Out_
size_t *_Value
);
291 _In_
unsigned int _Fill
);
297 _Inout_ _HEAPINFO
*_EntryInfo
);
309 _get_heap_handle(void);
311 #define _ALLOCA_S_THRESHOLD 1024
312 #define _ALLOCA_S_STACK_MARKER 0xCCCC
313 #define _ALLOCA_S_HEAP_MARKER 0xDDDD
315 #if(defined(_X86_) && !defined(__x86_64))
316 #define _ALLOCA_S_MARKER_SIZE 8
317 #elif defined(__ia64__) || defined(__x86_64)
318 #define _ALLOCA_S_MARKER_SIZE 16
319 #elif defined(__arm__)
320 #define _ALLOCA_S_MARKER_SIZE 8
323 #if !defined(RC_INVOKED)
324 static __inline
void *_MarkAllocaS(void *_Ptr
,unsigned int _Marker
) {
326 *((unsigned int*)_Ptr
) = _Marker
;
327 _Ptr
= (char*)_Ptr
+ _ALLOCA_S_MARKER_SIZE
;
334 #define _malloca(size) \
335 ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \
336 _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \
337 _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER))
339 #define _FREEA_INLINE
343 static __inline
void __cdecl
_freea(void *_Memory
) {
344 unsigned int _Marker
;
346 _Memory
= (char*)_Memory
- _ALLOCA_S_MARKER_SIZE
;
347 _Marker
= *(unsigned int *)_Memory
;
348 if(_Marker
==_ALLOCA_S_HEAP_MARKER
) {
352 else if(_Marker
!=_ALLOCA_S_STACK_MARKER
) {
353 _ASSERTE(("Corrupted pointer passed to _freea",0));
358 #endif /* RC_INVOKED */
361 #define alloca _alloca
365 #ifndef _HEAPHOOK_DEFINED
366 #define _HEAPHOOK_DEFINED
367 typedef int (__cdecl
*_HEAPHOOK
)(int,size_t,void *,void **);
374 _In_opt_ _HEAPHOOK _NewHook
);
376 #define _HEAP_MALLOC 1
377 #define _HEAP_CALLOC 2
379 #define _HEAP_REALLOC 4
380 #define _HEAP_MSIZE 5
381 #define _HEAP_EXPAND 6
390 #endif /* _MALLOC_H_ */