aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxukl <30969283+xukl@users.noreply.github.com>2023-05-02 07:56:20 +0800
committerGitHub <noreply@github.com>2023-05-01 16:56:20 -0700
commit8ce2dc424eab98b907b3117b7515190c62f63c7f (patch)
tree958237e7aae1d820e20e3f739bb4fb4d1b900b7c
parent3ed18cfbc707c75af83941e8fdf7f68f5a3b4803 (diff)
downloadpk-8ce2dc424eab98b907b3117b7515190c62f63c7f.zip
pk-8ce2dc424eab98b907b3117b7515190c62f63c7f.tar.gz
pk-8ce2dc424eab98b907b3117b7515190c62f63c7f.tar.bz2
pk: fix __do_brk when new addr is not feasible (#295)
Linux kernel simply return current brk when request brk addr is not feasible. The pk should probably do the same.
-rw-r--r--pk/elf.c1
-rw-r--r--pk/mmap.c9
2 files changed, 3 insertions, 7 deletions
diff --git a/pk/elf.c b/pk/elf.c
index bfc8daa..abc78e1 100644
--- a/pk/elf.c
+++ b/pk/elf.c
@@ -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:
diff --git a/pk/mmap.c b/pk/mmap.c
index dd0fe59..8f9a281 100644
--- a/pk/mmap.c
+++ b/pk/mmap.c
@@ -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) {