From 6fb355c58c23e932309829b6d57f17e91d93b018 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 14 Sep 2015 12:47:03 -0700 Subject: Increase VMR limit for SPEC --- pk/vm.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'pk') diff --git a/pk/vm.c b/pk/vm.c index bf07c61..2303ae1 100644 --- a/pk/vm.c +++ b/pk/vm.c @@ -14,9 +14,9 @@ typedef struct { int prot; } vmr_t; -#define MAX_VMR 32 +#define MAX_VMR (RISCV_PGSIZE / sizeof(vmr_t)) spinlock_t vm_lock = SPINLOCK_INIT; -static vmr_t vmrs[MAX_VMR]; +static vmr_t* vmrs; pte_t* root_page_table; static uintptr_t first_free_page; @@ -34,10 +34,15 @@ static uintptr_t __page_alloc() static vmr_t* __vmr_alloc(uintptr_t addr, size_t length, file_t* file, size_t offset, unsigned refcnt, int prot) { - for (vmr_t* v = vmrs; v < vmrs + MAX_VMR; v++) - { - if (v->refcnt == 0) - { + if (!vmrs) { + spinlock_lock(&vm_lock); + if (!vmrs) + vmrs = (vmr_t*)__page_alloc(); + spinlock_unlock(&vm_lock); + } + + for (vmr_t* v = vmrs; v < vmrs + MAX_VMR; v++) { + if (v->refcnt == 0) { if (file) file_incref(file); v->addr = addr; -- cgit v1.1