There has been a growing interest in translating C code to Rust due to Rust's robust memory and thread safety guarantees. Tools such as C2RUST enable syntax-guided transpilation from C to semantically equivalent Rust code. However, the resulting Rust programs often rely heavily on unsafe constructs, particularly raw pointers, which undermines Rust's safety guarantees. This paper aims to improve the memory safety of Rust programs generated by C2RUST by eliminating raw pointers. Specifically, we propose a raw pointer rewriting technique that lifts raw pointers in individual functions to appropriate Rust data structures. Technically, PR2 employs decision-tree-based prompting to guide the pointer lifting process. It also leverages code change analysis to guide the repair of errors introduced during rewriting, effectively addressing errors encountered during compilation and test case execution. We implement PR2 and evaluate it using gpt-4o-mini on 28 real-world C projects. It is shown that PR2 successfully eliminates 18.57% of local raw pointers across these projects, significantly enhancing the safety of the translated Rust code. On average, PR2 completes the transformation of a project in 5.02 hours, at a cost of $1.13.


翻译:近年来,由于Rust语言在内存和线程安全方面具有强大的保障能力,将C语言代码转译为Rust代码的研究日益增多。C2RUST等工具支持通过语法引导将C语言编译为语义等价的Rust代码。然而,生成的Rust程序严重依赖不安全结构(尤其是原始指针),这削弱了Rust的安全保障。本文旨在通过消除原始指针来提升C2RUST生成的Rust程序的内存安全性。具体而言,我们提出了一种原始指针重写技术,将单个函数中的原始指针提升为合适的Rust数据结构。技术上,PR2采用基于决策树的提示方法引导指针提升过程,同时利用代码变更分析指导重写过程中引入错误的修复,有效解决编译与测试用例执行阶段遇到的错误。我们基于PR2并在gpt-4o-mini上对28个真实C语言项目进行了评估。结果表明,PR2成功消除了这些项目中18.57%的局部原始指针,显著增强了转译后Rust代码的安全性。平均而言,PR2在5.02小时内以1.13美元的成本完成单个项目的转换。

0
下载
关闭预览

相关内容

Rust 是一种注重高效、安全、并行的系统程序语言。
自动编程:大型语言模型及其他
专知会员服务
36+阅读 · 2024年5月12日
【经典书】现代C语言教程,408页pdf手写教你写C代码
专知会员服务
66+阅读 · 2022年8月5日
【干货书】C++实战编程指南,附549页pdf与Slides
专知会员服务
84+阅读 · 2021年4月23日
【2020新书】C语言编程傻瓜式入门,第二版,464页pdf
专知会员服务
66+阅读 · 2020年10月15日
【经典书】算法C语言实现,Algorithms in C. 672页pdf
专知会员服务
82+阅读 · 2020年8月13日
82页《现代C++教程》:高速上手C++ 11/14/17/20
专知
21+阅读 · 2020年10月19日
放弃 RNN/LSTM 吧,因为真的不好用!望周知~
人工智能头条
19+阅读 · 2018年4月24日
福利 | 当Python遇上大数据与机器学习,入门so easy!
神经网络机器翻译原理:LSTM、seq2seq到Zero-Shot
北京思腾合力科技有限公司
11+阅读 · 2017年8月10日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
8+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
综述 | 3D场景图:开放挑战与未来方向
专知会员服务
1+阅读 · 今天15:00
21世纪的无人机战争
专知会员服务
2+阅读 · 今天14:05
《量子技术的军事任务技术适配与利用》
专知会员服务
2+阅读 · 今天13:51
美国从乌克兰无人机战争中学习经验
专知会员服务
7+阅读 · 6月21日
ICML 2026 | 面向视觉语言模型的语义鲁棒性认证
专知会员服务
5+阅读 · 6月21日
相关资讯
相关基金
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
8+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员