Source code of Windows XP (NT5)
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.

281 lines
9.6 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. *
  97. ****/
  98. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  99. #pragma once
  100. #endif
  101. #ifndef _INC_MALLOC
  102. #define _INC_MALLOC
  103. #if !defined(_WIN32)
  104. #error ERROR: Only Win32 target supported!
  105. #endif
  106. #ifndef _CRTBLD
  107. /* This version of the header files is NOT for user programs.
  108. * It is intended for use when building the C runtimes ONLY.
  109. * The version intended for public use will not have this message.
  110. */
  111. #error ERROR: Use of C runtime library internal header file.
  112. #endif /* _CRTBLD */
  113. #ifdef _MSC_VER
  114. /*
  115. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  116. * alignment.
  117. */
  118. #pragma pack(push,8)
  119. #endif /* _MSC_VER */
  120. #ifdef __cplusplus
  121. extern "C" {
  122. #endif
  123. #ifndef _INTERNAL_IFSTRIP_
  124. #include <cruntime.h>
  125. #endif /* _INTERNAL_IFSTRIP_ */
  126. #if !defined(_W64)
  127. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 /*IFSTRIP=IGN*/
  128. #define _W64 __w64
  129. #else
  130. #define _W64
  131. #endif
  132. #endif
  133. /* Define _CRTIMP */
  134. #ifndef _CRTIMP
  135. #ifdef CRTDLL
  136. #define _CRTIMP __declspec(dllexport)
  137. #else /* ndef CRTDLL */
  138. #ifdef _DLL
  139. #define _CRTIMP __declspec(dllimport)
  140. #else /* ndef _DLL */
  141. #define _CRTIMP
  142. #endif /* _DLL */
  143. #endif /* CRTDLL */
  144. #endif /* _CRTIMP */
  145. /* Define __cdecl for non-Microsoft compilers */
  146. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  147. #define __cdecl
  148. #endif
  149. #ifndef _SIZE_T_DEFINED
  150. #ifdef _WIN64
  151. typedef unsigned __int64 size_t;
  152. #else
  153. typedef _W64 unsigned int size_t;
  154. #endif
  155. #define _SIZE_T_DEFINED
  156. #endif
  157. /* Maximum heap request the heap manager will attempt */
  158. #ifdef _WIN64
  159. #define _HEAP_MAXREQ 0xFFFFFFFFFFFFFFE0
  160. #else
  161. #define _HEAP_MAXREQ 0xFFFFFFE0
  162. #endif
  163. /* Constants for _heapchk/_heapset/_heapwalk routines */
  164. #define _HEAPEMPTY (-1)
  165. #define _HEAPOK (-2)
  166. #define _HEAPBADBEGIN (-3)
  167. #define _HEAPBADNODE (-4)
  168. #define _HEAPEND (-5)
  169. #define _HEAPBADPTR (-6)
  170. #define _FREEENTRY 0
  171. #define _USEDENTRY 1
  172. #ifndef _HEAPINFO_DEFINED
  173. typedef struct _heapinfo {
  174. int * _pentry;
  175. size_t _size;
  176. int _useflag;
  177. } _HEAPINFO;
  178. #define _HEAPINFO_DEFINED
  179. #endif
  180. /* External variable declarations */
  181. #ifndef _INTERNAL_IFSTRIP_
  182. #if defined(_DLL) && defined(_M_IX86)
  183. /* Retained for compatibility with VC++ 5.0 and earlier versions */
  184. _CRTIMP unsigned int * __cdecl __p__amblksiz(void);
  185. #endif
  186. #endif /* _INTERNAL_IFSTRIP_ */
  187. extern unsigned int _amblksiz;
  188. #define _mm_free(a) _aligned_free(a)
  189. #define _mm_malloc(a, b) _aligned_malloc(a, b)
  190. /* Function prototypes */
  191. _CRTIMP void * __cdecl calloc(size_t, size_t);
  192. _CRTIMP void __cdecl free(void *);
  193. _CRTIMP void * __cdecl malloc(size_t);
  194. _CRTIMP void * __cdecl realloc(void *, size_t);
  195. _CRTIMP void __cdecl _aligned_free(void *);
  196. _CRTIMP void * __cdecl _aligned_malloc(size_t, size_t);
  197. _CRTIMP void * __cdecl _aligned_offset_malloc(size_t, size_t, size_t);
  198. _CRTIMP void * __cdecl _aligned_realloc(void *, size_t, size_t);
  199. _CRTIMP void * __cdecl _aligned_offset_realloc(void *, size_t, size_t, size_t);
  200. _CRTIMP int __cdecl _resetstkoflw (void);
  201. #ifndef _POSIX_
  202. void * __cdecl _alloca(size_t);
  203. _CRTIMP void * __cdecl _expand(void *, size_t);
  204. _CRTIMP size_t __cdecl _get_sbh_threshold(void);
  205. _CRTIMP int __cdecl _set_sbh_threshold(size_t);
  206. _CRTIMP int __cdecl _heapadd(void *, size_t);
  207. _CRTIMP int __cdecl _heapchk(void);
  208. _CRTIMP int __cdecl _heapmin(void);
  209. _CRTIMP int __cdecl _heapset(unsigned int);
  210. _CRTIMP int __cdecl _heapwalk(_HEAPINFO *);
  211. _CRTIMP size_t __cdecl _heapused(size_t *, size_t *);
  212. _CRTIMP size_t __cdecl _msize(void *);
  213. #if !__STDC__
  214. /* Non-ANSI names for compatibility */
  215. #define alloca _alloca
  216. #endif /* __STDC__*/
  217. #if defined(_M_MRX000) || defined(_M_PPC) || defined(_M_ALPHA)
  218. #pragma intrinsic(_alloca)
  219. #endif
  220. #endif /* _POSIX_ */
  221. #ifdef HEAPHOOK
  222. #ifndef _HEAPHOOK_DEFINED
  223. /* hook function type */
  224. typedef int (__cdecl * _HEAPHOOK)(int, size_t, void *, void **);
  225. #define _HEAPHOOK_DEFINED
  226. #endif /* _HEAPHOOK_DEFINED */
  227. /* set hook function */
  228. _CRTIMP _HEAPHOOK __cdecl _setheaphook(_HEAPHOOK);
  229. /* hook function must handle these types */
  230. #define _HEAP_MALLOC 1
  231. #define _HEAP_CALLOC 2
  232. #define _HEAP_FREE 3
  233. #define _HEAP_REALLOC 4
  234. #define _HEAP_MSIZE 5
  235. #define _HEAP_EXPAND 6
  236. #endif /* HEAPHOOK */
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. #ifdef _MSC_VER
  241. #pragma pack(pop)
  242. #endif /* _MSC_VER */
  243. #endif /* _INC_MALLOC */