diff --git a/kern/pmap.c b/kern/pmap.c index 9bd5767..01e1ff4 100644 --- a/kern/pmap.c +++ b/kern/pmap.c @@ -563,13 +563,14 @@ int user_mem_check(struct Env *env, const void *va, size_t len, int perm) { // LAB 3: Your code here. + uintptr_t to_report = (uintptr_t) va; const char* bottom = ROUNDDOWN(va, PGSIZE); size_t aligned_count = ROUNDUP(len, PGSIZE) / PGSIZE; pde_t mask = PTE_P | PTE_U | PTE_W; pde_t perms = mask; #define VALID ((perms & (perm | PTE_P)) == (perm | PTE_P)) -#define DO_CHECK if(!VALID) { user_mem_check_addr = (uintptr_t) bottom; return -E_FAULT; } +#define DO_CHECK if(!VALID) { user_mem_check_addr = to_report; return -E_FAULT; } while(aligned_count--) { perms &= env->env_pgdir[PDX(bottom)] & mask; @@ -577,6 +578,7 @@ user_mem_check(struct Env *env, const void *va, size_t len, int perm) perms &= (*pgdir_walk(env->env_pgdir, bottom, 0)) & mask; DO_CHECK; bottom += PGSIZE; + to_report = (uintptr_t) bottom; } return 0;