From 89d7cf197b2cae130565467bdfad5d5ef5fed2dd Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 9 Jul 2024 19:24:12 +0300 Subject: allow regions to have reserved areas + A reserved area is an area at the start of the region that should not be used unless explicitly asked for, for example null pages. As such, a small correction to my previous commit message: There's no danger in not locking req_mem() etc, as a null page will only be allocated when explicitly asked for. --- src/vmem.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/vmem.c') diff --git a/src/vmem.c b/src/vmem.c index 52e7bd2..6fb5474 100644 --- a/src/vmem.c +++ b/src/vmem.c @@ -18,19 +18,10 @@ stat_t init_uvmem(struct tcb *t) { t->uvmem.owner = t->tid; t->uvmem.vmem = t->proc.vmem; - - stat_t ret = OK; - if ((ret = init_region(&t->uvmem.region, UVMEM_START, UVMEM_END))) - return ret; - - /* if a user really wants to use the first page for something, they'll - * have to free it first, 'accepting' that no null-page is dangerous. */ - size_t size = 0; - vm_t v = alloc_fixed_region(&t->uvmem.region, - UVMEM_START, BASE_PAGE_SIZE, &size, - MR_NONBACKED); - assert(v == UVMEM_START && size == BASE_PAGE_SIZE); - return OK; + /* reserve 64KiB (arbitrary number but should be large enough that + * nobody accidentally indexes above NULL enough to find real memory) */ + return init_region(&t->uvmem.region, UVMEM_START, + UVMEM_END - UVMEM_START, SZ_64K); } /** @@ -132,8 +123,8 @@ static vm_t __clone_shared_region(struct tcb *d, struct tcb *s, if (ERR_CODE(v)) return v; - stat_t res = clone_region(d->uvmem.vmem, s->uvmem.vmem, start, v, size, - flags); + stat_t res = clone_region(d->uvmem.vmem, s->uvmem.vmem, + start, v, size, flags); if (res == OK) return v; -- cgit v1.3