Skip to content

Commit

Permalink
[smart] add mprotect config (RT-Thread#9082)
Browse files Browse the repository at this point in the history
Signed-off-by: Shell <[email protected]>
  • Loading branch information
polarvid authored Jun 22, 2024
1 parent 06ad67d commit fa2d806
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions components/lwp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ if RT_USING_LWP
config RT_LWP_SHM_MAX_NR
int "The maximum number of shared memory"
default 64

config LWP_USING_MPROTECT
bool
default n
help
ARCH has the support of mprotect
endif

if ARCH_MM_MPU
Expand Down
4 changes: 4 additions & 0 deletions components/lwp/lwp_user_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,17 @@ rt_inline rt_size_t lwp_user_mm_attr_to_kernel(int prot)

rt_size_t k_attr = 0;

#ifdef LWP_USING_MPROTECT
if ((prot & PROT_EXEC) || (prot & PROT_WRITE) ||
((prot & PROT_READ) && (prot & PROT_WRITE)))
k_attr = MMU_MAP_U_RWCB;
else if (prot == PROT_NONE)
k_attr = MMU_MAP_K_RWCB;
else
k_attr = MMU_MAP_U_ROCB;
#else /* !LWP_USING_MPROTECT */
k_attr = MMU_MAP_U_RWCB;
#endif /* LWP_USING_MPROTECT */

return k_attr;
}
Expand Down
4 changes: 3 additions & 1 deletion components/mm/mm_fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static int _write_fault(rt_varea_t varea, void *pa, struct rt_aspace_fault_msg *
}
else
{
LOG_I("%s: No permission on %s(attr=0x%lx)", __func__, VAREA_NAME(varea), varea->attr);
LOG_I("%s: No permission on %s(attr=0x%lx,writable=%s,fault_type=%d)",
__func__, VAREA_NAME(varea), varea->attr,
VAREA_IS_WRITABLE(varea) ? "True" : "False", msg->fault_type);
}
}
else if (msg->fault_type == MM_FAULT_TYPE_PAGE_FAULT)
Expand Down

0 comments on commit fa2d806

Please sign in to comment.