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.

209 lines
7.8 KiB

  1. ;***************************************************************************
  2. ;* USERGDI2.ASM
  3. ;*
  4. ;* Assembly routines used in computing heap space remaining for
  5. ;* USER, GDI, and any other heaps.
  6. ;*
  7. ;***************************************************************************
  8. INCLUDE TOOLPRIV.INC
  9. SWAPPRO = 0
  10. PMODE32 = 0
  11. PMODE = 1
  12. INCLUDE WINKERN.INC
  13. INCLUDE NEWEXE.INC
  14. ;** This slimy thing is from GDIOBJ.INC and is subtracted from the
  15. ;** object type nunbers only in 3.1
  16. LT_GDI_BASE EQU ('G' or ('O' * 256)) - 1
  17. ;** External functions
  18. externNP HelperVerifyLocHeap
  19. externNP HelperHandleToSel
  20. ;** Functions
  21. sBegin CODE
  22. assumes CS,CODE
  23. assumes DS,DATA
  24. .286p
  25. ; UserGdiDGROUP
  26. ; Returns a handle to the DGROUP segment for a given module
  27. ;
  28. ; HANDLE UserGdiDGROUP(
  29. ; HANDLE hModule)
  30. cProc UserGdiDGROUP, <PUBLIC,NEAR>, <di,si>
  31. parmW hModule
  32. cBegin
  33. mov ax,hModule ;Get the handle
  34. cCall HelperHandleToSel, <ax> ;Convert to a selector
  35. mov es,ax ;Point with ES for this
  36. xor ax,ax ;Prepare to return NULL
  37. cmp es:[ne_magic],NEMAGIC ;Make sure we have a module database
  38. jnz UGD_End ;It isn't so get out
  39. mov bx,es:[ne_pautodata] ;Point to the segment table entry
  40. mov ax,es:[bx].ns_handle ;Get the handle from the table
  41. cCall HelperHandleToSel, <ax> ;Convert to a selector for return
  42. UGD_End:
  43. cEnd
  44. ; UserGdiSpace
  45. ; This function was stolen from KERNEL where it is used to compute
  46. ; the space remaining in the USER and GDI heaps. It actually works
  47. ; on any local heap.
  48. ;
  49. ; DWORD UserGdiSpace(
  50. ; HANDLE hData)
  51. ; HIWORD of return is maximum size of heap (64K less statics, etc.)
  52. ; LOWORD of return is space remaining on heap
  53. cProc UserGdiSpace, <PUBLIC,NEAR>, <di,si,ds>
  54. parmW hData
  55. cBegin
  56. ;** Count the free space in this heap. First: Is this heap valid?
  57. mov ax,hData ;Get the heap selector
  58. cCall HelperVerifyLocHeap ;Call the verify routine
  59. mov ax,0 ;In case we jump -- set error
  60. mov dx,0 ; Use MOV to not mess up carry
  61. jc UGS_Exit ;No valid local heap!!
  62. ;** Loop through all local blocks, adding free space
  63. cCall HelperHandleToSel, <hData> ;Convert to selector
  64. mov ds,ax ;Point to the segment
  65. mov di,ds:[6] ;Get pHeapInfo
  66. mov di,[di].hi_first ;First arena header
  67. mov di,[di].la_free_next ;First free block
  68. UGS_Loop:
  69. add ax,[di].la_size ;Add in size of this block
  70. sub ax,SIZE LocalArenaFree ;Less block overhead
  71. mov si,[di].la_free_next ;Get next free block
  72. or si,si ;NULL?
  73. jz UGS_Break ;Yes, say we're done
  74. cmp si,di ;Last block? (points to self)
  75. mov di,si ;Save for next time around
  76. jnz UGS_Loop ;Not last block so loop some more
  77. UGS_Break:
  78. ;** We have the size of the local heap
  79. mov si,ax ;Save the size
  80. mov cx,ds ;Get the selector in a non-segreg
  81. lsl ax,cx ;Get the size of the segment
  82. neg ax ;64K - segment size
  83. add ax,si ;Add in the free holes in the heap
  84. mov dx,-1 ;Compute the max size of heap
  85. sub dx,ds:[6] ; which is 64K less statics
  86. UGS_Exit:
  87. cEnd
  88. ; UserGdiType
  89. ;
  90. ; Tries to compute the type of local heap block if possible
  91. ; Prototype:
  92. ;
  93. ; void PASCAL UserGdiType(
  94. ; LOCALENTRY FAR *lpLocal)
  95. cProc UserGdiType, <PUBLIC,NEAR>, <si,di>
  96. parmD lpLocal
  97. cBegin
  98. ;** Get info from our static variables
  99. mov ax,_DATA ;Get the variables first
  100. mov ds,ax ;Point to our DS
  101. mov bx,hUserHeap ;BX=User's heap block
  102. mov cx,hGDIHeap ;CX=GDI's heap block
  103. ;** See if we can do anything with this heap
  104. les si,lpLocal ;Get a pointer to the structure
  105. mov es:[si].le_wType,LT_NORMAL ;In case we don't find anything
  106. mov ax,es:[si].le_hHeap ;Get the heap pointer
  107. cmp ax,bx ;User's heap?
  108. jnz UGT_10 ;Nope, try next
  109. cCall GetUserType ;Call routine to get user type
  110. jmp SHORT UGT_End ;Get out
  111. UGT_10: cmp ax,cx ;GDI's heap?
  112. jnz UGT_End ;Nope, can't do anything with it
  113. cCall GetGDIType ;Call routine to get GDI type
  114. UGT_End:
  115. cEnd
  116. ;** Internal helper functions
  117. ; GetUserType
  118. ;
  119. ; Uses the tags in debug USER.EXE to give information on what type
  120. ; block is pointed to by the current LOCALENTRY structure.
  121. ; Caller: ES:SI points to the parameter LOCALENTRY structure
  122. ; Return: LOCALENTRY structure is correctly updated
  123. cProc GetUserType, <NEAR>
  124. cBegin
  125. ;** Make sure we have a function to call
  126. cmp WORD PTR lpfnGetUserLocalObjType + 2,0 ;Selector zero?
  127. je GUT_End ;Yes
  128. ;** Call USER to get the type
  129. push es ;Save ES
  130. mov bx,es:[si].le_wAddress ;Get the block address
  131. sub bx, la_fixedsize ;The USER call needs the arena header
  132. test es:[si].le_wFlags, LF_MOVEABLE ;Moveable block?
  133. jz @F ;No
  134. sub bx, (SIZE LocalArena) - la_fixedsize ;Moveable arena bigger
  135. @@: push bx ;Parameter arena handle
  136. call DWORD PTR lpfnGetUserLocalObjType ;Call the function
  137. pop es
  138. xor ah,ah ;Clear the upper byte
  139. mov es:[si].le_wType,ax ;Save the type
  140. GUT_End:
  141. cEnd
  142. ; GetGDIType
  143. ;
  144. ; Uses the tags in debug GDI.EXE to give information on what type
  145. ; block is pointed to by the current LOCALENTRY structure.
  146. ; Caller: ES:SI points to the parameter LOCALENTRY structure
  147. ; Return: LOCALENTRY structure is correctly updated
  148. cProc GetGDIType, <NEAR>, <ds>
  149. cBegin
  150. ;** All fixed blocks are unknown to us
  151. test es:[si].le_wFlags,LF_FIXED ;Is it fixed?
  152. jz GGT_10 ;Nope
  153. jmp SHORT GGT_End ;Yes, get out
  154. GGT_10:
  155. ;** Prepare to find the type
  156. cCall HelperHandleToSel,es:[si].le_hHeap ;Get the selector value
  157. mov cx,wTHFlags ;Save for when we trash DS
  158. mov ds,ax ;Get the heap pointer
  159. mov di,es:[si].le_wAddress ;Get the block pointer
  160. ;** Get the type word
  161. mov ax,[di+2] ;Get the type word from the heap
  162. and ax,05fffh ;Mask out the stock object flag
  163. test cx,TH_WIN30 ;In 3.0?
  164. jnz CGT_Win30 ;Yes
  165. sub ax,LT_GDI_BASE ;No, subtract type tag base
  166. CGT_Win30:
  167. cmp ax,LT_GDI_MAX ;Recognizable type code?
  168. ja GGT_End ;No, get out
  169. mov es:[si].le_wType,ax ;Save in the structure
  170. GGT_End:
  171. cEnd
  172. sEnd
  173. END