home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / Fortran.51 / DISK5 / OS2 / STDALLOC.AS$ / STDALLOC.bin
Text File  |  1989-08-31  |  2KB  |  105 lines

  1.     page    ,132
  2.     title    stdalloc - OS/2 routine to get memory for argv and envp
  3. ;***
  4. ;stdalloc.asm - OS/2 routine to get memory for argv and envp
  5. ;
  6. ;    Copyright (c) 1986-1990, Microsoft Corporation.  All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;    This routine returns memory from the heap.
  10. ;
  11. ;*******************************************************************************
  12.  
  13.  
  14. include    version.inc
  15. .xlist
  16. include    cmacros.inc
  17. include    msdos.inc
  18. include heap.inc
  19. .list
  20.  
  21.  
  22. sBegin    data
  23.     assumes    ds,data
  24.  
  25.     externW     _amblksiz    ; heap seg growth increment
  26.  
  27. sEnd    data
  28.  
  29. externP     malloc        ; get heap memory
  30.  
  31. sBegin    code
  32.     assumes ds,data
  33.     assumes cs,code
  34.  
  35. page
  36. ;***
  37. ;_stdalloc - OS/2 routine to get memory for argv and envp
  38. ;
  39. ;Purpose:
  40. ;    Call malloc() to try and get memory off the heap.
  41. ;    Used to allocate memory for the argv and envp arrays
  42. ;    and strings at startup time.
  43. ;
  44. ;    If carry is clear on return, then the allocation was
  45. ;    successful and DX:AX points to the allocated memory.
  46. ;    Carry set on return indicates allocation failure.
  47. ;
  48. ;    This is always a near routine since it is only called by the C run-time
  49. ;
  50. ;Entry:
  51. ;    AX    = number of bytes requested
  52. ;
  53. ;Exit:
  54. ;    Carry Clear (no error):
  55. ;        DX:AX   = address of allocated memory
  56. ;    Carry Set:
  57. ;        Error - unable to allocate
  58. ;
  59. ;Uses:
  60. ;    BX, CX are destroyed
  61. ;Preserves:
  62. ;    ES, SI, DI
  63. ;Exceptions:
  64. ;
  65. ;*******************************************************************************
  66.  
  67. cProc    _stdalloc,<PUBLIC,NEAR>,<es>
  68.  
  69. cBegin
  70.  
  71. ;
  72. ; First, try to get memory from the heap.
  73. ; Set the grow increment to a small value so that we don't eat up
  74. ; too much memory at runtime.
  75. ; ax = size of request
  76. ;
  77.     mov    cx,_HEAP_GROWSTART ; startup grow increment
  78.     xchg    cx,[_amblksiz]    ; set temp grow increment and save original
  79.  
  80.     push    cx        ; save original grow increment
  81.     push    ax        ; save size
  82.     call    malloc        ; heap request
  83.                 ; return value = <ax> or <dx:ax>
  84.     pop    bx        ; bx = size of request    (clean off stack)
  85.     pop    [_amblksiz]    ; restore original grow increment
  86.  
  87. if sizeD
  88.     mov    cx,dx        ; preserve dx
  89.     or    cx,ax        ; malloc return NULL ??
  90. else
  91.     mov    dx,ds        ; dx:ax = pointer
  92.     or    ax,ax        ; malloc return NULL ??
  93. endif
  94.  
  95.     jnz    return        ; success, carry is clear
  96.     stc            ; error, set carry
  97.  
  98. return:
  99.  
  100. cEnd    <nolocals>
  101.  
  102. sEnd    code
  103.  
  104.     end
  105.