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.

274 lines
6.9 KiB

  1. TITLE HANDLE - Handle Table Manager
  2. include kernel.inc
  3. ; This code assumes the following conditions
  4. ;
  5. errnz <lhe_address>
  6. DataBegin
  7. ;externW <pGlobalHeap,hGlobalHeap>
  8. DataEnd
  9. sBegin CODE
  10. assumes CS,CODE
  11. ; These are all of the internal subroutines defined in this source file.
  12. ;
  13. ; PUBLIC halloc, lhdref, henum
  14. ;-----------------------------------------------------------------------;
  15. ; halloc ;
  16. ; ;
  17. ; Allocates a local handle for a block. ;
  18. ; ;
  19. ; Arguments: ;
  20. ; AX = block that needs a handle ;
  21. ; DS:DI = address of local arena infomation structure ;
  22. ; ;
  23. ; Returns: ;
  24. ; AX,BX,CX = handle for that block ;
  25. ; DX preserved ;
  26. ; ;
  27. ; Error Returns: ;
  28. ; AX = 0 if no handles available ;
  29. ; DX = original AX ;
  30. ; ;
  31. ; Registers Preserved: ;
  32. ; DI,SI,DS,ES ;
  33. ; ;
  34. ; Registers Destroyed: ;
  35. ; ;
  36. ; Calls: ;
  37. ; nothing ;
  38. ; ;
  39. ; History: ;
  40. ; ;
  41. ; Wed Oct 01, 1986 05:44:44p -by- David N. Weise [davidw] ;
  42. ; Added this nifty comment block. ;
  43. ;-----------------------------------------------------------------------;
  44. cProc halloc,<PUBLIC,NEAR>
  45. cBegin nogen
  46. mov bx,[di].hi_hfree
  47. or bx,bx
  48. jnz have_a_handle
  49. push ax
  50. push dx
  51. mov cx,[di].hi_hdelta
  52. jcxz hafail
  53. push si
  54. push es
  55. call [di].hi_hexpand
  56. pop es
  57. pop si
  58. jcxz hafail
  59. mov bx,ax
  60. pop dx
  61. pop ax
  62. have_a_handle:
  63. xor cx,cx
  64. errnz <lhe_flags - he_flags>
  65. mov word ptr [bx].lhe_flags,cx ; Zero lock count and flags
  66. errnz <lhe_count-lhe_flags-1>
  67. errnz <lhe_link - he_link>
  68. xchg [bx].lhe_link,ax ; Remove handle from head of chain
  69. errnz <lhe_address-lhe_link> ; and store true address of object
  70. mov [di].hi_hfree,ax ; Update head of handle free list
  71. mov ax,bx ; Return handle to caller
  72. mov cx,ax
  73. ret
  74. hafail:
  75. xor ax,ax
  76. pop dx ; Flush stack
  77. pop dx ; Return original AX in DX
  78. ret ; return error
  79. cEnd nogen
  80. ;-----------------------------------------------------------------------;
  81. ; lhfree ;
  82. ; ;
  83. ; Frees the given local handle and returns a handle to the freelist. ;
  84. ; ;
  85. ; Arguments: ;
  86. ; SI = handle to free ;
  87. ; ;
  88. ; Returns: ;
  89. ; AX = 0 if valid handle ;
  90. ; ;
  91. ; Error Returns: ;
  92. ; AX = -1 if handle already free ;
  93. ; ;
  94. ; Registers Preserved: ;
  95. ; ;
  96. ; Registers Destroyed: ;
  97. ; ;
  98. ; Calls: ;
  99. ; nothing ;
  100. ; ;
  101. ; History: ;
  102. ; ;
  103. ; Tue Oct 14, 1986 04:14:25p -by- David N. Weise [davidw] ;
  104. ; Added this nifty comment block. ;
  105. ;-----------------------------------------------------------------------;
  106. cProc lhfree,<PUBLIC,NEAR>
  107. cBegin nogen
  108. or si,si ; Ignore zero handles
  109. jz hf1
  110. mov ax,HE_FREEHANDLE ; Mark handle as free
  111. xchg word ptr [si].lhe_flags,ax
  112. errnz <2-lhe_flags>
  113. inc ax ; Already free?
  114. jz hf2 ; Yes, return error
  115. errnz <1+HE_FREEHANDLE>
  116. mov ax,si ; Push handle on head of freelist
  117. xchg [di].hi_hfree,ax
  118. mov [si].lhe_link,ax
  119. hf1:
  120. xor ax,ax ; Return zero
  121. ret
  122. hf2:
  123. dec ax
  124. ret
  125. cEnd nogen
  126. ;-----------------------------------------------------------------------;
  127. ; lhdref ;
  128. ; ;
  129. ; Dereferences a local handle. ;
  130. ; ;
  131. ; Arguments: ;
  132. ; SI = handle ;
  133. ; ;
  134. ; Returns: ;
  135. ; AX = address of client data or zero for discarded objects ;
  136. ; CH = lock count ;
  137. ; CL = zero or LHE_DISCARDED flag ;
  138. ; ZF = 1 AX = 0 and CL != 0 ;
  139. ; ;
  140. ; Error Returns: ;
  141. ; ;
  142. ; Registers Preserved: ;
  143. ; ;
  144. ; Registers Destroyed: ;
  145. ; ;
  146. ; Calls: ;
  147. ; nothing ;
  148. ; ;
  149. ; History: ;
  150. ; ;
  151. ; Tue Oct 14, 1986 04:16:49p -by- David N. Weise [davidw] ;
  152. ; Added this nifty comment block. ;
  153. ;-----------------------------------------------------------------------;
  154. cProc lhdref,<PUBLIC,NEAR>
  155. cBegin nogen
  156. xor ax,ax
  157. mov cx,word ptr [si].lhe_flags
  158. errnz <2-lhe_flags>
  159. errnz <3-lhe_count>
  160. inc cx
  161. jz lhdref1
  162. errnz <1+LHE_FREEHANDLE>
  163. dec cx
  164. and cl,LHE_DISCARDED
  165. jnz lhdref1
  166. mov ax,[si].lhe_address
  167. lhdref1:
  168. or ax,ax
  169. ret
  170. cEnd nogen
  171. ;-----------------------------------------------------------------------;
  172. ; henum ;
  173. ; ;
  174. ; Enumerates the allocated handles in the local handle table with the ;
  175. ; specified discard level. ;
  176. ; ;
  177. ; Arguments: ;
  178. ; SI = zero first time called. Otherwise contains a pointer ;
  179. ; to the last handle returned. ;
  180. ; CX = #handles remaining. Zero first time called. ;
  181. ; DI = address of local arena information structure. ;
  182. ; ;
  183. ; Returns: ;
  184. ; SI = address of handle table entry ;
  185. ; CX = #handles remaining, including the one returned. ;
  186. ; ZF = 1 if SI = 0 and no more handle table entries. ;
  187. ; ;
  188. ; Error Returns: ;
  189. ; ;
  190. ; Registers Preserved: ;
  191. ; ;
  192. ; Registers Destroyed: ;
  193. ; AX ;
  194. ; ;
  195. ; Calls: ;
  196. ; nothing ;
  197. ; ;
  198. ; History: ;
  199. ; ;
  200. ; Tue Oct 14, 1986 04:19:15p -by- David N. Weise [davidw] ;
  201. ; Added this nifty comment block. ;
  202. ;-----------------------------------------------------------------------;
  203. cProc henum,<PUBLIC,NEAR>
  204. cBegin nogen
  205. or si,si ; Beginning of enumeration?
  206. jnz lcdhenext ; No, return next handle
  207. mov ax,[di].hi_htable ; Yes, start with last handle table block
  208. lcdhtloop:
  209. mov si,ax ; SI = address of handle table block
  210. or si,si ; Any more handle table blocks?
  211. jz lcdheall ; No, return zero
  212. lodsw ; Get # handles in this block
  213. errnz ht_count
  214. mov cx,ax ; into CX
  215. lcdheloop: ; Loop to process each handle table entry
  216. mov ax,word ptr [si].lhe_flags
  217. errnz <lhe_flags - he_flags>
  218. errnz <2-lhe_flags>
  219. errnz <3-lhe_count>
  220. inc ax ; Free handle?
  221. jz lcdhenext ; Yes, skip this handle
  222. errnz <1+LHE_FREEHANDLE>
  223. errnz <LHE_FREEHANDLE - HE_FREEHANDLE >
  224. dec ax
  225. cmp [di].hi_dislevel,0 ; Enumerating all allocated handles?
  226. je lcdheall ; Yes, return this handle
  227. test al,LHE_DISCARDED ; No, handle already discarded?
  228. jnz lcdhenext ; Yes, skip this handle
  229. and al,LHE_DISCARDABLE ; Test if DISCARDABLE
  230. cmp [di].hi_dislevel,al ; at the current discard level
  231. jne lcdhenext ; No, skip this handle
  232. or ah,ah ; Is handle locked?
  233. jnz lcdhenext ; Yes, skip this handle
  234. lcdheall:
  235. or si,si ; No, then return handle to caller
  236. ret ; with Z flag clear
  237. lcdhenext:
  238. lea si,[si].SIZE LocalHandleEntry ; Point to next handle table entry
  239. errnz <LocalHandleEntry - HandleEntry>
  240. loop lcdheloop ; Process next handle table entry
  241. lodsw ; end of this block, go to next
  242. jmp lcdhtloop
  243. cEnd nogen
  244. sEnd CODE
  245. end