Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!comp.vuw.ac.nz!am.dsir.govt.nz!dsiramd!actrix!templar!jbickers From: jbickers@templar.actrix.co.nz (John Bickers) Newsgroups: comp.sys.amiga.tech Subject: Re: stack setting? Message-ID: <4530.tnews@templar.actrix.co.nz> Date: 3 Jul 90 23:35:03 GMT Followup-To: comp.sys.amiga.tech Organization: TAP, NZAmigaUG. Lines: 161 Quoted from - peterk@cbmger.UUCP (Peter Kittel GERMANY): > In article <13580002@hpspdra.HP.COM> ric@hpspdra.HP.COM (Ric Peregrino) writes: > >I have ported a wave editor program to the amiga and found that the > >default stack of 4000 is too small. I tried using a system call in > >the program to automatically set the stack, but it seems to fail. > >Anybody know why this is, or how it can be done? [...] > Sorry, I only can tell you why this failed (ran into similar things > myself): Invoking system makes up a new CLI for this very command and One Bryce Nesbitt wrote some code a while back to do this sort of thing. The stack size can be found by examining your task structure. So one possible way to treat this is to detect that the stack is too small, and error out, with something like: "Sorry bud(ette), your stack is too small." Or you can reset your stack yourself. He wrote a little function to do this, that I have adjusted a little to work with Lattice C and keep stack checking. Hm. Decisions decisions. 127 lines. What the heck... -------------------- 8< -------------------- ;************************************************************************** ;*** stkset.a (JJB TEMPLAR) *** ;*** Date begun: 3/7/89. *** ;*** Last modified: 3/7/89. *** ;************************************************************************** ;*** This module is cut directly from AmigaLine7 (Bryce Nesbitt). See *** ;*** his documentation below for particulars. However, I have added *** ;*** some code to also 'tickle' the __base value used by Lattice stack *** ;*** checking. *** ;*** Problem: should allocation of the new stack memory be done here *** ;*** instead of in the caller? *** ;************************************************************************** LATTICE EQU 1 ; Comment out if don't want __base involved ;--------------------------------------------------------------------------- ;NAME ; SetStack -- use a different process stack ; V1.0 Tuesday 19-Jan-88 04:14:15 By Bryce Nesbitt ; ;SYNOPSIS ; SetStack(newstack,size) ; a1 d0 ; ; char *newstack; ; long size; ; ;FUNCTION ; This function points the current process' stack to a new memory ; location. The active part of the old stack is duplicated, so no ; context is lost. SetStack() also tickles the proper fields in the task ; structure to tell the system about the change. At this time it does ; not deallocate the old stack. ; ;USAGE ; Typically this is used by a process that needs a larger stack than it ; might have been started with. The stack size can be found with: ; ; #include "libraries/dosextens.h" ; ... ; stack=*(ULONG *)( ((struct Process *)FindTask(0L))->pr_ReturnAddr ); ; ; Or in English, the long word at the address pointed to by pr_ReturnAddr. ; ;WARNINGS ; A future revision of exec may do stack blowout checking every time a ; process/task is switched out. This protective feature will not be ; available to programs that use funky methods of swapping stacks. ; ; This only works for processes, tasks are not eligible. ; ; Don't skimp on stack... you'll get burned. Any call to the dos.library, ; for example, takes just under 1600 bytes *minimum*. ; ;INPUTS ; newstack - Pointer to memory block for stack. Must be longword aligned. ; size - The size of the block. Must be an even multiple of 4 bytes. ; ;SEE ALSO ; AddTask() ; ;SetStack() ;V1.0 Tuesday 19-Jan-88 04:14:15 (C)1988 Bryce Nesbitt ;1712 Marin Ave. Berkeley, Ca 94707-2206 415-524-2110 ;ucbvax!hoser!bryce -or- bryce@hoser.berkeley.EDU ; ;Structure of stack: ; ; ------- ; -4 size ; -8 finalRTS ; ... ; -size blowoutdata ;For checking stack blowouts ;************************************************************************** csect text XDEF _SetStack XDEF SetStack IFD LATTICE XREF __base ; offset for stack checking base ; stack is checked with: ; cmpa.l __base(a4),a7 ; bcs.w __xcovf ENDC _SetStack: move.l 4(a7),a1 move.l 8(a7),d0 SetStack: movem.l d2/a2-a4/a6,-(a7) ; Assembler entry (params = reg) ; NOT @function compatible IFD LATTICE move.l a1,__base(a4) ; set __base before a4 used ENDC move.l d0,a0 adda.l a1,a0 ;a1+size=a0 move.l 4,a6 ;exec library move.l $114(a6),a3 ;Internal "magic";FindTask(0L); lea.l $b0(a3),a2 ;&pr_ReturnAddr move.l (a2),a3 ;Get pr_ReturnAddr move.l (a3)+,d1 ;Get old stack size. a3+... move.l a3,d2 ;...now points to old stack top move.l a0,a4 copystack: move.w -(a3),-(a4) cmp.l a3,a7 bne.s copystack move.l d0,-4(a0) ;Set new stack size value move.l d2,a3 sub.l d1,a3 move.l (a3),(a1) ;Copy bottom long addq.b #1,$127(a6) ;Internal "magic" move.l a0,(a2) subq.l #4,(a2) ;pr_ReturnAddr is 4 under top... sub.l a7,d2 ;Get old stack offset sub.l d2,a0 ;index into new stack move.l a0,a7 jsr -$138(a6) ;Public Permit(); movem.l (a7)+,d2/a2-a4/a6 rts END -------------------- 8< -------------------- Assembles ok with Lattice's asm program. > Best regards, Dr. Peter Kittel // E-Mail to Adios. -- *** John Bickers, TAP, NZAmigaUG. jbickers@templar.actrix.co.nz *** *** "Man, Machine -> Super Human Being" - Kraftwerk. ***