mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
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.
This commit is contained in:
parent
7243bcb7da
commit
f1d8978804
Notes:
sideshowbarker
2024-07-18 01:05:47 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/f1d89788049 Pull-request: https://github.com/SerenityOS/serenity/pull/10925
5 changed files with 14 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue