rust/zerocopy/src/macros.rs
Source file repositories/reference/linux-study-clean/rust/zerocopy/src/macros.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/zerocopy/src/macros.rs- Extension
.rs- Size
- 66170 bytes
- Lines
- 1826
- 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
enum NotZerocopyfunction only_derive_is_allowed_to_implement_this_traitfunction only_derive_is_allowed_to_implement_this_traitfunction test_transmutefunction dropfunction test_transmute_reffunction test_try_transmutefunction dropfunction test_try_transmute_reffunction test_try_transmute_mutfunction test_transmute_mutfunction test_macros_evaluate_args_oncefunction test_include_valuefunction test_cryptocorrosion_derive_traits
Annotated Snippet
fn only_derive_is_allowed_to_implement_this_trait() {}
}
// SAFETY: This macro only accepts `#[repr(C)]` and
// `#[repr(transparent)]` structs, and this `impl` block requires all
// field types to be `FromBytes`, which is a sub-trait of `FromZeros`.
unsafe impl $(<$($tyvar),*>)? $crate::FromZeros for $name$(<$($tyvar),*>)?
where
$(
$($tuple_field_ty: $crate::FromBytes,)*
)?
$(
$($field_ty: $crate::FromBytes,)*
)?
{
fn only_derive_is_allowed_to_implement_this_trait() {}
}
// SAFETY: This macro only accepts `#[repr(C)]` and
// `#[repr(transparent)]` structs, and this `impl` block requires all
// field types to be `FromBytes`.
unsafe impl $(<$($tyvar),*>)? $crate::FromBytes for $name$(<$($tyvar),*>)?
where
$(
$($tuple_field_ty: $crate::FromBytes,)*
)?
$(
$($field_ty: $crate::FromBytes,)*
)?
{
fn only_derive_is_allowed_to_implement_this_trait() {}
}
// SAFETY: This macro only accepts `#[repr(C)]` and
// `#[repr(transparent)]` structs, this `impl` block requires all field
// types to be `IntoBytes`, and a padding check is used to ensures that
// there are no padding bytes.
unsafe impl $(<$($tyvar),*>)? $crate::IntoBytes for $name$(<$($tyvar),*>)?
where
$(
$($tuple_field_ty: $crate::IntoBytes,)*
)?
$(
$($field_ty: $crate::IntoBytes,)*
)?
(): $crate::util::macro_util::PaddingFree<
Self,
{
$crate::cryptocorrosion_derive_traits!(
@struct_padding_check #[repr($repr)]
$(($($tuple_field_ty),*))?
$({$($field_ty),*})?
)
},
>,
{
fn only_derive_is_allowed_to_implement_this_trait() {}
}
// SAFETY: This macro only accepts `#[repr(C)]` and
// `#[repr(transparent)]` structs, and this `impl` block requires all
// field types to be `Immutable`.
unsafe impl $(<$($tyvar),*>)? $crate::Immutable for $name$(<$($tyvar),*>)?
where
$(
$($tuple_field_ty: $crate::Immutable,)*
)?
$(
$($field_ty: $crate::Immutable,)*
)?
{
fn only_derive_is_allowed_to_implement_this_trait() {}
}
};
(@assert_allowed_struct_repr #[repr(transparent)]) => {};
(@assert_allowed_struct_repr #[repr(C)]) => {};
(@assert_allowed_struct_repr #[$_attr:meta]) => {
compile_error!("repr must be `#[repr(transparent)]` or `#[repr(C)]`");
};
(
@struct_padding_check #[repr(transparent)]
$(($($tuple_field_ty:ty),*))?
$({$($field_ty:ty),*})?
) => {
// SAFETY: `#[repr(transparent)]` structs cannot have the same layout as
Annotation
- Detected declarations: `enum NotZerocopy`, `function only_derive_is_allowed_to_implement_this_trait`, `function only_derive_is_allowed_to_implement_this_trait`, `function test_transmute`, `function drop`, `function test_transmute_ref`, `function test_try_transmute`, `function drop`, `function test_try_transmute_ref`, `function test_try_transmute_mut`.
- 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.