v0.19: Fix some bugs in std/os signals #1492

Merged
fare merged 6 commits from jay/gerbil:v0.19-fix-signals into v0.19-staging 2026-09-12 18:23:56 +00:00
Member

Fixes portability and correctness bugs introduced in :std/os signal handling by #1484:

  • kqueue FFI declarations used invalid C type identifiers.
  • Oversized kill arguments could truncate and select unintended targets.
  • Concurrent initialization could route Linux signals to an unused dispatcher.

Focused Linux tests pass. Paired benchmarks found no statistically significant registration or callback-latency regression. Restored kill checks add approximately 13 ns in a zero-signal probe; synthetic burst throughput was approximately 1% lower.

Native BSD/macOS kqueue smoke testing remains pending.

Warning

LLM-assisted with gpt-6-astra and gerbil-mcp.

Fixes portability and correctness bugs introduced in `:std/os` signal handling by #1484: - `kqueue` FFI declarations used invalid C type identifiers. - Oversized `kill` arguments could truncate and select unintended targets. - Concurrent initialization could route Linux signals to an unused dispatcher. Focused Linux tests pass. Paired benchmarks found no statistically significant registration or callback-latency regression. Restored `kill` checks add approximately 13 ns in a zero-signal probe; synthetic burst throughput was approximately 1% lower. Native BSD/macOS `kqueue` smoke testing remains pending. > [!WARNING] > LLM-assisted with `gpt-6-astra` and `gerbil-mcp`.
Keep errno handling while rejecting C-int overflow before kill can select an unintended target. Exercise the production binding only through a C test double.
Preserve caller-owned thread masks. Let signalfd consume pending blocked signals alongside sigaction delivery, forwarding both through the existing dispatcher. Serialize descriptor updates and consumption with registration and removal.
vyzo left a comment

jay is this still WIP?

jay is this still WIP?
Author
Member

@vyzo hey, yes, I had astra go to town on this and I have not had time yet to validate its work or do any performance benchmarking. This week and weekend is super busy for me. You are welcome to take this over if you would like, or scrap it, otherwise I will have some more time next week!

@vyzo hey, yes, I had astra go to town on this and I have not had time yet to validate its work or do any performance benchmarking. This week and weekend is super busy for me. You are welcome to take this over if you would like, or scrap it, otherwise I will have some more time next week!
Owner

it's ok we can wait for you.

it's ok we can wait for you.
Keep the three independent safety fixes without the receiver cost.
The smallest tested receiver still slows registration and callbacks
after activation. Preserve it on v0.19-blocked-signals-deferred.

This reverts commit 1cac361603.
jay changed title from WIP: v0.19: Fix some bugs in std/os signals to v0.19: Fix some bugs in std/os signals 2026-09-11 00:55:06 +00:00
jay requested reviews from vyzo, fare 2026-09-11 00:55:46 +00:00
vyzo left a comment

generally looks good, but i left a couple of comments that need addressing.

i would strongly prefer to put the ffi test support stuffs in a separate signal-test-support module that gets compiled with the stdlib.

generally looks good, but i left a couple of comments that need addressing. i would strongly prefer to put the ffi test support stuffs in a separate signal-test-support module that gets compiled with the stdlib.
@ -55,2 +55,2 @@
(def-C-type/pointer kevent "struct kevent" release: "ffi_free")
(def-C-type/pointer timespec "struct timespec" release: "ffi_free")
(C-declare "typedef struct kevent ffi_kevent;")
(C-declare "typedef struct timespec ffi_timespec;")
Owner

note that we already have timespec as def-C-struct, you might want to reuse that. it also avoids mallocs.

note that we already have timespec as def-C-struct, you might want to reuse that. it also avoids mallocs.
@ -0,0 +14,4 @@
(lambda (output)
(display #<<END-SCHEME
(import :std/ffi)
(C-declare #<<END-C
Owner

why not create a separate signal-test-support module that is compiled and contains the ffi code.

this is the pattern we use for tests that require native code.

why not create a separate signal-test-support module that is compiled and contains the ffi code. this is the pattern we use for tests that require native code.
Author
Member

@vyzo addressed your feedback

@vyzo addressed your feedback
vyzo approved these changes 2026-09-11 19:07:19 +00:00
vyzo left a comment

lgtm. @fare you want to do a clanker assisted pass?

lgtm. @fare you want to do a clanker assisted pass?
Owner

The clanker (Sol High) is satisfied—except for the part where we assume that pid_t is int, and don't check. But I believe that is a Gambit FFI issue. Maybe we need to improve the Gambit FFI at some point?

Clanky also asks for test runs on BSD, but oh well.

The clanker (Sol High) is satisfied—except for the part where we assume that pid_t is int, and don't check. But I believe that is a Gambit FFI issue. Maybe we need to improve the Gambit FFI at some point? Clanky also asks for test runs on BSD, but oh well.
fare force-pushed v0.19-fix-signals from 8805340a50 to 9d0639d043 2026-09-12 18:15:22 +00:00 Compare
fare merged commit 69d96e16a0 into v0.19-staging 2026-09-12 18:23:56 +00:00
Sign in to join this conversation.
No description provided.