Forcrat: Automatic I/O API Translation from C to Rust via Origin and Capability Analysis
Jaemin Hong, Sukyoung Ryu
Abstract
Translating C to Rust is a promising way to enhance the reliability of legacy system programs. Although the industry has developed an automatic C-to-Rust translator, C2Rust, its translation remains unsatisfactory. One major reason is that C2Rust retains C standard library (libc) function calls instead of replacing them with functions from the Rust standard library (Rust std). However, little work has been done on replacing library functions in C2Rust-generated code. In this work, we focus on replacing the I/O API, an important subset of library functions. This poses challenges due to the semantically different designs of I/O APIs in libc and Rust std. First, the two APIs offer different sets of types that represent the origins (e.g., standard input, files) and capabilities (e.g., read, write) of streams used for I/O. Second, they use different error-checking mechanisms: libc uses internal indicators, while Rust std uses return values. To address these challenges, we propose two static analysis techniques, origin and capability analysis and error source analysis, and use their results to replace the I/O API. Our evaluation shows that the proposed approach is (1) correct, with all 32 programs that have test suites passing the tests after transformation, (2) efficient, analyzing and transforming 422k LOC in 14 seconds, and (3) widely applicable, replacing 82% of I/O API calls.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext f285a0ee-ee4f-46fd-8800-de7e36744e14Cited by top-tier papers3
- Hayroll: A Modular Wrapper for Translating C Macros and Conditional Compilation to RustHaoran Peng, Baris Kasikci, Gilbert Louis Bernstein, Michael D. ErnstPLDI 2026 · 1 citation
- Project-Level C-to-Rust Translation via Pointer Knowledge GraphsZhiqiang Yuan, Wenjun Mao, Zhuo Chen, Xiyue Shang et al.FSE 2026
- Rust’s Type Checker Implementation Is Unsound: An Empirical Study on Soundness Bugs in rustcYusung Sim, Sukyoung Ryu, Jaemin HongISSTA 2026
Builds on8
- Translating C to safer RustMehmet Emre, Ryan Schroeder, Kyle Dewey, Ben HardekopfOOPSLA 2021 · 60 citations
- Ownership Guided C to Rust TranslationHanliang Zhang, Cristina David, Yijun Yu, Meng WangCAV 2023 · 37 citations
- Aliasing Limits on Translating C to Safe RustMehmet Emre, Peter Boyland, Aesha Parekh, Ryan Schroeder et al.OOPSLA 2023 · 32 citations
- Concrat: An Automatic C-to-Rust Lock API Translator for Concurrent ProgramsJaemin Hong, Sukyoung RyuICSE 2023 · 17 citations
- Don't Write, but Return: Replacing Output Parameters with Algebraic Data Types in C-to-Rust TranslationJaemin Hong, Sukyoung RyuPLDI 2024 · 17 citations
Related papers
- To Tag, or Not to Tag: Translating C's Unions to Rust's Tagged UnionsJaemin Hong, Sukyoung RyuASE 2024 · 6 citations
- &inator: Correct, Precise C-to-Rust Interface TranslationVictor Chen, Ayden Coughlin, Michael D. BondPLDI 2026 · 1 citation
- Scylla: Translating an Applicative Subset of C to Safe RustAymeric Fromherz, Jonathan ProtzenkoOOPSLA 2026 · 6 citations
- GenC2Rust: Towards Generating Generic Rust Code from CXiafa Wu, Brian DemskyICSE 2025 · 4 citations
- A Sound Static Analysis Approach to I/O API MigrationShangyu Li, Zhaoyang Zhang, Sizhe Zhong, Diyu Zhou et al.OOPSLA 2025
