diff options
author | Andrew Kaster <akaster@serenityos.org> | 2021-11-14 15:52:48 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-16 00:13:22 +0100 |
commit | f1d8978804900311d348da1651d7e17ad218b80f (patch) | |
tree | d7328d766b4d52beffefb91457264f0850759b15 | |
parent | 7243bcb7da80357210db2aaf57094878b5208db0 (diff) | |
download | serenity-f1d8978804900311d348da1651d7e17ad218b80f.zip |
AK+Kernel: Remove implicit conversion from Userspace<T*> to FlatPtr
This feels like it was a refactor transition kind of conversion. The
places that were relying on it can easily be changed to explicitly ask
for the ptr() or a new vaddr() method on Userspace<T*>.
FlatPtr can still implicitly convert to Userspace<T> because the
constructor is not explicit, but there's quite a few more places that
are relying on that conversion.
-rw-r--r-- | AK/Userspace.h | 9 | ||||
-rw-r--r-- | Kernel/StdLib.cpp | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/mmap.cpp | 10 | ||||
-rw-r--r-- | Kernel/Syscalls/ptrace.cpp | 2 | ||||
-rw-r--r-- | Kernel/Syscalls/thread.cpp | 2 |
5 files changed, 14 insertions, 11 deletions
diff --git a/AK/Userspace.h b/AK/Userspace.h index 8d99a54172..267862424e 100644 --- a/AK/Userspace.h +++ b/AK/Userspace.h @@ -10,6 +10,10 @@ #include <AK/StdLibExtras.h> #include <AK/Types.h> +#ifdef KERNEL +# include <Kernel/VirtualAddress.h> +#endif + namespace AK { template<typename T> @@ -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<T>(m_ptr); } #else Userspace(T ptr) : m_ptr(ptr) diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 5c7c915bd9..35ef6c60ed 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -15,7 +15,7 @@ ErrorOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<const char*> 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 e934cc98ba..68a001890d 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -276,7 +276,7 @@ ErrorOr<FlatPtr> Process::sys$mprotect(Userspace<void*> 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<FlatPtr> Process::sys$madvise(Userspace<void*> 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<FlatPtr> Process::sys$munmap(Userspace<void*> 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<FlatPtr> Process::sys$msyscall(Userspace<void*> 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 19cd8043c4..e8c96336d2 100644 --- a/Kernel/Syscalls/ptrace.cpp +++ b/Kernel/Syscalls/ptrace.cpp @@ -178,7 +178,7 @@ ErrorOr<u32> Process::peek_user_data(Userspace<const u32*> address) ErrorOr<void> Process::poke_user_data(Userspace<u32*> 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 f32fe56e8c..84c9830857 100644 --- a/Kernel/Syscalls/thread.cpp +++ b/Kernel/Syscalls/thread.cpp @@ -87,7 +87,7 @@ void Process::sys$exit_thread(Userspace<void*> exit_value, Userspace<void*> 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()); } |