kernel: Move validate_user_memory_range to kernel.h and rename it.

It has more general use than just in the VM code; basically anything
which receives buffers from userland should be invoking this if it
does anything besides user_memcpy (which alreay does it.)
This commit is contained in:
Augustin Cavalier
2022-06-03 15:35:17 -04:00
parent 3e9b842151
commit 77694f9225
2 changed files with 21 additions and 19 deletions
+17
View File
@@ -40,6 +40,23 @@
((addr_t)(x) >= USER_BASE && (addr_t)(x) <= USER_TOP)
#endif
#ifdef __cplusplus
// Validate that an address range is fully in userspace.
static inline bool
is_user_address_range(const void* addr, size_t size)
{
addr_t address = (addr_t)addr;
// Check for overflows on all addresses.
if ((address + size) < address)
return false;
// Validate that both the start and end address are in userspace
return IS_USER_ADDRESS(address) && IS_USER_ADDRESS(address + size - 1);
}
#endif
#define DEBUG_KERNEL_STACKS
// Note, debugging kernel stacks doesn't really work yet. Since the
// interrupt will also try to use the stack on a page fault, all