summaryrefslogtreecommitdiff
path: root/libcpu
diff options
context:
space:
mode:
authorligr <[email protected]>2025-03-13 12:29:55 +0800
committerRbb666 <[email protected]>2025-03-17 17:40:55 +0800
commit9da813b1511fc61de192b6255d7a3abc030d3b54 (patch)
tree9ea61eaa589076db3d8621911c6c94610eebc20f /libcpu
parentb04aacbd9470e1aee0fe2dd0e6f06a520ea98d0d (diff)
[libcpu][risc-v]add code for handling exception scenarios in _unmap_area.
Diffstat (limited to 'libcpu')
-rw-r--r--libcpu/risc-v/common64/mmu.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/libcpu/risc-v/common64/mmu.c b/libcpu/risc-v/common64/mmu.c
index db5a79b5a3..badb7bebe6 100644
--- a/libcpu/risc-v/common64/mmu.c
+++ b/libcpu/risc-v/common64/mmu.c
@@ -263,10 +263,23 @@ static size_t _unmap_area(struct rt_aspace *aspace, void *v_addr)
lvl_entry[i] = ((rt_ubase_t *)aspace->page_table + lvl_off[i]);
pentry = lvl_entry[i];
+ /* check if lvl_entry[0] is valid. if no, return 0 directly. */
+ if (!PTE_USED(*pentry))
+ {
+ return 0;
+ }
+
/* find leaf page table entry */
while (PTE_USED(*pentry) && !PAGE_IS_LEAF(*pentry))
{
i += 1;
+
+ if (i >= 3)
+ {
+ unmapped = 0;
+ break;
+ }
+
lvl_entry[i] = ((rt_ubase_t *)PPN_TO_VPN(GET_PADDR(*pentry), PV_OFFSET) +
lvl_off[i]);
pentry = lvl_entry[i];
@@ -278,6 +291,10 @@ static size_t _unmap_area(struct rt_aspace *aspace, void *v_addr)
{
_unmap_pte(pentry, lvl_entry, i);
}
+ else
+ {
+ unmapped = 0; /* invalid pte, return 0. */
+ }
return unmapped;
}