Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!linus!philabs!seismo!hao!hplabs!sri-unix!eric@cit-vax
From: eric%cit-vax@sri-unix.UUCP
Newsgroups: net.unix-wizards
Subject: Re: stack allocator
Message-ID: <2886@sri-arpa.UUCP>
Date: Fri, 8-Jul-83 03:39:36 EDT
Article-I.D.: sri-arpa.2886
Posted: Fri Jul  8 03:39:36 1983
Date-Received: Mon, 11-Jul-83 20:21:59 EDT
Lines: 53

BINGO!!

    From thompson.umn-cs@Rand-Relay Thu Jul  7 23:35:19 1983
    Date: 7 Jul 1983 12:16:34-PDT
    From: thompson.umn-cs@Rand-Relay
    Return-Path: 
    Subject: Stack allocation in C
    To: eric@cit-vax
    Via:  UMN-CS; 7 Jul 83 23:14-PDT
	
    We have been using a stack allocation routine in our image processing
    software for a year and a half without difficulties.  (This of course does
    not exactly answer your question.)  The automatic stack manipulation on
    calls and returns makes this somewhat difficult to do.  Here is our code:
	
    /*
     *      getspace(nbytes)
     *
     *      VAX-11 version.
     *
     *      Dynamically allocates storage space on run time stack.  Returns
     *      a pointer to a 'nbytes' byte area.  Space is freed when routine
     *      which called 'getspace' returns.
     */
	
	    .align  1
	    .text
	    .globl  _getspace
    _getspace:
	    .word   0x0             /* no need to save registers */
	    movl    4(ap),r0        /* temporarily save 'nbytes' */
	    movl    16(fp),r1       /* save address of calling routine */
	    movl    $__fake,16(fp)  /* insert a fake return address */
	    ret                     /* jump to fake return address */
    __fake:
	    bicl2   $03,sp          /* align stack to double word boundary */
				    /* (almost certainly not necessary) */
	    subl2   r0,sp           /* get extra space */
	    bicl2   $03,sp          /* align stack (again) */
	    movl    sp,r0           /* return start of storage area */
	    jmp     (r1)            /* go back to calling program */
				    /* (this one's for real!) */
	
Guess it can be done after all. Since this is a function, you
could melt yourself by doing something like somefunc(1,getspace(10),2)
and having a big hole between the 1 argument and the 2 argument to
getfunc.

				    * Eric Holstege
				    * Caltech, Pasadena, CA.
				    * (eric@cit-vax)
				    * (...!ucbvax!cithep!citcsv!eric)
				    * (...!research!citcsv!eric)