@@ -35,7 +35,7 @@ impl BootloaderConfig {
35
35
0x3D ,
36
36
] ;
37
37
#[ doc( hidden) ]
38
- pub const SERIALIZED_LEN : usize = 97 ;
38
+ pub const SERIALIZED_LEN : usize = 115 ;
39
39
40
40
/// Creates a new default configuration with the following values:
41
41
///
@@ -69,12 +69,14 @@ impl BootloaderConfig {
69
69
pre_release,
70
70
} = version;
71
71
let Mappings {
72
- aslr,
73
72
kernel_stack,
74
73
boot_info,
75
74
framebuffer,
76
75
physical_memory,
77
76
page_table_recursive,
77
+ aslr,
78
+ dynamic_range_start,
79
+ dynamic_range_end,
78
80
} = mappings;
79
81
let FrameBuffer {
80
82
minimum_framebuffer_height,
@@ -107,21 +109,36 @@ impl BootloaderConfig {
107
109
Option :: Some ( m) => concat_1_9 ( [ 1 ] , m. serialize ( ) ) ,
108
110
} ,
109
111
) ;
110
- let buf = concat_78_9 (
112
+ let buf = concat_78_1 ( buf, [ ( * aslr) as u8 ] ) ;
113
+ let buf = concat_79_9 (
114
+ buf,
115
+ match dynamic_range_start {
116
+ Option :: None => [ 0 ; 9 ] ,
117
+ Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
118
+ } ,
119
+ ) ;
120
+ let buf = concat_88_9 (
121
+ buf,
122
+ match dynamic_range_end {
123
+ Option :: None => [ 0 ; 9 ] ,
124
+ Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
125
+ } ,
126
+ ) ;
127
+
128
+ let buf = concat_97_9 (
111
129
buf,
112
130
match minimum_framebuffer_height {
113
131
Option :: None => [ 0 ; 9 ] ,
114
132
Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
115
133
} ,
116
134
) ;
117
- let buf = concat_87_9 (
135
+ let buf = concat_106_9 (
118
136
buf,
119
137
match minimum_framebuffer_width {
120
138
Option :: None => [ 0 ; 9 ] ,
121
139
Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
122
140
} ,
123
141
) ;
124
- let buf = concat_96_1 ( buf, [ ( * aslr) as u8 ] ) ;
125
142
126
143
buf
127
144
}
@@ -177,13 +194,12 @@ impl BootloaderConfig {
177
194
let ( & page_table_recursive_some, s) = split_array_ref ( s) ;
178
195
let ( & page_table_recursive, s) = split_array_ref ( s) ;
179
196
let ( & [ alsr] , s) = split_array_ref ( s) ;
197
+ let ( & dynamic_range_start_some, s) = split_array_ref ( s) ;
198
+ let ( & dynamic_range_start, s) = split_array_ref ( s) ;
199
+ let ( & dynamic_range_end_some, s) = split_array_ref ( s) ;
200
+ let ( & dynamic_range_end, s) = split_array_ref ( s) ;
180
201
181
202
let mappings = Mappings {
182
- aslr : match alsr {
183
- 1 => true ,
184
- 0 => false ,
185
- _ => return Err ( ( ) ) ,
186
- } ,
187
203
kernel_stack : Mapping :: deserialize ( & kernel_stack) ?,
188
204
boot_info : Mapping :: deserialize ( & boot_info) ?,
189
205
framebuffer : Mapping :: deserialize ( & framebuffer) ?,
@@ -197,6 +213,21 @@ impl BootloaderConfig {
197
213
[ 1 ] => Option :: Some ( Mapping :: deserialize ( & page_table_recursive) ?) ,
198
214
_ => return Err ( ( ) ) ,
199
215
} ,
216
+ aslr : match alsr {
217
+ 1 => true ,
218
+ 0 => false ,
219
+ _ => return Err ( ( ) ) ,
220
+ } ,
221
+ dynamic_range_start : match dynamic_range_start_some {
222
+ [ 0 ] if dynamic_range_start == [ 0 ; 8 ] => Option :: None ,
223
+ [ 1 ] => Option :: Some ( u64:: from_le_bytes ( dynamic_range_start) ) ,
224
+ _ => return Err ( ( ) ) ,
225
+ } ,
226
+ dynamic_range_end : match dynamic_range_end_some {
227
+ [ 0 ] if dynamic_range_end == [ 0 ; 8 ] => Option :: None ,
228
+ [ 1 ] => Option :: Some ( u64:: from_le_bytes ( dynamic_range_end) ) ,
229
+ _ => return Err ( ( ) ) ,
230
+ } ,
200
231
} ;
201
232
( mappings, s)
202
233
} ;
@@ -314,12 +345,6 @@ impl Default for ApiVersion {
314
345
#[ derive( Debug , Default , PartialEq , Eq , Clone , Copy ) ]
315
346
#[ non_exhaustive]
316
347
pub 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 ,
323
348
/// Configures how the kernel stack should be mapped.
324
349
pub kernel_stack : Mapping ,
325
350
/// Specifies where the [`crate::BootInfo`] struct should be placed in virtual memory.
@@ -338,6 +363,20 @@ pub struct Mappings {
338
363
///
339
364
/// Defaults to `None`, i.e. no recursive mapping.
340
365
pub page_table_recursive : Option < Mapping > ,
366
+ /// Whether to randomize non-statically configured addresses.
367
+ /// The kernel base address will be randomized when it's compiled as
368
+ /// a position independent executable.
369
+ ///
370
+ /// Defaults to `false`.
371
+ pub aslr : bool ,
372
+ /// The lowest virtual address for dynamic addresses.
373
+ ///
374
+ /// Defaults to `0`.
375
+ pub dynamic_range_start : Option < u64 > ,
376
+ /// The highest virtual address for dynamic addresses.
377
+ ///
378
+ /// Defaults to `0xffff_ffff_ffff_f000`.
379
+ pub dynamic_range_end : Option < u64 > ,
341
380
}
342
381
343
382
impl Mappings {
@@ -346,12 +385,14 @@ impl Mappings {
346
385
/// enabled.
347
386
pub const fn new_default ( ) -> Self {
348
387
Self {
349
- aslr : false ,
350
388
kernel_stack : Mapping :: new_default ( ) ,
351
389
boot_info : Mapping :: new_default ( ) ,
352
390
framebuffer : Mapping :: new_default ( ) ,
353
391
physical_memory : Option :: None ,
354
392
page_table_recursive : Option :: None ,
393
+ aslr : false ,
394
+ dynamic_range_start : None ,
395
+ dynamic_range_end : None ,
355
396
}
356
397
}
357
398
@@ -360,7 +401,6 @@ impl Mappings {
360
401
let phys = rand:: random ( ) ;
361
402
let recursive = rand:: random ( ) ;
362
403
Self {
363
- aslr : rand:: random ( ) ,
364
404
kernel_stack : Mapping :: random ( ) ,
365
405
boot_info : Mapping :: random ( ) ,
366
406
framebuffer : Mapping :: random ( ) ,
@@ -374,6 +414,17 @@ impl Mappings {
374
414
} else {
375
415
Option :: None
376
416
} ,
417
+ aslr : rand:: random ( ) ,
418
+ dynamic_range_start : if rand:: random ( ) {
419
+ Option :: Some ( rand:: random ( ) )
420
+ } else {
421
+ Option :: None
422
+ } ,
423
+ dynamic_range_end : if rand:: random ( ) {
424
+ Option :: Some ( rand:: random ( ) )
425
+ } else {
426
+ Option :: None
427
+ } ,
377
428
}
378
429
}
379
430
}
0 commit comments