Commit Graph

665 Commits

Author SHA1 Message Date
Ariel Abreu
7e2ade452a
Add NOTE_MACHTIME support
This is actually used in libdispatch for pretty much all non-wall-clock
timers, so as you might imagine, it's used quite frequently and we were
processing it incorrectly, leading to stalls in some programs that use
such timers for short intervals/deadlines.
2023-10-04 00:27:01 -04:00
CuriousTommy
599a9e8316
Merge pull request #4 from darlinghq/remove_lkm
Remove LKM
2023-07-26 11:57:27 -07:00
Thomas A
7c71d0d993 Update CMake Version To 3.13 2023-07-26 10:28:23 -07:00
Thomas A
203b36b0da Update Include Path To Use XNU Repo Instead 2023-05-19 10:58:19 -07:00
Thomas A
7e944dd0e3 Don't Depend On <lkm/api.h> 2023-05-16 11:57:42 -07:00
Thomas A
a60532d647 Update Minimum CMake Version to 3.10 2022-11-30 22:27:10 -08:00
Thomas A
2c0ddde743 Add "private.h" symbol-link in "linux" directory 2022-09-10 12:48:48 -07:00
Ariel Abreu
8411c8c69f
Support EV_DISPATCH together with EV_ONESHOT
Apple uses this combination to defer deletion of knotes until they're re-enabled.
2022-09-06 00:52:42 -04:00
Ariel Abreu
5118b93d80
Merge pull request #3 from trungnt2910/dev/trungnt2910/wsl1-support
fix: Socket SO_ACCEPTCONN hack for WSL1
2022-09-01 10:12:54 -04:00
Trung Nguyen
4e6a9f048b
fix: Socket SO_ACCEPTCONN hack for WSL1
As SO_ACCEPTCONN does not work properly on these systems,
we have to rely on Darling to report listening sockets in
libsystem_kernel and keep a registry of listening sockets
in libkqueue.
2022-08-25 09:18:03 +07:00
Ariel Abreu
8572682de1
Fix FD leaks in FS, Mach port, and proc filters 2022-06-30 22:43:03 -04:00
Ariel Abreu
dfe9fbc0d2
Various synchronization and resource management fixes
The two most notable fixes are:
1) libsystem_kernel now delegates closing kqueue descriptor to us.
Rather than close the descriptor and inform us later, it allows us to
handle kqueue closing ourselves.
This avoids a double-close that was causing issues (most notably
with multi-threaded programs).
2) We now `map_delete` all references to kqueues being freed. We were
previously only deleting the original FD reference.

In addition, wherever `kqueue_delref` is called, the `kq_mtx` must be held.
This is required because that function can call `kqueue_free`, which
requires that lock to be held. While inefficient, this should help avoid
races between threads concurrently modifying the kqueue map. A better
solution should be devised later to make this more efficient.
2022-06-15 11:42:47 -04:00
Ariel Abreu
8b748d1070
Use a special version of dup
libsystem_kernel's `sys_dup` and `sys_dup2` call `kqueue_dup`, so if we
use the normal `dup` call in libkqueue, we end up recursing back into
libkqueue (unecessarily).
2022-03-09 17:13:29 -05:00
Ariel Abreu
f3f8cb99b0
Fix kqueue_close_cb logic to use EV_RECEIPT
Using this flag tells kevent to keep processing even when an error is
encountered adding an event. This means that it will actually check both
EVFILT_READ and EVFILT_WRITE now.

With the old code, we were leaking descriptors created for EVFILT_WRITE.
2022-03-09 17:09:26 -05:00
Ariel Abreu
f721a1d2d8
Keep processing events after EV_RECEIPT and remove unnecessary race check
I added that race check back when I was trying to use libkqueue with update-sources because launchd was segfaulting and libkqueue seemed to be the cause, but I can't reproduce this anymore. The way it was, it was actually causing issues with EPOLLET events.
2022-03-09 17:07:16 -05:00
Ariel Abreu
ed45525ac4
Use kprintf rather than logging to a file 2022-02-26 01:14:07 -05:00
Ariel Abreu
9b4eecbd88
Don't check for new events if KEVENT_FLAG_ERROR_EVENTS is given
We were dropping events before because libdispatch calls kevent with this flag to update a knote without checking for new events; when it did that and we handed it some new events, it would ignore them since they didn't contain `EV_ERROR`, which meant those events were lost forever.
2022-02-25 16:15:41 -05:00
Ariel Abreu
76d8aa3dce
Only process EV_DISPATCH and EV_ONESHOT when we get a valid event
If the copyout callback for a filter indicates that the event should be ignored/dropped, we should not process EV_DISPATCH or EV_ONESHOT, as this would lead to missing actual events in the future.

