rust/kernel/cred.rs

Source file repositories/reference/linux-study-clean/rust/kernel/cred.rs

File Facts

System
Linux kernel
Corpus path
rust/kernel/cred.rs
Extension
.rs
Size
3496 bytes
Lines
93
Domain
Rust Kernel Layer
Bucket
Rust API Membrane
Inferred role
Rust Kernel Layer: implementation source
Status
source implementation candidate

Why This File Exists

Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.

Dependency Surface

Detected Declarations

Annotated Snippet

fn inc_ref(&self) {
        // SAFETY: The existence of a shared reference means that the refcount is nonzero.
        unsafe { bindings::get_cred(self.0.get()) };
    }

    #[inline]
    unsafe fn dec_ref(obj: core::ptr::NonNull<Credential>) {
        // SAFETY: The safety requirements guarantee that the refcount is nonzero. The cast is okay
        // because `Credential` has the same representation as `struct cred`.
        unsafe { bindings::put_cred(obj.cast().as_ptr()) };
    }
}

Annotation

Implementation Notes