Skip to content

Commit 9da813b

Browse files
GorrayLiRbb666
authored andcommitted
[libcpu][risc-v]add code for handling exception scenarios in _unmap_area.
1 parent b04aacb commit 9da813b

File tree

1 file changed

+17
-0
lines changed
  • libcpu/risc-v/common64

1 file changed

+17
-0
lines changed

libcpu/risc-v/common64/mmu.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,23 @@ static size_t _unmap_area(struct rt_aspace *aspace, void *v_addr)
263263
lvl_entry[i] = ((rt_ubase_t *)aspace->page_table + lvl_off[i]);
264264
pentry = lvl_entry[i];
265265

266+
/* check if lvl_entry[0] is valid. if no, return 0 directly. */
267+
if (!PTE_USED(*pentry))
268+
{
269+
return 0;
270+
}
271+
266272
/* find leaf page table entry */
267273
while (PTE_USED(*pentry) && !PAGE_IS_LEAF(*pentry))
268274
{
269275
i += 1;
276+
277+
if (i >= 3)
278+
{
279+
unmapped = 0;
280+
break;
281+
}
282+
270283
lvl_entry[i] = ((rt_ubase_t *)PPN_TO_VPN(GET_PADDR(*pentry), PV_OFFSET) +
271284
lvl_off[i]);
272285
pentry = lvl_entry[i];
@@ -278,6 +291,10 @@ static size_t _unmap_area(struct rt_aspace *aspace, void *v_addr)
278291
{
279292
_unmap_pte(pentry, lvl_entry, i);
280293
}
294+
else
295+
{
296+
unmapped = 0; /* invalid pte, return 0. */
297+
}
281298

282299
return unmapped;
283300
}

0 commit comments

Comments
 (0)