Guardian Programmer's Guide

Table Of Contents
Managing Memory
Guardian Programmer’s Guide 421922-014
17 - 9
Managing the Native User Data Areas
globals-heap size is 1.1 GB. On the TNS/E platform, the maximum globals-heap size is
1536 MB.
If your program needs data areas in addition to the area provided by the globals-heap
segment, you can allocate one or more flat segments or selectable segments, as
described later in this section under Using (Extended) Data Segments.
How the Main and Priv Stacks Are Used
The main and priv stacks for a process are made up of stack frames, each of which
contains the activation record for a procedure called during process execution: the
main stack contains the stack frames for nonprivileged procedure calls, and the priv
stack contains the stack frames for privileged procedure calls. When a nonprivileged
process begins execution, a main stack and priv stack are created. Execution
automatically switches to the priv stack when a privileged procedure is called and back
to the main stack when that procedure finishes.
Contents of a stack frame include local variables, saved registers, and parameters to
called procedures. The frame size is variable, depending on the number of registers,
variables, and parameters. As shown in Figure 17-3, both the main stack and the priv
stack begin at fixed addresses and grows from higher to lower addresses as additional
space is needed. Use the HEADROOM_ENSURE procedure to ensure the priv stack
has sufficient room to grow.
Figure 17-4 shows an example of a main stack for a native process.
When the main procedure starts to execute a stack frame is created for it and its local
variables are added to the stack frame as shown in Figure 17-4(a). The sp (stack
pointer) register points to the last (lowest-addressed) byte in the stack frame.
When the main procedure calls another procedure (procedure 1 in Figure 17-4), the
main procedure places up to four parameters (in the TNS/R environment) or 8
parameters (in the TNS/E environment) into stacked registers and stores any
additional parameters into an area within the stack frame known as the callout area.
The instruction that transfers control to the called procedure also stores the return
address into the ra (return address) register.
The called procedure (procedure 1) then does the following:
Decrements the sp register to allocate its own stack frame, with room for local
variables, saved registers, and enough callout space for parameters to be passed
to any procedures it calls.
Stores registers (including the return address and any of the saved registers that it
will use) into its stack frame.
Stores the parameter registers into their reserved locations in the main procedure’s
callout area. This area is also referred to as the called procedure's callin area
because the called procedure can access this area as part of its own stack frame.
(Note that if any of these operations are not needed, they might be eliminated by
optimization.)