Unix Stack Frame Questions

Andy Tan tan at epic.epic.com
Sat Mar 23 09:43:43 AEST 1991


I am trying to save the content of stack frame, so I can restore it later.
The same source code runs on SunOS 3.x well, however, it does not work on
SunOS 4.x.  

The following is part of my save C procedures:
save(){
	....
	int stack_size, stack_bot;
	/* stack_bot is the last automatic variables in
	   this procedure */
	
	if (setjmp(save_state) == 0) {
		....
		stack_bot = (int) &stack_bot;
		....
	}
	else {
		....
	}
}

Unix/C gurus, please help me with the following questions:

1. Is it right to assume that the address of the last automatic
   variable is the bottom of stack frame ?
2. How come save_state[2], which stores the Stack Pointer for
   SunOS 4.x, is far away from the assumed stack bottom ?
   Note:  save_state[14], which stores the SP for SunOS 3.x, is
	  very close to the assumed stack bottom.
3. Any major differences in the way of stack frame manipulation
   are there between SunOS 3.x and SunOS 4.x ?
4. Any better solutions to save and restore stack frame for
   SunOS 4.x ?

Any help with you guys will be greatly appreciated.

-- 
-Andy Tan



More information about the Comp.unix.programmer mailing list