Skip to content

Commit

Permalink
Merge branch 'ignore-exceptions-from-subprocesses' into 8.36.0-with-s…
Browse files Browse the repository at this point in the history
…ubprocess-fix
  • Loading branch information
vorporeal committed Oct 9, 2024
2 parents 5575af9 + 6cd4f88 commit 7fea849
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,29 @@ handleExceptions(void *const userData)
kern_return_t kr = mach_msg(&exceptionMessage.header, MACH_RCV_MSG, 0,
sizeof(exceptionMessage), g_exceptionPort, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
if (kr == KERN_SUCCESS) {
break;
// Only handle exceptions generated in this process. Task-level exception
// handlers are inherited by subprocesses, and we don't want to handle or
// report exceptions in arbitrary subprocesses of the one in which we were
// installed.
if (exceptionMessage.task.name == mach_task_self()) {
break;
}

SentryCrashLOG_DEBUG("Received exception from subprocess. Ignoring message and waiting for another.");
// Send a reply saying "I didn't handle this exception".
replyMessage.header.msgh_id = exceptionMessage.header.msgh_id;
replyMessage.header.msgh_bits = exceptionMessage.header.msgh_bits & MACH_MSGH_BITS_REMOTE_MASK;
replyMessage.header.msgh_remote_port = exceptionMessage.header.msgh_remote_port;
replyMessage.header.msgh_local_port = MACH_PORT_NULL;
replyMessage.header.msgh_size = sizeof(MachReplyMessage);

replyMessage.NDR = exceptionMessage.NDR;
// Tell the kernel that we failed to handle the exception, so that
// the next handler in the chain gets invoked.
replyMessage.returnCode = KERN_FAILURE;

mach_msg(&replyMessage.header, MACH_SEND_MSG, sizeof(replyMessage), 0, MACH_PORT_NULL,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}

// Loop and try again on failure.
Expand Down

0 comments on commit 7fea849

Please sign in to comment.