This makes xtrace print more useful debugging information for posix_spawn. There are other syscalls that could definitely benefit from having more detailed output (e.g. `kevent` and friends).
Also, I was noticing segfaults when processes exited with pthread_terminate; they were due to xtrace using pthread keys after pthread_terminate had been called, which cleans up pthread keys. This new static key approach should be fault free, if only at the expense of leaking some memory per-thread. TODO: add a death hook in libsystem_kernel to notify xtrace when a thread is *actually* going to die.
* Fix the Carbon framework to properly reexport the right frameworks
* Add many missing Carbon-related type definitions
* A couple of fixes in some submodules (see their commits)
...and use it in the various printing functions, instead of `__simple_vsprintf`. This fixes some buffer overflow issues with really long messages (like for applications with long path names when logging the execv expansion message).
Also, install an empty `/Library/Preferences` directory.
POSIX_SPAWN_CLOEXEC_DEFAULT is set to close all fds inherited by the new process except for those explicitly marked as inheritable (or those newly created by posix_spawn actions). We can replicate this by adding O_CLOEXEC to all open fds in the child before performing our actions (except special fds like commpage).
Other than that, some new actions have also been implemented: chdir, fchdir, and inherit. chdir and fchdir change the cwd of the child to the given path or fd. inherit ensures the given fd is inherited by the child (i.e. that O_CLOEXEC is not set on it).
The new env var XTRACE_KPRINTF can be set, which will cause xtrace to print all tracing messages with kprintf (so you can view them with dmesg).
The current implementation just does a simple little substitution between regular printf and kprintf, which can result in messages being broken up over multiple lines due to the way kernel messages are presented. This should be fixed eventually (possibly by buffering output until a newline).
This commit also gets rid of xtrace's simple.{c,h}, using libsystem_kernel's "simple" functions instead.
Some of these (like __simple_printf and __simple_kprintf) were already externally visible, but now all of the functions in the simple.h header are externally visible.
One benefit of this is that we can use these in xtrace and get rid of the redundant code in xtrace's simple.{c,h}