Fil-C introduces memory-safe context switching
Fil-C has introduced memory-safe versions of traditional C context-switching APIs, wrapping context states in runtime-managed, opaque structures to prevent dangling stacks and machine state corruption. The runtime restricts jumps to active ancestor frames, enforces fiber thread affinity, and integrates context stacks with its concurrent garbage collector to track GC roots.
Hot take: Retrofitting memory safety onto C's most volatile stack-manipulating primitives is a masterclass in runtime-level defense, proving that even legacy C's most 'depraved' features can be tamed without discarding compatibility.
- –**Opaque Buffers:** Context state is encapsulated in opaque, non-spoofable runtime objects (`zjmp_buf` and `zfiber_context`).
- –**Ancestor Checks:** `longjmp` walks the stack to ensure the target is an ancestor frame, preventing returning-twice or dangling stack vulnerabilities.
- –**Stack Redirection:** The `ucontext` APIs ignore user-supplied stack pointers (`ss_sp`), automatically allocating secure, runtime-managed stacks instead.
- –**Thread-Bound Fibers:** Fibers are bound to their originating threads, maintaining the compiler's invariant thread pointer state.
- –**GC Integration:** Tracks 'grey' `zfiber_contexts` during GC mark phases to prevent mutator-GC races.
DISCOVERED
1h ago
2026-06-30
PUBLISHED
5h ago
2026-06-30
RELEVANCE
AUTHOR
modeless