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.

221 lines
7.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // mem.h - interface for memory functions in mem.c
  24. ////
  25. #ifndef __MEM_H__
  26. #define __MEM_H__
  27. #include "winlocal.h"
  28. #include <memory.h>
  29. #define MEM_VERSION 0x00000106
  30. // handle to mem engine
  31. //
  32. DECLARE_HANDLE32(HMEM);
  33. // <dwFlags> values in MemAlloc
  34. //
  35. #define MEM_NOZEROINIT 0x00000001
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. // MemInit - initialize mem engine
  40. // <dwVersion> (i) must be MEM_VERSION
  41. // <hInst> (i) instance handle of calling module
  42. // <dwFlags> (i) control flags
  43. // 0 reserved; must be zero
  44. // return handle (NULL if error)
  45. //
  46. #ifdef NOTRACE
  47. #define MemInit(dwVersion, hInst) 1
  48. #else
  49. HMEM DLLEXPORT WINAPI MemInit(DWORD dwVersion, HINSTANCE hInst);
  50. #endif
  51. // MemTerm - shut down mem engine
  52. // <hMem> (i) handle returned from MemInit or NULL
  53. // return 0 if success
  54. //
  55. #ifdef NOTRACE
  56. #define MemTerm(hMem) 0
  57. #else
  58. int DLLEXPORT WINAPI MemTerm(HMEM hMem);
  59. #endif
  60. // MemAlloc - allocate memory block
  61. // <hMem> (i) handle returned from MemInit or NULL
  62. // <sizBlock> (i) size of block, in bytes
  63. // <dwFlags> (i) control flags
  64. // MEM_NOZEROINIT do not initialize block
  65. // return pointer to block, NULL if error
  66. //
  67. #ifdef NOTRACE
  68. #ifdef _WIN32
  69. #define MemAlloc(hMem, sizBlock, dwFlags) \
  70. HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizBlock)
  71. #else
  72. #define MemAlloc(hMem, sizBlock, dwFlags) \
  73. GlobalAllocPtr(GMEM_MOVEABLE | GMEM_ZEROINIT, sizBlock)
  74. #endif
  75. #else
  76. #define MemAlloc(hMem, sizBlock, dwFlags) \
  77. MemAllocEx(hMem, sizBlock, dwFlags, TEXT(__FILE__), __LINE__)
  78. LPVOID DLLEXPORT WINAPI MemAllocEx(HMEM hMem, long sizBlock, DWORD dwFlags,
  79. LPCTSTR lpszFileName, unsigned uLineNumber);
  80. #endif
  81. // MemReAlloc - reallocate memory block
  82. // <hMem> (i) handle returned from MemInit or NULL
  83. // <lpBlock> (i) pointer returned from MemAlloc
  84. // <sizBlock> (i) new size of block, in bytes
  85. // <dwFlags> (i) control flags
  86. // MEM_NOZEROINIT do not initialize block
  87. // return pointer to block, NULL if error
  88. //
  89. #ifdef NOTRACE
  90. #ifdef _WIN32
  91. #define MemReAlloc(hMem, lpBlock, sizBlock, dwFlags) \
  92. HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpBlock, sizBlock)
  93. #else
  94. #define MemReAlloc(hMem, lpBlock, sizBlock, dwFlags) \
  95. GlobalReAllocPtr(lpBlock, sizBlock, GMEM_MOVEABLE | GMEM_ZEROINIT)
  96. #endif
  97. #else
  98. #define MemReAlloc(hMem, lpBlock, sizBlock, dwFlags) \
  99. MemReAllocEx(hMem, lpBlock, sizBlock, dwFlags, TEXT(__FILE__), __LINE__)
  100. LPVOID DLLEXPORT WINAPI MemReAllocEx(HMEM hMem, LPVOID lpBlock, long sizBlock,
  101. DWORD dwFlags, LPCTSTR lpszFileName, unsigned uLineNumber);
  102. #endif
  103. // MemFree - free memory block
  104. // <hMem> (i) handle returned from MemInit or NULL
  105. // <lpBlock> (i) pointer returned from MemAlloc
  106. // return NULL if success, lpBlock if error
  107. //
  108. // NOTE: the return value of this function is designed to allow the
  109. // user of this function to easily assign NULL to a freed pointer,
  110. // as the following example demonstrates:
  111. //
  112. // if ((p = MemFree(hMem, p)) != NULL)
  113. // ; // error
  114. //
  115. #ifdef NOTRACE
  116. #ifdef _WIN32
  117. #define MemFree(hMem, lpBlock) \
  118. (!HeapFree(GetProcessHeap(), 0, lpBlock) ? lpBlock : NULL)
  119. #else
  120. #define MemFree(hMem, lpBlock) \
  121. (GlobalFreePtr(lpBlock) == 0 ? NULL : lpBlock)
  122. #endif
  123. #else
  124. #define MemFree(hMem, lpBlock) \
  125. MemFreeEx(hMem, lpBlock, TEXT(__FILE__), __LINE__)
  126. LPVOID DLLEXPORT WINAPI MemFreeEx(HMEM hMem, LPVOID lpBlock,
  127. LPCTSTR lpszFileName, unsigned uLineNumber);
  128. #endif
  129. // MemSize - get size of memory block
  130. // <hMem> (i) handle returned from MemInit or NULL
  131. // <lpBlock> (i) pointer returned from MemAlloc
  132. // return size of block if success, 0 if error
  133. //
  134. #ifdef NOTRACE
  135. #ifdef _WIN32
  136. #define MemSize(hMem, lpBlock) \
  137. (max(0, (long) HeapSize(GetProcessHeap(), 0, lpBlock)))
  138. #else
  139. #define MemSize(hMem, lpBlock) \
  140. ((long) GlobalSize(GlobalPtrHandle(lpBlock)))
  141. #endif
  142. #else
  143. long DLLEXPORT WINAPI MemSize(HMEM hMem, LPVOID lpBlock);
  144. #endif
  145. ////
  146. // memory buffer macros/functions
  147. ////
  148. #ifdef _WIN32
  149. #define MemCCpy(dest, src, count) _fmemccpy(dest, src, c, count)
  150. #define MemChr(buf, count) _fmemchr(buf, c, count)
  151. #define MemCmp(buf1, buf2, count) _fmemcmp(buf1, buf2, count)
  152. #define MemCpy(dest, src, count) _fmemcpy(dest, src, count) // CopyMemory(dest, src, (DWORD) count)
  153. #define MemICmp(buf1, buf2, count) _fmemicmp(buf1, buf2, count)
  154. #define MemMove(dest, src, count) _fmemmove(dest, src, count) // MoveMemory(dest, src, (DWORD) count)
  155. #define MemSet(dest, c, count) _fmemset(dest, c, count) // FillMemory(dest, (DWORD) count, (BYTE) c)
  156. #else
  157. #define MemCCpy(dest, src, count) MemCCpyEx(dest, src, count)
  158. void _huge* DLLEXPORT MemCCpyEx(void _huge* dest, const void _huge* src, int c, long count);
  159. #define MemChr(buf, count) MemChrEx(buf, count)
  160. void _huge* DLLEXPORT MemChrEx(void _huge* buf, int c, long count);
  161. #define MemCmp(buf1, buf2, count) MemCmpEx(buf1, buf2, count)
  162. int DLLEXPORT MemCmpEx(const void _huge* buf1, void _huge* buf2, long count);
  163. #define MemCpy(dest, src, count) MemCpyEx(dest, src, count)
  164. void _huge* DLLEXPORT MemCpyEx(void _huge* dest, const void _huge* src, long count);
  165. #define MemICmp(buf1, buf2, count) MemICmpEx(buf1, buf2, count)
  166. int DLLEXPORT MemICmpEx(const void _huge* buf1, void _huge* buf2, long count);
  167. #define MemMove(dest, src, count) MemMoveEx(dest, src, count)
  168. void _huge* DLLEXPORT MemMoveEx(void _huge* dest, const void _huge* src, long count);
  169. #define MemSet(dest, c, count) MemSetEx(dest, c, count)
  170. void _huge* DLLEXPORT MemSetEx(void _huge* dest, int c, long count);
  171. #endif
  172. ////
  173. // LocalAlloc macros
  174. ////
  175. #define LocalPtrHandle(lp) \
  176. ((HLOCAL) LocalHandle(lp))
  177. #define LocalLockPtr(lp) \
  178. ((BOOL) (LocalLock(LocalPtrHandle(lp)) != NULL))
  179. #define LocalUnlockPtr(lp) \
  180. LocalUnlock(LocalPtrHandle(lp))
  181. #define LocalAllocPtr(flags, cb) \
  182. (LocalLock(LocalAlloc((flags), (cb))))
  183. #define LocalReAllocPtr(lp, cbNew, flags) \
  184. (LocalUnlockPtr(lp), LocalLock(LocalReAlloc(LocalPtrHandle(lp) , (cbNew), (flags))))
  185. #define LocalFreePtr(lp) \
  186. (LocalUnlockPtr(lp), (INT64) LocalFree(LocalPtrHandle(lp)))
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif // __MEM_H__