home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PMC101.ZIP / LIBSRC.ZIP / BMWALK.ASM (.txt) < prev    next >
Assembly Source File  |  1994-06-24  |  5KB  |  153 lines

  1. ;──────────────────────────────────────────────────────────────────────────────
  2. ;                                MEMBLOCK Walk
  3. ;──────────────────────────────────────────────────────────────────────────────
  4. ;
  5. ; Borland C++ 4.0 for WIN32 prototype:
  6. ; void  __pascal mbwalk (MEMBLOCK *mb, WalkMBInf *inf);
  7. ;
  8. ; version 0.3
  9. ; - White Shadow -
  10. ;
  11. .386p
  12. Ideal
  13. include "bmmalloc.inc"
  14.  
  15. Public MBWALK
  16.  
  17.  
  18. ;──────────────────────────────────────────────────────────────────────────────
  19. Segment _TEXT byte public use32 'CODE'
  20. Assume  cs:_TEXT, ds:DGROUP
  21.  
  22.  
  23. ; -- argument stack offsets
  24. arg1 = 4                ; -> MEMBLOCK
  25. arg2 = 0                ; -> WalkMBInf
  26.  
  27. INFFLAG_ResetWalk       = 01h
  28. INFFLAG_AllocArea       = 02h
  29. INFFLAG_LastNode        = 04h
  30. INFFLAG_CorruptMB       = 08h
  31. INFFLAG_UninitMB        = 10h
  32.  
  33. MBWALK:         push ebx esi ebp
  34. pct = (4)+(3*4)
  35.  
  36.                 ;-- Load MEMBLOCK info
  37.                 mov  esi, [esp+pct+arg1]        ; -> MEMBLOCK
  38.                 mov  ebx, [esi+MEMBLOCK.base]   ; linear adx of MEMBLOCK
  39.                 sub  ebx, [_database]           ; relative ofs to DGROUP
  40.                 mov  ebp, [esi+MEMBLOCK.size]
  41.                 add  ebp, ebx                   ; -> last byte of MB + 1
  42.  
  43.                 ;-- MEMBLOCK uninitalized?
  44.                 cmp  ebp, ebx
  45.                 je   UninitMB
  46.  
  47. If DebugMode    ;-- Check MEMBLOCK signature
  48.                 cmp  [dword ebx], MBSig
  49.                 jne  CorruptMB
  50.                 add  ebx, MBSigSize             ; -> first node
  51. EndIf
  52.  
  53.                 ;-- Continue?
  54.                 mov  esi, [esp+pct+arg2]        ; -> WalkMBInf
  55.                 test [esi+WalkMBInf.flags], INFFLAG_ResetWalk
  56.                 jz   ContinuedWalk
  57.  
  58.                 ;-- Reset to begining of MEMBLOCK
  59.                 mov  [esi+WalkMBInf.flags], 0   ; kill all flags
  60.  
  61.                 jmp  GetNodeInf
  62.  
  63. ;---------------
  64.  
  65. ContinuedWalk:
  66.                 ;-- Already at last node, or corrupted MB?
  67.                 test [esi+WalkMBInf.flags], INFFLAG_LastNode OR INFFLAG_CorruptMB
  68.                 jnz  Exit
  69.  
  70.                 ;-- Get last MemNode adx
  71.                 mov  ebx, [esi+WalkMBInf.adx]
  72.                 sub  ebx, size MemNode
  73.  
  74.                 ;-- Check last node
  75.                 mov  eax, [ebx+MemNode.size]
  76. If DebugMode
  77.                 xor  eax, NodeSigKey
  78.                 cmp  [ebx+MemNode.sig], eax
  79.                 jne  CorruptMB
  80.                 xor  eax, NodeSigKey
  81. EndIf
  82.  
  83.                 ;-- point to Ret node
  84.                 and  eax, 7fffffffh
  85.                 add  ebx, size MemNode
  86.                 add  ebx, eax
  87.                 cmp  ebx, ebp                   ; past end?
  88.                 jae  CorruptMB
  89.  
  90. ;---------------
  91.  
  92. GetNodeInf:
  93. ; ebx -> MemNode to return
  94. ; esi -> WalkMBInf
  95.  
  96. If DebugMode    ;-- Ret node valid?
  97.                 mov  eax, [ebx+MemNode.size]
  98.                 xor  eax, NodeSigKey
  99.                 cmp  [ebx+MemNode.sig], eax
  100.                 jne  CorruptMB
  101. EndIf
  102.  
  103.                 ;-- MemArea adx
  104.                 mov  eax, ebx
  105.                 add  eax, size MemNode
  106.                 mov  [esi+WalkMBInf.adx], eax
  107.  
  108.                 ;-- Free area?
  109.                 and  [esi+WalkMBInf.flags], NOT (INFFLAG_AllocArea)
  110.                 test [ebx+MemNode.size], 80000000h
  111.                 jz   FreeArea
  112.                 or   [esi+WalkMBInf.flags], INFFLAG_AllocArea
  113. FreeArea:
  114.  
  115.                 ;-- Area size
  116.                 mov  eax, [ebx+MemNode.size]
  117.                 and  eax, 7fffffffh
  118.                 mov  [esi+WalkMBInf.size], eax
  119.  
  120.                 ;-- Point to next node
  121.                 add  ebx, size MemNode
  122.                 add  ebx, eax
  123.  
  124.                 ;-- Is MemNode to ret the last node?
  125.                 cmp  ebx, ebp
  126.                 ja   CorruptMB                  ; no, error
  127.                 jb   Exit                       ; no, more nodes
  128.  
  129.                 ;-- Set last node flag
  130.                 or   [esi+WalkMBInf.flags], INFFLAG_LastNode
  131.  
  132. ;---------------
  133.  
  134. Exit:           pop  ebp esi ebx
  135.                 ret  8                          ; 2 args
  136.  
  137. ;---------------
  138.  
  139. CorruptMB:      mov  ebx, [esp+pct+arg2]        ; -> WalkMBInf
  140.                 or   [ebx+WalkMBInf.flags], INFFLAG_CorruptMB
  141.                 jmp  Exit
  142.  
  143. ;---------------
  144.  
  145. UninitMB:       mov  ebx, [esp+pct+arg2]        ; -> WalkMBInf
  146.                 or   [ebx+WalkMBInf.flags], INFFLAG_UninitMB
  147.                 jmp  Exit
  148.  
  149.  
  150. ;──────────────────────────────────────────────────────────────────────────────
  151. EndS            _TEXT
  152. End
  153.