Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

322 lines
11 KiB

  1. /***
  2. *malloc.h - declarations and definitions for memory allocation functions
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the function declarations for memory allocation functions;
  8. * also defines manifest constants and types used by the heap routines.
  9. * [System V]
  10. *
  11. * [Public]
  12. *
  13. *Revision History:
  14. * 01-08-87 JMB Standardized header, added heap consistency routines
  15. * 02-26-87 BCM added the manifest constant _HEAPBADPTR
  16. * 04-13-87 JCR Added size_t and "void *" to declarations
  17. * 04-24-87 JCR Added 'defined' statements around _heapinfo
  18. * 05-15-87 SKS Cleaned up _CDECL and near/far ptr declarations
  19. * corrected #ifdef usage, and added _amblksiz
  20. * 12-11-87 JCR Added "_loadds" functionality
  21. * 12-18-87 JCR Added _FAR_ to declarations
  22. * 02-05-88 JCR Added DLL _amblksiz support
  23. * 02-10-88 JCR Cleaned up white space
  24. * 04-21-88 WAJ Added _FAR_ to halloc/_fmalloc/_nmalloc
  25. * 05-13-88 GJF Added new heap functions
  26. * 05-18-88 GJF Removed #defines, added prototypes for _heapchk, _heapset
  27. * and _heapwalk
  28. * 05-25-88 GJF Added _bheapseg
  29. * 08-22-88 GJF Modified to also work for the 386 (small model only,
  30. * no far or based heap support)
  31. * 12-07-88 JCR DLL refers to _amlbksiz directly now
  32. * 01-10-89 JCR Removed sbrk() prototype
  33. * 04-28-89 SKS Put parentheses around negative constants
  34. * 05-03-89 JCR Added _INTERNAL_IFSTRIP for relinc usage
  35. * 08-01-89 GJF Cleanup, now specific to OS/2 2.0 (i.e., 386 flat model)
  36. * 10-27-89 JCR Removed near (_n) and _freect/memavl/memmax prototypes
  37. * 10-30-89 GJF Fixed copyright
  38. * 11-02-89 JCR Changed "DLL" to "_DLL"
  39. * 03-01-90 GJF Added #ifndef _INC_MALLOC and #include <cruntime.h>
  40. * stuff. Also, removed some (now) useless preprocessor
  41. * directives.
  42. * 03-21-90 GJF Replaced _cdecl with _CALLTYPE1 in prototypes.
  43. * 04-10-90 GJF Made stackavail() _CALLTYPE1, _amblksiz _VARTYPE1.
  44. * 01-17-91 GJF ANSI naming.
  45. * 08-20-91 JCR C++ and ANSI naming
  46. * 09-23-91 JCR stackavail() not supported in WIN32
  47. * 09-28-91 JCR ANSI names: DOSX32=prototypes, WIN32=#defines for now
  48. * 01-18-92 JCR put _CRTHEAP_ ifdefs in; this stuff is only needed
  49. * for a heap implemented in the runtime (not OS)
  50. * 08-05-92 GJF Function calling type and variable type macros.
  51. * 08-22-92 SRW Add alloca intrinsic pragma for MIPS
  52. * 09-03-92 GJF Merged two changes above.
  53. * 09-23-92 SRW Change winheap code to call NT directly always
  54. * 01-21-93 GJF Removed support for C6-386's _cdecl.
  55. * 02-02-93 SRW Removed bogus semicolon on #pragma
  56. * 04-06-93 SKS Replace _CRTAPI1/2 with __cdecl, _CRTVAR1 with nothing
  57. * 04-07-93 SKS Add _CRTIMP keyword for CRT DLL model
  58. * Use link-time aliases for old names, not #define's
  59. * 04-20-93 SKS _alloca is a compiler intrinsic so alloca must be
  60. * #define-d, not aliased as link time using OLDNAMES.LIB.
  61. * 09-27-93 GJF Merged NT SDK and Cuda versions. Also, changed the
  62. * value of _HEAP_MAXREQ to be more useful (smaller
  63. * value to guarantee page-rounding will not overflow).
  64. * 10-13-93 GJF Replaced _MIPS_ with _M_MRX000.
  65. * 12-13-93 SKS Add _heapused().
  66. * 04-12-94 GJF Special definition for _amblksiz for _DLL. Also,
  67. * conditionally include win32s.h for DLL_FOR_WIN32S.
  68. * 05-03-94 GJF Made special definition of _amblksiz for _DLL also
  69. * conditional on _M_IX86.
  70. * 10-02-94 BWT Add PPC support.
  71. * 11-03-94 GJF Ensure 8 byte alignment.
  72. * 02-11-95 CFW Add _CRTBLD to avoid users getting wrong headers.
  73. * 02-14-95 CFW Clean up Mac merge.
  74. * 05-22-95 GJF Updated _HEAP_MAXREQ.
  75. * 05-24-95 CFW Add heap hook.
  76. * 12-14-95 JWM Add "#pragma once".
  77. * 03-07-96 GJF Added prototypes for small-block heap's get/set
  78. * threshold functions.
  79. * 02-04-97 GJF Cleaned out obsolete support for Win32s, _CRTAPI* and
  80. * _NTSDK.
  81. * 08-13-97 GJF Strip __p__amblksiz prototype from release version.
  82. * 09-30-97 JWM Restored not-so-obsolete _CRTAPI1 support.
  83. * 10-07-97 RDL Added IA64.
  84. * 12-15-98 GJF Changes for 64-bit size_t.
  85. * 05-13-99 PML Remove _CRTAPI1
  86. * 05-17-99 PML Remove all Macintosh support.
  87. * 10-06-99 PML Add _W64 modifier to types which are 32 bits in Win32,
  88. * 64 bits in Win64.
  89. * 11-08-99 GB Add _aligned_malloc(), _aligned_realloc, _aligned_free()
  90. * _aligned_offset_malloc() and _aligned_offset_realloc().
  91. * 12-10-99 GB Add _resetstkoflw().
  92. * 12-16-99 GB Changed HEAP_MAXREQ to 0xFFFFFFFFFFFFFFE0 for Win64
  93. * 01-07-00 GB Fixed macro _mm_free.
  94. * 12-08-00 PML Make _resetstkoflw() available to POSIX build.
  95. * 04-17-01 PML _resetstkoflw() now returns an int success code.
  96. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  97. * 11-03-01 PML Add _get_heap_handle (and intptr_t)
  98. * 03-04-02 PML Add __declspec(noalias, restrict) support
  99. *
  100. ****/
  101. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  102. #pragma once
  103. #endif
  104. #ifndef _INC_MALLOC
  105. #define _INC_MALLOC
  106. #if !defined(_WIN32)
  107. #error ERROR: Only Win32 target supported!
  108. #endif
  109. #ifndef _CRTBLD
  110. /* This version of the header files is NOT for user programs.
  111. * It is intended for use when building the C runtimes ONLY.
  112. * The version intended for public use will not have this message.
  113. */
  114. #error ERROR: Use of C runtime library internal header file.
  115. #endif /* _CRTBLD */
  116. #ifdef _MSC_VER
  117. /*
  118. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  119. * alignment.
  120. */
  121. #pragma pack(push,8)
  122. #endif /* _MSC_VER */
  123. #ifdef __cplusplus
  124. extern "C" {
  125. #endif
  126. #ifndef _INTERNAL_IFSTRIP_
  127. #include <cruntime.h>
  128. #endif /* _INTERNAL_IFSTRIP_ */
  129. #if !defined(_W64)
  130. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 /*IFSTRIP=IGN*/
  131. #define _W64 __w64
  132. #else
  133. #define _W64
  134. #endif
  135. #endif
  136. /* Define _CRTIMP */
  137. #ifndef _CRTIMP
  138. #ifdef CRTDLL
  139. #define _CRTIMP __declspec(dllexport)
  140. #else /* ndef CRTDLL */
  141. #ifdef _DLL
  142. #define _CRTIMP __declspec(dllimport)
  143. #else /* ndef _DLL */
  144. #define _CRTIMP
  145. #endif /* _DLL */
  146. #endif /* CRTDLL */
  147. #endif /* _CRTIMP */
  148. /* Define _CRTNOALIAS, _CRTRESTRICT */
  149. #if _MSC_FULL_VER >= 14002050 /*IFSTRIP=IGN*/
  150. #ifndef _CRTNOALIAS
  151. #ifndef _INTERNAL_IFSTRIP_
  152. #define _CRTNOALIAS
  153. #else
  154. #define _CRTNOALIAS __declspec(noalias)
  155. #endif
  156. #endif /* _CRTNOALIAS */
  157. #ifndef _CRTRESTRICT
  158. #ifndef _INTERNAL_IFSTRIP_
  159. #define _CRTRESTRICT
  160. #else
  161. #define _CRTRESTRICT __declspec(restrict)
  162. #endif
  163. #endif /* _CRTRESTRICT */
  164. #else
  165. #ifndef _CRTNOALIAS
  166. #define _CRTNOALIAS
  167. #endif /* _CRTNOALIAS */
  168. #ifndef _CRTRESTRICT
  169. #define _CRTRESTRICT
  170. #endif /* _CRTRESTRICT */
  171. #endif
  172. /* Define __cdecl for non-Microsoft compilers */
  173. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  174. #define __cdecl
  175. #endif
  176. #ifndef _SIZE_T_DEFINED
  177. #ifdef _WIN64
  178. typedef unsigned __int64 size_t;
  179. #else
  180. typedef _W64 unsigned int size_t;
  181. #endif
  182. #define _SIZE_T_DEFINED
  183. #endif
  184. #ifndef _INTPTR_T_DEFINED
  185. #ifdef _WIN64
  186. typedef __int64 intptr_t;
  187. #else
  188. typedef _W64 int intptr_t;
  189. #endif
  190. #define _INTPTR_T_DEFINED
  191. #endif
  192. /* Maximum heap request the heap manager will attempt */
  193. #ifdef _WIN64
  194. #define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
  195. #else
  196. #define _HEAP_MAXREQ 0xFFFFFFE0
  197. #endif
  198. /* Constants for _heapchk/_heapset/_heapwalk routines */
  199. #define _HEAPEMPTY (-1)
  200. #define _HEAPOK (-2)
  201. #define _HEAPBADBEGIN (-3)
  202. #define _HEAPBADNODE (-4)
  203. #define _HEAPEND (-5)
  204. #define _HEAPBADPTR (-6)
  205. #define _FREEENTRY 0
  206. #define _USEDENTRY 1
  207. #ifndef _HEAPINFO_DEFINED
  208. typedef struct _heapinfo {
  209. int * _pentry;
  210. size_t _size;
  211. int _useflag;
  212. } _HEAPINFO;
  213. #define _HEAPINFO_DEFINED
  214. #endif
  215. /* External variable declarations */
  216. #ifndef _INTERNAL_IFSTRIP_
  217. #if defined(_DLL) && defined(_M_IX86)
  218. /* Retained for compatibility with VC++ 5.0 and earlier versions */
  219. _CRTIMP unsigned int * __cdecl __p__amblksiz(void);
  220. #endif
  221. #endif /* _INTERNAL_IFSTRIP_ */
  222. extern unsigned int _amblksiz;
  223. #define _mm_free(a) _aligned_free(a)
  224. #define _mm_malloc(a, b) _aligned_malloc(a, b)
  225. /* Function prototypes */
  226. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl calloc(size_t, size_t);
  227. _CRTIMP _CRTNOALIAS void __cdecl free(void *);
  228. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl malloc(size_t);
  229. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl realloc(void *, size_t);
  230. _CRTIMP _CRTNOALIAS void __cdecl _aligned_free(void *);
  231. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl _aligned_malloc(size_t, size_t);
  232. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl _aligned_offset_malloc(size_t, size_t, size_t);
  233. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl _aligned_realloc(void *, size_t, size_t);
  234. _CRTIMP _CRTNOALIAS _CRTRESTRICT void * __cdecl _aligned_offset_realloc(void *, size_t, size_t, size_t);
  235. _CRTIMP int __cdecl _resetstkoflw (void);
  236. #ifndef _POSIX_
  237. void * __cdecl _alloca(size_t);
  238. _CRTIMP void * __cdecl _expand(void *, size_t);
  239. _CRTIMP size_t __cdecl _get_sbh_threshold(void);
  240. _CRTIMP int __cdecl _set_sbh_threshold(size_t);
  241. _CRTIMP int __cdecl _heapadd(void *, size_t);
  242. _CRTIMP int __cdecl _heapchk(void);
  243. _CRTIMP int __cdecl _heapmin(void);
  244. _CRTIMP int __cdecl _heapset(unsigned int);
  245. _CRTIMP int __cdecl _heapwalk(_HEAPINFO *);
  246. _CRTIMP size_t __cdecl _heapused(size_t *, size_t *);
  247. _CRTIMP size_t __cdecl _msize(void *);
  248. _CRTIMP intptr_t __cdecl _get_heap_handle(void);
  249. #if !__STDC__
  250. /* Non-ANSI names for compatibility */
  251. #define alloca _alloca
  252. #endif /* __STDC__*/
  253. #endif /* _POSIX_ */
  254. #ifdef HEAPHOOK
  255. #ifndef _HEAPHOOK_DEFINED
  256. /* hook function type */
  257. typedef int (__cdecl * _HEAPHOOK)(int, size_t, void *, void **);
  258. #define _HEAPHOOK_DEFINED
  259. #endif /* _HEAPHOOK_DEFINED */
  260. /* set hook function */
  261. _CRTIMP _HEAPHOOK __cdecl _setheaphook(_HEAPHOOK);
  262. /* hook function must handle these types */
  263. #define _HEAP_MALLOC 1
  264. #define _HEAP_CALLOC 2
  265. #define _HEAP_FREE 3
  266. #define _HEAP_REALLOC 4
  267. #define _HEAP_MSIZE 5
  268. #define _HEAP_EXPAND 6
  269. #endif /* HEAPHOOK */
  270. #ifdef __cplusplus
  271. }
  272. #endif
  273. #ifdef _MSC_VER
  274. #pragma pack(pop)
  275. #endif /* _MSC_VER */
  276. #endif /* _INC_MALLOC */