Commit Graph

3 Commits

Author SHA1 Message Date
Ariel Abreu
87778ae3e3
Add back some fixes from old psynch code and attach cancellation flags directly onto uthreads 2020-11-18 11:45:16 -05:00
Ariel Abreu
35919a3eaf
In-kernel kqueues! (mostly)
This commit brings a huge makeover to the way Darling does kqueues. It enables us to emulate kqueues more accurately by using XNU's own code as much as we can. In doing so, it also increases the LKM's use of XNU's BSD code and systems.
Part of the commit makes the BSD memory system (partially) usable, which should also help with future use of XNU's BSD code.

With this commit, the update branch now works to the point the `darling shell` actually enters a shell, background processes launched by launchd (seem) to run correctly, and various CLI utilities and scripting languages also (seem) to run correctly.

There are certain features that have not yet been implemented, however. Notably, I had to #ifndef away kqworkq and kqworkloop support, as it would require in-kernel pthread operation support.
Also, EVFILT_SIGNAL and EVFILT_FS have not yet been implemented. And though it has been coded in, EVFILT_VNODE has not been tested yet--but that's okay, as I expect to make more commits to continue implementing kqueue and ironing out any issues that pop up in testing.
EVFILT_SOCK has been partially coded, but I commented it all out due to identifier clashes between XNU's network headers and Linux's that I didn't want to resolve right now.

Among other changes, this commit also makes the process notification API in the task registry more generic, so that other subsystems in the LKM can listen for events as necessary. We use it to implement EVFILT_PROC, but we also make use of it
to listen for when a process is forked, so we can close its kqueues in the child.

I'm actually suprised at how easily the EVFILT_TIMER and EVFILT_MACHPORT filters work with all this plumbing in place, seemingly with no issues. In fact, EVFILT_MACHPORT works better than how it used to with libkqueue and now handles
the Mach message test program I created locally just as well as macOS does (a little slower, of course).

For the actual details of the implementation, please refer to the code and the (many) comments I left in `kqueue.c`. There are a few important TODO and BUG comments I left there.
2020-10-26 23:17:06 -04:00
Ariel Abreu
cd6d3e1402
Actually destroy uthreads and prevent a false panic in procs.c 2020-09-22 12:21:55 -04:00