The frame structure


If you've been poking around in /usr/include , you may have already discovered the header files that describe your system's stack and the frames on the stack. These files are in different locations on Solaris 1 and Solaris 2 systems.

Solaris 1 header files

On Solaris 1, you will want to look in the /usr/include subdirectory for your system's architecture; sun2 , sun3 , sun3x , sun4 , sun4c , or sun4m . Within that directory, you'll find the stack described in asm_linkage.h .

asm_linkage.h diagrams a stack and defines several stack- related functions and assembly language macros. However, asm_linkage.h does not describe the contents of a stack in any real detail. It just shows a nice diagram. To get the details of what a frame on the stack looks like, we have to look at frame.h which can be found in the same directory as asm_linkage.h .

Since the stack basically looks the same between the BSD-based SunOS and the SVR4-based Solaris 2, we will use a Solaris 2 system throughout the rest of this chapter.

Solaris 2 header files

On Solaris 2 systems, the stack is diagrammed in /usr/include/sys/stack.h ; however, again, the actual definition of the frame structure is in /usr/include/sys/frame.h . First, let's look at a trimmed -down picture of /usr/include/sys/stack.h .

Example 17-1 Excerpt from /usr/include/sys/stack.h
 /*   * A stack frame looks like:   *   * %fp->                                  *      -------------------------------   *        Locals, temps, saved floats     *      -------------------------------   *        outgoing parameters past 6      *      --------------------------------\   *        6 words for callee to dump       *        register arguments               *      -------------------------------  > minimum stack frame   *        One word struct-ret address      *      -------------------------------    *        16 words to save IN and          * %sp->  LOCAL register on overflow       *      --------------------------------/   */ 

Here is the frame structure as described in this partial view of /usr/include/sys/frame.h on a SPARCstation 20 system running Solaris 2.3.

 /*   * Definition of the sparc stack frame (when it is pushed on the stack).   */  struct frame {      int     fr_local[8];           /* saved locals */       int     fr_arg[6];             /* saved arguments [0 - 5] */       struct frame    *fr_savfp;     /* saved frame pointer */       int     fr_savpc;              /* saved program counter */       char    *fr_stret;             /* struct return addr */       int     fr_argd[6];            /* arg dump area */       int     fr_argx[1];            /* array of args past the sixth */  }; 

Let's talk about the SPARC frame structure in detail.

The first eight integers in a frame, fr_local [0] through fr_local [7] , are the contents of the local registers %l0 through %l7 . These are full 32-bit words. Local registers are used locally within a routine only and are not used to pass information to another routine.

The next six integers, fr_arg [0] through fr_arg [5] , contain the first six arguments a routine or procedure receives when being called. If more than six arguments were sent, we will find the remainder of them elsewhere on the stack.

The next word in the frame structure contains the address of the previous frame. In other words, this is a pointer to another frame structure. This corresponds to register %i6, which is the old stack pointer ( %o6 ) belonging to the calling routine.

The next word, fr_savpc , contains the PC or program counter of the last instruction executed by the calling routine. When you look at this, you will usually find a call or jump instruction. When we "pop" the stack to return to the calling routine, this PC is used as the reference for where execution is to continue.

The next word, fr_stret , is specifically set aside for use by functions that return structures. The address of the returned structure is placed here.

The next six words, fr_argd [0] through fr_argd [5] , are used occasionally as a temporary storage space for the six arguments normally kept in the fr_arg variables .

And finally, we get to fr_argx . If more than six calling arguments were used, they would be placed at the end of the frame starting at fr_argx . Although we see fr_argx defined as an integer array of 1 in length, fr_argx represents the rest of the frame and can be of varying size, depending on the needs of the routines in use. What may surprise you, however, is that the frame containing the seventh and additional arguments will not be the same frame that contains the first six calling arguments. We will come back to this later. For now, it is important to note that SPARC stack frames do not have a fixed size .



PANIC. UNIX System Crash Dump Analysis Handbook
PANIC! UNIX System Crash Dump Analysis Handbook (Bk/CD-ROM)
ISBN: 0131493868
EAN: 2147483647
Year: 1994
Pages: 289
Authors: Chris Drake

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net