Ralf Baechle wrote:
On Thu, Nov 15, 2007 at 09:46:25AM +0100, Franck Bui-Huu wrote:
Ralf Baechle wrote:
Another reason is to get rid of the classic trampoline the kernel installs
on the stack. On some multiprocessor systems it requires a cacheflush
BTW, could we get rid of the trampoline so easily ? I mean won't we have
to keep it for backward compatibility reasons ?
There has to be some way for user code to unwind the call stack through
signal handler frames. For Linux/MIPS systems that use GCC as their
system compiler, this is done by code in libgcc which is part of the GCC
runtime.
Currently the unwinder examines the code at the signal handler return
address and if it detects one of the several know trampoline code
sequences, it makes assumptions about the way the kernel lays out the
stack. In particular, it assumes that there is a struct sigcontext at a
well known offset from the stack pointer at entry to the signal handler.
The code that handles this is in gcc/config/mips/linux-unwind.h
As of GCC-4.3 the location of the trampoline is unimportant, but the
location of the sigcontext relative to the value in $sp is important and
should not be changed unless there really is no other choice.
The trampolines are an implementation detail. Little software needs to
know about it, so while I expect some slight colateral damage from getting
rid of trampolines it's not going to be painful. GDB is the primary piece
of software that will need to change.
And any user code that uses SIGSEGV to detect and handle dereferencing
null pointers.
Some of the other architectures have an sa_restorer field in struct
sigaction but we don't have that on MIPS.
One way to deal with this would be to do a similar as IRIX where the
sigaction(2) takes a 4th argument which takes the role of sa_restorer.
For backward compatibility an SA_RESTORER field. So if the SA_RESTORER
is clear we'd be using a classic trampoline, if it's set the value of
the 4th argument.
Or slightly crazier, put a kernel address into the $ra register of the
invoked signal handler. So the signal handler will cause an address
error exception which then can be trapped. Additional advantage - some of
the "Don't let your children do this ..." sections of code can go away ;-)
I am liking the idea of putting the trampoline code in the (as of yet
non-existent vdso). This eliminates the need to flush the icache, but
maintains the ability of user code to unwind through signal frames.
Putting a .eh_frame section in the vdso would be even better as that
would eliminate the need for libgcc to do code reading and let the
kernel use any means desired to return from signal handlers.
David Daney