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.

278 lines
6.4 KiB

  1. page ,132
  2. ;-----------------------------Module-Header-----------------------------;
  3. ; Module Name: HEAP.ASM
  4. ;
  5. ; This module contains functions for dealing with external local heaps
  6. ;
  7. ; Created: 09-20-90
  8. ; Author: Todd Laney [ToddLa]
  9. ;
  10. ; Copyright (c) 1984-1990 Microsoft Corporation
  11. ;
  12. ; Exported Functions: none
  13. ;
  14. ; Public Functions: HeapCreate
  15. ; HeapDestroy
  16. ; HeapAlloc
  17. ; HeapFree
  18. ;
  19. ; Public Data: none
  20. ;
  21. ; General Description:
  22. ;
  23. ; Restrictions:
  24. ;
  25. ;-----------------------------------------------------------------------;
  26. ?PLM = 1
  27. ?WIN = 0
  28. ?NODATA = 1
  29. .286p
  30. .xlist
  31. include cmacros.inc
  32. include windows.inc
  33. .list
  34. MIN_HEAPSIZE = 128
  35. GMEM_SHARE = GMEM_DDESHARE
  36. externFP LocalInit ; in KERNEL
  37. externFP LocalAlloc ; in KERNEL
  38. externFP LocalReAlloc ; in KERNEL
  39. externFP LocalFree ; in KERNEL
  40. externFP LocalCompact ; in KERNEL
  41. externFP GlobalAlloc ; in KERNEL
  42. externFP GlobalLock ; in KERNEL
  43. externFP GlobalUnlock ; in KERNEL
  44. externFP GlobalFree ; in KERNEL
  45. ; The following structure should be used to access high and low
  46. ; words of a DWORD. This means that "word ptr foo[2]" -> "foo.hi".
  47. LONG struc
  48. lo dw ?
  49. hi dw ?
  50. LONG ends
  51. FARPOINTER struc
  52. off dw ?
  53. sel dw ?
  54. FARPOINTER ends
  55. createSeg INIT, InitSeg, word, public, CODE
  56. sBegin InitSeg
  57. assumes cs,InitSeg
  58. assumes ds,nothing
  59. assumes es,nothing
  60. ;---------------------------Public-Routine------------------------------;
  61. ; HeapCreate
  62. ;
  63. ; Create a external heap
  64. ;
  65. ; Entry:
  66. ; cbSize is the initial size of the heap
  67. ;
  68. ; Returns:
  69. ; AX = handle to heap
  70. ; Error Returns:
  71. ; AX = 0
  72. ; Registers Preserved:
  73. ; BP,DS,SI,DI
  74. ; Registers Destroyed:
  75. ; AX,BX,CX,DX,FLAGS
  76. ; Calls:
  77. ; GlobalAlloc, LocalInit
  78. ; History:
  79. ; Fri 21-Sep-1990 13:45:58 -by- Todd Laney [ToddLa]
  80. ; Created.
  81. ;-----------------------------------------------------------------------;
  82. assumes ds,nothing
  83. assumes es,nothing
  84. cProc HeapCreate, <FAR,PUBLIC>, <>
  85. ParmW cbSize
  86. cBegin
  87. mov ax,cbSize
  88. cmp ax,MIN_HEAPSIZE
  89. jg hc_alloc
  90. mov ax,MIN_HEAPSIZE
  91. mov cbSize,ax
  92. hc_alloc:
  93. cCall GlobalAlloc, <GHND+GMEM_SHARE,0,ax>
  94. or ax,ax
  95. jz hc_exit
  96. cCall GlobalLock, <ax>
  97. push dx
  98. mov ax,cbSize
  99. dec ax
  100. cCall LocalInit,<dx,0,ax>
  101. pop ax
  102. hc_exit:
  103. cEnd
  104. ;---------------------------Public-Routine------------------------------;
  105. ; HeapDestroy
  106. ;
  107. ; Destroys a external heap
  108. ;
  109. ; Entry:
  110. ; hHeap contains heap handle (ie the selector)
  111. ;
  112. ; Returns:
  113. ; none
  114. ; Error Returns:
  115. ; none
  116. ; Registers Preserved:
  117. ; BP,DS,SI,DI
  118. ; Registers Destroyed:
  119. ; AX,BX,CX,DX,FLAGS
  120. ; Calls:
  121. ; GlobalUnlock, GlobalFree
  122. ; History:
  123. ; Fri 21-Sep-1990 13:45:58 -by- Todd Laney [ToddLa]
  124. ; Created.
  125. ;-----------------------------------------------------------------------;
  126. assumes ds,nothing
  127. assumes es,nothing
  128. cProc HeapDestroy, <FAR,PUBLIC>, <>
  129. ParmW hHeap
  130. cBegin
  131. cCall GlobalUnlock, <hHeap> ; !!! only need in REAL mode
  132. cCall GlobalFree, <hHeap>
  133. cEnd
  134. sEnd
  135. ifndef SEGNAME
  136. SEGNAME equ <_TEXT>
  137. endif
  138. createSeg %SEGNAME, CodeSeg, word, public, CODE
  139. sBegin CodeSeg
  140. assumes cs,CodeSeg
  141. assumes ds,nothing
  142. assumes es,nothing
  143. ;---------------------------Public-Routine------------------------------;
  144. ; HeapAlloc
  145. ;
  146. ; allocate memory from a external heap
  147. ;
  148. ; Entry:
  149. ; hHeap contains heap handle (ie the selector)
  150. ; cbSize contains the requested size of the allocation
  151. ;
  152. ; Returns:
  153. ; DX:AX = pointer to allocated object
  154. ; Error Returns:
  155. ; DX:AX = NULL
  156. ; Registers Preserved:
  157. ; BP,DS,SI,DI
  158. ; Registers Destroyed:
  159. ; AX,BX,CX,DX,FLAGS
  160. ; Calls:
  161. ; LocalAlloc
  162. ; History:
  163. ; Fri 21-Sep-1990 13:45:58 -by- Todd Laney [ToddLa]
  164. ; Created.
  165. ;-----------------------------------------------------------------------;
  166. assumes ds,nothing
  167. assumes es,nothing
  168. cProc HeapAlloc, <FAR,PUBLIC>, <ds>
  169. ParmW hHeap
  170. ParmW cbSize
  171. cBegin
  172. mov ds,hHeap
  173. cCall LocalAlloc, <LPTR, cbSize>
  174. xor dx,dx
  175. or ax,ax
  176. jz hal_exit
  177. mov dx,ds
  178. hal_exit:
  179. cEnd
  180. ;---------------------------Public-Routine------------------------------;
  181. ; HeapReAlloc
  182. ;
  183. ; reallocate memory from a external heap
  184. ;
  185. ; Entry:
  186. ; lpObject contains the pointer to the object to be reallocated
  187. ; cbSize contains the requested size of the reallocation
  188. ;
  189. ; Returns:
  190. ; DX:AX = pointer to allocated object
  191. ; Error Returns:
  192. ; DX:AX = NULL
  193. ; Registers Preserved:
  194. ; BP,DS,SI,DI
  195. ; Registers Destroyed:
  196. ; AX,BX,CX,DX,FLAGS
  197. ; Calls:
  198. ; LocalAlloc
  199. ; History:
  200. ; Wed 8-Jan-1991 1: 2: 3 -by- David Levine [DavidLe]
  201. ; Created based on HeapAlloc.
  202. ;-----------------------------------------------------------------------;
  203. assumes ds,nothing
  204. assumes es,nothing
  205. cProc HeapReAlloc, <FAR,PUBLIC>, <ds>
  206. ParmD lpObject
  207. ParmW cbSize
  208. cBegin
  209. lds ax,lpObject
  210. AllocFlags EQU LMEM_MOVEABLE OR LMEM_ZEROINIT
  211. cCall LocalReAlloc, <ax, cbSize, AllocFlags>
  212. xor dx,dx
  213. or ax,ax
  214. jz hral_exit
  215. mov dx,ds
  216. hral_exit:
  217. cEnd
  218. ;---------------------------Public-Routine------------------------------;
  219. ; HeapFree
  220. ;
  221. ; free memory from a external heap
  222. ;
  223. ; Entry:
  224. ; hObject contains the object to free
  225. ;
  226. ; Returns:
  227. ; none
  228. ; Error Returns:
  229. ; none
  230. ; Registers Preserved:
  231. ; BP,DS,SI,DI
  232. ; Registers Destroyed:
  233. ; AX,BX,CX,DX,FLAGS
  234. ; Calls:
  235. ; LocalFree
  236. ; History:
  237. ; Fri 21-Sep-1990 13:45:58 -by- Todd Laney [ToddLa]
  238. ; Created.
  239. ;-----------------------------------------------------------------------;
  240. assumes ds,nothing
  241. assumes es,nothing
  242. cProc HeapFree, <FAR,PUBLIC>, <ds>
  243. ParmD lpObject
  244. cBegin
  245. lds ax,lpObject
  246. cCall LocalFree, <ax>
  247. cEnd
  248. sEnd CodeSeg
  249. end