PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
mpu.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <pbl/kernel/section.h>

Data Structures

struct  pbl_mpu_region
 Memory region. More...
 

Macros

#define PBL_KERNEL_READONLY_DATA   PBL_SECTION(".kernel_unpriv_ro_bss")
 Places a variable where unprivileged code can read it but not write to it.
 
#define PBL_KERNEL_READONLY_DATA_SET(var, val)
 Assign a PBL_KERNEL_READONLY_DATA variable.
 
#define PBL_MPU_NO_ACCESS   0U
 No access.
 
#define PBL_MPU_P_RW   1U
 Privileged read/write, no unprivileged access.
 
#define PBL_MPU_P_RW_U_RO   2U
 Privileged read/write, unprivileged read-only.
 
#define PBL_MPU_P_RW_U_RW   3U
 Privileged and unprivileged read/write.
 
#define PBL_MPU_P_RO   4U
 Privileged read-only, no unprivileged access.
 
#define PBL_MPU_P_RO_U_RO   5U
 Privileged and unprivileged read-only.
 
#define PBL_MPU_ACCESS_MSK   7U
 Mask of the access attribute.
 
#define PBL_MPU_NORMAL_NC   (0U << 3)
 Normal memory, not cached.
 
#define PBL_MPU_NORMAL_WT   (1U << 3)
 Normal memory, write-through cached.
 
#define PBL_MPU_NORMAL_WB   (2U << 3)
 Normal memory, write-back cached.
 
#define PBL_MPU_DEVICE   (3U << 3)
 Device memory: accesses are not merged, reordered or cached.
 
#define PBL_MPU_TYPE_MSK   (3U << 3)
 Mask of the memory type attribute.
 
#define PBL_MPU_EXEC   (1U << 5)
 Instructions may be fetched from the region.
 
#define PBL_MPU_SHAREABLE   (1U << 6)
 Coherent with other bus masters.
 

Functions

int pbl_mpu_region_add (const struct pbl_mpu_region *region)
 Add a static region, for every thread and until reset.
 
void pbl_mpu_user_ro_write (void *dst, const void *src, size_t n)
 Write to the PBL_MPU_P_RW_U_RO region from privileged code.
 
bool pbl_mpu_region_is_stack_guard (uintptr_t start, uintptr_t end)
 Check whether a stack guard covers any of a memory range.
 
const struct pbl_mpu_region * pbl_mpu_region_firmware (void)
 Get the memory of the running firmware image, to check pointers against.
 
bool pbl_mpu_region_contains (const struct pbl_mpu_region *region, const void *ptr)
 Check whether a region contains an address.
 
bool pbl_mpu_region_contains_buffer (const struct pbl_mpu_region *region, const void *buf, size_t length)
 Check whether a region contains a whole buffer.
 
bool pbl_mpu_region_contains_cstring (const struct pbl_mpu_region *region, const char *str, size_t max_length)
 Check whether a region contains a whole NUL-terminated string.
 
void pbl_mpu_regions_print (void(*print)(void *ctx, const char *line), void *ctx)
 Print every programmed region, one line at a time.
 

Variables

const struct pbl_mpu_region pbl_soc_mpu_regions []
 Regions the SoC declares, with CONFIG_SOC_HAS_MPU_REGIONS.
 
const size_t pbl_soc_num_mpu_regions
 Number of entries in pbl_soc_mpu_regions.