Revert the MPU hack by splitting the store in 2

This commit is contained in:
Julien Cretin
2021-09-15 19:36:35 +02:00
committed by Julien Cretin
parent 596b47886c
commit 18ba4368e4
4 changed files with 62 additions and 42 deletions

View File

@@ -349,7 +349,7 @@ index 348c746a5..5465c95f4 100644
}
}
diff --git a/kernel/src/process.rs b/kernel/src/process.rs
index c52754be3..f5c833ea7 100644
index c52754be3..ae6a58341 100644
--- a/kernel/src/process.rs
+++ b/kernel/src/process.rs
@@ -359,6 +359,15 @@ pub trait ProcessType {
@@ -404,37 +404,33 @@ index c52754be3..f5c833ea7 100644
fn update_stack_start_pointer(&self, stack_pointer: *const u8) {
if stack_pointer >= self.mem_start() && stack_pointer < self.mem_end() {
self.debug.map(|debug| {
@@ -1751,6 +1789,37 @@ impl<C: 'static + Chip> Process<'_, C> {
@@ -1751,6 +1789,33 @@ impl<C: 'static + Chip> Process<'_, C> {
return Err(ProcessLoadError::MpuInvalidFlashLength);
}
+ // Allocate MPU region for the storage locations. The storage locations are currently
+ // readable by all processes due to lack of stable app id.
+ 'storage_location: for storage_location in kernel.storage_locations() {
+ // We work around MPU limitations on Nordic by also trying unallocated_size = 0x40000.
+ // Note that just using the next power of 2 doesn't work.
+ for &unallocated_size in &[storage_location.size, 0x40000] {
+ if chip
+ .mpu()
+ .allocate_region(
+ storage_location.address as *const u8,
+ unallocated_size,
+ storage_location.size,
+ mpu::Permissions::ReadOnly,
+ &mut mpu_config,
+ )
+ .is_some()
+ {
+ continue 'storage_location;
+ }
+ if config::CONFIG.debug_load_processes {
+ debug!(
+ "[!] flash=[{:#010X}:{:#010X}] process={:?} - couldn't allocate flash region",
+ storage_location.address,
+ storage_location.address + unallocated_size,
+ process_name
+ );
+ }
+ for storage_location in kernel.storage_locations() {
+ if chip
+ .mpu()
+ .allocate_region(
+ storage_location.address as *const u8,
+ storage_location.size,
+ storage_location.size,
+ mpu::Permissions::ReadOnly,
+ &mut mpu_config,
+ )
+ .is_some()
+ {
+ continue;
+ }
+ if config::CONFIG.debug_load_processes {
+ debug!(
+ "[!] flash=[{:#010X}:{:#010X}] process={:?} - couldn't allocate flash region",
+ storage_location.address,
+ storage_location.address + storage_location.size,
+ process_name
+ );
+ }
+ return Ok((None, remaining_memory));
+ }