id: ffi-08 original_id: P.UNS.FFI.08 level: P impact: HIGH Handle Errors Properly in FFI Summary FFI functions must use C-compatible error handling (return codes, errno, out parameters). Rust's Result
阅读全文
Choose Appropriate Data Layout for Struct/Tuple/Enum
id: mem-01 original_id: P.UNS.MEM.01 level: P impact: HIGH Choose Appropriate Data Layout for Struct/Tuple/Enum Summary Use #[repr(...)] attributes to control data layout when interfacing with C, doin
阅读全文
Use Dedicated Opaque Type Pointers Instead of c_void for C Opaque Types
id: ffi-17 original_id: P.UNS.FFI.17 level: P impact: MEDIUM Use Dedicated Opaque Type Pointers Instead of c_void for C Opaque Types Summary Instead of using *mut c_void for opaque C handles, create d
阅读全文
Do Not Dereference Pointers Cast to Misaligned Types
id: ptr-04 original_id: G.UNS.PTR.01 level: G impact: HIGH clippy: cast_ptr_alignment Do Not Dereference Pointers Cast to Misaligned Types Summary When casting a pointer to a different type, ensure th
阅读全文
Ensure C-ABI Compatibility for Strings Between Rust and C
id: ffi-06 original_id: P.UNS.FFI.06 level: P impact: HIGH Ensure C-ABI Compatibility for Strings Between Rust and C Summary When passing strings across FFI, ensure both sides agree on encoding, null-
阅读全文
Use MaybeUninit<T> for Uninitialized Memory
id: mem-06 original_id: G.UNS.MEM.01 level: G impact: HIGH clippy: uninit_assumed_init, uninit_vec Use MaybeUninit for Uninitialized Memory Summary Use MaybeUninit<T> instead of mem::uninitializ
阅读全文
Do Not Use Union Variants Across Different Lifetimes
id: union-02 original_id: P.UNS.UNI.02 level: P impact: CRITICAL Do Not Use Union Variants Across Different Lifetimes Summary Do not write to one union field and read from another field that has a dif
阅读全文
Add Safety Section in Docs for Public Unsafe Functions
id: safety-10 original_id: G.UNS.SAS.01 level: G impact: HIGH clippy: missing_safety_doc Add Safety Section in Docs for Public Unsafe Functions Summary Public unsafe functions must have a # Safety sec
阅读全文
Ensure Consistent Data Layout for Custom Types
id: ffi-13 original_id: P.UNS.FFI.13 level: P impact: HIGH Ensure Consistent Data Layout for Custom Types Summary Types shared between Rust and C must have #[repr(C)] to ensure the memory layout match
阅读全文
Unsafe Code Authors Must Verify Safety Invariants
id: safety-02 original_id: P.UNS.SAS.02 level: P impact: CRITICAL Unsafe Code Authors Must Verify Safety Invariants Summary When writing unsafe code, you are taking responsibility for upholding all sa
阅读全文