Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: don@zl2tnm.gen.nz (Don Stokes)
Subject: Re: Need alloca which allocates storage IN the stack frame (Ultrix)
Date: 21 Jan 93 11:16:47 GMT	[thread overview]
Message-ID: <9915020@zl2tnm.gen.nz> (raw)
In-Reply-To: 1993Jan19.204025.4666@ccad.uiowa.edu

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


  parent reply	other threads:[~1993-01-21 11:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-01-19 20:40 Need alloca which allocates storage IN the stack frame (Ultrix) Timothy VanFosson
1993-01-20 14:52 ` zrepachol
1993-01-21 11:16 ` Don Stokes [this message]
1993-01-21 16:30   ` Timothy VanFosson
1993-01-21 22:58     ` John Wroclawski
1993-01-22 14:47       ` Marcus J Ranum
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox