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.

134 lines
5.8 KiB

  1. /*****************************************************************************
  2. * *
  3. * MEM.H *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1990. *
  6. * All Rights reserved. *
  7. * *
  8. ******************************************************************************
  9. * *
  10. * Module Intent: Exports memory management functionality.
  11. * Most functions map directly to Window's *
  12. * memory manager calls. *
  13. ******************************************************************************
  14. * *
  15. * Current Owner: RHobbs *
  16. * *
  17. *****************************************************************************/
  18. #if defined( __cplusplus )
  19. extern "C" {
  20. #endif
  21. /*****************************************************************************
  22. * *
  23. * Prototypes *
  24. * *
  25. *****************************************************************************/
  26. HANDLE PASCAL FAR GhDupGh(HANDLE);
  27. HANDLE PASCAL FAR GhDupSz(LPSTR);
  28. VOID FAR PASCAL MakeGlobalPool (void);
  29. VOID FAR PASCAL FreeGlobalPool (void);
  30. HANDLE FAR PASCAL _VirtualAlloc(LPVOID, DWORD, DWORD, DWORD, LPSTR, UINT);
  31. LPVOID FAR PASCAL _VirtualLock(LPVOID, DWORD, LPSTR, UINT);
  32. BOOL FAR PASCAL _VirtualUnlock(LPVOID, DWORD, LPSTR, UINT);
  33. int FAR PASCAL _VirtualFree(LPVOID, DWORD, DWORD, LPSTR, UINT);
  34. /*****************************************************************************
  35. * *
  36. * Defines *
  37. * *
  38. *****************************************************************************/
  39. #if defined(MOSMAP) && !defined(NOMOSMEM)
  40. // Mos server can't be limited in the number of handles. However, sometimes
  41. // debug layer is needed to track memory leaks. Simply comment out next line
  42. // or compile with NOMOSMEM
  43. #define MOSMEM
  44. #endif
  45. #ifndef _MAC
  46. #define DLLGMEM_ZEROINIT (GMEM_MOVEABLE | GMEM_ZEROINIT)
  47. #else
  48. #define DLLGMEM_ZEROINIT (GMEM_MOVEABLE | GMEM_SHARE | GMEM_ZEROINIT | GMEM_PMODELOCKSTRATEGY)
  49. #endif
  50. #define _LOCALALLOC LocalAlloc
  51. #define _LOCALLOCK LocalLock
  52. #define _LOCALUNLOCK LocalUnlock
  53. #define _LOCALFREE LocalFree
  54. #if defined(_DEBUG) && !defined(_MSDN) && !defined(MOSMEM)
  55. #include <windowsx.h>
  56. HANDLE FAR PASCAL _GlobalAlloc(UINT, DWORD, LPSTR, UINT);
  57. LPVOID FAR PASCAL _GlobalLock(HANDLE, LPSTR, UINT);
  58. BOOL FAR PASCAL _GlobalUnlock(HANDLE, LPSTR, UINT);
  59. HANDLE FAR PASCAL _GlobalFree(HANDLE, LPSTR, UINT);
  60. HANDLE FAR PASCAL _GlobalReAlloc(HANDLE, DWORD, UINT, LPSTR, UINT);
  61. HANDLE FAR PASCAL _GlobalRelease(HANDLE, LPSTR, UINT);
  62. HANDLE FAR PASCAL _GlobalAdd(HANDLE, LPSTR, UINT);
  63. DWORD FAR PASCAL _GlobalSize(HANDLE, LPSTR, UINT);
  64. #define _GLOBALALLOC(a,b) _GlobalAlloc(a,b,s_aszModule,__LINE__)
  65. #define _GLOBALLOCK(a) _GlobalLock(a,s_aszModule, __LINE__)
  66. #define _GLOBALSIZE(a) _GlobalSize(a,s_aszModule, __LINE__)
  67. #define _GLOBALUNLOCK(a) _GlobalUnlock(a,s_aszModule, __LINE__)
  68. #define _GLOBALFREE(a) _GlobalFree(a,s_aszModule, __LINE__)
  69. #define _GLOBALREALLOC(a,b,c) _GlobalReAlloc(a,b,c,s_aszModule, __LINE__)
  70. #define _GLOBALRELEASE(a) _GlobalRelease(a, s_aszModule, __LINE__)
  71. #define _GLOBALADD(a) _GlobalAdd(a, s_aszModule, __LINE__)
  72. #define _GLOBALALLOCPTR(a,b) (_GLOBALLOCK(_GLOBALALLOC(a,b)))
  73. #define _GLOBALFREEPTR(a) (_GLOBALUNLOCK(GlobalPtrHandle((LPVOID)a)), \
  74. _GLOBALFREE(GlobalPtrHandle((LPVOID)a)))
  75. #define _VIRTUALALLOC(a,b,c,d) _VirtualAlloc(a,b,c,d,s_aszModule,__LINE__)
  76. #define _VIRTUALLOCK(a,b) _VirtualLock(a,b,s_aszModule, __LINE__)
  77. #define _VIRTUALUNLOCK(a,b) _VirtualUnlock(a,b,s_aszModule, __LINE__)
  78. #define _VIRTUALFREE(a,b,c) _VirtualFree(a,b,c,s_aszModule, __LINE__)
  79. DWORD PASCAL FAR CheckMem(VOID);
  80. DWORD PASCAL FAR GetMemUsed(VOID);
  81. #else
  82. #if defined( MOSMEM ) // {
  83. // We can't afford to have memory overhead on the server.... => no debug, no moveable
  84. #define _GLOBALALLOC(a,b) GlobalAlloc((a)&~GMEM_MOVEABLE,b)
  85. #define _GLOBALREALLOC(a,b,c) GlobalReAlloc(a,b,((c)&~GMEM_MODIFY)|GMEM_MOVEABLE)
  86. #define _GLOBALALLOCPTR(a,b) (_GLOBALALLOC(a,b))
  87. #else // }{
  88. #define _GLOBALALLOC GlobalAlloc
  89. #define _GLOBALREALLOC GlobalReAlloc
  90. #define _GLOBALALLOCPTR GlobalAllocPtr
  91. #endif // }
  92. #define _GLOBALLOCK (VOID FAR *)GlobalLock
  93. #define _GLOBALUNLOCK GlobalUnlock
  94. #define _GLOBALFREE GlobalFree
  95. #define _GLOBALSIZE GlobalSize
  96. #define _GLOBALRELEASE(a) (a)
  97. #define _GLOBALADD(a) (a)
  98. #define _GLOBALFREEPTR GlobalFreePtr
  99. #define _VIRTUALALLOC(a,b,c,d) VirtualAlloc(a,b,c,d)
  100. #define _VIRTUALLOCK(a,b) VirtualLock(a,b)
  101. #define _VIRTUALUNLOCK(a,b) VirtualUnlock(a,b)
  102. #define _VIRTUALFREE(a,b,c) VirtualFree(a,b,c)
  103. #endif // _DEBUG
  104. #define FCheckGh( gh ) TRUE
  105. #define LhFromP(pv) LocalHandle( (WORD)(pv) )
  106. // Flags to be use to control block manager allocation
  107. #define THREADED_ELEMENT 1
  108. #ifdef _MAC
  109. #define USE_VIRTUAL_MEMORY 0
  110. #else
  111. #define USE_VIRTUAL_MEMORY 0
  112. #endif
  113. #if defined( __cplusplus )
  114. }
  115. #endif