|
|
Microsoft OS/2 SDK 12-15-1987
TITLE stdalloc - memory allocation routine for stdargv, stdenvp ;*** ;stdalloc.asm - memory allocation routine for stdargv, stdenvp ; ; Copyright (c) 1985-1987, Microsoft Corporation. All rights reserved. ; ;Purpose: ; Memory allocation for stdargv and stdenvp. ; ;******************************************************************************* include version.inc .xlist ifdef _QC ;[3] Move these includes out of version.inc include \sl\qc\src\include\kernel.inc ;[3] include \sl\qc\src\include\kmac.inc ;[3] endif ;_QC ;[3] include cmacros.inc include msdos.inc include brkctl.inc .list sBegin data assumes ds,data externW _psp ; PSP segment # externW _abrktb ; break table for allocation externW _asizds ; break table for allocation end ifdef _QC ; [1] extrn __QCrtcsip:DWORD ; [1] endif ;_QC ; [1] sEnd data sBegin code assumes ds,data assumes cs,code externNP _amsg_exit ; write error and die routine page ;*** ;_myalloc - low overhead heap allocation ; ;Purpose: ; Used to allocate heap space, without the overhead of ; malloc for both wildcard arguments and environment strings, ptrs. ; ; Tries to find space in heap, failing this calls dos to extend ; heap and tries again, failing this spits out error message and ; dies. ; ;Entry: ; BP = number of bytes in table ( argv/ or envp ) ; AX = total number of bytes to allocate table and strings ; DI = error message number in case of death. ; ;Exit: ; BP = points to table ; AX = size of table in bytes. ; ;Uses: ; ;Exceptions: ; If can't get enough memory, gives ; error 2009/2008: no space for enviroment/arguments ; and then dies. ; ;******************************************************************************* cProc _myalloc,<NEAR,PUBLIC>,<> cBegin nogen assumes ds,data mov dx,ax ; save size of environment add ax,[_abrktb].sz ; ax = DS offset of end of environment jc _hpovr ; environment won't fit w/in 64k ; give error cmp [_asizds],ax ; will env fit in allocated mem? jnc _hpok ; yes, go move it ; need more memory add ax,15d ; round up to nearest paragraph push ax ; save this for later rcr ax,1 ; shift right including carry from add mov cl,3 shr ax,cl ; convert to # of paragraphs mov cx,ds mov bx,[_psp] sub cx,bx ; DGROUP - _PSP add ax,cx ; make # of paragraphs _PSP relative mov es,bx ; seg addr of mem area mov bx,ax ; set up for OS call callos setmem ; change size of mem block to bx paras pop ax ; restore (env size + 15) jc _hpovr ; not enough memory, give error and al,0F0h ; round down to nearest paragraph addr dec ax mov [_asizds],ax ; store new last byte of DGROUP _hpok: xchg ax,bp ; ax = size of env ptr table mov bp,[_abrktb].sz ; bp points to mem for storing env ptrs add [_abrktb].sz,dx ; update bottom of heap ret _hpovr: ifdef _QC ; [1] extrn $F_PSP:WORD ;[2] mov ds,cs:[$F_PSP] ;[2] get PSP mov ax,ds:[PSP_DGROUP_SEG] ;[2] get DGROUP mov ds, ax ;[2] ds = DGROUP pop word ptr [__QCrtcsip] ; [1] Offset mov word ptr [__QCrtcsip+2], cs ; [1] Segment (proc is near) endif ;_QC ; [1] mov ax,di ; error 2009/2008: no space for enviroment/arguments jmp _amsg_exit ; give error and die cEnd nogen sEnd code end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.