Port-sparc64 archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Stack bias
On Tue, 11 Aug 2009, der Mouse wrote:
> >> "Without stack" != "using %o6 as a stack pointer". Leaf routines
> >> may very well need %sp for nothing at all - everything they need of
> >> the stack may come off %fp.
The convention in the ABI is that the stack pointer points to the register
save area for that stack frame. Now the kernel is designed in such a way
that if the stack is not accessible on a trap any dirty register windows
are saved to the PCB instead. This allows you to zorch the stack pointer
and frame pointer and still run, at least for a little. But the PCB
only has space to save as many register windows as the CPU implements.
If you try to use the 'save' and 'restore' instructions and use more
windows than the CPU contains the kernel will kill you.
> > They can instead use %fp for whatever they like, but need to leave
> > %sp untouched.
Uh, no.
> It seems to me this also means that the "low bit of %o6" test is not
> safe. The scenario: routine A calls (leaf) routine B, and B scribbles
> on (its) %fp. When B returns, for at least one instruction, A's %sp
> will be whatever trash B left there; an interrupt during that interval
> is likely to destroy the high halves of all A's registers. But if I
> can think of this in thirty seconds, ABI designers surely can with all
> the time at their disposal, so I must be missing something. What?
If you have a valid register window you need to be certain that the
associated %o6 register always points to a valid register save area or an
invalid address. Otherwise you may very well get some sort of data
corruption. This is because the register windows are managed by the
kernel.
The same is true of 32-bit SPARCs, except they only need to worry about
32-bit registers so they don't test the low bit of %o6. The 32bit
kernel always saves and restores register windows to the location
pointed to by %o6 with no offset. If you want to use some other stack
convention you need to make changes to the userland binaries (or the
compiler that generates them) as well as the kernel.
Eduardo
Home |
Main Index |
Thread Index |
Old Index