home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / dec / 7033 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  1.9 KB

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