I'm not quite sure why we used to always create our own kqueue, but that could cause all sorts of issues. For example, if the user decided to add events via a different kevent call and then use kevent_qos to poll, they wouldn't get any events because we're actually listening to a different kqueue. Another example: since the kqueue was always shared between kevent_qos calls, different kqueue fds called on kevent_qos would all operate on the same kqueue.
Of course, in the `kq=-1` case, we still perform the correct behavior of using our default kqueue. But if the user gave us a kqueue, let's use it.
macOS and BSD make sockets created from `accept` inherit the listening socket's O_NONBLOCK flag (and maybe some others, but that requires further testing).
The comment pretty much explains it: we need to make sure we have enough space for the vchroot path fixup. This was causing segfaults when trying to use Unix sockets sometimes (consistently reproducible with the Mio test suite's Unix socket tests).
[skip ci]
Skipping CI because I know the build is currently broken with this commit; I'm going to revert our use of mDNSResponder and add back our libsystem_dnssd stub, and then patch up libresolv/libinfo to fix DNS resolution (if necessary)
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.