id: ffi-07 original_id: P.UNS.FFI.07 level: P impact: HIGH Do Not Implement Drop for Types Passed to External Code Summary If a type will be passed to external code that manages its lifetime, don't im
阅读全文
Prefer Reentrant Versions of C-API or Syscalls
id: mem-04 original_id: P.UNS.MEM.04 level: P impact: HIGH Prefer Reentrant Versions of C-API or Syscalls Summary When calling C functions or system calls, use reentrant (_r) versions to avoid data ra
阅读全文
Do Not Manually Convert Immutable Pointer to Mutable
id: ptr-05 original_id: G.UNS.PTR.02 level: G impact: CRITICAL clippy: cast_ref_to_mut Do Not Manually Convert Immutable Pointer to Mutable Summary Never cast *const T to *mut T and dereference it to
阅读全文
Exported Rust Functions Must Be Designed for Thread-Safety
id: ffi-10 original_id: P.UNS.FFI.10 level: P impact: CRITICAL Exported Rust Functions Must Be Designed for Thread-Safety Summary Functions exported to C with #[no_mangle] extern "C" may be called fro
阅读全文
Mutable Return from Immutable Parameter is Wrong
id: safety-08 original_id: P.UNS.SAS.08 level: P impact: CRITICAL clippy: mut_from_ref Mutable Return from Immutable Parameter is Wrong Summary A function taking &self or &T must not return &a
阅读全文
Be Careful with UB When Referencing #[repr(packed)] Struct Fields
id: ffi-11 original_id: P.UNS.FFI.11 level: P impact: HIGH clippy: unaligned_references Be Careful with UB When Referencing #[repr(packed)] Struct Fields Summary Creating references to fields in #[rep
阅读全文
Handle Panics When Crossing FFI Boundaries
id: ffi-04 original_id: P.UNS.FFI.04 level: P impact: CRITICAL clippy: panic_in_result_fn Handle Panics When Crossing FFI Boundaries Summary Panics must not unwind across FFI boundaries. Use catch_unw
阅读全文
Do Not Blindly Use Unsafe for Performance
id: general-02 original_id: P.UNS.02 level: P impact: CRITICAL Do Not Blindly Use Unsafe for Performance Summary Do not assume that using unsafe will automatically improve performance. Always measure
阅读全文
Use Third-Party Crates for Bitfields
id: mem-05 original_id: P.UNS.MEM.05 level: P impact: MEDIUM Use Third-Party Crates for Bitfields Summary Use crates like bitflags, bitvec, or modular-bitfield instead of manual bit manipulation for c
阅读全文
Use Portable Type Aliases from std or libc
id: ffi-05 original_id: P.UNS.FFI.05 level: P impact: HIGH Use Portable Type Aliases from std or libc Summary Use type aliases from std::os::raw or the libc crate for C-compatible types. Don't assume
阅读全文