kernel: add memory domain APIs
Add the following application-facing memory domain APIs: k_mem_domain_init() - to initialize a memory domain k_mem_domain_destroy() - to destroy a memory domain k_mem_domain_add_partition() - to add a partition into a domain k_mem_domain_remove_partition() - to remove a partition from a domain k_mem_domain_add_thread() - to add a thread into a domain k_mem_domain_remove_thread() - to remove a thread from a domain A memory domain would contain some number of memory partitions. A memory partition is a memory region (might be RAM, peripheral registers, flash...) with specific attributes (access permission, e.g. privileged read/write, unprivileged read-only, execute never...). Memory partitions would be defined by set of MPU regions or MMU tables underneath. A thread could only belong to a single memory domain any point in time but a memory domain could contain multiple threads. Threads in the same memory domain would have the same access permission to the memory partitions belong to the memory domain. The memory domain APIs are used by unprivileged threads to share data to the threads in the same memory and protect sensitive data from threads outside their domain. It is not only for improving the security but also useful for debugging (unexpected access would cause exception). Jira: ZEP-2281 Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
This commit is contained in:
parent
de85fdedf9
commit
e9c9702818
17 changed files with 928 additions and 15 deletions
|
@ -200,6 +200,46 @@ extern "C" {
|
|||
#define _ARCH_THREAD_STACK_BUFFER(sym) \
|
||||
((char *)(sym) + MPU_GUARD_ALIGN_AND_SIZE)
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
#ifdef CONFIG_ARM_MPU
|
||||
#ifndef _ASMLANGUAGE
|
||||
#include <arch/arm/cortex_m/mpu/arm_mpu.h>
|
||||
|
||||
#define K_MEM_PARTITION_P_NA_U_NA (NO_ACCESS | NOT_EXEC)
|
||||
#define K_MEM_PARTITION_P_RW_U_RW (P_RW_U_RW | NOT_EXEC)
|
||||
#define K_MEM_PARTITION_P_RW_U_RO (P_RW_U_RO | NOT_EXEC)
|
||||
#define K_MEM_PARTITION_P_RW_U_NA (P_RW_U_NA | NOT_EXEC)
|
||||
#define K_MEM_PARTITION_P_RO_U_RO (P_RO_U_RO | NOT_EXEC)
|
||||
#define K_MEM_PARTITION_P_RO_U_NA (P_RO_U_NA | NOT_EXEC)
|
||||
#endif /* _ASMLANGUAGE */
|
||||
#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
|
||||
BUILD_ASSERT_MSG(!(((size) & ((size) - 1))) && (size) >= 32 && \
|
||||
!((u32_t)(start) & ((size) - 1)), \
|
||||
"the size of the partition must be power of 2" \
|
||||
" and greater than or equal to 32." \
|
||||
"start address of the partition must align with size.")
|
||||
#endif /* CONFIG_ARM_MPU*/
|
||||
#ifdef CONFIG_NXP_MPU
|
||||
#ifndef _ASMLANGUAGE
|
||||
#include <arch/arm/cortex_m/mpu/nxp_mpu.h>
|
||||
|
||||
#define K_MEM_PARTITION_P_NA_U_NA (MPU_REGION_SU)
|
||||
#define K_MEM_PARTITION_P_RW_U_RW (MPU_REGION_READ | MPU_REGION_WRITE | \
|
||||
MPU_REGION_SU)
|
||||
#define K_MEM_PARTITION_P_RW_U_RO (MPU_REGION_READ | MPU_REGION_SU_RW)
|
||||
#define K_MEM_PARTITION_P_RW_U_NA (MPU_REGION_SU_RW)
|
||||
#define K_MEM_PARTITION_P_RO_U_RO (MPU_REGION_READ | MPU_REGION_SU)
|
||||
#define K_MEM_PARTITION_P_RO_U_NA (MPU_REGION_SU_RX)
|
||||
#endif /* _ASMLANGUAGE */
|
||||
#define _ARCH_MEM_PARTITION_ALIGN_CHECK(start, size) \
|
||||
BUILD_ASSERT_MSG((size) % 32 == 0 && (size) >= 32 && \
|
||||
(u32_t)(start) % 32 == 0, \
|
||||
"the size of the partition must align with 32" \
|
||||
" and greater than or equal to 32." \
|
||||
"start address of the partition must align with 32.")
|
||||
#endif /* CONFIG_NXP_MPU */
|
||||
#endif /* CONFIG_USERSPACE */
|
||||
|
||||
#ifdef CONFIG_ARM_USERSPACE
|
||||
#ifndef _ASMLANGUAGE
|
||||
/* Syscall invocation macros. arm-specific machine constraints used to ensure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue