home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / WINLBSRC.ZIP / WINMEM.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  3.3 KB  |  139 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      WINMEM.ASM -- Windows memory suballocator helper functions   |
  3. ;[]-----------------------------------------------------------------[]
  4.  
  5. ;
  6. ;       C/C++ Run Time Library - Version 5.0
  7. ;       Copyright (c) 1991, 1992 by Borland International
  8. ;       All Rights Reserved.
  9.  
  10.         INCLUDE RULES.ASI
  11.  
  12.         locals
  13.  
  14.         public __RLS_TEMP_BLOCK
  15.         public __GET_TEMP_BLOCK
  16.         public __SIZ_TEMP_BLOCK
  17.  
  18.         extrn   GLOBALALLOC:far
  19.         extrn   GLOBALFREE:far
  20.  
  21.         extrn   GLOBALLOCK:far
  22.         extrn   GLOBALUNLOCK:far
  23.  
  24.         extrn   GLOBALHANDLE:far
  25.         extrn   GLOBALSIZE:far
  26.  
  27.         extrn   __WinAllocFlag:word
  28.  
  29.         GMEM_MOVEABLE       equ 2
  30.  
  31.  
  32. Code_Seg@
  33.  
  34. __GET_TEMP_BLOCK  proc    far
  35.  
  36. ;
  37. ; Function __GET_TEMP_BLOCK: allocate a memory block
  38. ;
  39. ; Inputs:
  40. ;       DX:AX   =       size of block to allocate
  41. ; Outputs:
  42. ;       DX:AX   =       address of block
  43.  
  44.         local   Temp:word=STACKFRAMESIZE
  45.  
  46.         push    bp
  47.         mov     bp, sp
  48.         sub     sp, STACKFRAMESIZE
  49.  
  50.         mov     [Temp], ax
  51.  
  52.         mov     ax, __WinAllocFlag
  53.         or      ax, GMEM_MOVEABLE
  54.         push    ax              ;GLOBALALLOC flags
  55.  
  56.         mov     ax, [Temp]      ;lower 16-bits of size
  57.         push    dx              ;push 32-bit size
  58.         push    ax
  59.  
  60.         call    GLOBALALLOC     ;allocate block.  ax = handle
  61.         or      ax, ax          ;error allocating?
  62.         jz      @@Error
  63.         push    ax
  64.         call    GLOBALLOCK      ;dx:ax is pointer to block
  65.         ;; check our assumption that offsets are always zero
  66.         or      ax, ax          ;zero offset
  67.         jnz     @@Error         ; nope, return NULL
  68.  
  69. @@Exit:
  70.         mov     sp, bp
  71.         pop     bp
  72.         ret
  73.  
  74. @@Error:
  75.         xor     dx, dx
  76.         jmp     @@Exit
  77.  
  78. __GET_TEMP_BLOCK  endp
  79.  
  80. __RLS_TEMP_BLOCK  proc    far
  81.  
  82. ;
  83. ; Function __RLS_TEMP_BLOCK: free a memory block
  84. ;
  85. ; Inputs:
  86. ;       ES:DI   =       block address
  87. ; Outputs:
  88. ;       none
  89. ; Assumptions:
  90. ;       DI = 0
  91.  
  92.         push    es              ;selector of block
  93.         call    GLOBALHANDLE    ;ax = handle of block
  94.         or      ax, ax          ;no such block?
  95.         jz      @@Error         ; yes
  96.  
  97.         push    ax              ;push handle for GLOBALFREE
  98.         push    ax              ;push handle for GLOBALUNLOCK
  99.         call    GLOBALUNLOCK    ;unlock block
  100.         call    GLOBALFREE      ;free block
  101. @@Error:
  102.         ;; No block was found with the given address.  Just return.
  103.         ret
  104.  
  105. __RLS_TEMP_BLOCK  endp
  106.  
  107. __SIZ_TEMP_BLOCK  proc    far
  108.  
  109. ;
  110. ; Function __SIZ_TEMP_BLOCK: Return the size of an allocated block.
  111. ;
  112. ; Inputs:
  113. ;       ES:DI   =       block address
  114. ; Outputs:
  115. ;       DX:AX   =       block size
  116. ; Assumptions:
  117. ;       DI = 0
  118.  
  119.         push    es              ;selector of block
  120.         call    GLOBALHANDLE    ;ax = handle of block
  121.         or      ax, ax          ;no such block?
  122.         jz      @@Error         ; yes
  123.         push    ax              ;handle of block
  124.         call    GLOBALSIZE      ;dx:ax is size of block
  125.         ret
  126.  
  127. @@Error:
  128.         ;; Not much to do besides return 0.
  129.         xor     dx, dx
  130.         ;; ax already zero
  131.         ret
  132.  
  133. __SIZ_TEMP_BLOCK  endp
  134.  
  135. Code_EndS@
  136.         end
  137.