@@ -35,7 +35,7 @@ impl BootloaderConfig {
3535 0x3D ,
3636 ] ;
3737 #[ doc( hidden) ]
38- pub const SERIALIZED_LEN : usize = 96 ;
38+ pub const SERIALIZED_LEN : usize = 97 ;
3939
4040 /// Creates a new default configuration with the following values:
4141 ///
@@ -69,6 +69,7 @@ impl BootloaderConfig {
6969 pre_release,
7070 } = version;
7171 let Mappings {
72+ aslr,
7273 kernel_stack,
7374 boot_info,
7475 framebuffer,
@@ -120,6 +121,7 @@ impl BootloaderConfig {
120121 Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
121122 } ,
122123 ) ;
124+ let buf = concat_96_1 ( buf, [ ( * aslr) as u8 ] ) ;
123125
124126 buf
125127 }
@@ -174,8 +176,14 @@ impl BootloaderConfig {
174176 let ( & physical_memory, s) = split_array_ref ( s) ;
175177 let ( & page_table_recursive_some, s) = split_array_ref ( s) ;
176178 let ( & page_table_recursive, s) = split_array_ref ( s) ;
179+ let ( & [ alsr] , s) = split_array_ref ( s) ;
177180
178181 let mappings = Mappings {
182+ aslr : match alsr {
183+ 1 => true ,
184+ 0 => false ,
185+ _ => return Err ( ( ) ) ,
186+ } ,
179187 kernel_stack : Mapping :: deserialize ( & kernel_stack) ?,
180188 boot_info : Mapping :: deserialize ( & boot_info) ?,
181189 framebuffer : Mapping :: deserialize ( & framebuffer) ?,
@@ -306,6 +314,12 @@ impl Default for ApiVersion {
306314#[ derive( Debug , Default , PartialEq , Eq , Clone , Copy ) ]
307315#[ non_exhaustive]
308316pub struct Mappings {
317+ /// Whether to randomize non-statically configured addresses.
318+ /// The kernel base address will be randomized when it's compiled as
319+ /// a position independent executable.
320+ ///
321+ /// Defaults to `false`.
322+ pub aslr : bool ,
309323 /// Configures how the kernel stack should be mapped.
310324 pub kernel_stack : Mapping ,
311325 /// Specifies where the [`crate::BootInfo`] struct should be placed in virtual memory.
@@ -332,6 +346,7 @@ impl Mappings {
332346 /// enabled.
333347 pub const fn new_default ( ) -> Self {
334348 Self {
349+ aslr : false ,
335350 kernel_stack : Mapping :: new_default ( ) ,
336351 boot_info : Mapping :: new_default ( ) ,
337352 framebuffer : Mapping :: new_default ( ) ,
@@ -345,6 +360,7 @@ impl Mappings {
345360 let phys = rand:: random ( ) ;
346361 let recursive = rand:: random ( ) ;
347362 Self {
363+ aslr : rand:: random ( ) ,
348364 kernel_stack : Mapping :: random ( ) ,
349365 boot_info : Mapping :: random ( ) ,
350366 framebuffer : Mapping :: random ( ) ,
0 commit comments