ReactOS  0.4.13-dev-257-gfabbd7c
malloc.h
Go to the documentation of this file.
1 
6 #ifndef _MALLOC_H_
7 #define _MALLOC_H_
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
18 extern "C" {
19 #endif
20 
21 #ifdef _WIN64
22 #define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
23 #else
24 #define _HEAP_MAXREQ 0xFFFFFFE0
25 #endif
26 
27 #ifndef _STATIC_ASSERT
28 #define _STATIC_ASSERT(expr) extern char (*static_assert(void)) [(expr) ? 1 : -1]
29 #endif
30 
31 /* Return codes for _heapwalk() */
32 #define _HEAPEMPTY (-1)
33 #define _HEAPOK (-2)
34 #define _HEAPBADBEGIN (-3)
35 #define _HEAPBADNODE (-4)
36 #define _HEAPEND (-5)
37 #define _HEAPBADPTR (-6)
38 
39 /* Values for _heapinfo.useflag */
40 #define _FREEENTRY 0
41 #define _USEDENTRY 1
42 
43 #ifndef _HEAPINFO_DEFINED
44 #define _HEAPINFO_DEFINED
45  /* The structure used to walk through the heap with _heapwalk. */
46  typedef struct _heapinfo {
47  int *_pentry;
48  size_t _size;
49  int _useflag;
50  } _HEAPINFO;
51 #endif
52 
53  extern unsigned int _amblksiz;
54 
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
58 #endif
59 
60 #ifdef __DO_ALIGN_DEFINES
61 #pragma push_macro("_aligned_free")
62 #pragma push_macro("_aligned_malloc")
63 #undef _aligned_free
64 #undef _aligned_malloc
65 #endif
66 
67 #define _mm_free(a) _aligned_free(a)
68 #define _mm_malloc(a,b) _aligned_malloc(a,b)
69 
70 #ifndef _CRT_ALLOCATION_DEFINED
71 #define _CRT_ALLOCATION_DEFINED
72 
76  void*
77  __cdecl
78  calloc(
79  _In_ size_t _NumOfElements,
81 
82  void
83  __cdecl
84  free(
85  _Pre_maybenull_ _Post_invalid_ void *_Memory);
86 
90  void*
91  __cdecl
92  malloc(
93  _In_ size_t _Size);
94 
98  void*
99  __cdecl
100  realloc(
101  _Pre_maybenull_ _Post_invalid_ void *_Memory,
102  _In_ size_t _NewSize);
103 
107  _CRTIMP
108  void*
109  __cdecl
110  _recalloc(
111  _Pre_maybenull_ _Post_invalid_ void *_Memory,
112  _In_ size_t _Count,
113  _In_ size_t _Size);
114 
115 #ifdef __DO_ALIGN_DEFINES
116 
117  _CRTIMP
118  void
119  __cdecl
121  _Pre_maybenull_ _Post_invalid_ void *_Memory);
122 
126  _CRTIMP
127  void*
128  __cdecl
130  _In_ size_t _Size,
131  _In_ size_t _Alignment);
132 
133 #endif /* __DO_ALIGN_DEFINES */
134 
138  _CRTIMP
139  void*
140  __cdecl
142  _In_ size_t _Size,
143  _In_ size_t _Alignment,
144  _In_ size_t _Offset);
145 
149  _CRTIMP
150  void*
151  __cdecl
153  _Pre_maybenull_ _Post_invalid_ void *_Memory,
154  _In_ size_t _Size,
155  _In_ size_t _Alignment);
156 
160  _CRTIMP
161  void*
162  __cdecl
163  _aligned_recalloc(
164  _Pre_maybenull_ _Post_invalid_ void *_Memory,
165  _In_ size_t _Count,
166  _In_ size_t _Size,
167  _In_ size_t _Alignment);
168 
172  _CRTIMP
173  void*
174  __cdecl
176  _Pre_maybenull_ _Post_invalid_ void *_Memory,
177  _In_ size_t _Size,
178  _In_ size_t _Alignment,
179  _In_ size_t _Offset);
180 
184  _CRTIMP
185  void*
186  __cdecl
187  _aligned_offset_recalloc(
188  _Pre_maybenull_ _Post_invalid_ void *_Memory,
189  _In_ size_t _Count,
190  _In_ size_t _Size,
191  _In_ size_t _Alignment,
192  _In_ size_t _Offset);
193 
194 #endif /* _CRT_ALLOCATION_DEFINED */
195 
196 #ifdef __DO_ALIGN_DEFINES
197 #undef __DO_ALIGN_DEFINES
198 
199 #pragma pop_macro("_aligned_malloc")
200 #pragma pop_macro("_aligned_free")
201 
202 #endif
203 
204 #define _MAX_WAIT_MALLOC_CRT 60000
205 
206  _CRTIMP int __cdecl _resetstkoflw (void);
207 
208  _CRTIMP
209  unsigned long
210  __cdecl
212  _In_ unsigned long _NewValue);
213 
217  _CRTIMP
218  void*
219  __cdecl
220  _expand(
221  _In_opt_ void *_Memory,
222  _In_ size_t _NewSize);
223 
225  _CRTIMP
226  size_t
227  __cdecl
228  _msize(
229  _In_ void *_Memory);
230 
231 #ifdef __GNUC__
232 #undef _alloca
233 #define _alloca(x) __builtin_alloca((x))
234 #else
237  void*
238  __cdecl
239  _alloca(
240  _In_ size_t _Size);
241 #endif
242 
244  _CRTIMP
245  size_t
246  __cdecl
247  _get_sbh_threshold(void);
248 
249  _CRTIMP
250  int
251  __cdecl
253  _In_ size_t _NewValue);
254 
255  _CRTIMP
256  errno_t
257  __cdecl
259  _In_ size_t _Value);
260 
261  _CRTIMP
262  errno_t
263  __cdecl
265  _Out_ size_t *_Value);
266 
268  _CRTIMP
269  int
270  __cdecl
271  _heapadd(
272  _In_ void *_Memory,
273  _In_ size_t _Size);
274 
276  _CRTIMP
277  int
278  __cdecl
279  _heapchk(void);
280 
282  _CRTIMP
283  int
284  __cdecl
285  _heapmin(void);
286 
287  _CRTIMP
288  int
289  __cdecl
290  _heapset(
291  _In_ unsigned int _Fill);
292 
293  _CRTIMP
294  int
295  __cdecl
296  _heapwalk(
297  _Inout_ _HEAPINFO *_EntryInfo);
298 
299  _CRTIMP
300  size_t
301  __cdecl
302  _heapused(
303  size_t *_Used,
304  size_t *_Commit);
305 
306  _CRTIMP
307  intptr_t
308  __cdecl
309  _get_heap_handle(void);
310 
311 #define _ALLOCA_S_THRESHOLD 1024
312 #define _ALLOCA_S_STACK_MARKER 0xCCCC
313 #define _ALLOCA_S_HEAP_MARKER 0xDDDD
314 
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
321 #endif
322 
323 #if !defined(RC_INVOKED)
324  static __inline void *_MarkAllocaS(void *_Ptr,unsigned int _Marker) {
325  if(_Ptr) {
326  *((unsigned int*)_Ptr) = _Marker;
327  _Ptr = (char*)_Ptr + _ALLOCA_S_MARKER_SIZE;
328  }
329  return _Ptr;
330  }
331 #endif
332 
333 #undef _malloca
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))
338 #undef _FREEA_INLINE
339 #define _FREEA_INLINE
340 
341 #ifndef RC_INVOKED
342 #undef _freea
343  static __inline void __cdecl _freea(void *_Memory) {
344  unsigned int _Marker;
345  if(_Memory) {
346  _Memory = (char*)_Memory - _ALLOCA_S_MARKER_SIZE;
347  _Marker = *(unsigned int *)_Memory;
348  if(_Marker==_ALLOCA_S_HEAP_MARKER) {
349  free(_Memory);
350  }
351 #ifdef _ASSERTE
352  else if(_Marker!=_ALLOCA_S_STACK_MARKER) {
353  _ASSERTE(("Corrupted pointer passed to _freea",0));
354  }
355 #endif
356  }
357  }
358 #endif /* RC_INVOKED */
359 
360 #ifndef NO_OLDNAMES
361 #define alloca _alloca
362 #endif
363 
364 #ifdef HEAPHOOK
365 #ifndef _HEAPHOOK_DEFINED
366 #define _HEAPHOOK_DEFINED
367  typedef int (__cdecl *_HEAPHOOK)(int,size_t,void *,void **);
368 #endif
369 
370  _CRTIMP
371  _HEAPHOOK
372  __cdecl
373  _setheaphook(
374  _In_opt_ _HEAPHOOK _NewHook);
375 
376 #define _HEAP_MALLOC 1
377 #define _HEAP_CALLOC 2
378 #define _HEAP_FREE 3
379 #define _HEAP_REALLOC 4
380 #define _HEAP_MSIZE 5
381 #define _HEAP_EXPAND 6
382 #endif
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 
388 #pragma pack(pop)
389 
390 #endif /* _MALLOC_H_ */
#define realloc
Definition: debug_ros.c:6
#define _Ret_notnull_
Definition: no_sal2.h:592
_Check_return_ _Ret_maybenull_ _In_ size_t _In_ size_t _Offset
Definition: malloc.h:143
_CRTIMP void __cdecl _aligned_free(_Pre_maybenull_ _Post_invalid_ void *_Memory)
_CRTIMP errno_t __cdecl _get_amblksiz(_Out_ size_t *_Value)
struct _heapinfo _HEAPINFO
#define _Post_invalid_
Definition: no_sal2.h:457
void __cdecl free(_Pre_maybenull_ _Post_invalid_ void *_Memory)
#define _ALLOCA_S_STACK_MARKER
Definition: malloc.h:312
#define __cdecl
Definition: accygwin.h:79
_Check_return_ _Ret_maybenull_ _In_ size_t _Count
Definition: malloc.h:112
#define _CRTIMP
Definition: crtdefs.h:60
_Check_return_ _Ret_maybenull_ _In_ size_t _SizeOfElements
Definition: malloc.h:80
#define _Check_return_
Definition: no_sal2.h:13
static __inline void __cdecl _freea(void *_Memory)
Definition: malloc.h:343
void *CDECL _aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
Definition: heap.c:372
#define _In_opt_
Definition: no_sal2.h:213
#define _ALLOCA_S_HEAP_MARKER
Definition: malloc.h:313
_CRTIMP int __cdecl _resetstkoflw(void)
Definition: stack.c:38
size_t _size
Definition: malloc.h:48
unsigned int _amblksiz
#define _Out_
Definition: no_sal2.h:323
#define _ASSERTE(expr)
Definition: crtdbg.h:105
_Check_return_ _CRTIMP size_t __cdecl _get_sbh_threshold(void)
Definition: heap.c:338
_Check_return_ _CRTIMP int __cdecl _heapadd(_In_ void *_Memory, _In_ size_t _Size)
int errno_t
Definition: crtdefs.h:353
__kernel_size_t size_t
Definition: linux.h:237
_CRTIMP int __cdecl _heapwalk(_Inout_ _HEAPINFO *_EntryInfo)
void *CDECL _aligned_offset_realloc(void *memblock, size_t size, size_t alignment, size_t offset)
Definition: heap.c:424
int intptr_t
Definition: crtdefs.h:283
_CRTIMP intptr_t __cdecl _get_heap_handle(void)
Definition: heap.c:269
#define _Ret_maybenull_
Definition: no_sal2.h:590
_Check_return_ _CRTIMP int __cdecl _heapmin(void)
Definition: malloc.c:133
void *CDECL _aligned_malloc(size_t size, size_t alignment)
Definition: heap.c:415
void *CDECL _aligned_realloc(void *memblock, size_t size, size_t alignment)
Definition: heap.c:539
#define _Inout_
Definition: no_sal2.h:244
int _useflag
Definition: malloc.h:49
#define _Pre_maybenull_
Definition: no_sal2.h:495
_CRTIMP size_t __cdecl _heapused(size_t *_Used, size_t *_Commit)
Definition: stubs.c:44
#define _In_
Definition: no_sal2.h:204
_CRTIMP errno_t __cdecl _set_amblksiz(_In_ size_t _Value)
void * _expand(void *_ptr, size_t _size)
Definition: malloc.c:100
_Check_return_ _CRTIMP int __cdecl _heapchk(void)
Definition: malloc.c:123
_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_NumOfElements *_SizeOfElements) void *__cdecl calloc(_In_ size_t _NumOfElements
#define calloc
Definition: rosglue.h:14
_Check_return_ _Ret_maybenull_ _In_ size_t _In_ size_t _Size
Definition: malloc.h:112
static __inline void * _MarkAllocaS(void *_Ptr, unsigned int _Marker)
Definition: malloc.h:324
int * _pentry
Definition: malloc.h:47
#define malloc
Definition: debug_ros.c:4
int _Value
Definition: setjmp.h:188
_Check_return_ _Ret_maybenull_ _In_ size_t _Alignment
Definition: malloc.h:143
_CRTIMP int __cdecl _heapset(_In_ unsigned int _Fill)
_CRTIMP int __cdecl _set_sbh_threshold(_In_ size_t _NewValue)
_CRTIMP unsigned long __cdecl _set_malloc_crt_max_wait(_In_ unsigned long _NewValue)
_Check_return_ _Ret_maybenull_ _In_ size_t _NewSize
Definition: malloc.h:102
_Check_return_ _CRTIMP size_t __cdecl _msize(_In_ void *_Memory)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31