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.

200 lines
8.0 KiB

  1. ; HGROUP.INC
  2. ;
  3. ; WARNING: This file contains structures used by both 16-bit and 32-bit code.
  4. ; Make sure the structures align the same in both!
  5. ;
  6. ; These structures support *handle groups*. Handle groups are global
  7. ; memory blocks that are ganged together so than when one gets freed,
  8. ; all get freed automatically. This solves the problems of cleanup when
  9. ; a Win32 thunk has to copy a shared block (for say DDE or clipboard)
  10. ; to repack a structure or move data into a shared heap. Figuring out
  11. ; when to free these intermediate copies is a nightmare (especially for DDE).
  12. ; Since the copy and the original are one "virtual block", a better solution
  13. ; is to put them in a handle group. Then all copies get cleaned
  14. ; up automatically.
  15. ;
  16. ; A "global block" is either a Win16 global memory block or a native
  17. ; Win32 global memory block. Blocks of different types can and do mix in the
  18. ; same group. Groups are disjoint.
  19. ;
  20. ; No attempt is made to keep the blocks in a group consistent. Win32
  21. ; apps cannot assume that DDE blocks represent shared memory. These blocks
  22. ; are used for short term, one way, read-only data transfer.
  23. ;
  24. ; If any member of a group is freed by an app (or dll), the memory
  25. ; managers nuke the entire group and free all of its members (due
  26. ; to implementation reasons, Win32 handles may not be freed till
  27. ; later. However, the group itself will disappear.)
  28. ;
  29. ; A block can also defect from a group. Blocks defect if they're cleaned
  30. ; up as a result of process termination. Since such a cleanup is probably
  31. ; unintentional and an abornal event, we prefer the memory leak to
  32. ; causing other apps to crash. Defections don't affect any other member
  33. ; of the group.
  34. ;
  35. ;
  36. ;
  37. ; For example, suppose a 32-bit DDE server posts a WM_DDE_DATA message.
  38. ; The DDE thunk gets a native Win32 handle that can't be used out of context.
  39. ;
  40. ; The DDE thunk gamely creates a Win16 copy of the block, creates a
  41. ; new group and puts the copy and original in the group. Then it sends
  42. ; the Win16 copy to the client. Both blocks (and the group) will get
  43. ; cleaned up when either the server or the client frees his block. Neither
  44. ; the thunk nor the group manager cares which way it happens.
  45. ;
  46. ; The DDE thunk can also do this to repack a structure. It can make
  47. ; a repacked copy and gang it to the original. All group members act
  48. ; as a single "virtual handle" which is what an app would expect to see
  49. ; in Win3.1.
  50. ;
  51. ;-------------------------------------------------------------------------
  52. ; This structure contains the global variables (in K16) used by the group
  53. ; manager. These globals are locked in linear memory since they're used
  54. ; by K32 as well. They're packaged in a structure to simplify commmunication
  55. ; between the two kernels.
  56. ;
  57. ; Access to this structure is synchronized by Win16Lock.
  58. ;
  59. ;
  60. ; hg_wSelHeap:
  61. ; Contains the *selector* of a movable Win16 global block which is an
  62. ; array of HG_NODE structs. Every element is on exactly one of three
  63. ; linked lists: the handle list, the death list and the free list.
  64. ;
  65. ; Initial value: 0. Lazily initialized.
  66. ;
  67. ; hg_wHndList:
  68. ; 16-bit offset into wSelHeap of the first node in the handle list (-1
  69. ; if empty). Each node represents a Win32 or Win16 handle that is part
  70. ; of some existing group. The list is not sorted in any way.
  71. ;
  72. ; For implementation reasons, NULL handles can appear on this list for
  73. ; short times (*)
  74. ;
  75. ; Initial value: -1.
  76. ;
  77. ;
  78. ; hg_wDeathList:
  79. ; 16-bit offset into wSelHeap of the first node in the death list (-1
  80. ; if empty). Each node represents a Win32 handle who is logically
  81. ; dead becaues their groups got nuked. The Win32 heap manager walks this
  82. ; list periodically and frees the handles. To keep innocent apps from
  83. ; paying a performance penalty, we set the TDBF_HGCLEANUP flag in
  84. ; the hTask iff the death list contains any handles with that hTask.
  85. ;
  86. ; DeathList handles do not have group id's. Their group has already gone.
  87. ;
  88. ; Initial value: -1.
  89. ;
  90. ; hg_wFreeList:
  91. ; 16-bit offset into wSelHeap of the first node in the free list (-1
  92. ; if empty). Basically, all nodes that aren't being used for some other
  93. ; purpose.
  94. ;
  95. ;
  96. ; hg_wDontTouch:
  97. ; normally 0. Set to 1 by certain routines to tell GlobalFree
  98. ; not to examine or modify the HG database. Used to prevent
  99. ; unwanted recursion when destroying groups. This flag is always set
  100. ; and reset within a single Win16 lock session.
  101. ;
  102. ;
  103. ; hg_wDeadGroup:
  104. ; used for communication between free_object and GlobalFree. free_object
  105. ; sets this global to the hgroup of the dying handle (unless
  106. ; hg_wDontTouch is set.) GlobalFree uses this to nuke the group
  107. ; and all its other members.
  108. ;
  109. ;
  110. ; (*) Why do NULL handles appear in the handle list? Because nodes need to
  111. ; defect from their group when they get freed since we can't have
  112. ; invalid handles in the database. But we can't always unlink the node
  113. ; at that time since it may be a group leader. So we null out its
  114. ; handle but leave the node intact to serve as a group leader.
  115. ;
  116. ; GrowHGHeap runs a garbage collector that goes and cleans up
  117. ; old groups that have no real handles left (BUGBUG: Not yet.)
  118. ;
  119. ;
  120. ; MAINTENANCE WARNING: If you change this structure, you have to build
  121. ; both k16 and k32 again. Also, you must ensure that all fields align
  122. ; identically in both 32-bit and 16-bit code.
  123. ;
  124. ; THIS STRUCTURE IS PROTECTED BY THE crstGHeap16Lock, *not* the
  125. ; Win16Mutex! Beware!
  126. ;
  127. ;------------------------------------------------------------------------
  128. HG_GLOBALS STRUCT
  129. hg_wSelHeap dw 0
  130. hg_wHndList dw -1 ;Offset into wSelHeap
  131. hg_wDeathList dw -1 ;Offset into wSelHeap
  132. hg_wFreeList dw -1 ;Offset into wSelHeap
  133. hg_wSlotCnt dw 0 ;# of HG_NODE slots in hg_wSelHeap
  134. hg_wDontTouch dw 0 ;Special use: see above
  135. hg_wDeadGroup dw -1 ;Special use: see above
  136. HG_GLOBALS ENDS
  137. ;------------------------------------------------------------------------
  138. ; This structure represents nodes in the group manager's database.
  139. ; Each node lives on one of three linked lists: the handle list, the
  140. ; death list, and the free list.
  141. ;
  142. ; hgn_wNext: Next node in list (as 16-bit offset into hg_wSelHeap).
  143. ;
  144. ; hgn_wGroup: Handle-list nodes only: the group id. The group id
  145. ; is the address (16-bit offset into hg_wSelHeap) of
  146. ; a designated group member (called the group leader).
  147. ; All members of a group must use the same group leader.
  148. ;
  149. ; hgn_hTask16: Win32 handle-list and death-list nodes only: the
  150. ; hTask of the Win32 process that created the handle.
  151. ; Set to 0 for Win16 handles.
  152. ; Native handles are private to each process so they can
  153. ; be disambiguated only by using hTask16.
  154. ;
  155. ; hgn_wChkMk: Private field used by CheckHGHeap.
  156. ;
  157. ; hgn_dwHnd: Handle-list and death-list nodes only: the heap handle
  158. ; (either Win32, or a zero-extended Win16 handle).
  159. ; Death-list nodes can only contain native handles here.
  160. ;
  161. ; hgn_Flags: Flag bits
  162. ;
  163. ;
  164. ; MAINTENANCE WARNING: If you change this structure, you have to build
  165. ; both k16 and k32 again. Also, you must ensure that all fields align
  166. ; identically in both 32-bit and 16-bit code. You must also change
  167. ; SCALE_BY_SIZEOF_HGNODE to reflect any size changes.
  168. ;
  169. ; THIS STRUCTURE IS PROTECTED BY THE crstGHeap16Lock, *not* the
  170. ; Win16Mutex! Beware!
  171. ;
  172. ;
  173. ;------------------------------------------------------------------------
  174. HG_NODE STRUCT
  175. hgn_wNext dw 0 ;Next HG_NODE (offset into wSelHeap)
  176. hgn_wGroup dw 0 ;Group leader (offset into wSelHeap)
  177. hgn_hTask16 dw 0 ;Context of native Win32 handle
  178. hgn_wChkMk dw 0 ;For CheckHGHeap's private use.
  179. hgn_dwHnd dd 0 ;Win32 handle or 0-extended Win16 handle
  180. hgn_Flags dd 0 ;Padding
  181. HG_NODE ENDS
  182. HGF_CANONICAL equ 00000001h ;This handle is a canonical DDE_EXECUTE handle
  183. HGF_BLOWITAWAY equ 00000002h ;Used by HGGarbageCollect
  184. SCALE_BY_SIZEOF_HGNODE macro reg
  185. shl reg,4
  186. endm