This commit pretty much just implements the bridge between userspace and kernel code for kqueues; for the real details of the change, check out the commit in the LKM.
We need to initialize the flags in case we terminate as soon as we're created (because `_pthread_wqthread` requires valid flags).
This also fixes the x86_64 assembly to ensure that the 6th argument is actually passed (for some reason, the old code was causing the 6th argument to be a copy of the 5th). We don't need to specifically use `rbx`, so just use `r` and let the compiler decide what to use.
These are for guarded ports. While I believe we don't currently deliver port guard violation exceptions, there are certain updated programs (like `notifyd`) that need to be able to create and destroy Mach ports using `mach_port_{construct,destruct}`. This commit therefore adds some of the necessary plumbing (which is enough to satisfy `notifyd`) and leaves it up to a future commit to add proper support for guarded ports and port guard violation exceptions.
The main goal of this commit is to make it more easy to add or update any architecture we want to support (such as ARM64). Any changes we want to make would be done in the architectures.cmake file.
The secondary goal of this commit is to encourage a more architecture generic nomenclature. We shouldn't use i368/x86_64 unless we are dealing with code that is specific to those architectures.
First, libpthread now expects `workq_kernreturn` not to return when called with `WQOPS_THREAD_RETURN`. We have to resume the thread and give it a special value for `nkevents` that tells it to kill itself.
Next, Apple has reworked the priority system into a "Quality of Service" (QoS) system. Unfortunately, since we're building libdispatch with a few different settings than Apple's configuration, it seems that they've forgotten to correctly set QoS in some cases, so we have to it for them so that libdispatch doesn't blow up.
Finally, `WQOPS_SETUP_DISPATCH` has been stubbed so libdispatch thinks everything is fine. In the future, we might want to do something with the values it passes in, but for now we have nothing to do with them.
I was accidentally clobbering the `stack_addr` arg which is actually the `flags` arg for workqueues.
Also, use `stack_addr` from `args` instead of `rdi` (which is the dthread pointer) because the user could have allocated a custom stack and libpthread passes that in.
Finally, workqueues have a separate flag to indicate that the TSD base has been set.
This fix allows the child to actually return correctly.
It was present in an older commit but it got removed in a commit from a few months ago, in what looks like an accidental change (not sure how this code was still working, though).
I don't know why Apple felt the need to move those functions out, but we need to implement `strncmp` for ourselves because we use it before libplatform is initialized