Path: utzoo!utgpu!attcan!uunet!husc6!mailrus!cornell!uw-beaver!fluke!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: alloca(3) for MINIX-ST Message-ID: <547@uvicctr.UUCP> Date: 8 Nov 88 22:39:51 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 130 EFTH MINIX report #57 - November 1988 - alloca(3) for MINIX-ST There follows an implementation of alloca(3) for MINIX-ST. The code is directly derived from Peter S. Housel's alloca(3) for MINIX-XT. "man" pages are included. ---------------------------------------------------------- echo x - alloca.3 gres '^X' '' > alloca.3 << '/' XSUBROUTINES X alloca(3) - allocate space on the stack X XINVOCATION X char *alloca( size ) X unsigned size; X XEXPLANATION X Alloca(3) allocates bytes on the stack. Blocks X allocated within a stack frame are released on exit X from the current subroutine. X XRESULTS X o/w : Pointer to allocated memory. X NULL : No room for block. X XREFERENCES X chmem(1), malloc(3) / echo x - free.3 gres '^X' '' > free.3 << '/' XSUBROUTINES X free(3) - release allocated memory X XINVOCATION X free( p ) X char *p; X XEXPLANATION X Free(3) releases a block previously allocated by malloc(3), X realloc(3) or calloc(3). X XREFERENCES X malloc(3) / echo x - malloc.3 gres '^X' '' > malloc.3 << '/' XSUBROUTINES X malloc(3) - memory allocation routines X XINVOCATION X char *malloc( size ) X unsigned size; X X char *realloc( old, size ) X char *old; X unsigned size; X X char *calloc( n, size ) X unsigned n; X unsigned size; X XEXPLANATION X These routines allocate blocks of memory above the X process' bss section. Malloc(3) requests bytes. X Realloc(3) requests a change in an block's X allocation to . Calloc(3) allocates times X bytes, and then clears the memory before returning. X XRESULTS X o/w : Pointer to allocated memory. X NULL : No room for block. For realloc(3), is not X released. X XREFERENCES X chmem(1), brk(2), alloca(3), free(3) / echo x - alloca.s gres '^X' '' > alloca.s << '/' X .define _alloca X .sect text X! X! alloca() for Minix X! by Peter S. Housel 8/15/88 - in the public domain X! X! Changed for 68000 - Terrence W. Holm & X! - Frans Meulenbroeks - Nov. 1988 X! X! Stack frame: X! on entry on return X! | ... | | ... | X! |-----------| <=caller sp |-----------| X! | size arg | | | X! |-----------| |alloca data| X! | ret addr | | ... | X! |-----------| <=sp |-----------| <= return value in d0 X! | dummy word| X! |-----------| <= sp X! X .globl _alloca X .globl _brksize X_alloca: X move.l (a7),a0 ! save return address X move.l a7,d0 X add.l #6,d0 ! d0 = sp from calling routine X clr.l d1 X move.w 4(a7),d1 X sub.l d1,d0 ! d0 = beginning of alloca block X and.b #0xfc,d0 ! round to long address X move.l _brksize,d1 X add.l #40,d1 ! ensure space below new sp X cmp.l d1,d0 X ble fail X move.l d0,a7 ! set new sp X sub.l #2,a7 ! push a dummy value for caller to remove X jmp (a0) ! jump back to caller Xfail: X clr.l d0 ! return NULL pointer X rts / ---------------------------------------------------------- Frans Meulenbroeks uunet!mcvax!philmds!prle!cst!meulenbr Terrence W. Holm uw-beaver!uvicctr!tholm