@@ -144,6 +144,7 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
144
144
/// memory is not (identity) mapped (UEFI does only identity mapping).
145
145
/// * The memory at `address` must not be modified after calling `load` or the
146
146
/// program may observe unsynchronized mutation.
147
+ #[ deprecated( "Please use load() instead." ) ]
147
148
pub unsafe fn load_with_offset (
148
149
address : usize ,
149
150
offset : usize ,
@@ -193,16 +194,40 @@ pub enum MbiLoadError {
193
194
impl core:: error:: Error for MbiLoadError { }
194
195
195
196
/// A Multiboot 2 Boot Information struct.
196
- pub struct BootInformation {
197
- inner : * const BootInformationInner ,
198
- offset : usize ,
197
+ #[ derive( Debug ) ]
198
+ #[ repr( transparent) ]
199
+ pub struct BootInformation < ' a > ( & ' a BootInformationInner < ' a > ) ;
200
+
201
+ impl < ' a > BootInformation {
202
+ /// Loads the [`BootInformation`] from a pointer..
203
+ pub unsafe fn load ( ptr : * const ( ) ) -> Result < Self , MbiLoadError > {
204
+ if ptr. is_null ( ) {
205
+ return Err ( MbiLoadError :: IllegalAddress ) ;
206
+ }
207
+
208
+ // not aligned
209
+ if ptr. align_offset ( 8 ) != 0 {
210
+ return Err ( MbiLoadError :: IllegalAddress ) ;
211
+ }
212
+
213
+ let mbi = & * ptr. cast :: < BootInformationInner > ( ) ;
214
+
215
+ // Check if total size is a multiple of 8.
216
+ // See MbiLoadError::IllegalTotalSize for comments
217
+ if mbi. total_size & 0b111 != 0 {
218
+ return Err ( MbiLoadError :: IllegalTotalSize ( multiboot. total_size ) ) ;
219
+ }
220
+
221
+ Ok ( Self ( mbi) )
222
+ }
199
223
}
200
224
201
225
#[ derive( Clone , Copy ) ]
202
- #[ repr( C ) ]
203
- struct BootInformationInner {
226
+ #[ repr( C ) , align ( 8 ) ]
227
+ struct BootInformationInner < ' a > {
204
228
total_size : u32 ,
205
229
_reserved : u32 ,
230
+ // followed by multiboot2 tags ...
206
231
}
207
232
208
233
impl BootInformationInner {
@@ -565,7 +590,7 @@ pub trait TagTrait: Pointee {
565
590
// All sized tags automatically have a Pointee implementation where
566
591
// Pointee::Metadata is (). Hence, the TagTrait is implemented automatically for
567
592
// all tags that are sized.
568
- impl < T : Pointee < Metadata = ( ) > > TagTrait for T {
593
+ impl < T : Pointee < Metadata = ( ) > > TagTrait for T {
569
594
#[ allow( clippy:: unused_unit) ]
570
595
fn dst_size ( _: & Tag ) -> Self :: Metadata {
571
596
( )
@@ -737,16 +762,16 @@ mod tests {
737
762
FramebufferType :: RGB {
738
763
red: FramebufferField {
739
764
position: 16 ,
740
- size: 8
765
+ size: 8 ,
741
766
} ,
742
767
green: FramebufferField {
743
768
position: 8 ,
744
- size: 8
769
+ size: 8 ,
745
770
} ,
746
771
blue: FramebufferField {
747
772
position: 0 ,
748
- size: 8
749
- }
773
+ size: 8 ,
774
+ } ,
750
775
}
751
776
) ;
752
777
}
@@ -798,22 +823,22 @@ mod tests {
798
823
FramebufferColor {
799
824
red: 255 ,
800
825
green: 0 ,
801
- blue: 0
826
+ blue: 0 ,
802
827
} ,
803
828
FramebufferColor {
804
829
red: 0 ,
805
830
green: 255 ,
806
- blue: 0
831
+ blue: 0 ,
807
832
} ,
808
833
FramebufferColor {
809
834
red: 0 ,
810
835
green: 0 ,
811
- blue: 255
836
+ blue: 255 ,
812
837
} ,
813
838
FramebufferColor {
814
839
red: 0 ,
815
840
green: 0 ,
816
- blue: 0
841
+ blue: 0 ,
817
842
}
818
843
]
819
844
) ,
@@ -946,28 +971,28 @@ mod tests {
946
971
vbe. mode_info. red_field,
947
972
VBEField {
948
973
position: 16 ,
949
- size: 8
974
+ size: 8 ,
950
975
}
951
976
) ;
952
977
assert_eq ! (
953
978
vbe. mode_info. green_field,
954
979
VBEField {
955
980
position: 8 ,
956
- size: 8
981
+ size: 8 ,
957
982
}
958
983
) ;
959
984
assert_eq ! (
960
985
vbe. mode_info. blue_field,
961
986
VBEField {
962
987
position: 0 ,
963
- size: 8
988
+ size: 8 ,
964
989
}
965
990
) ;
966
991
assert_eq ! (
967
992
vbe. mode_info. reserved_field,
968
993
VBEField {
969
994
position: 24 ,
970
- size: 8
995
+ size: 8 ,
971
996
}
972
997
) ;
973
998
assert_eq ! (
0 commit comments