Languages and runtimes
Fil-C documents memory-safe context switching
- Category: Languages
- Status: developing
- Sources: Fil-C documentation, discussion
- Summary: Fil-C, the memory-safe C and C++ compiler, published documentation for memory-safe implementations of the
setjmp/longjmpanducontext(getcontext,setcontext,makecontext,swapcontext) context-switching APIs. Thesetjmppath stores an opaque jump buffer unreachable from user code, requires directsetjmpcalls so the compiler cannot optimize away the safety guarantees, validates that eachlongjmptargets a live descendant stack frame, and preserves garbage-collection roots; misuse that would otherwise produce a torn machine state triggers a runtime panic rather than memory corruption. Theucontextpath uses opaque fiber-context objects with internally allocated stacks, enforces thread affinity so a context cannot migrate between threads, and integrates with the collector through fiber tracking. The documentation statesucontextsupport is new since release 0.680, requires building from source, and is not yet thoroughly tested, whilesetjmp/longjmpis described as more solid. - Why it matters: Context-switching APIs are a recurring memory-safety escape hatch in C, and constraining them to fail closed extends Fil-C's guarantees to coroutine and fiber code that previously relied on raw register and stack manipulation.