rust-unsafe-safety
Skill76 starsChanged 4 days agoApache-2.0View on GitHub
编写、修改、封装或审查 TGOSKits 中的 unsafe 块、unsafe 函数或特征、unsafe impl、裸指针、外部函数接口、用户内存、内存映射输入输出、直接内存访问或手工布局代码时使用。
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- arceos-test-adapterSkill
- arch-platform-portingSkill
- board-linux-starry-debugSkill
- board-uboot-fsck-repairSkill
- crates-io-ownerSkill
- cross-kernel-driverSkill
- feature-developmentSkill
- humanizerSkill
- markdown-doc-writerSkill
- multi-arch-layeringSkill
- qemu-gdb-debuggingSkill
- reassign-pr-reviewersSkill
- resolve-github-issueSkill
- review-open-prsSkill
- review-single-prSkill
- rust-api-designSkill
- rust-code-qualitySkill
- rust-concurrency-safetySkill
- starry-syscall-compatibilitySkill
- starry-test-suitSkill
- test-qualitySkill
- update-std-testsSkill
The file
Files
Rust 非安全代码健全性
1. 适用方式
本技能关注 Rust 编译器不能证明、必须由实现者维护的内存安全前置条件。任何新增或改变 unsafe 边界的改动都要完整阅读 契约与证明。涉及硬件、外部函数接口、用户地址空间或直接内存访问时,还要完整阅读 硬件与外部边界。
不要因为某个上层接口是安全函数就跳过本技能;安全包装内部的裸指针、手工 Send 或 Sync、共享内存和设备缓冲区仍需要完整证明。
2. 基本要求
unsafe 块尽可能小,只包围需要放宽检查的操作。块前说明实际证明:指针来源与有效范围、对齐、初始化、别名、生命周期、并发访问、释放责任和外部状态。不能只写“调用方保证安全”或“已经检查”。对能够由实现内部维护前置条件的操作提供安全包装,把最小非安全内核隐藏在边界内;只有调用方确实必须承担无法检查的条件时才暴露 unsafe 接口。
每个 unsafe fn 的 # Safety 文档说明调用方必须满足的前置条件;每个 unsafe trait 的 # Safety 文档说明实现者必须维持的不变量,unsafe impl 说明如何满足这些义务。trait 的安全方法不因所属 trait 是 unsafe 就把额外安全义务转给调用方;确需调用方承担条件的方法单独声明为 unsafe fn。责任区分依据 Rust Reference。能够在函数内部验证或通过类型表达的条件不应推给调用方。
新增或实质改变非安全边界的代码在合入前需要熟悉 Rust 非安全代码和相应领域的审查人确认。测试、解释器或静态检查可以补充证据,不能替代逐项安全证明。
3. 验收条件
安全接口对所有安全调用方都必须健全,包括错误、取消、恐慌、重复调用和并发路径。审查应从安全入口追踪到每个非安全操作,再追踪资源释放;测试覆盖边界和失败,但测试通过不能替代安全证明。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

