Concurrent programs suffer from data races. To prevent data races, programmers use locks. However, programs can eliminate data races only when they acquire and release correct locks at correct timing. The lock API of C, in which people have developed a large portion of legacy system programs, does not validate the correct use of locks. On the other hand, Rust, a recently developed system programming language, provides a lock API that guarantees the correct use of locks via type checking. This makes rewriting legacy system programs in Rust a promising way to retrofit safety into them. Unfortunately, manual C-to-Rust translation is extremely laborious due to the discrepancies between their lock APIs. Even the state-of-the-art automatic C-to-Rust translator retains the C lock API, expecting developers to replace them with the Rust lock API. In this work, we propose an automatic tool to replace the C lock API with the Rust lock API. It facilitates C-to-Rust translation of concurrent programs with less human effort than the current practice. Our tool consists of a Rust code transformer that takes a lock summary as an input and a static analyzer that efficiently generates precise lock summaries. We show that the transformer is scalable and widely applicable while preserving the semantics; it transforms 66 KLOC in 2.6 seconds and successfully handles 74% of real-world programs. We also show that the analyzer is scalable and precise; it analyzes 66 KLOC in 4.3 seconds.
翻译:同步程序会受到数据竞赛的影响。 为了防止数据竞赛, 程序员会使用锁。 但是, 程序只有在他们获取并及时发布正确锁时, 程序才能消除数据竞赛。 CPI 锁在C 中, 人们开发了大量遗留系统程序, 无法验证锁的正确使用。 另一方面, Rust 是一个最近开发的系统编程语言, 提供了一个锁 API, 保证通过类型检查正确使用锁。 这让 Rust 中重写遗留系统程序成为将安全转换到它们的一个有希望的方法。 不幸的是, 手动 C到 Rust 翻译由于锁 API 之间的差异而非常费力。 即使是最先进的自动 C- RPI 也保留了 CAPI, 期待开发者用 Rust 锁 API 语言来取代锁 。 我们提议一个自动工具, 用 Rust lock 的 API, 用比当前的做法更少的人的努力来取代 C- 。 我们的工具由 Rust combal 解译器组成了一个可应用的 K- Rexal 缩略图, 。 我们的 K- transleving 和 K- translational 。