Handling mach exceptions in 64bit OS X application

Posted by Brad S on Stack Overflow See other posts from Stack Overflow or by Brad S
Published on 2010-05-13T02:25:26Z Indexed on 2010/05/13 2:34 UTC
Read the original article Hit count: 547

Filed under:
|
|
|
|

I have been able to register my own mach port to capture mach exceptions in my applications and it works beautifully when I target 32 bit. However when I target 64 bit, my exception handler catch_exception_raise() gets called but the array of exception codes that is passed to the handler are 32 bits wide. This is expected in a 32 bit build but not in 64 bit.

In the case where I catch EXC_BAD_ACCESS the first code is the error number and the second code should be the address of the fault. Since the second code is 32 bits wide the high 32 bits of the 64 bit fault address is truncated.

I found a flag in <mach/exception_types.h> I can pass in task_set_exception_ports() called MACH_EXCEPTION_CODES which from looking at the Darwin sources appears to control the size of the codes passed to the handler. It looks like it is meant to be ored with the behavior passed in to task_set_exception_ports().

However when I do this and trigger an exception, my mach port gets notified, I call exc_server() but my handler never gets called, and when the reply message is sent back to the kernel I get the default exception behavior.

I am targeting the 10.6 SDK.

I really wish apple would document this stuff better. Any one have any ideas?

© Stack Overflow or respective owner

Related posts about darwin

Related posts about osx