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.

489 lines
17 KiB

  1. MASTER_OBJECT_SIZE equ 512
  2. LOCALHEAP_SIG EQU 'HL'
  3. GLOBALHEAP_SIG EQU 'HG'
  4. ; Debug fill constants
  5. DBGFILL_ALLOC equ 0fdh
  6. DBGFILL_FREE equ 0fbh
  7. DBGFILL_BUFFER equ 0f9h
  8. DBGFILL_STACK equ 0f7h
  9. ife PMODE32
  10. ; Data structure that describes an allocation arena. Both the local
  11. ; and global allocators use this structure at the beginning of their
  12. ; information structures.
  13. ;
  14. HeapInfo STRUC
  15. hi_check DW ? ; arena check word (non-zero enables heap checking)
  16. hi_freeze DW ? ; arena frozen word (non-zero prevents compaction)
  17. hi_count DW ? ; #entries in arena
  18. hi_first DW ? ; first arena entry (sentinel, always busy)
  19. hi_last DW ? ; last arena entry (sentinel, always busy)
  20. hi_ncompact DB ? ; #compactions done so far (max of 3)
  21. hi_dislevel DB ? ; current discard level
  22. hi_distotal DW ? ; total amount discarded so far
  23. hi_htable DW ? ; head of handle table list
  24. hi_hfree DW ? ; head of free handle table list
  25. hi_hdelta DW ? ; #handles to allocate each time
  26. hi_hexpand DW ? ; address of near procedure to expand handles for
  27. ; this arena
  28. hi_pstats DW ? ; address of statistics table or zero
  29. HeapInfo ENDS
  30. else ; PMODE32
  31. ; Data structure that describes an allocation arena. Both the local
  32. ; and global allocators use this structure at the beginning of their
  33. ; information structures.
  34. ;
  35. HeapInfo STRUC
  36. hi_check DW ? ; arena check word (non-zero enables heap checking)
  37. hi_freeze DW ? ; arena frozen word (non-zero prevents compaction)
  38. hi_count DW ? ; #entries in arena
  39. hi_first DW ? ; first arena entry (sentinel, always busy)
  40. DW ?
  41. hi_last DW ? ; last arena entry (sentinel, always busy)
  42. DW ?
  43. hi_ncompact DB ? ; #compactions done so far (max of 3)
  44. hi_dislevel DB ? ; current discard level
  45. hi_distotal DD ? ; total amount discarded so far
  46. hi_htable DW ? ; head of handle table list
  47. hi_hfree DW ? ; head of free handle table list
  48. hi_hdelta DW ? ; #handles to allocate each time
  49. hi_hexpand DW ? ; address of near procedure to expand handles for
  50. ; this arena
  51. hi_pstats DW ? ; address of statistics table or zero
  52. HeapInfo ENDS
  53. phi_first equ dword ptr hi_first
  54. phi_last equ dword ptr hi_last
  55. endif ; PMODE32
  56. ; Handle table entry.
  57. HandleEntry STRUC
  58. he_address DW ? ; actual address of object
  59. he_flags DB ? ; flags and priority level
  60. he_seg_no DB ? ; 0-based segment number for discardable code
  61. HandleEntry ENDS
  62. he_EMSPID_no equ byte ptr he_seg_no
  63. FreeHandleEntry STRUC
  64. he_link DW ?
  65. he_free DW ?
  66. FreeHandleEntry ENDS
  67. LocalHandleEntry STRUC
  68. lhe_address DW ? ; actual address of object
  69. lhe_flags DB ? ; flags and priority level
  70. lhe_count DB ? ; lock count
  71. LocalHandleEntry ENDS
  72. LocalFreeHandleEntry STRUC
  73. lhe_link DW ?
  74. lhe_free DW ?
  75. LocalFreeHandleEntry ENDS
  76. he_owner EQU he_address ; Discarded objects contain owner field
  77. ; here so we know when to free handle
  78. ; table entries of discarded objects.
  79. HE_DISCARDABLE EQU 00Fh ; Discard level of this object
  80. HE_DISCARDED EQU 040h ; Marks objects that have been discarded.
  81. HE_FREEHANDLE EQU 0FFFFh ; Use -1 to mark free handle table entries
  82. LHE_DISCARDABLE EQU 00Fh ; Discard level of this object
  83. LHE_DISCARDED EQU 040h ; Marks objects that have been discarded.
  84. LHE_USERFLAGS EQU 01Fh ; Mask for user setable flags
  85. LHE_FREEHANDLE EQU 0FFFFh ; Use -1 to mark free handle table entries
  86. HE_ALIGN = 4-1
  87. HE_MASK = NOT HE_ALIGN
  88. ; Handles are allocated in blocks of N, where N is the hi_hdelta field
  89. ; in the local heap information structure. The last word of each block
  90. ; of handles is used to thread the blocks together, allowing all handles
  91. ; to be enumerated. The first word of every block is the number of
  92. ; handle table entries in the block. Not only does it save us code
  93. ; in henum, but it also has the convenient property of placing all
  94. ; handle entries on 2 byte boundaries (i.e. 2, 6, 10, 14), since the
  95. ; LA_MOVEABLE bit is 02h. Thus the address of the he_address field of
  96. ; a handle table entry is also the address of the handle table entry
  97. ; itself.
  98. HandleTable STRUC
  99. ht_count DW ? ; # handletable entries in this block
  100. ht_entry DB SIZE HandleEntry DUP (?)
  101. HandleTable ENDS
  102. LocalHandleTable STRUC
  103. lht_count DW ? ; # handletable entries in this block
  104. lht_entry DB SIZE LocalHandleEntry DUP (?)
  105. LocalHandleTable ENDS
  106. ; Local arena objects are kept in a doubly linked list.
  107. LocalArena STRUC
  108. la_prev DW ? ; previous arena entry (first entry points to self)
  109. la_next DW ? ; next arena entry (last entry points to self)
  110. la_handle DW ? ; back link to handle table entry
  111. LocalArena ENDS
  112. la_fixedsize = la_handle ; Fixed arena headers stop here
  113. LA_MINBLOCKSIZE = la_fixedsize*4 ;*** This must be larger than LocalArenaFree
  114. ; free blocks have these extra items.
  115. la_size = la_handle ; size of block (includes header data)
  116. LocalArenaFree STRUC
  117. DB SIZE LocalArena DUP (?)
  118. la_free_prev DW ? ; previous free entry
  119. la_free_next DW ? ; next free entry
  120. LocalArenaFree ENDS
  121. la_freefixedsize = SIZE LocalArenaFree ; Free block header stops here
  122. ; Local arena objects are aligned on 4 byte boundaries, leaving the
  123. ; low order two bits always zero.
  124. LA_ALIGN = 4-1
  125. LA_MASK = NOT LA_ALIGN
  126. LA_FREE = 00h
  127. LA_BUSY = 01h ; Saved in la_prev field of header
  128. errnz <LA_ALIGN - LA_MOVEABLE - LA_BUSY>
  129. ; Flags passed to LocalAlloc (zero is the default case)
  130. LA_MOVEABLE EQU 02h ; Saved in la_prev field of header
  131. LA_NOCOMPACT EQU 10h
  132. LA_ZEROINIT EQU 40h
  133. LA_MODIFY EQU 80h
  134. ; Data structure that describes the local arena. Allocated as the first
  135. ; object in each local heap. _pLocalHeap is a reserved location each
  136. ; automatic data segment that contains the pointer to this structure.
  137. LocalInfo STRUC
  138. DB SIZE HeapInfo DUP (?)
  139. li_notify DD ? ; Far proc to call whenever a local block is moved
  140. li_lock DW ? ; arena lock word
  141. li_extra DW ? ; minimum amount to grow DS by
  142. li_minsize DW ? ; minimum size of heap
  143. li_sig DW ? ; signature for local heap
  144. LocalInfo ENDS
  145. ; Notify procedure message codes
  146. LN_OUTOFMEM = 0 ; Out of memory - arg1 = #bytes needed
  147. LN_MOVE = 1 ; Object moved - arg1 = handle arg2 = old location
  148. LN_DISCARD = 2 ; Object discard? - arg1 = handle, arg2 = discard flags
  149. ; Returns new discard flags in AX
  150. LocalStats STRUC
  151. ls_ljoin DW ? ; #calls to ljoin
  152. ls_falloc DW ? ; #calls to lalloc with forward search
  153. ls_fexamine DW ? ; #arena entries examined by ls_falloc calls
  154. ls_fcompact DW ? ; #calls to lcompact by ls_falloc calls
  155. ls_ffound DW ? ; #ls_falloc calls that found a block
  156. ls_ffoundne DW ? ; #ls_falloc calls that failed to find a block
  157. ls_malloc DW ? ; #calls to lalloc with backward search
  158. ls_mexamine DW ? ; #arena entries examined by ls_malloc calls
  159. ls_mcompact DW ? ; #calls to lcompact by ls_malloc calls
  160. ls_mfound DW ? ; #ls_malloc calls that found a block
  161. ls_mfoundne DW ? ; #ls_malloc calls that failed to find a block
  162. ls_fail DW ? ; #times lalloc failed because unable to grow DS
  163. ls_lcompact DW ? ; #calls to lcompact
  164. ls_cloop DW ? ; #repeated compacts after discarding
  165. ls_cexamine DW ? ; #entries examined in compaction loop
  166. ls_cfree DW ? ; #free entries examined in compaction loop
  167. ls_cmove DW ? ; #moveable entries moved by compaction
  168. LocalStats ENDS
  169. IncLocalStat MACRO n
  170. if KDEBUG
  171. inc ds:&n[di+SIZE LocalInfo]
  172. endif
  173. ENDM
  174. ; Global arena objects are kept in a doubly linked list.
  175. ;
  176. ifdef WOWJUNK
  177. GlobalArena STRUC
  178. ga_count DB ? ; lock count for movable segments
  179. ga_flags DB ? ; 1 byte available for flags
  180. ga_owner DW ? ; DOS 2.x 3.x owner field (current task)
  181. ga_size DW ? ; DOS 2.x 3.x size, in paragraphs, not incl. header
  182. ga_prev DW ? ; previous arena entry (first points to self)
  183. ga_next DW ? ; next arena entry (last points to self)
  184. ga_handle DW ? ; back link to handle table entry
  185. ga_lruprev DW ? ; Previous handle in lru chain
  186. ga_lrunext DW ? ; Next handle in lru chain
  187. GlobalArena ENDS
  188. else
  189. GlobalArena STRUC
  190. ga_count DB ? ; lock count for movable segments
  191. ga_owner DW ? ; DOS 2.x 3.x owner field (current task)
  192. ga_size DW ? ; DOS 2.x 3.x size, in paragraphs, not incl. header
  193. ga_flags DB ? ; 1 byte available for flags
  194. ga_prev DW ? ; previous arena entry (first points to self)
  195. ga_next DW ? ; next arena entry (last points to self)
  196. ga_handle DW ? ; back link to handle table entry
  197. ga_lruprev DW ? ; Previous handle in lru chain
  198. ga_lrunext DW ? ; Next handle in lru chain
  199. GlobalArena ENDS
  200. endif; WOW
  201. ga_sig = byte ptr ga_count ; DOS =< 3.x signature byte for fixed segs
  202. ga_freeprev = word ptr ga_lruprev ; links for free segs
  203. ga_freenext = word ptr ga_lrunext ; links for free segs
  204. if PMODE32
  205. DEFAULT_ARENA_SIZE equ 8000h ; Initial length of arena array
  206. ;
  207. ; 32 bit Protect Mode Arena
  208. ;
  209. GlobalArena32 STRUC
  210. pga_next DD ? ; next arena entry (last points to self)
  211. pga_prev DD ? ; previous arena entry (first points to self)
  212. pga_address DD ? ; 32 bit linear address of memory
  213. pga_size DD ? ; 32 bit size in bytes
  214. pga_handle DW ? ; back link to handle table entry
  215. pga_owner DW ? ; Owner field (current task)
  216. pga_count DB ? ; lock count for movable segments
  217. pga_pglock DB ? ; # times page locked
  218. pga_flags DB ? ; 1 word available for flags
  219. pga_selcount DB ? ; Number of selectors allocated
  220. pga_lruprev DD ? ; Previous entry in lru chain
  221. pga_lrunext DD ? ; Next entry in lru chain
  222. GlobalArena32 ENDS
  223. .ERRNZ 32-size GlobalArena32
  224. pga_sig = word ptr pga_count
  225. pga_freeprev = dword ptr pga_lruprev ; links for free segs
  226. pga_freenext = dword ptr pga_lrunext ; links for free segs
  227. endif ; PMODE32
  228. GA_SIGNATURE = 04Dh
  229. GA_ENDSIG = 05Ah
  230. ; there are many special kinds of blocks, marked in the owner word
  231. GA_SENTINAL = -1 ; a sentinal block
  232. GA_BOGUS_BLOCK = -7 ; a block temporary marked allocated
  233. GA_BURGERMASTER = -3 ; the master object
  234. GA_NOT_THERE = -4 ; used with EEMS to link out unallocatable
  235. ; memory such as the EGA etc.
  236. GA_PHANTOM = -5 ; A block that has no EMS banks banked in.
  237. GA_WRAITH = -6 ; A block used to hold up partition headers.
  238. ; Global arena objects are aligned on 2 para. boundaries, leaving the
  239. ; low order bit always zero.
  240. GA_ALIGN = 2-1
  241. GA_MASK = NOT GA_ALIGN
  242. GA_FIXED = 1
  243. ; It is specific to WOW only. This handle was generated by WIN32, ChandanC.
  244. GA_WOWHANDLE = 3
  245. errnz <GA_FIXED-GA_ALIGN>
  246. ; Low byte of flags passed to GlobalAlloc (zero is the default case)
  247. GA_ALLOCHIGH EQU 01h ; Flag to indicate allocate high
  248. GA_MOVEABLE EQU 02h
  249. GA_SEGTYPE EQU 0Ch ; These 2 bits stored in he_flags field
  250. GA_DGROUP EQU 04h
  251. GA_DISCCODE EQU 08h
  252. GA_NOCOMPACT EQU 10h
  253. GA_NODISCARD EQU 20h
  254. GA_ZEROINIT EQU 40h
  255. GA_MODIFY EQU 80h
  256. GA_NEWEXPANDED EQU 80h ; Use new EMS allocation scheme
  257. ; These flags for use by KERNEL only (caller's CS must match)
  258. GA_INTFLAGS = GA_ALLOCHIGH+GA_SEGTYPE or (GA_CODE_DATA+GA_ALLOC_DOS) shl 8
  259. ; High byte of flags remembered in handle table (he_flags field)
  260. GA_DISCARDABLE EQU 01h ; Boolean flag for global object, not a level.
  261. GA_CODE_DATA EQU 02h ; CODE or DATA seg that belongs to a task.
  262. ;GA_DGROUP EQU 04h
  263. ;GA_DISCCODE EQU 08h
  264. GA_ALLOC_LOW EQU 10h ; Alloc in Lower land, overrides GA_ALLOC_EMS
  265. GA_SHAREABLE EQU 20h ; Shareable object
  266. GA_DDESHARE EQU 20h ; A shared memory object used for DDE.
  267. ;HE_DISCARDED EQU 40h ; Marks objects that have been discarded.
  268. ;GAH_NOTIFY EQU 40h
  269. GA_ALLOC_DOS EQU 80h ; Alloc in DOS land if protected mode
  270. GA_USERFLAGS = GA_SHAREABLE + GA_DISCARDABLE
  271. ; Flags stored in the global arena header
  272. GAH_PHANTOM EQU 01h ; This block is either a phantom or a wraith
  273. GAH_DONT_GROW EQU 02h ; Don't grow this data segment.
  274. GAH_DGROUP EQU GA_DGROUP
  275. GAH_DISCCODE EQU GA_DISCCODE
  276. GAH_NOTIFY EQU 40h
  277. GAH_FIXED EQU 80h
  278. GAH_CURSORICON EQU 10h ; WOW uses this flag
  279. ;
  280. ; GAH_PHANTOM is unused in Win 3.0 and Win 3.1
  281. ; ChandanC
  282. ;
  283. GAH_WOWDDEFREEHANDLE EQU GAH_PHANTOM ; This is used to mark the DDE handle
  284. ;
  285. ; Global Memory Stats definitions
  286. ; Offsets in array
  287. ;
  288. cGLOBALALLOC EQU 0
  289. cGLOBALREALLOC EQU 4
  290. cGLOBALFREE EQU 8
  291. cGLOBALFREEALL EQU 12
  292. cGLOBALLOCK EQU 16
  293. cGLOBALUNLOCK EQU 20
  294. cGLOBALSIZE EQU 24
  295. cGLOBALCOMPACT EQU 28
  296. cLOCKSEGMENT EQU 32
  297. cUNLOCKSEGMENT EQU 36
  298. cGLOBALFIX EQU 40
  299. cGLOBALUNFIX EQU 44
  300. cGLOBALHANDLE EQU 48
  301. cGLOBALFLAGS EQU 52
  302. NGLOBALSTATS EQU (56/4)
  303. ; Data structure that describes the global arena. Allocated at the end
  304. ; of the local heap information structure. DO NOT CHANGE THE ORDER OF
  305. ; THE ENTRIES! The alt sequence and normal sequence must match!
  306. GlobalInfo STRUC
  307. DB SIZE HeapInfo DUP (?)
  308. gi_lrulock DW ? ; Lock out access to LRU chain from interrupt level
  309. ife PMODE32
  310. gi_lruchain DW ? ; First handle in lru chain (most recently used)
  311. else
  312. gi_lruchain DD ? ; First handle in lru chain (most recently used)
  313. endif
  314. gi_lrucount DW ? ; #entries in LRU chain
  315. ife PMODE32
  316. gi_reserve DW ? ; #paras to reserve for disc code, 0 => not enabled
  317. gi_disfence DW ? ; Fence for discardable code.
  318. else
  319. gi_reserve DD ? ; #paras to reserve for disc code, 0 => not enabled
  320. gi_disfence DD ? ; Fence for discardable code.
  321. endif
  322. gi_free_count DW ? ; Count of all the free partitions.
  323. gi_alt_first DW ? ; first entry in alternate arena
  324. gi_alt_last DW ? ; last entry in alternate arena
  325. gi_alt_count DW ? ; count of entries in alternate arena
  326. gi_alt_lruchain DW ? ; First handle in lru chain (most recently used)
  327. gi_alt_lrucount DW ? ; #entries in LRU chain
  328. gi_alt_reserve DW ? ; alternate reserve
  329. gi_alt_disfence DW ? ; Fence for discardable code.
  330. gi_alt_free_count DW ? ; Count of all the free partitions.
  331. gi_alt_pPhantom DW ? ; Pointer to the first pPhantom block.
  332. gi_disfence_hi DW ? ; High word of fence
  333. gi_flags DW ? ; some flags! !!! should merge with freeze and check
  334. gi_stats DD NGLOBALSTATS dup(?)
  335. GlobalInfo ENDS
  336. gi_cmpflags = byte ptr hi_dislevel ; Flags to control gcompact
  337. gi_disfence_lo = word ptr gi_disfence
  338. GIF_INT2 EQU 01h
  339. BOOT_COMPACT EQU 80h
  340. COMPACT_ALLOC EQU 40h ; Fast abort in gcompact for allocations
  341. CMP_FLAGS EQU GA_NODISCARD or GA_NOCOMPACT or GA_DISCCODE or COMPACT_ALLOC
  342. ; Notify procedure message codes
  343. GN_MOVE = 1 ; Object moved - arg1 = handle arg2 = old location
  344. GN_DISCARD = 2 ; Object discard? - arg1 = handle, arg2 = discard flags
  345. ; Returns new discard flags in AX
  346. SASTRUC STRUC
  347. sa_size dw 0 ; size, in bytes, of the alias list
  348. sa_allocated dw 0 ; number of allocated entries
  349. SASTRUC ENDS
  350. SAENTRY STRUC
  351. sae_sel dw 0 ; selector of the object
  352. sae_alias dw 0 ; alias of the object
  353. SAENTRY ENDS
  354. MAXFHCACHELEN = 12 ; Max number of file handles cached
  355. MINFHCACHELEN = 2 ; Min number of file handles cached
  356. fhCacheStruc struc
  357. Cachefh dw ? ; File handle
  358. CacheExe dw ? ; Exe handle
  359. fhCacheStruc ends
  360. ; NAMETBL is a structure defining a private resource called a name table.
  361. ; It is a resource that maps string resource types and names into unique
  362. ; ordinal ids - this way all resources identified by name or type with
  363. ; a string can actually be loaded by id. This is for OS/2 compatibility
  364. ; with named resources.
  365. ;
  366. ; typedef struct nametbl { /* ntbl */
  367. ; int cbEntry; /* size of structure */
  368. ; int idType; /* type id or string replc if (idType & RSORDID) */
  369. ; int idName; /* name id or string replc if (idName & RSORDID) */
  370. ; char achTypeName[1]; /* 0 term type followed by 0 term name */
  371. ; } NAMETBL;
  372. ntbl struc
  373. ntbl_cbEntry dw ?
  374. ntbl_idType dw ?
  375. ntbl_idName dw ?
  376. ntbl_achTypeName db ?
  377. ntbl ends
  378. RT_NAMETABLE equ 15
  379. ifdef WOW
  380. if PMODE32
  381. PAGE_READWRITE EQU 0004h
  382. MEM_COMMIT EQU 1000h
  383. MEM_RESERVE EQU 2000h
  384. MEM_RELEASE EQU 8000h
  385. MEM_COMMIT_RESERVE EQU 3000h
  386. endif
  387. endif
  388. ifdef WOW
  389. ife PMODE32
  390. DpmiBlock struc
  391. DBSize dw 0
  392. DBSel dw 0
  393. DBHandleLow dw 0
  394. DBHandleHigh dw 0
  395. DpmiBlock ends
  396. NUM_DPMI_BLOCKS equ 20
  397. endif
  398. endif
  399. ifdef WOW_x86
  400. FLAT_SEL equ 23H
  401. endif