Memory Safe Context Switching (longjmp, setjmp) in Fil-C
Fil-C introduces a memory-safe implementation of context switching using longjmp and setjmp, ensuring that non-local jumps do not compromise memory safety guarantees. This approach maintains Fil-C's strong safety properties while preserving the performance and flexibility needed for systems programming.
背景メモ
Fil-Cは、C言語のメモリ安全性を保証するために開発されたコンパイラ/ランタイムプロジェクト。既存のC/C++コードを大幅に書き換えずに、メモリ破壊バグ(use-after-free、バッファオーバーフローなど)を実行時に検出・防止するのが目標。通常のCコンパイラ(GCC/Clang)の代わりにfil-cでコードをビルドすると、自動的にメモリ安全なバイナリが生成される。この記事で扱われている「コンテキストスイッチ」は、setjmp/longjmpというC標準ライブラリの機能で、関数の呼び出し階層を強制的にジャンプして戻す処理。OSのスレッド切り替えではなく、ユーザー空間での制御フロー操作。Fil-Cはこの非局所ジャンプをメモリ安全性を保ったまま実装する工夫を説明している。著者Filip Pizloはコンパイラ/ランタイム研究者で、以前はWebKitのJavaScriptエンジン(JavaScriptCore)の主要開発者。