ReactOS 0.4.15-dev-7788-g1ad9096
malloc.h
Go to the documentation of this file.
1
6#ifndef _INC_MALLOC
7#define _INC_MALLOC
8
9#include <crtdefs.h>
10
11#pragma pack(push,_CRT_PACKING)
12
13#ifndef _MM_MALLOC_H_INCLUDED
14#define _MM_MALLOC_H_INCLUDED
15#endif
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#ifdef _WIN64
22#define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
23#else
24#define _HEAP_MAXREQ 0xFFFFFFE0
25#endif
26
27/* Return codes for _heapwalk() */
28#define _HEAPEMPTY (-1)
29#define _HEAPOK (-2)
30#define _HEAPBADBEGIN (-3)
31#define _HEAPBADNODE (-4)
32#define _HEAPEND (-5)
33#define _HEAPBADPTR (-6)
34
35/* Values for _heapinfo.useflag */
36#define _FREEENTRY 0
37#define _USEDENTRY 1
38
39#ifndef _HEAPINFO_DEFINED
40#define _HEAPINFO_DEFINED
41 /* The structure used to walk through the heap with _heapwalk. */
42 typedef struct _heapinfo {
43 int *_pentry;
44 size_t _size;
47#endif
48
49 extern unsigned int _amblksiz;
50
51/* Make sure that X86intrin.h doesn't produce here collisions. */
52#if (!defined (_XMMINTRIN_H_INCLUDED) && !defined (_MM_MALLOC_H_INCLUDED)) || defined(_aligned_malloc)
53#define __DO_ALIGN_DEFINES
54#endif
55
56#ifdef __DO_ALIGN_DEFINES
57#pragma push_macro("_aligned_free")
58#pragma push_macro("_aligned_malloc")
59#undef _aligned_free
60#undef _aligned_malloc
61#endif
62
63#define _mm_free(a) _aligned_free(a)
64#define _mm_malloc(a,b) _aligned_malloc(a,b)
65
66#ifndef _CRT_ALLOCATION_DEFINED
67#define _CRT_ALLOCATION_DEFINED
68
72 void*
74 calloc(
75 _In_ size_t _NumOfElements,
77
78 void
81 _Pre_maybenull_ _Post_invalid_ void *_Memory);
82
86 void*
88 malloc(
89 _In_ size_t _Size);
90
94 void*
96 realloc(
97 _Pre_maybenull_ _Post_invalid_ void *_Memory,
98 _In_ size_t _NewSize);
99
103 _CRTIMP
104 void*
105 __cdecl
106 _recalloc(
107 _Pre_maybenull_ _Post_invalid_ void *_Memory,
108 _In_ size_t _Count,
109 _In_ size_t _Size);
110
111#ifdef __DO_ALIGN_DEFINES
112
113 _CRTIMP
114 void
115 __cdecl
117 _Pre_maybenull_ _Post_invalid_ void *_Memory);
118
122 _CRTIMP
123 void*
124 __cdecl
126 _In_ size_t _Size,
127 _In_ size_t _Alignment);
128
129#endif /* __DO_ALIGN_DEFINES */
130
134 _CRTIMP
135 void*
136 __cdecl
138 _In_ size_t _Size,
140 _In_ size_t _Offset);
141
145 _CRTIMP
146 void*
147 __cdecl
149 _Pre_maybenull_ _Post_invalid_ void *_Memory,
150 _In_ size_t _Size,
151 _In_ size_t _Alignment);
152
156 _CRTIMP
157 void*
158 __cdecl
159 _aligned_recalloc(
160 _Pre_maybenull_ _Post_invalid_ void *_Memory,
161 _In_ size_t _Count,
162 _In_ size_t _Size,
163 _In_ size_t _Alignment);
164
168 _CRTIMP
169 void*
170 __cdecl
172 _Pre_maybenull_ _Post_invalid_ void *_Memory,
173 _In_ size_t _Size,
174 _In_ size_t _Alignment,
175 _In_ size_t _Offset);
176
180 _CRTIMP
181 void*
182 __cdecl
183 _aligned_offset_recalloc(
184 _Pre_maybenull_ _Post_invalid_ void *_Memory,
185 _In_ size_t _Count,
186 _In_ size_t _Size,
187 _In_ size_t _Alignment,
188 _In_ size_t _Offset);
189
190#endif /* _CRT_ALLOCATION_DEFINED */
191
192#ifdef __DO_ALIGN_DEFINES
193#undef __DO_ALIGN_DEFINES
194
195#pragma pop_macro("_aligned_malloc")
196#pragma pop_macro("_aligned_free")
197
198#endif
199
200#define _MAX_WAIT_MALLOC_CRT 60000
201
202 _CRTIMP int __cdecl _resetstkoflw (void);
203
204 _CRTIMP
205 unsigned long
206 __cdecl
208 _In_ unsigned long _NewValue);
209
213 _CRTIMP
214 void*
215 __cdecl
216 _expand(
217 _In_opt_ void *_Memory,
218 _In_ size_t _NewSize);
219
221 _CRTIMP
222 size_t
223 __cdecl
225 _In_ void *_Memory);
226
227#ifdef __GNUC__
228#undef _alloca
229#define _alloca(x) __builtin_alloca((x))
230#else
233 void*
234 __cdecl
235 _alloca(
236 _In_ size_t _Size);
237#endif
238
240 _CRTIMP
241 size_t
242 __cdecl
243 _get_sbh_threshold(void);
244
245 _CRTIMP
246 int
247 __cdecl
249 _In_ size_t _NewValue);
250
251 _CRTIMP
252 errno_t
253 __cdecl
255 _In_ size_t _Value);
256
257 _CRTIMP
258 errno_t
259 __cdecl
261 _Out_ size_t *_Value);
262
264 _CRTIMP
265 int
266 __cdecl
268 _In_ void *_Memory,
269 _In_ size_t _Size);
270
272 _CRTIMP
273 int
274 __cdecl
275 _heapchk(void);
276
278 _CRTIMP
279 int
280 __cdecl
281 _heapmin(void);
282
283 _CRTIMP
284 int
285 __cdecl
287 _In_ unsigned int _Fill);
288
289 _CRTIMP
290 int
291 __cdecl
293 _Inout_ _HEAPINFO *_EntryInfo);
294
295 _CRTIMP
296 size_t
297 __cdecl
298 _heapused(
299 size_t *_Used,
300 size_t *_Commit);
301
302 _CRTIMP
304 __cdecl
305 _get_heap_handle(void);
306
307#define _ALLOCA_S_THRESHOLD 1024
308#define _ALLOCA_S_STACK_MARKER 0xCCCC
309#define _ALLOCA_S_HEAP_MARKER 0xDDDD
310
311#if(defined(_X86_) && !defined(__x86_64))
312#define _ALLOCA_S_MARKER_SIZE 8
313#elif defined(__ia64__) || defined(__x86_64) || defined(__arm64__)
314#define _ALLOCA_S_MARKER_SIZE 16
315#elif defined(__arm__)
316#define _ALLOCA_S_MARKER_SIZE 8
317#endif
318
319#if !defined(RC_INVOKED)
320 static __inline void *_MarkAllocaS(void *_Ptr,unsigned int _Marker) {
321 if(_Ptr) {
322 *((unsigned int*)_Ptr) = _Marker;
323 _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE;
324 }
325 return _Ptr;
326 }
327#endif
328
329#undef _malloca
330#define _malloca(size) \
331 ((((size) + _ALLOCA_S_MARKER_SIZE) <= _ALLOCA_S_THRESHOLD) ? \
332 _MarkAllocaS(_alloca((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_STACK_MARKER) : \
333 _MarkAllocaS(malloc((size) + _ALLOCA_S_MARKER_SIZE),_ALLOCA_S_HEAP_MARKER))
334#undef _FREEA_INLINE
335#define _FREEA_INLINE
336
337#ifndef RC_INVOKED
338#undef _freea
339 static __inline void __cdecl _freea(void *_Memory) {
340 unsigned int _Marker;
341 if(_Memory) {
342 _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
343 _Marker = *(unsigned int *)_Memory;
344 if(_Marker==_ALLOCA_S_HEAP_MARKER) {
345 free(_Memory);
346 }
347#ifdef _ASSERTE
348 else if(_Marker!=_ALLOCA_S_STACK_MARKER) {
349 _ASSERTE(("Corrupted pointer passed to _freea",0));
350 }
351#endif
352 }
353 }
354#endif /* RC_INVOKED */
355
356#ifndef NO_OLDNAMES
357#define alloca _alloca
358#endif
359
360#ifdef HEAPHOOK
361#ifndef _HEAPHOOK_DEFINED
362#define _HEAPHOOK_DEFINED
363 typedef int (__cdecl *_HEAPHOOK)(int,size_t,void *,void **);
364#endif
365
366 _CRTIMP
367 _HEAPHOOK
368 __cdecl
369 _setheaphook(
370 _In_opt_ _HEAPHOOK _NewHook);
371
372#define _HEAP_MALLOC 1
373#define _HEAP_CALLOC 2
374#define _HEAP_FREE 3
375#define _HEAP_REALLOC 4
376#define _HEAP_MSIZE 5
377#define _HEAP_EXPAND 6
378#endif
379
380#ifdef __cplusplus
381}
382#endif
383
384#pragma pack(pop)
385
386#endif /* _INC_MALLOC */
#define __cdecl
Definition: accygwin.h:79
int _Value
Definition: setjmp.h:214
#define _ASSERTE(expr)
Definition: crtdbg.h:113
int intptr_t
Definition: crtdefs.h:304
#define _CRTIMP
Definition: crtdefs.h:72
int errno_t
Definition: crtdefs.h:374
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
__kernel_size_t size_t
Definition: linux.h:237
_CRTIMP void __cdecl _aligned_free(_Pre_maybenull_ _Post_invalid_ void *_Memory)
void * _expand(void *_ptr, size_t _size)
Definition: malloc.c:100
struct _heapinfo _HEAPINFO
_Check_return_ _CRTIMP int __cdecl _heapchk(void)
Definition: malloc.c:123
_Check_return_ _Ret_maybenull_ _In_ size_t _SizeOfElements
Definition: malloc.h:76
#define _ALLOCA_S_STACK_MARKER
Definition: malloc.h:308
_Check_return_ _Ret_maybenull_ _In_ size_t _Count
Definition: malloc.h:108
_CRTIMP int __cdecl _heapwalk(_Inout_ _HEAPINFO *_EntryInfo)
unsigned int _amblksiz
_CRTIMP int __cdecl _set_sbh_threshold(_In_ size_t _NewValue)
static __inline void * _MarkAllocaS(void *_Ptr, unsigned int _Marker)
Definition: malloc.h:320
static __inline void __cdecl _freea(void *_Memory)
Definition: malloc.h:339
_Check_return_ _Ret_maybenull_ _In_ size_t _In_ size_t _Offset
Definition: malloc.h:140
_Check_return_ _CRTIMP int __cdecl _heapadd(_In_ void *_Memory, _In_ size_t _Size)
_CRTIMP intptr_t __cdecl _get_heap_handle(void)
Definition: heap.c:381
_CRTIMP errno_t __cdecl _set_amblksiz(_In_ size_t _Value)
_CRTIMP unsigned long __cdecl _set_malloc_crt_max_wait(_In_ unsigned long _NewValue)
_Check_return_ _Ret_maybenull_ _In_ size_t _Alignment
Definition: malloc.h:139
_Check_return_ _CRTIMP size_t __cdecl _msize(_In_ void *_Memory)
_Check_return_ _Ret_maybenull_ _In_ size_t _NewSize
Definition: malloc.h:98
_Check_return_ _CRTIMP int __cdecl _heapmin(void)
Definition: malloc.c:133
_CRTIMP int __cdecl _heapset(_In_ unsigned int _Fill)
_Check_return_ _Ret_maybenull_ _In_ size_t _In_ size_t _Size
Definition: malloc.h:109
_CRTIMP errno_t __cdecl _get_amblksiz(_Out_ size_t *_Value)
#define _ALLOCA_S_HEAP_MARKER
Definition: malloc.h:309
_Check_return_ _CRTIMP size_t __cdecl _get_sbh_threshold(void)
Definition: heap.c:542
_CRTIMP size_t __cdecl _heapused(size_t *_Used, size_t *_Commit)
Definition: stubs.c:45
_CRTIMP int __cdecl _resetstkoflw(void)
Definition: stack.c:38
#define _Inout_
Definition: ms_sal.h:378
#define _Ret_maybenull_
Definition: ms_sal.h:529
#define _Pre_maybenull_
Definition: ms_sal.h:681
#define _Check_return_
Definition: ms_sal.h:557
#define _Post_invalid_
Definition: ms_sal.h:695
#define _Out_
Definition: ms_sal.h:345
#define _Ret_notnull_
Definition: ms_sal.h:528
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#define _Post_writable_byte_size_(size)
Definition: ms_sal.h:652
#define calloc
Definition: rosglue.h:14
void *CDECL _aligned_offset_realloc(void *memblock, MSVCRT_size_t size, MSVCRT_size_t alignment, MSVCRT_size_t offset)
Definition: heap.c:639
void *CDECL _aligned_malloc(MSVCRT_size_t size, MSVCRT_size_t alignment)
Definition: heap.c:630
void *CDECL _aligned_offset_malloc(MSVCRT_size_t size, MSVCRT_size_t alignment, MSVCRT_size_t offset)
Definition: heap.c:587
void *CDECL _aligned_realloc(void *memblock, MSVCRT_size_t size, MSVCRT_size_t alignment)
Definition: heap.c:754
int * _pentry
Definition: malloc.h:43
int _useflag
Definition: malloc.h:45
size_t _size
Definition: malloc.h:44