Subject: Re: delivering faulted-upon address in trap frame to userland
To: None <M.Drochner@fz-juelich.de>
From: Christos Zoulas <christos@zoulas.com>
List: port-i386
Date: 10/17/2006 18:22:26
On Oct 17, 10:55pm, M.Drochner@fz-juelich.de (Matthias Drochner) wrote:
-- Subject: Re: delivering faulted-upon address in trap frame to userland

| I've actually found one, which made me reconsider these things.
| It is mono which tries to find out the limits of its stack by probing
| the addresses. It does so as a last resort; other OSes use constants
| or sysctls. This could be changed, but the fact remains that a user
| program shouldn't notice if a kernel uses some <insert your favorite
| curse here> segmentation techniques instead of a plain paging model.
| So we should issue a SIGSEGV in any case where an unmapped address
| is accessed. And since that poor i386 doesn't tell anything on that
| catch-all GP fault which would help finding out the real reason we
| don't have much choice than to issue that SIGSEGV on everything causing
| a GPF.

Yes, I agree.

| > I think that sending SIGILL is wrong (because this is not an illegal
| > instruction).
| 
| Reading the siginfo manpage I'd say that a SIGILL leaves much room
| for interpretation. It can be ILLOPC or ILLOPN, and a lot more. It
| is actually the most generic among the signals in question as I see it.

Right, but is overloading it with other unrelated to "Illegal Instruction"
problems correct? So now when your program dies from something that is
related to a "Bus Error", it will print "Illegal Instruction" instead.
This is not good; none of the other OS's do that.

| > Perhaps it is better to just put 0
| > as the address instead of cr2?
| 
| I wouldn't use 0, or -1, or 0xdeadbeef, to avoid confusion with
| traps generated by real user program errors.
| Perhaps 0x12345678 (but I wouldn't seriously object 0x87654321:-).

I don't mind putting a constant there: 0BAD1DEA

| > What do other OS's do?
| 
| I've checked Linux and FreeBSD; both aren't correct according to
| SUSv3: FreeBSD sends a SIGBUS without a correct address, and Linux
| sends a SIGSEGV, also without a correct address, iirc.
| It seems that SUSv3's siginfo specification didn't consider the
| sad i386 reality... anyway, user code dealing with that is very
| OS dependant anyway, and SUSvX isn't going to change that. So I'd
| say for us it is OK to remove the wrong use of cr2, and keep the
| code as simple as possible, and stay compatible, would be the
| most reasonable thing to do.
| 
| What do you think of the appended patch?

I don't see the benefit of changing the signal from SIGBUS to SIGILL
just because we don't have the faulting address available. I really
think that we should not send SIGILL back because you usually get
SIGILL when you start executing garbage, not when you are inside
your regular code.

christos