Fault exception trashes a register causing a crash in [NSInvocation invoke]
- by Mike Weller
I have an NSOperation which fetches some objects from a core data persistent store and sums up a few totals. Sometimes an object is deleted while the operation in in progress, so a core data fault exception occurs. I try/catch the exception while summing to ignore it because I just want to skip objects that cannot be faulted in.
However, when one of these fault exceptions occurs (and I swallow it) there is a crash after the invocation returns in [NSInvocation invoke]. It's a bad memory access when dereferencing the value in r10 which according to GDB on a successful run points to one of these:
(gdb) x 0x38388348
0x38388348 <OBJC_IVAR_$_NSInvocation._retdata>: 0x00000008
If a fault exception occured a value of 0x02 is in the register which causes the crash.
A quick google search tells me that r10 should be saved by the callee, meaning it is not being restored by whatever code is changing it when this exception occurs.
Can anybody explain this? I'm not an expert when it comes to these kinds of low-level details