process/vm: implement access_ok()
This commit is contained in:
committed by
Balazs Gerofi
parent
e29a40331d
commit
42bbf5f2a4
@ -830,4 +830,8 @@ void proc_init();
|
|||||||
void set_timer();
|
void set_timer();
|
||||||
struct sig_pending *hassigpending(struct thread *thread);
|
struct sig_pending *hassigpending(struct thread *thread);
|
||||||
|
|
||||||
|
#define VERIFY_READ 0
|
||||||
|
#define VERIFY_WRITE 1
|
||||||
|
int access_ok(struct process_vm *vm, int type, uintptr_t addr, size_t len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -3677,3 +3677,35 @@ debug_log(unsigned long arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int access_ok(struct process_vm *vm, int type, uintptr_t addr, size_t len) {
|
||||||
|
struct vm_range *range, *next;
|
||||||
|
|
||||||
|
range = lookup_process_memory_range(vm, addr, addr + len);
|
||||||
|
|
||||||
|
while (range) {
|
||||||
|
if ((type == VERIFY_WRITE && !(range->flag & VR_PROT_WRITE)) ||
|
||||||
|
(type == VERIFY_READ && !(range->flag & VR_PROT_READ))) {
|
||||||
|
kprintf("%s: 0x%llx - 0x%llx does not have prot %s (request was %0x%llx-0x%llx %zu)\n",
|
||||||
|
__FUNCTION__, range->start, range->end,
|
||||||
|
type == VERIFY_WRITE ? "write" : "ready",
|
||||||
|
addr, addr+len, len);
|
||||||
|
return -EACCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr + len < range->end)
|
||||||
|
break;
|
||||||
|
|
||||||
|
next = next_process_memory_range(vm, range);
|
||||||
|
if (range->end != next->start) {
|
||||||
|
kprintf("%s: 0x%llx - 0x%llx and 0x%llx - 0x%llx are not adjacent (request was %0x%llx-0x%llx %zu)\n",
|
||||||
|
__FUNCTION__, range->start, range->end,
|
||||||
|
next->start, next->end,
|
||||||
|
addr, addr+len, len);
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
range = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user