1-
2- pub mod stack;
1+ use core:: ops:: { Add , Sub , Div , Rem } ;
32
43#[ repr( transparent) ]
54#[ derive( Debug , Clone , Copy , PartialEq , Eq , Ord , PartialOrd , Hash ) ]
65pub struct PhysAddr ( usize ) ;
76
87impl PhysAddr {
8+ pub const MAX : Self = Self ( usize:: MAX ) ;
9+
910 #[ inline]
1011 pub fn new ( addr : usize ) -> Self {
1112 Self ( addr)
@@ -15,6 +16,58 @@ impl PhysAddr {
1516 pub fn as_usize ( & self ) -> usize {
1617 self . 0
1718 }
19+
20+ pub fn as_mut_ptr < T > ( & self ) -> * mut T {
21+ self . 0 as * mut T
22+ }
23+
24+ pub fn checked_add ( & self , other : usize ) -> Option < Self > {
25+ self . 0 . checked_add ( other) . map ( Self )
26+ }
27+
28+ pub fn checked_sub ( & self , other : usize ) -> Option < Self > {
29+ self . 0 . checked_sub ( other) . map ( Self )
30+ }
31+
32+ pub fn is_multiple_of ( & self , align : usize ) -> bool {
33+ self . 0 . is_multiple_of ( align)
34+ }
35+ }
36+
37+ impl Add < usize > for PhysAddr {
38+ type Output = Self ;
39+
40+ #[ inline]
41+ fn add ( self , rhs : usize ) -> Self :: Output {
42+ Self ( self . 0 + rhs)
43+ }
44+ }
45+
46+ impl Sub < usize > for PhysAddr {
47+ type Output = Self ;
48+
49+ #[ inline]
50+ fn sub ( self , rhs : usize ) -> Self :: Output {
51+ Self ( self . 0 - rhs)
52+ }
53+ }
54+
55+ impl Div < usize > for PhysAddr {
56+ type Output = Self ;
57+
58+ #[ inline]
59+ fn div ( self , rhs : usize ) -> Self :: Output {
60+ Self ( self . 0 / rhs)
61+ }
62+ }
63+
64+ impl Rem < usize > for PhysAddr {
65+ type Output = Self ;
66+
67+ #[ inline]
68+ fn rem ( self , rhs : usize ) -> Self :: Output {
69+ Self ( self . 0 % rhs)
70+ }
1871}
1972
2073impl From < PhysAddr > for usize {
@@ -38,6 +91,16 @@ impl VirtAddr {
3891 pub fn as_usize ( & self ) -> usize {
3992 self . 0
4093 }
94+
95+ #[ inline]
96+ pub fn saturating_add ( & self , other : usize ) -> Self {
97+ Self ( self . 0 . saturating_add ( other) )
98+ }
99+
100+ #[ inline]
101+ pub fn saturating_sub ( & self , other : usize ) -> Self {
102+ Self ( self . 0 . saturating_sub ( other) )
103+ }
41104}
42105
43106impl From < VirtAddr > for usize {
0 commit comments