HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 85 (of 101)
Chapter 11 Software Development
October 29, 2013
On Itanium the stack works a bit differently. While on PA-RISC the stack holds both register
contents and local variables mixed together in the same area, the Itanium architecture splits the
stack region into 2 parts and separates the register contents from other local variables.
The register stack starts at the lower end of the stack region and grows upwards, while the
normal stack starts at the upper end and grows downwards. The guard page is located in the
middle of the stack to separate both parts from each other.
We also have 2 different processor registers for each part of the stack. The backingstore pointer
$bsp always points to the current upper end of the register stack, and the stack pointer $sp
always points to the current lower end of of the normal stack:
0x7ffff000
-maxdsiz
v
$bsp
v
0x7ffff000
-maxdsiz/2
v
0x80000000
-maxdsiz/2
V
$sp
v
0x80000000
v
register
Stack
unused *1
==>
guar
d
page
Unused *2
<==
normal
stack
*1: reserved for the register stack
*2: reserved for the normal stack
A stack overflow occurs if either $bsp or $sp reach the guard page. To find out the register
values, use gdb as follows:
$ gdb -q myprog 7565
:
(gdb) p/x $bsp
$3 = 0x200000007efff348
(gdb) p/x $sp
$4 = 0x200000007ffff3d0
(gdb) x/x ($sp+$bsp)/2 ### address in the middle of the guard page
0x200000007f7ff38c: Error accessing memory address
0x200000007f7ff38c: Bad address.
(gdb) q
The same checks can be done with a core file.
In a multithreaded program, each thread needs its own stack. While the initial thread (also called
the primordial thread) uses the process stack, as described above, any other thread will use a
memory mapped region as its stack, which will be allocated immediately before the thread is
created, and which will be unmapped after the thread has exited.
Each thread stack has the same layout as the primordial thread stack, but its size is not
determined by the kernel parameter maxdsiz, but rather by the program, or by the default pthread
stacksize, which is 64k on PA-RISC, and 256k on Itanium. Obviously thread stacks are much