diff --git a/AK/Userspace.h b/AK/Userspace.h index 8d99a541725..267862424e0 100644 --- a/AK/Userspace.h +++ b/AK/Userspace.h @@ -10,6 +10,10 @@ #include #include +#ifdef KERNEL +# include +#endif + namespace AK { template @@ -20,8 +24,6 @@ class Userspace { public: Userspace() = default; - operator FlatPtr() const { return (FlatPtr)m_ptr; } - // Disable default implementations that would use surprising integer promotion. bool operator==(const Userspace&) const = delete; bool operator<=(const Userspace&) const = delete; @@ -38,7 +40,8 @@ public: explicit operator bool() const { return m_ptr != 0; } FlatPtr ptr() const { return m_ptr; } - T unsafe_userspace_ptr() const { return (T)m_ptr; } + VirtualAddress vaddr() const { return VirtualAddress(m_ptr); } + T unsafe_userspace_ptr() const { return reinterpret_cast(m_ptr); } #else Userspace(T ptr) : m_ptr(ptr) diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 5c7c915bd9f..35ef6c60edf 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -15,7 +15,7 @@ ErrorOr> try_copy_kstring_from_user(Userspace user_str, size_t user_str_size) { - bool is_user = Kernel::Memory::is_user_range(VirtualAddress(user_str), user_str_size); + bool is_user = Kernel::Memory::is_user_range(user_str.vaddr(), user_str_size); if (!is_user) return EFAULT; Kernel::SmapDisabler disabler; diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index e934cc98bae..68a001890d2 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -276,7 +276,7 @@ ErrorOr Process::sys$mprotect(Userspace addr, size_t size, int p REQUIRE_PROMISE(prot_exec); } - auto range_to_mprotect = TRY(expand_range_to_page_boundaries(addr, size)); + auto range_to_mprotect = TRY(expand_range_to_page_boundaries(addr.ptr(), size)); if (!range_to_mprotect.size()) return EINVAL; @@ -411,7 +411,7 @@ ErrorOr Process::sys$madvise(Userspace address, size_t size, int VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); - auto range_to_madvise = TRY(expand_range_to_page_boundaries(address, size)); + auto range_to_madvise = TRY(expand_range_to_page_boundaries(address.ptr(), size)); if (!range_to_madvise.size()) return EINVAL; @@ -469,7 +469,7 @@ ErrorOr Process::sys$munmap(Userspace addr, size_t size) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); - TRY(address_space().unmap_mmap_range(VirtualAddress { addr }, size)); + TRY(address_space().unmap_mmap_range(addr.vaddr(), size)); return 0; } @@ -576,10 +576,10 @@ ErrorOr Process::sys$msyscall(Userspace address) return 0; } - if (!Memory::is_user_address(VirtualAddress { address })) + if (!Memory::is_user_address(address.vaddr())) return EFAULT; - auto* region = address_space().find_region_containing(Memory::VirtualRange { VirtualAddress { address }, 1 }); + auto* region = address_space().find_region_containing(Memory::VirtualRange { address.vaddr(), 1 }); if (!region) return EINVAL; diff --git a/Kernel/Syscalls/ptrace.cpp b/Kernel/Syscalls/ptrace.cpp index 19cd8043c45..e8c96336d2f 100644 --- a/Kernel/Syscalls/ptrace.cpp +++ b/Kernel/Syscalls/ptrace.cpp @@ -178,7 +178,7 @@ ErrorOr Process::peek_user_data(Userspace address) ErrorOr Process::poke_user_data(Userspace address, u32 data) { - Memory::VirtualRange range = { VirtualAddress(address), sizeof(u32) }; + Memory::VirtualRange range = { address.vaddr(), sizeof(u32) }; auto* region = address_space().find_region_containing(range); if (!region) return EFAULT; diff --git a/Kernel/Syscalls/thread.cpp b/Kernel/Syscalls/thread.cpp index f32fe56e8c5..84c98308579 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -87,7 +87,7 @@ void Process::sys$exit_thread(Userspace exit_value, Userspace stac PerformanceManager::add_thread_exit_event(*current_thread); if (stack_location) { - auto unmap_result = address_space().unmap_mmap_range(VirtualAddress { stack_location }, stack_size); + auto unmap_result = address_space().unmap_mmap_range(stack_location.vaddr(), stack_size); if (unmap_result.is_error()) dbgln("Failed to unmap thread stack, terminating thread anyway. Error code: {}", unmap_result.error()); }