home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!comp.vuw.ac.nz!zl2tnm!toyunix!don
- Newsgroups: comp.sys.dec
- Subject: Re: Need alloca which allocates storage IN the stack frame (Ultrix)
- Message-ID: <9915020@zl2tnm.gen.nz>
- From: don@zl2tnm.gen.nz (Don Stokes)
- Date: 21 Jan 93 11:16:47 GMT
- Sender: news@zl2tnm.gen.nz (GNEWS Version 2.0 news poster.)
- References: <1993Jan19.204025.4666@ccad.uiowa.edu>
- Distribution: world
- Organization: The Wolery
- Lines: 37
-
- timv@ccad.uiowa.edu (Timothy VanFosson) writes:
- > Does anyone have an implementation of alloca() which actually
- > sets aside storage in the stack frame? I'm trying to port
- > the NIH Class Library and have everything working except the
- > process classes, and I've narrowed it down to the DEC implementation
- > of alloca() not being what NIH expects.
-
- You don't say what system you want this for. It kinda matters, since you
- can't really do an alloca() in C.
-
- Anyway, since it's short, here's a VAX MACRO alloca() (code filched from GCC,
- comments by me):
-
- .title ALLOCA allocate dynamic storage on stack
-
- .psect $CODE, long,pic,rel,shr,exe,rd,nowrt
- .entry ALLOCA, ^M<> ; Entry point, save no general registers.
-
- subl2 4(AP), SP ; Allocate stack space
- movl 16(FP), R1 ; Get return address from soon to be redundant
- ; stack frame (used for returning)
- movq 8(FP), AP ; Restore AP & FP from stack frame
- bicl #3, SP ; Longword-align stack
- addl2 #28, SP ; Deallocate now-redundant frame from stack
- ; (This is not done until we are finished with
- ; the frame, since the size of the block
- ; alloca()ed could be smaller than 28 bytes
- ; and it would be bad if we were interrupted.)
- movl SP, R0 ; Return address of bottom of stack
- jmp (R1) ; Return without unwinding stack.
-
- .end
-
- --
- Don Stokes, ZL2TNM (DS555) don@zl2tnm.gen.nz (home)
- Network Manager, Computing Services Centre don@vuw.ac.nz (work)
- Victoria University of Wellington, New Zealand +64-4-495-5052
-