Subject: Re: SIGTRAP for traced processes and COMPAT_MACH
To: Matthew Orgass <>
From: Emmanuel Dreyfus <>
List: tech-kern
Date: 11/30/2003 11:01:42
Matthew Orgass <> wrote:

>   Why would darwin_trapsignal call trapsignal if a mach exception is
> raised?  I thought the point of this is to not do so.

darwin_trapsignal calls trapsignal if no Mach exception was generated,
so that a signal can be sent.
>   Since kpsignal2 is static this is better there, but I don't see how it
> would benefit trapsignal.

signals sent by traps for illegal instruction, memory fault and many
others are sent through trapsignal. trapsignal can call do
kpsignal/kpsignal1/kpsignal2 chain, or it can directly call kpsendsig
for an immediate signal delivery. 

If we interecept the signal in kpsignal2, we need to intercept it in
trapsignal too.
>   Also, should kevents be sent if a Mach exception is raised?

I see no need for this now... Only compatibility code is interested into
Mach exceptions.
>   So: does this really need to apply generally to all signals?  If not,
> the origional idea of just calling e_trapsignal for SIGTRAP would seem to
> make the most sense.

Yes. Darwin has yet another weird feature called softsignal. You request
it using ptrace(PT_SIGEXC, 0, 0, 0);
Once you did that, any signal (except non catchable signal such as
SIGKILL or SIGSTOP, of course) is inhibited, and a Mach exception is
sent in place of the signal. 

The Mach exception is sent to the port registered for EXC_SOFTWARE
exceptions. The exception message contains a code array, with code[0] =
SOFT_SIGNAL and code[1] set to the signal number. More code elements may
be used for siginfo information, I have not checked that yet.

Darwin's gdb uses that feature: it gets any signal to the traced process
as a Mach exception. In order to emulate this, any call to [k]psignal in
the kernel should be intercepted by COMPAT_MACH code to eventually
generate a Mach exception and inhibit the signal delivery.

I implemented my yesterday's proposal (an emulation hooked cheksignal
function in kpsignal2 and trapsignal), and this works fine. I'm awaiting
for opinions about this before committing it...

Emmanuel Dreyfus
Il y a 10 sortes de personnes dans le monde: ceux qui comprennent 
le binaire et ceux qui ne le comprennent pas.