Kernel: Add copy_from_user() and copy_from_user_typed()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
73ddd0b0c5
commit
6e4cd6300d
@ -438,7 +438,6 @@ namespace MemoryManager
|
|||||||
// Userspace pointer not aligned on page boundary
|
// Userspace pointer not aligned on page boundary
|
||||||
if (user_ptr != user_page)
|
if (user_ptr != user_page)
|
||||||
{
|
{
|
||||||
// FIXME: Validate that this page is writable by the user, not just the kernel.
|
|
||||||
if (!validate_user_writable_page(user_page)) return false;
|
if (!validate_user_writable_page(user_page)) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,6 +456,34 @@ namespace MemoryManager
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool copy_from_user(const void* user, void* kernel, usize size)
|
||||||
|
{
|
||||||
|
uintptr_t user_ptr = (uintptr_t)user;
|
||||||
|
uintptr_t user_page = align_down<ARCH_PAGE_SIZE>(user_ptr);
|
||||||
|
|
||||||
|
char* kernel_ptr = (char*)kernel;
|
||||||
|
|
||||||
|
// Userspace pointer not aligned on page boundary
|
||||||
|
if (user_ptr != user_page)
|
||||||
|
{
|
||||||
|
if (!validate_user_writable_page(user_page)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (size--)
|
||||||
|
{
|
||||||
|
// Crossed a page boundary, gotta check the page tables again before touching any memory!!
|
||||||
|
if (user_ptr % ARCH_PAGE_SIZE)
|
||||||
|
{
|
||||||
|
if (!validate_user_writable_page(user_ptr)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*kernel_ptr++ = *(char*)user_ptr;
|
||||||
|
user_ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
usize free()
|
usize free()
|
||||||
{
|
{
|
||||||
return free_mem;
|
return free_mem;
|
||||||
|
@ -45,6 +45,13 @@ namespace MemoryManager
|
|||||||
return copy_to_user(user, kernel, sizeof(T));
|
return copy_to_user(user, kernel, sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool copy_from_user(const void* user, void* kernel, usize size);
|
||||||
|
|
||||||
|
template <typename T> bool copy_from_user_typed(const T* user, T* kernel)
|
||||||
|
{
|
||||||
|
return copy_from_user(user, kernel, sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
Result<void> map_frames_at(u64 virt, u64 phys, usize count, int flags);
|
Result<void> map_frames_at(u64 virt, u64 phys, usize count, int flags);
|
||||||
|
|
||||||
Result<u64> alloc_at(u64 virt, usize count, int flags);
|
Result<u64> alloc_at(u64 virt, usize count, int flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user