home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 038 / pmd110.zip / HEAP.DIF < prev    next >
Text File  |  1994-11-14  |  5KB  |  234 lines

  1. *** c:\bp\rtl\sys\heap.asm    Wed Oct 28 07:00:00 1992
  2. --- heap.asm    Sat Oct 22 16:58:30 1994
  3. ***************
  4. *** 20,27 ****
  5.       EXTRN    FreeList:DWORD,HeapError:DWORD
  6.   
  7. ! ; Local variables
  8.   
  9.   AllocSize    DW    ?
  10.   
  11.   DATA    ENDS
  12.   
  13. --- 20,36 ----
  14.       EXTRN    FreeList:DWORD,HeapError:DWORD
  15.   
  16. ! ;;MemCheck externals
  17.   
  18. +         EXTRN   CheckMEM:BYTE,StoreAlloc:DWORD,FreeAlloc:DWORD
  19. + ;; Local variables
  20.   AllocSize    DW    ?
  21.   
  22. + ;; Memchecker variable
  23. + MemSize         DW      ?
  24.   DATA    ENDS
  25.   
  26. ***************
  27. *** 39,42 ****
  28. --- 48,52 ----
  29.       PUBLIC    GetFreMem,GetFreMax,NewMemory,DisMemory
  30.   
  31.   ; New and GetMem standard procedures
  32.   
  33. ***************
  34. *** 161,167 ****
  35.   NewMemory:
  36.   
  37.       OR    AX,AX
  38. !     JE    @@9
  39. !     MOV    AllocSize,AX
  40.   @@1:    CALL    PointerSize
  41.       MOV    DI,OFFSET DS:FreeList
  42. --- 171,200 ----
  43.   NewMemory:
  44.   
  45. + ;; memchecker code
  46. +         mov     [MemSize],ax
  47.       OR    AX,AX
  48. ! ;; this jump was too far, so changed by memchecker
  49. ! ;;        JE      @@9
  50. !         jne     @@m0
  51. !         jmp     @@9
  52. ! ;; memchecker code
  53. ! ;; add 8 or 16 bytes to allocated memory for overflow checking
  54. ! @@m0:   cmp     CheckMem,0             ; is MemCheck code enabled?
  55. !         je      @@m1
  56. !         cmp     ax,65512               ; 65536-8-16
  57. !         ja      @@CheckUpperArea
  58. !         add     ax,16
  59. !         jmp     short @@m1
  60. ! @@CheckUpperArea:
  61. !         cmp     ax,65520               ; 65536-8-8
  62. !         ja      @@m1
  63. !         add     ax,8
  64. ! @@m1:
  65. !         MOV    AllocSize,AX
  66.   @@1:    CALL    PointerSize
  67.       MOV    DI,OFFSET DS:FreeList
  68. ***************
  69. *** 173,177 ****
  70.       MOV    SI,ES
  71.       CMP    SI,HeapPtr.w2
  72. !     JE    @@6
  73.       CMP    DX,ES:[DI].mSize.w2
  74.       JA    @@2
  75. --- 206,216 ----
  76.       MOV    SI,ES
  77.       CMP    SI,HeapPtr.w2
  78. ! ;; memchecker changed jump, else out of range
  79. ! ;;        JE      @@6
  80. !         jne     @@m3
  81. !         jmp     short @@6
  82. ! @@m3:
  83.       CMP    DX,ES:[DI].mSize.w2
  84.       JA    @@2
  85. ***************
  86. *** 213,216 ****
  87. --- 252,261 ----
  88.       POP    DX
  89.       CLC
  90. + ;; memchecker code
  91. +         jc      @@NoCheck1        ; if error don't check
  92. +         call    MemCheckAddPtr
  93. + @@NoCheck1:
  94.   @@5:    RET
  95.   @@9:    XOR    AX,AX
  96. ***************
  97. *** 240,243 ****
  98. --- 285,294 ----
  99.       POP    AX
  100.       POP    DX
  101. + ;; memchecker code
  102. +         jc      @@NoCheck2        ; if error don't check
  103. +         call    MemCheckAddPtr
  104. + @@NoCheck2:
  105.       CLC
  106.       RET
  107. ***************
  108. *** 245,253 ****
  109.       CALL    HeapError
  110.       CMP    AL,1
  111. !     JB    @@5
  112. !     JE    @@9
  113.       MOV    AX,AllocSize
  114.       JMP    @@1
  115.   
  116.   ; Dispose memory
  117.   ; In    AX    = Size
  118. --- 296,353 ----
  119.       CALL    HeapError
  120.       CMP    AL,1
  121. !         JB      @@5
  122. !         JE      @@9
  123.       MOV    AX,AllocSize
  124.       JMP    @@1
  125.   
  126. + ;;memchecker code
  127. + MemCheckAddPtr:
  128. +         cmp     CheckMem,0        ; if MemCheck disabled
  129. +         je      @@NoCheck         ; don't check
  130. +         mov     cx,MemSize
  131. +         jcxz    @@NoCheck         ; if size = 0, don't check
  132. +         cmp     dx,0              ; check if returned pointer is nil
  133. +         jne     @@no_error
  134. +         cmp     ax,0
  135. +         je      @@NoCheck         ; don't check
  136. + @@no_error:
  137. +         cmp     cx,65520          ; is there room for upper memory check?
  138. +         ja      @@StorePointer2
  139. +         mov     si,ax             ; save ax
  140. +         mov     es,dx
  141. +         mov     di,ax
  142. +         add     di,cx
  143. +         cmp     cx,65512
  144. +         ja      @@m22
  145. +         add     di,8              ; correct if we have a lower memory also
  146. + @@m22:  mov     ax,0cccch         ; fill last 8 bytes with 0CCh
  147. +         mov     cx,4
  148. +         cld
  149. +         rep     stosw
  150. +         mov     ax,si             ; restore ax
  151. +         mov     cx,MemSize
  152. +         cmp     cx,65512          ; is there room for lower memory check?
  153. +         ja      @@StorePointer2
  154. +         mov     es,dx
  155. +         mov     di,ax
  156. +         mov     ax,0cccch         ; fill first 8 bytes with 0CCh
  157. +         mov     cx,4
  158. +         cld
  159. +         rep stosw
  160. +         mov     ax,di             ; first 8 bytes are skipped
  161. + @@StorePointer2:
  162. +         push    dx                ; push ptr
  163. +         push    ax
  164. +         push    [MemSize]         ; else push size
  165. +         call    dword ptr [StoreAlloc]
  166. + @@NoCheck:
  167. +         ret
  168.   ; Dispose memory
  169.   ; In    AX    = Size
  170. ***************
  171. *** 257,260 ****
  172. --- 357,385 ----
  173.   DisMemory:
  174.   
  175. + ;; memchecker code
  176. +         cmp     CheckMem,0
  177. +         je      @@DisMemoryStart
  178. +         or      ax,ax                  ; if Size = 0
  179. +         jne     @@m1
  180. +         jmp     short @@4              ; then no check
  181. + @@m1:
  182. +         push    bx                     ; push ptr
  183. +         push    cx
  184. +         push    ax                     ; push size
  185. +         call    dword ptr [FreeAlloc]
  186. + ;; add the extra overflow memory area size
  187. +         cmp     ax,65512               ; 65536-8-16
  188. +         ja      @@UpperArea
  189. +         add     ax,16
  190. +         sub     cx,8
  191. +         jmp     short @@DisMemoryStart
  192. + @@UpperArea:
  193. +         cmp     ax,65520               ; 65536-8-8
  194. +         ja      @@DisMemoryStart
  195. +         add     ax,8
  196. + @@DisMemoryStart:
  197.       OR    AX,AX
  198.       JE    @@6
  199. ***************
  200. *** 367,370 ****
  201. --- 492,496 ----
  202.       AND    AX,8
  203.       RET
  204.   
  205.   CODE    ENDS
  206.