EmbarkStudios / crash-handling

Collection of crates to deal with crashes
Apache License 2.0
138 stars 13 forks source link

Improve MacOS support #25

Closed Jake-Shadle closed 2 years ago

Jake-Shadle commented 2 years ago

Adds a mach ports based IPC client/server to crash-context. As stated in the docs, if using a crash-context::CrashContext between processes on MacOS, the information in the context must (for now?) be passed via a mach port, as the port descriptors will be translated (on the sender or the receiver is...unclear) into values that are actually useful. In particular, in a crash process, mach_task_self() is used to say the crash occurred in that task, but mach_task_self returns the same value in every task, and indeed on every task on every machine on the same kernel! It's only when it is sent over a mach port that the task name will be turned into an actual unique identifier so that a process that wishes to eg. dump that task will not actually be dumping itself.

This also improves the mac exception handler for user signals, and makes the SIGABRT signal use a "user signal" underneath, to ensure that the crash context always has a separate handler thread (where the exception port is listening) and a crash thread (where the exception was actually source) as previously they would be the same in the SIGABRT case which makes crash analysis more difficult. It also means that explicitly raising an exception will actually wait for the user handler to finish processing it and return a result, rather than just continue on.