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.

168 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. kernel32.h
  5. Abstract:
  6. The heap manager is identical (exactly) to the Win9x heap manager. The code
  7. is the same and the corresponding conversion code and defines are in
  8. support.c and kernel32.h The exact win9x sources are in heap.c and lmem.c.
  9. All the heap functions come in heap.c and the local/global functions come
  10. in lmem.c.
  11. The SHIM code comes in EmulateHeap.cpp. This hooks the heap calls and calls
  12. the Win9x code to emulate the Win9x heap. After the heap management by the
  13. Win9x heap, the underneath calls to the Virtual memory functions are handled
  14. in support.c. The only difference comes in the way Win9x handles 'SHARED'
  15. and "PRIVATE' heaps.Win9x creates the process default heap as a SHARED heap
  16. and uses it in kernel mode too. We also create it as a SHARED heap but do
  17. not share it with the kernel. Win9x links all the PRIVATE heaps for the
  18. process in the PDB data structure. We fake this structure with only the
  19. required elements and allow the Win9x code to handle this structure.
  20. Notes:
  21. None.
  22. History:
  23. 11/16/2000 prashkud & linstev Created
  24. --*/
  25. #ifndef _KERNEL32_H_
  26. #define _KERNEL32_H_
  27. #include "windows.h"
  28. #define INTERNAL
  29. #define EXTERNAL
  30. #define KERNENTRY WINAPI
  31. #define PAGESHIFT 12
  32. #define PAGESIZE (1 << PAGESHIFT)
  33. #define PAGEMASK (PAGESIZE - 1)
  34. #define CRST CRITICAL_SECTION
  35. //BUGBUG - did this to prevent build error, but should make no difference
  36. #define typObj LockCount
  37. #define typObjCrst 0
  38. #define InitCrst(_x_) InitializeCriticalSection(_x_)
  39. #define DestroyCrst(_x_) DeleteCriticalSection(_x_)
  40. #define EnterCrst(_x_) EnterCriticalSection(_x_)
  41. #define LeaveCrst(_x_) LeaveCriticalSection(_x_)
  42. #define Assert(_x_)
  43. /* PageReserve flags */
  44. #define PR_FIXED 0x00000008 /* don't move during PageReAllocate */
  45. #define PR_4MEG 0x00000001 /* allocate on 4mb boundary */
  46. #define PR_STATIC 0x00000010 /* see PageReserve documentation */
  47. /* PageCommit default pager handle values */
  48. #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
  49. #define PD_NOINIT 0x00000002 /* swappable uninitialized pages */
  50. #define PD_FIXEDZERO 0x00000003 /* fixed zero-initialized pages */
  51. #define PD_FIXED 0x00000004 /* fixed uninitialized pages */
  52. /* PageCommit flags */
  53. #define PC_FIXED 0x00000008 /* pages are permanently locked */
  54. #define PC_LOCKED 0x00000080 /* pages are made present and locked*/
  55. #define PC_LOCKEDIFDP 0x00000100 /* pages are locked if swap via DOS */
  56. #define PC_WRITEABLE 0x00020000 /* make the pages writeable */
  57. #define PC_USER 0x00040000 /* make the pages ring 3 accessible */
  58. #define PC_INCR 0x40000000 /* increment "pagerdata" each page */
  59. #define PC_PRESENT 0x80000000 /* make pages initially present */
  60. #define PC_STATIC 0x20000000 /* allow commit in PR_STATIC object */
  61. #define PC_DIRTY 0x08000000 /* make pages initially dirty */
  62. #define PC_CACHEDIS 0x00100000 /* Allocate uncached pages - new for WDM */
  63. #define PC_CACHEWT 0x00080000 /* Allocate write through cache pages - new for WDM */
  64. #define PC_PAGEFLUSH 0x00008000 /* Touch device mapped pages on alloc - new for WDM */
  65. /* PageReserve arena values */
  66. #define PR_PRIVATE 0x80000400 /* anywhere in private arena */
  67. #define PR_SHARED 0x80060000 /* anywhere in shared arena */
  68. #define PR_SYSTEM 0x80080000 /* anywhere in system arena */
  69. // This can be anything since it only affects flags which are ignored
  70. #define MINSHAREDLADDR 1
  71. // This is used for validation, which is identical on NT - no allocation can be at > 0x7fffffff
  72. #define MAXSHAREDLADDR 0x7fffffff
  73. // This is used for validation, old value was 0x00400000, but now just make it 1
  74. #define MINPRIVATELADDR 1
  75. // Used to determine if a heap is private, was 0x3fffffff, but now make it 0x7fffffff
  76. #define MAXPRIVATELADDR 0x7fffffff
  77. extern ULONG PageCommit(ULONG page, ULONG npages, ULONG hpd, ULONG pagerdata, ULONG flags);
  78. extern ULONG PageDecommit(ULONG page, ULONG npages, ULONG flags);
  79. extern ULONG PageReserve(ULONG page, ULONG npages, ULONG flags);
  80. #define PageFree(_x_, _y_) VirtualFree((LPVOID) _x_, 0, MEM_RELEASE)
  81. #define PvKernelAlloc0(_x_) VirtualAlloc(0, _x_, MEM_COMMIT, PAGE_READWRITE)
  82. #define FKernelFree(_x_) VirtualFree((LPVOID) _x_, 0, MEM_RELEASE)
  83. extern CRITICAL_SECTION *NewCrst();
  84. extern VOID DisposeCrst(CRITICAL_SECTION *lpcs);
  85. #define FillBytes(a, b, c) memset(a, c, b)
  86. #define SetError(_x_) SetLastError(_x_)
  87. #define dprintf(_x_) OutputDebugStringA(_x_)
  88. #define DebugOut(_x_)
  89. #define DEB_WARN 0
  90. #define DEB_ERR 1
  91. #include "EmulateHeap_heap.h"
  92. #define HeapSize _HeapSize
  93. #define HeapCreate _HeapCreate
  94. #define HeapDestroy _HeapDestroy
  95. #define HeapReAlloc _HeapReAlloc
  96. #define HeapAlloc _HeapAlloc
  97. #define HeapFree _HeapFree
  98. #define HeapFreeInternal _HeapFree
  99. #define LocalReAlloc _LocalReAlloc
  100. #define LocalAllocNG _LocalAlloc
  101. #define LocalFreeNG _LocalFree
  102. #define LocalLock _LocalLock
  103. #define LocalCompact _LocalCompact
  104. #define LocalShrink _LocalShrink
  105. #define LocalUnlock _LocalUnlock
  106. #define LocalSize _LocalSize
  107. #define LocalHandle _LocalHandle
  108. #define LocalFlags _LocalFlags
  109. //BUGBUG: don't think we need these - looks like they're required for kernel heap support
  110. #define EnterMustComplete()
  111. #define LeaveMustComplete()
  112. // For lmem.c
  113. typedef struct _pdb {
  114. struct heapinfo_s *hheapLocal; // DON'T MOVE THIS!!! handle to heap in private memeory
  115. struct lhandle_s *plhFree; // Local heap free handle list head ptr
  116. struct heapinfo_s *hhi_procfirst; // linked list of heaps for this process
  117. struct lharray_s *plhBlock; // local heap lhandle blocks
  118. } PDB, *PPDB;
  119. extern PDB **pppdbCur;
  120. #define GetCurrentPdb() (*pppdbCur)
  121. extern HANDLE hheapKernel;
  122. extern HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
  123. extern DWORD APIENTRY HeapSize(HHEAP hheap, DWORD flags, LPSTR lpMem);
  124. extern BOOL APIENTRY HeapFreeInternal(HHEAP hheap, DWORD flags, LPSTR lpMem);
  125. #define HEAP_SHARED 0x04000000 // put heap in shared memory
  126. #define HEAP_LOCKED 0x00000080 // put heap in locked memory
  127. #ifdef WINBASEAPI
  128. #undef WINBASEAPI
  129. #define WINBASEAPI
  130. #endif
  131. #endif // _KERNEL32_H_