[comp.sys.amiga] SetStack

dillon@CORY.BERKELEY.EDU (Matt Dillon) (01/21/88)

>;    SetStack(newstack,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.

	You CAN'T deallocate the old stack,  Because it will be deallocated
by the parent task... For instance, my shell allocates the stack for the
'command', then deallocates after it is through.  Also, the parent may
depend on the task structure not changing, so it is probably better NOT to
diddle the pointers... at least they should be the same on program exit.

					-Matt

bryce@hoser.berkeley.edu (Bryce Nesbitt) (01/21/88)

In article <> dillon@CORY.BERKELEY.EDU (Matt Dillon) writes:
|
|>;    SetStack(newstack,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.
|
|	You CAN'T deallocate the old stack,  Because it will be deallocated
|by the parent task...

That is exactly why it does not.   It would be desirable if it could.
An unused stack is wasted memory.


|Also, the parent may
|depend on the task structure not changing, so it is probably better NOT to
|diddle the pointers... at least they should be the same on program exit.

pr_ReturnAddr always points to the top-4 of the *currently* executing
stack.  The size of the currently executing stack is stored in
the long at top-4.  At top-8 is the return address used during process 
removal.
 
This is the only thing SetStack() does or should diddle with.


Not keeping pr_ReturnAddr as a pointer to the *currently executing*
stack destroys stack checking algorithms.  With it you can have a nice
clean stack check every time the process is switched out.
Matter of fact, I'm running that right now.

|\ /|  . Ack! (NAK, SOH, EOT)
{o O} . bryce@hoser.berkeley.EDU -or- ucbvax!hoser!bryce (or try "cogsci")
 (")
  U	"As an engineer, I only set the value of a product... not the cost."
	-Bryce Nesbitt