kernel: mem_domain: extend sane_partition for non-overlapping regions
This commit extends the implementation of sane_partition(..) in
kernel/mem_domain.c so that it generates an ASSERT if partitions
inside a mem_domain overlap. This extension is only implemented
for the case when the MPU requires non-overlapping regions.
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
diff --git a/kernel/mem_domain.c b/kernel/mem_domain.c
index 86bcf1a..5637141 100644
--- a/kernel/mem_domain.c
+++ b/kernel/mem_domain.c
@@ -13,7 +13,8 @@
static u8_t max_partitions;
-#if defined(CONFIG_EXECUTE_XOR_WRITE) && __ASSERT_ON
+#if (defined(CONFIG_EXECUTE_XOR_WRITE) || \
+ defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS)) && __ASSERT_ON
static bool sane_partition(const struct k_mem_partition *part,
const struct k_mem_partition *parts,
u32_t num_parts)
@@ -42,6 +43,13 @@
if (last < parts[i].start || cur_last < part->start) {
continue;
}
+#if defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS)
+ /* Partitions overlap */
+ __ASSERT(false, "overlapping partitions <%x...%x>, <%x...%x>",
+ part->start, last,
+ parts[i].start, cur_last);
+ return false;
+#endif
cur_write = K_MEM_PARTITION_IS_WRITABLE(parts[i].attr);
cur_exec = K_MEM_PARTITION_IS_EXECUTABLE(parts[i].attr);
@@ -92,7 +100,8 @@
__ASSERT((parts[i]->start + parts[i]->size) >
parts[i]->start, "");
-#if defined(CONFIG_EXECUTE_XOR_WRITE)
+#if defined(CONFIG_EXECUTE_XOR_WRITE) || \
+ defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS)
__ASSERT(sane_partition_domain(domain,
parts[i]),
"");
@@ -144,7 +153,8 @@
__ASSERT(part != NULL, "");
__ASSERT((part->start + part->size) > part->start, "");
-#if defined(CONFIG_EXECUTE_XOR_WRITE)
+#if defined(CONFIG_EXECUTE_XOR_WRITE) || \
+ defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS)
__ASSERT(sane_partition_domain(domain, part), "");
#endif