22// SPDX-License-Identifier: Apache-2.0 OR MIT
33// Copyright OxidOS Automotive SRL 2025.
44
5+ //! Physical and virtual pointers.
6+
57use crate :: utilities:: alignment:: { Alignment , AlwaysAligned } ;
68use crate :: utilities:: ordering:: SmallerPair ;
79use crate :: utilities:: pointers:: {
@@ -14,70 +16,105 @@ use core::num::NonZero;
1416use core:: ops:: Sub ;
1517use core:: ptr:: NonNull ;
1618
19+ /// A pointer from the perspective of the memory management system.
1720#[ repr( transparent) ]
1821pub struct Pointer < const IS_VIRTUAL : bool , const IS_MUTABLE : bool , T : Alignment > (
1922 Ptr < IS_MUTABLE , T > ,
2023) ;
2124
25+ /// An immutable pointer from the perspective of the memory management system.
2226pub type ImmutablePointer < const IS_VIRTUAL : bool , T > = Pointer < IS_VIRTUAL , false , T > ;
27+ /// A mutable pointer from the perspective of the memory management system.
2328pub type MutablePointer < const IS_VIRTUAL : bool , T > = Pointer < IS_VIRTUAL , true , T > ;
2429
30+ /// A physical pointer.
2531pub type PhysicalPointer < const IS_MUTABLE : bool , T > = Pointer < false , IS_MUTABLE , T > ;
32+ /// An immutable physical pointer.
2633pub type ImmutablePhysicalPointer < T > = PhysicalPointer < false , T > ;
34+ /// A mutable physical pointer.
2735pub type MutablePhysicalPointer < T > = PhysicalPointer < true , T > ;
2836
37+ /// A virtual pointer.
2938pub type VirtualPointer < const IS_MUTABLE : bool , T > = Pointer < true , IS_MUTABLE , T > ;
39+ /// An immutable virtual pointer.
3040pub type ImmutableVirtualPointer < T > = VirtualPointer < false , T > ;
41+ /// A mutable virtual pointer.
3142pub type MutableVirtualPointer < T > = VirtualPointer < true , T > ;
3243
44+ /// A valid virtual pointer, that is, a virtual pointer that belongs to the kernel or to a process.
3345#[ repr( transparent) ]
3446pub struct ValidVirtualPointer < const IS_USER : bool , const IS_MUTABLE : bool , T : Alignment > (
3547 Pointer < true , IS_MUTABLE , T > ,
3648) ;
3749
50+ /// A valid immutable virtual pointer.
3851pub type ValidImmutableVirtualPointer < const IS_USER : bool , T > =
3952 ValidVirtualPointer < IS_USER , false , T > ;
53+ /// A valid mutable virtual pointer.
4054pub type ValidMutableVirtualPointer < const IS_USER : bool , T > = ValidVirtualPointer < IS_USER , true , T > ;
4155
56+ /// A user virtual pointer.
4257pub type UserVirtualPointer < const IS_MUTABLE : bool , T > = ValidVirtualPointer < true , IS_MUTABLE , T > ;
58+ /// An immutable user virtual pointer.
4359pub type ImmutableUserVirtualPointer < T > = UserVirtualPointer < false , T > ;
60+ /// A mutable user virtual pointer.
4461pub type MutableUserVirtualPointer < T > = UserVirtualPointer < true , T > ;
4562
63+ /// A kernel virtual pointer.
4664pub type KernelVirtualPointer < const IS_MUTABLE : bool , T > =
4765 ValidVirtualPointer < false , IS_MUTABLE , T > ;
66+ /// An immutable kernel virtual pointer.
4867pub type ImmutableKernelVirtualPointer < T > = KernelVirtualPointer < false , T > ;
68+ /// A mutable kernel virtual pointer.
4969pub type MutableKernelVirtualPointer < T > = KernelVirtualPointer < true , T > ;
5070
71+ /// A nullable pointer from the perspective of the memory management system.
5172pub enum NullablePointer < const IS_VIRTUAL : bool , const IS_MUTABLE : bool , T : Alignment > {
5273 Null ,
5374 NonNull ( Pointer < IS_VIRTUAL , IS_MUTABLE , T > ) ,
5475}
5576
77+ /// An immutable nullable pointer from the perspective of the memory management system.
5678pub type ImmutableNullablePointer < const IS_VIRTUAL : bool , T > =
5779 NullablePointer < IS_VIRTUAL , false , T > ;
80+ /// A mutable nullable pointer from the memory management system pe
5881pub type MutableNullablePointer < const IS_VIRTUAL : bool , T > = NullablePointer < IS_VIRTUAL , true , T > ;
5982
83+ /// A nullable physical pointer.
6084pub type NullablePhysicalPointer < const IS_MUTABLE : bool , T > = NullablePointer < false , IS_MUTABLE , T > ;
85+ /// An immutable nullable physical pointer.
6186pub type ImmutableNullablePhysicalPointer < T > = NullablePhysicalPointer < false , T > ;
87+ /// A mutable nullable physical pointer.
6288pub type MutableNullablePhysicalPointer < T > = NullablePhysicalPointer < true , T > ;
6389
90+ /// A nullable virtual pointer.
6491pub type NullableVirtualPointer < const IS_MUTABLE : bool , T > = NullablePointer < true , IS_MUTABLE , T > ;
92+ /// An immutable nullable virtual pointer.
6593pub type ImmutableNullableVirtualPointer < T > = NullableVirtualPointer < false , T > ;
94+ /// A mutable nullable virtual pointer.
6695pub type MutableNullableVirtualPointer < T > = NullableVirtualPointer < true , T > ;
6796
97+ /// A valid nullable virtual pointer, that is, a virtual pointer that belongs to the kernel or to a
98+ /// process.
6899pub enum ValidNullableVirtualPointer < const IS_USER : bool , const IS_MUTABLE : bool , T : Alignment > {
69100 Null ,
70101 NonNull ( ValidVirtualPointer < IS_USER , IS_MUTABLE , T > ) ,
71102}
72103
104+ /// A user nullable virtual pointer.
73105pub type UserNullableVirtualPointer < const IS_MUTABLE : bool , T > =
74106 ValidNullableVirtualPointer < true , IS_MUTABLE , T > ;
107+ /// An immutable user nullable virtual pointer.
75108pub type ImmutableUserNullableVirtualPointer < T > = UserNullableVirtualPointer < false , T > ;
109+ /// A mutable user nullable virtual pointer.
76110pub type MutableUserNullableVirtualPointer < T > = UserNullableVirtualPointer < true , T > ;
77111
112+ /// A kernel nullable virtual pointer.
78113pub type KernelNullableVirtualPointer < const IS_MUTABLE : bool , T > =
79114 ValidNullableVirtualPointer < false , IS_MUTABLE , T > ;
115+ /// An immutable kernel virtual pointer.
80116pub type ImmutableKernelNullableVirtualPointer < T > = KernelNullableVirtualPointer < false , T > ;
117+ /// A mutable kernel virtual pointer.
81118pub type MutableKernelNullableVirtualPointer < T > = KernelNullableVirtualPointer < true , T > ;
82119
83120impl < const IS_VIRTUAL : bool , const IS_MUTABLE : bool , T : Alignment >
0 commit comments