process/vm: implement access_ok()
This commit is contained in:
committed by
Masamichi Takagi
parent
a697f5e98d
commit
2db69d0f24
@ -834,4 +834,8 @@ void copy_fp_regs(struct thread *from, struct thread *to);
|
||||
void restore_fp_regs(struct thread *proc);
|
||||
void clear_fp_regs(void);
|
||||
|
||||
#define VERIFY_READ 0
|
||||
#define VERIFY_WRITE 1
|
||||
int access_ok(struct process_vm *vm, int type, uintptr_t addr, size_t len);
|
||||
|
||||
#endif
|
||||
|
||||
@ -3607,3 +3607,35 @@ debug_log(unsigned long arg)
|
||||
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