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.

384 lines
9.1 KiB

  1. page ,132
  2. ;-----------------------------Module-Header-----------------------------;
  3. ; Module Name: PAGELOCK
  4. ;
  5. ; This module contains functions for page locking memory using DPMI
  6. ;
  7. ; Created: 03-20-90
  8. ; Author: Todd Laney [ToddLa]
  9. ;
  10. ; Copyright (c) 1984-1990 Microsoft Corporation
  11. ;
  12. ; Exported Functions: none
  13. ;
  14. ; Public Functions: DpmiPageLock
  15. ; DpmiPageUnlock
  16. ;
  17. ; Public Data: none
  18. ;
  19. ; General Description:
  20. ;
  21. ; Restrictions:
  22. ;
  23. ;-----------------------------------------------------------------------;
  24. ?PLM = 1
  25. ?WIN = 0
  26. ?NODATA = 1
  27. .286
  28. .xlist
  29. include cmacros.inc
  30. include int31.inc
  31. .list
  32. externA __AHINCR ; KERNEL
  33. externFP GlobalHandle ; KERNEL
  34. externFP GlobalHandleNoRip ; KERNEL
  35. externFP GlobalFix ; KERNEL
  36. externFP GlobalUnFix ; KERNEL
  37. ifndef SEGNAME
  38. SEGNAME equ <_TEXT>
  39. endif
  40. createSeg %SEGNAME, CodeSeg, word, public, CODE
  41. Int31_SelMgt_Get_Base EQU ((Int31_Sel_Mgt shl 8) + SelMgt_Get_Base )
  42. Int31_Lock_Region EQU ((Int31_Page_Lock shl 8) + Lock_Region )
  43. Int31_Unlock_Region EQU ((Int31_Page_Lock shl 8) + Unlock_Region )
  44. ; The following structure should be used to access high and low
  45. ; words of a DWORD. This means that "word ptr foo[2]" -> "foo.hi".
  46. LONG struc
  47. lo dw ?
  48. hi dw ?
  49. LONG ends
  50. FARPOINTER struc
  51. off dw ?
  52. sel dw ?
  53. FARPOINTER ends
  54. sBegin CodeSeg
  55. assumes cs,CodeSeg
  56. assumes ds,nothing
  57. assumes es,nothing
  58. ;---------------------------Public-Routine------------------------------;
  59. ; DpmiPageLock
  60. ;
  61. ; page lock a region using DPMI
  62. ;
  63. ; Entry:
  64. ; lpBase Selector:offset of base of region to lock
  65. ; dwSize size in bytes of region to lock
  66. ;
  67. ; Returns:
  68. ; NZ
  69. ; AX = TRUE if successful
  70. ;
  71. ; Error Returns:
  72. ; Z
  73. ; AX = FALSE if error
  74. ;
  75. ; Registers Preserved:
  76. ; BP,DS,SI,DI
  77. ; Registers Destroyed:
  78. ; AX,BX,CX,DX,FLAGS
  79. ; Calls:
  80. ; INT 31h
  81. ; History:
  82. ;
  83. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  84. ; Created.
  85. ;-----------------------------------------------------------------------;
  86. assumes ds,nothing
  87. assumes es,nothing
  88. cProc DpmiPageLock, <NEAR>, <>
  89. ; parmD lpBase
  90. ; parmD dwSize
  91. cBegin nogen
  92. mov cx,Int31_Lock_Region
  93. jmp short DpmiPageLockUnLock
  94. cEnd nogen
  95. ;---------------------------Public-Routine------------------------------;
  96. ; DpmiPageUnlock
  97. ;
  98. ; un-page lock a region using DPMI
  99. ;
  100. ; Entry:
  101. ; lpBase Selector:offset of base of region to unlock
  102. ; dwSize size in bytes of region to unlock
  103. ;
  104. ; Returns:
  105. ; NZ
  106. ; AX = TRUE if successful
  107. ;
  108. ; Error Returns:
  109. ; Z
  110. ; AX = FALSE if error
  111. ;
  112. ; Registers Preserved:
  113. ; BP,DS,SI,DI
  114. ; Registers Destroyed:
  115. ; AX,BX,CX,DX,FLAGS
  116. ; Calls:
  117. ; INT 31h
  118. ; History:
  119. ;
  120. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  121. ; Created.
  122. ;-----------------------------------------------------------------------;
  123. assumes ds,nothing
  124. assumes es,nothing
  125. cProc DpmiPageUnlock, <NEAR>, <>
  126. ; parmD lpBase
  127. ; parmD dwSize
  128. cBegin nogen
  129. mov cx,Int31_Unlock_Region
  130. errn$ DpmiPageLockUnLock
  131. cEnd nogen
  132. cProc DpmiPageLockUnLock, <NEAR>, <si,di>
  133. parmD lpBase
  134. parmD dwSize
  135. cBegin
  136. mov si,cx ; save lock/unlock flag
  137. mov ax,Int31_SelMgt_Get_Base
  138. mov bx,lpBase.sel
  139. int 31h ; returns CX:DX selector base
  140. jc dpl_exit
  141. mov bx,cx ; BX:CX is base
  142. mov cx,dx
  143. add cx,lpBase.off ; add offset into selector base
  144. adc bx,0
  145. mov ax,si ; get lock/unlock flag
  146. mov si,dwSize.hi ; SI:DI length
  147. mov di,dwSize.lo
  148. int 31h ; lock or unlock it
  149. dpl_exit:
  150. cmc ; set carry iff success
  151. sbb ax,ax ; return TRUE/FALSE
  152. cEnd
  153. ;---------------------------Public-Routine------------------------------;
  154. ; HugePageLock
  155. ;
  156. ; page lock a range of windows allocated memory
  157. ;
  158. ; Entry:
  159. ; lpBase Selector:offset of base of region to lock
  160. ; dwSize size in bytes of region to lock
  161. ;
  162. ; Returns:
  163. ; AX = TRUE if successful
  164. ;
  165. ; Error Returns:
  166. ; AX = FALSE if error
  167. ;
  168. ; Registers Preserved:
  169. ; BP,DS,SI,DI
  170. ; Registers Destroyed:
  171. ; AX,BX,CX,DX,FLAGS
  172. ; Calls:
  173. ; INT 31h
  174. ; History:
  175. ;
  176. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  177. ; Created.
  178. ;-----------------------------------------------------------------------;
  179. assumes ds,nothing
  180. assumes es,nothing
  181. cProc HugePageLock, <FAR, PUBLIC>, <>
  182. parmD lpBase
  183. parmD dwSize
  184. cBegin
  185. mov ax,lpBase.sel ; NULL pointer, invalid
  186. or ax,ax
  187. jz GPageLock_Exit
  188. call HugeGlobalFix ; fix the memory, then page lock
  189. cCall DpmiPageLock,<lpBase, dwSize>
  190. jnz GPageLock_Exit
  191. mov ax,lpBase.sel ; page lock failed, un-fix
  192. call HugeGlobalUnFix ; and return failure
  193. xor ax,ax
  194. GPageLock_Exit:
  195. cEnd
  196. ;---------------------------Public-Routine------------------------------;
  197. ; HugePageUnlock
  198. ;
  199. ; un-page lock a range of windows alocated memory, (locked with HugePageLock)
  200. ;
  201. ; Entry:
  202. ; lpBase Selector:offset of base of region to lock
  203. ; dwSize size in bytes of region to lock
  204. ;
  205. ; Returns:
  206. ; none
  207. ;
  208. ; Registers Preserved:
  209. ; BP,DS,SI,DI
  210. ; Registers Destroyed:
  211. ; AX,BX,CX,DX,FLAGS
  212. ; Calls:
  213. ; INT 31h
  214. ; History:
  215. ;
  216. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  217. ; Created.
  218. ;-----------------------------------------------------------------------;
  219. assumes ds,nothing
  220. assumes es,nothing
  221. cProc HugePageUnlock, <FAR, PUBLIC>, <>
  222. parmD lpBase
  223. parmD dwSize
  224. cBegin
  225. cCall DpmiPageUnlock,<lpBase, dwSize>
  226. mov ax,lpBase.sel
  227. call HugeGlobalUnFix
  228. cEnd
  229. ;---------------------------Public-Routine------------------------------;
  230. ; HugeGlobalFix
  231. ;
  232. ; fix the global object that represents the passed selector
  233. ;
  234. ; Entry:
  235. ; AX = SELECTOR
  236. ;
  237. ; Returns:
  238. ; none
  239. ;
  240. ; Registers Preserved:
  241. ; BP,DS,SI,DI
  242. ; Registers Destroyed:
  243. ; AX,BX,CX,DX,FLAGS
  244. ; Calls:
  245. ; GlobalFix
  246. ; HugeGlobalHandle
  247. ; History:
  248. ;
  249. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  250. ; Created.
  251. ;-----------------------------------------------------------------------;
  252. assumes ds,nothing
  253. assumes es,nothing
  254. HugeGlobalFix proc near
  255. call HugeGlobalHandle
  256. jz HugeGlobalFixExit
  257. cCall GlobalFix,<ax>
  258. HugeGlobalFixExit:
  259. ret
  260. HugeGlobalFix endp
  261. ;---------------------------Public-Routine------------------------------;
  262. ; HugeGlobalUnFix
  263. ;
  264. ; un-fix the global object that represents the passed selector
  265. ;
  266. ; Entry:
  267. ; AX = SELECTOR
  268. ;
  269. ; Returns:
  270. ; none
  271. ;
  272. ; Registers Preserved:
  273. ; BP,DS,SI,DI
  274. ; Registers Destroyed:
  275. ; AX,BX,CX,DX,FLAGS
  276. ; Calls:
  277. ; HugeGlobalHandle
  278. ; GlobalUnFix
  279. ; History:
  280. ;
  281. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  282. ; Created.
  283. ;-----------------------------------------------------------------------;
  284. assumes ds,nothing
  285. assumes es,nothing
  286. HugeGlobalUnFix proc near
  287. call HugeGlobalHandle
  288. jz HugeGlobalUnFixExit
  289. cCall GlobalUnFix,<ax>
  290. HugeGlobalUnFixExit:
  291. ret
  292. HugeGlobalUnFix endp
  293. ;---------------------------Public-Routine------------------------------;
  294. ; HugeGlobalHandle
  295. ;
  296. ; Entry:
  297. ; AX = SELECTOR to global object
  298. ;
  299. ; Returns:
  300. ; NZ
  301. ; AX = HANDLE of global object
  302. ;
  303. ; Error Returns:
  304. ; Z
  305. ; AX = 0 if error
  306. ;
  307. ; Registers Preserved:
  308. ; BP,DS,SI,DI
  309. ; Registers Destroyed:
  310. ; AX,BX,CX,DX,FLAGS
  311. ; Calls:
  312. ; GlobalHandleNoRip
  313. ; History:
  314. ;
  315. ; Wed 04-Jan-1990 13:45:58 -by- Todd Laney [ToddLa]
  316. ; Created.
  317. ;-----------------------------------------------------------------------;
  318. assumes ds,nothing
  319. assumes es,nothing
  320. HugeGlobalHandle proc near
  321. push si
  322. mov si,ax
  323. or ax,ax ; test for NULL pointer!
  324. jz HugeGlobalHandleExit
  325. HugeGlobalHandleAgain:
  326. cCall GlobalHandleNoRip,<si>
  327. sub si,__AHINCR
  328. or ax,ax
  329. jz HugeGlobalHandleAgain
  330. HugeGlobalHandleExit:
  331. pop si
  332. ret
  333. HugeGlobalHandle endp
  334. sEnd
  335. end