rust/zerocopy/src/pointer/ptr.rs
Source file repositories/reference/linux-study-clean/rust/zerocopy/src/pointer/ptr.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/zerocopy/src/pointer/ptr.rs- Extension
.rs- Size
- 68898 bytes
- Lines
- 1587
- 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.
- Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct ZstDststruct Dstfunction pubfunction Okfunction Okfunction Okfunction Okfunction test_try_cast_into_explicit_countfunction test_try_cast_into_no_leftover_restores_original_slicefunction Err
Annotated Snippet
struct ZstDst {
u: [u8; 8],
slc: [()],
}
test!(ZstDst, 8, 0, Some(0));
test!(ZstDst, 7, 0, None);
test!(ZstDst, 8, usize::MAX, Some(usize::MAX));
test!(ZstDst, 7, usize::MAX, None);
#[derive(KnownLayout, Immutable)]
#[repr(C)]
struct Dst {
u: [u8; 8],
slc: [u8],
}
test!(Dst, 8, 0, Some(0));
test!(Dst, 7, 0, None);
test!(Dst, 9, 1, Some(1));
test!(Dst, 8, 1, None);
// If we didn't properly check for overflow, this would cause the
// metadata to overflow to 0, and thus the cast would spuriously
// succeed.
test!(Dst, 8, usize::MAX - 8 + 1, None);
}
#[test]
fn test_try_cast_into_no_leftover_restores_original_slice() {
let bytes = [0u8; 4];
let ptr = Ptr::from_ref(&bytes[..]);
let res = ptr.try_cast_into_no_leftover::<[u8; 2], BecauseImmutable>(None);
match res {
Ok(_) => panic!("should have failed due to leftover bytes"),
Err(CastError::Size(e)) => {
assert_eq!(e.into_src().len(), 4, "Should return original slice length");
}
Err(e) => panic!("wrong error type: {:?}", e),
}
}
#[test]
fn test_iter_exclusive_yields_disjoint_ptrs() {
let mut arr = [0u8, 1, 2, 3];
{
let mut iter = Ptr::from_mut(&mut arr[..]).iter();
let first = iter.next().unwrap().as_mut();
let second = iter.next().unwrap().as_mut();
*first = 10;
*second = 20;
*first = 30;
}
assert_eq!(arr, [30, 20, 2, 3]);
}
}
Annotation
- Detected declarations: `struct ZstDst`, `struct Dst`, `function pub`, `function Ok`, `function Ok`, `function Ok`, `function Ok`, `function test_try_cast_into_explicit_count`, `function test_try_cast_into_no_leftover_restores_original_slice`, `function Err`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.