Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!ur-tut!sunybcs!boulder!hao!ames!ucbcad!ucbvax!hoser.berkeley.edu!bryce From: bryce@hoser.berkeley.edu.UUCP Newsgroups: comp.sys.amiga Subject: Re: Dynamic Stack Allocation Message-ID: <21484@ucbvax.BERKELEY.EDU> Date: Wed, 28-Oct-87 01:20:41 EST Article-I.D.: ucbvax.21484 Posted: Wed Oct 28 01:20:41 1987 Date-Received: Sat, 31-Oct-87 00:19:39 EST References: <4585@zen.berkeley.edu> <21440@ucbvax.BERKELEY.EDU> <4314@well.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: bryce@hoser.berkeley.edu.UUCP (Bryce Nesbitt) Organization: University of California at Berkeley Lines: 106 Keywords: Stack, CLI, Workbench, Process, Task, Environment, Bogus, Schlage Summary: Warning! Bogus information has been presented. ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) writes: >bryce@hoser.berkeley.edu (Bryce Nesbitt) writes: > >> From C, simply get a pointer to your task with "FindTask(0L);" This returns >> a pointer to struct Task from the exec/tasks.h include file. tc_SPLower is >> the lower bound of the stack tc_SPupper is the upper bound +2. > > Gee Byrce, I'm surprised you missed this. > Yes, there are tc_SP{Upper,Lower} fields in the task control block, > but these are not what DOS uses for the stack... > ...To find out the size of the stack DOS allocated for you when your > program was started, you say: > stacksize = ((struct Process *) FindTask (0L)) -> pr_StackSize; Guess what Leo? We are _both_ wrong! So much for Samaritanism. Actually we are both right. Got that one figured out yet? There is a not_so_subtle difference between the Workbench and the CLI. pr_StackSize GIVES THE WRONG ANSWER!! Better yet, pr_StackSize and cli_DefaultStack, both declared as longs, are stored in different units! I was so confused about the issue Leo brought up that only a sample program saved me. Try it from Workbench, "run" and direct CLI. Set a new stack number before each trial. Take note of just who's stack pr_StackSize represents (Hint: It's not always yours). Take note that my solution will not work either. (Also be on the lookout for a certain piece of commercial Amiga software that, when run from the CLI, seems to use 8,000 more bytes than it needs to... then complain to the programmer. :-) /* * stack_test.c 27-Oct-87. Bryce Nesbitt * * Created so I could have a clue. Just how is that stacksize stuff saved? * * This program points out that CLI started programs will have the stacksize * from cli_DefaultStack. This size is also saved at 4(a7) at startup... but * that is not available to a C program. THE NORMAL TASK STRUCTURE REFERS TO * THE CLI PROCESSES' STACK... NOT THE ONE YOU ARE RUNNING ON! * * From the Workbench there is no cli_DefaultStack. Here the normal task * structures take hold. * */ #include "exec/types.h" #include "exec/tasks.h" #include "libraries/dosextens.h" #include "stdio.h" struct Process *FindTask(); main() { register struct Process *Process; register FILE *Handle; struct CommandLineInterface *CLI; if (!(Handle=fopen("con:0/11/250/128/Stack Window","a"))) exit(20); /* "a" is used so the window won't flicker */ Process=FindTask(0L); if (CLI=(struct CommandLineInterface *)(Process->pr_CLI<<2)) { if (CLI->cli_Background) fprintf(Handle,"Background"); else fprintf(Handle,"Foreground"); fprintf(Handle," CLI #%ld\n\n",Process->pr_TaskNum); fprintf(Handle,"cli_DefaultStack is: %ld\n\n",\ CLI->cli_DefaultStack<<2); } else { fprintf(Handle,"This is not a CLI process\n"); fprintf(Handle,"Stack is %ld\n\n",Process->pr_StackSize); } /* Other useless information (we already know the stack size) */ fprintf(Handle,"pr_StackSize %ld\n",Process->pr_StackSize); fprintf(Handle,"pr_StackBase $%lx\n\n",Process->pr_StackBase<<2); fprintf(Handle,"tc_SPLower $%lx\n",Process->pr_Task.tc_SPLower); fprintf(Handle,"tc_SPUpper $%lx\n",Process->pr_Task.tc_SPUpper); fprintf(Handle,"Upper-Lower %ld\n\n", (long)Process->pr_Task.tc_SPUpper-\ (long)Process->pr_Task.tc_SPLower); fprintf(Handle,"tc_SPReg $%lx\n",Process->pr_Task.tc_SPReg); Delay(75L); /* Be quick :-) */ fprintf(Handle,"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); /* Dramatic exit :-) */ fclose(Handle); } |\ /| . Ack! (NAK, SOH, EOT) {o O} . bryce@hoser.berkeley.EDU -or- ucbvax!hoser!bryce (") U "I never said you _could_, I merely said you _should_." -Humpty Dumpty