Some filters (e.g. EVFILT_PROC) do specifically want to process EV_ONESHOT even when dropping an event, so this also introduces a special filter ID (EVFILT_DROP_POSTPROCESS) that enables the old behavior for individual events. Additionally, rather than just using `0` as a special filter ID, this commit introduces EVFILT_DROP (to be clear about its meaning).
2022-02-25 16:12:17 -05:00
Ariel Abreu
bcef9ea04b
Handle no-event case in copyin for EVFILT_MACHPORT 2022-02-20 01:03:17 -05:00
Ariel Abreu
532529e49c
Implement EVFILT_PROC with darlingserver 2022-02-12 00:38:04 -05:00
Ariel Abreu
975d7457cd
Implement EVFILT_MACHPORT with darlingserver
See the darlingserver repo for the majority of the logic behind the new implementation.

TODO: libkqueue needs proper kevent_qos support in order to be able to use the data_out parameter passed in to kevent_qos calls (which is what *should* be passed as the default buffer to use when ext[0] is not available in EVFILT_MACHPORT).
2022-02-10 13:23:16 -05:00
Ariel Abreu
b395f5bf0d
Disable EVFILT_{MACHPORT,PROC}
These need to be reimplemented for darlingserver. This commit simply replaces them with code that prints "TODO" and then aborts.
2022-01-28 00:10:59 -05:00
Ariel Abreu
3f76738619
Handle race condition when waiting for events
If multiple threads are waiting on the same kqueue, they'll all be woken up at the same time, however only one can acquire the lock at a time. The one that acquires it first gets to consume some events from the kqueue while everyone else waits. But, after they're done and they release the lock, the next person will have *less events available*. We were previously neglecting to check for this and trying to consume more events than were available (leading to some nasty deadlocks with certain events like EVFILT_USER).
2020-10-07 12:50:08 -04:00
Ariel Abreu
9a94fadf15
Workaround an issue caused by a flag
When we pass back EV_VANISHED to libdispatch, it thinks we're telling it the source vanished (because that's really what it means) and it explodes
2020-10-06 08:28:31 -04:00
Ariel Abreu
3c34d903b4
Initial update to clean up include directories
"initial" because there might some additional modifications necessary later on
2020-05-14 12:57:41 -04:00
Lubos Dolezel
0bed997345 Add internal kqueue_dup() 2020-04-27 11:27:13 +02:00
Lubos Dolezel
2c2d5cfd06 Provide kqueue_atfork() 2020-03-31 11:22:23 +02:00
Lubos Dolezel
d534499fdb Prevent fd leaks in EVFILT_READ/WRITE 2020-03-22 19:17:58 +01:00
Lubos Dolezel
cf2248b1ed Crash fix 2020-03-06 17:28:12 +01:00
Lubos Dolezel
24c025368b Enforce non-zero timer timeout (0 means disabled) 2020-02-23 23:25:18 +01:00
Lubos Dolezel
8c9ce7a18b Fix resetting timer deadline (darlinghq/darling#688) 2020-02-23 22:30:02 +01:00
Luboš Doležel
d7ea5ec719
Merge pull request #2 from TheBrokenRail/patch-1
Move LKM to src/external
2020-02-17 09:02:20 +01:00
TheBrokenRail
6fa9c41c9c
Move LKM to src/external 2020-02-16 13:58:47 -05:00
Lubos Dolezel
6bf29621b1 Build fix 2020-01-28 15:49:15 +01:00
Lubos Dolezel
c01ee564d8 Small change for newer XNUs 2020-01-27 19:26:42 +01:00
Andrew Hyatt
ae2fbcd28e
Allow i386 or x86_64 only builds 2019-08-13 14:11:14 -04:00
Lubos Dolezel
7ac3d4fbb1 Fixes for kqueue timers (darlinghq/darling#420) 2018-11-07 20:25:45 +01:00
Lubos Dolezel
2c12e86fc6 More fixes 2018-09-06 10:33:55 +02:00
Lubos Dolezel
1d627ad694 Attempt to fix darlinghq/darling#420 2018-08-27 11:30:03 +02:00
Lubos Dolezel
f411d4553d Prevent leaking of machport/proc/signal fds across execve() 2017-07-13 20:12:22 +02:00
Lubos Dolezel
22005641d9 Adapt to new EVFILT_MACHPORT LKM API 2017-07-13 12:20:42 +02:00
Lubos Dolezel
3605093fd5 Fixes for launchd 2017-07-10 16:02:01 +02:00
Lubos Dolezel
284c5896a6 Fix build on i386 2017-04-29 19:39:41 +02:00
Lubos Dolezel
fa8dc2dbbd Make libkqueue fat 2017-04-29 19:27:46 +02:00
Lubos Dolezel
0e5c51eeae Bug fixes for launchd 2017-04-24 16:52:19 +02:00
Lubos Dolezel
b5750589d7 Implement EVFILT_FS (partially) 2017-04-21 09:54:13 +02:00
Lubos Dolezel
9f7cfeaef7 Add support for EVFILT_PROC 2017-04-20 00:04:06 +02:00
Lubos Dolezel
903c4f4199 Fix vnode incorrectly working with inotify 2017-04-18 17:08:13 +02:00
Lubos Dolezel
2451eea5e8 Add EV_MACHPORT support 2017-04-18 17:07:59 +02:00
Lubos Dolezel
9e2eb6157b Use special close() variant for libkqueue to avoid deadlocks 2017-04-16 18:03:21 +02:00