I assume the fix would be to install an EXC_BAD_ACCESS
handler after kicking off the app event loop.  That would
make sure that Carbon never saw it.
But I don't know how to do that.


I don't have a 10.5 mac to see if this is moot with the changes to CrashReporter.app.

mach/mach.h has thread_set_exception_ports() to install handlers for mach exceptions. There is also a task_ version for all the threads in a task.

The basics are like:

        /* recieve right */
        kret = mach_port_allocate(mach_task_self(),
                                                        MACH_PORT_RIGHT_RECIEVE,
                                                        &exception_port);

        /* send right */
        kret = mach_port_insert_right(mach_task_self(),
                                                        exception_port,
                                                        exception_port,
                                                        
MACH_MSG_TYPE_MAKE_SEND);

        /* select exc type */
        kret = thread_set_exception_ports(mach_thread_self(),
                                                                
EXC_MASK_BAD_ACCESS,
                                                                exception_port,
                                                                
EXCEPTION_DEFAULT,
                                                                
THEAD_STATE_NONE);

Then you do what you want with the exception; in the common case that means set up fake sigcontext and deliver to signal handler code.

Amit Singh's osx kernel book has example code (http://macosxbook.com/ book/src/ in fig. 9-38). http://tinyurl.com/46dsgp is a production example with comments @ the phrase ``Mach's exception mechanism''.

It's Apple's bug, and that's too far to have to go to work around it, IMO, but the technique might be interesting or handy for this kind of software atop osx.

-Josh


Reply via email to