Starnix Agent Guide

This guide captures Starnix-specific invariants and pitfalls on top of the repository-wide rules in //AGENTS.md. See subdirectory AGENTS.md files (such as modules/binderfs/AGENTS.md) for module-specific notes.

Synchronization & LockGuarded (starnix_sync)

  • Always use LockDep locks: Use starnix_sync::{LockDepMutex, LockDepRwLock} (or DynamicLockDepMutex / DynamicLockDepRwLock when the lock level is chosen dynamically at runtime) instead of fuchsia_sync, parking_lot, std::sync, or raw starnix_sync::{Mutex, RwLock}. Production Starnix targets enforce this via -Wclippy::disallowed_types and src/starnix/config/clippy.toml (starnix_clippy_lints in src/starnix/config/BUILD.gn).
  • Wrap lock-updated, lock-free-read fields in LockGuarded<T, S>: When an atomic or RCU primitive (AtomicBool, AtomicUsize, AtomicMonotonicInstant, RcuArc, RcuArray, RcuBox, RcuDroppableArc, RcuOptionArc, RcuOptionBox, RcuWeak, etc.) is mutated under an external lock guarding state S and read lock-free, wrap it in starnix_sync::LockGuarded<T, S> (src/starnix/lib/starnix_sync/src/lock_guarded.rs). Readers call lock-free accessors directly on LockGuarded, while writers must call field.write(&guard) with a guard implementing WriteProof<S> (such as LockDepGuard<'_, S>, LockDepWriteGuard<'_, S>, RwSeqLockGuard, or a mutable mutable_state::Guard), preventing unlocked or pre-validation stores at compile time.
  • Mutate LockGuarded fields before downgrading a LockDepRwLock: LockDepWriteGuard::downgrade() (src/starnix/lib/starnix_sync/src/lock_dep_mutex.rs) consumes LockDepWriteGuard<'_, S> (which implements WriteProof<S>) and returns LockDepReadGuard<'_, S> (which does not). When updating a LockGuarded<T, S> field alongside LockDepRwLock-protected state, perform the field.write(&guard) update while still holding LockDepWriteGuard, before downgrading -- never mutate after downgrading.

Linux UAPI & Source References

  • Do not reference Linux kernel files outside include/uapi/, arch/*/include/uapi/, and Documentation/: Do not cite GPL kernel implementation paths or kernel-internal headers (such as fs/*.c, net/*.c, or non-UAPI include/linux/*.h) in comments, docstrings, or commit messages. Cite only UAPI headers (include/uapi/, arch/*/include/uapi/, or in-tree third_party/android/platform/bionic/libc/kernel/uapi/), Documentation/, manpages, or observable Linux behavior.
  • Use //src/starnix/lib/linux_uapi for Linux UAPI types and constants: Do not hand-define Linux UAPI constants or structs in starnix_uapi or kernel/module crates, and do not hand-edit the generated src/starnix/lib/linux_uapi/src/{arm64,riscv64,x86_64}.rs files. Add missing <linux/...> headers to src/starnix/lib/linux_uapi/wrapper.h and regenerate via ./src/starnix/lib/linux_uapi/generate.py from the checkout root (see src/starnix/lib/linux_uapi/README.md), in a dedicated preliminary CL before consumer CLs.