Subject: Re: delivering faulted-upon address in trap frame to userland
To: None <port-i386@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: port-i386
Date: 09/01/2006 23:35:13
In article <200609012204.AAA0000098524@zel459.zel.kfa-juelich.de>,
Matthias Drochner <M.Drochner@fz-juelich.de> wrote:
>-=-=-=-=-=-
>
>
>M.Drochner@fz-juelich.de said:
>> It should be noted that the code implementing this on i386 (and
>> probably amd64) is not quite correct
>
>OK, before I completely forget about this I'll try to
>describe the problem and a possible fix.
>
>The problem is that SA_SIGINFO expects the address of the
>faulting memory reference to be delivered in the SIGSEGV
>and SIGBUS cases. And if we can't provide this, it is better
>to generate a SIGILL which just requires the address of the faulting
>instruction than to deliver wrong data.
>We can't provide the fault address of memory references
>unless it is a plain page fault. Blame Intel for this, but
>it is just a fact. CR2 is only set on page faults, the other
>uses in trap.c are wrong. The address of the faulting instruction
>is always gathered easily of course.
>(We _could_ find out the address of data references, but that would
>require emulation techniques which are clearly not worth the effort
>here.)
>
>Here is a patch which cleans this up quite radically. I haven't found
>bad side effects of this, just good ones, see
>http://lists.freedesktop.org/archives/liboil/2006-August/000106.html
>
>There might be bad effects in case programs catch SIGSEGV but get
>a SIGILL now, but I didn't find one so far.
>
>What do you think?
I think that sending SIGILL is wrong (because this is not an illegal
instruction). Perhaps it is better to just put 0
as the address instead of cr2? What do other OS's do?
christos