Skip to content

Commit

Permalink
pk: fix __do_brk when new addr is not feasible (#295)
Browse files Browse the repository at this point in the history
Linux kernel simply return current brk when request brk addr is not
feasible. The pk should probably do the same.
  • Loading branch information
xukl committed May 1, 2023
1 parent 3ed18cf commit 8ce2dc4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions pk/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void load_elf(const char* fn, elf_info* info)
}

file_decref(file);
info->brk = ROUNDUP(info->brk_min, RISCV_PGSIZE);
return;

fail:
Expand Down
9 changes: 2 additions & 7 deletions pk/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,8 @@ uintptr_t do_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, of
uintptr_t __do_brk(size_t addr)
{
uintptr_t newbrk = addr;
if (addr < current.brk_min)
newbrk = current.brk_min;
else if (addr > current.brk_max)
newbrk = current.brk_max;

if (current.brk == 0)
current.brk = ROUNDUP(current.brk_min, RISCV_PGSIZE);
if (addr < current.brk_min || addr > current.brk_max)
return current.brk;

uintptr_t newbrk_page = ROUNDUP(newbrk, RISCV_PGSIZE);
if (current.brk > newbrk_page) {
Expand Down

0 comments on commit 8ce2dc4

Please sign in to comment.