LibBareMetal: Add more assertions in copy_{to,from}_user()

Assert that the source/destination address is in kernel space when
appropriate. This is mostly to give ourselves an error if we're doing
something we were not expecting to be doing.
This commit is contained in:
Andreas Kling 2020-04-14 12:52:13 +02:00
parent 815b73bdcc
commit 236dcf7702
Notes: sideshowbarker 2024-07-19 07:36:12 +09:00

View file

@ -50,6 +50,7 @@ extern "C" {
void copy_to_user(void* dest_ptr, const void* src_ptr, size_t n)
{
ASSERT(Kernel::is_user_range(VirtualAddress(dest_ptr), n));
ASSERT(!Kernel::is_user_range(VirtualAddress(src_ptr), n));
Kernel::SmapDisabler disabler;
memcpy(dest_ptr, src_ptr, n);
}
@ -57,6 +58,7 @@ void copy_to_user(void* dest_ptr, const void* src_ptr, size_t n)
void copy_from_user(void* dest_ptr, const void* src_ptr, size_t n)
{
ASSERT(Kernel::is_user_range(VirtualAddress(src_ptr), n));
ASSERT(!Kernel::is_user_range(VirtualAddress(dest_ptr), n));
Kernel::SmapDisabler disabler;
memcpy(dest_ptr, src_ptr, n);
}