mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:27:35 +00:00
Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
This commit is contained in:
parent
7ee10c6926
commit
79fa9765ca
262 changed files with 2415 additions and 2600 deletions
|
@ -13,7 +13,7 @@
|
|||
#include <Kernel/Memory/MemoryManager.h>
|
||||
#include <Kernel/StdLib.h>
|
||||
|
||||
Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Userspace<const char*> user_str, size_t user_str_size)
|
||||
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);
|
||||
if (!is_user)
|
||||
|
@ -40,14 +40,14 @@ Kernel::KResultOr<NonnullOwnPtr<Kernel::KString>> try_copy_kstring_from_user(Use
|
|||
return new_string;
|
||||
}
|
||||
|
||||
KResultOr<Time> copy_time_from_user(timespec const* ts_user)
|
||||
ErrorOr<Time> copy_time_from_user(timespec const* ts_user)
|
||||
{
|
||||
timespec ts {};
|
||||
TRY(copy_from_user(&ts, ts_user, sizeof(timespec)));
|
||||
return Time::from_timespec(ts);
|
||||
}
|
||||
|
||||
KResultOr<Time> copy_time_from_user(timeval const* tv_user)
|
||||
ErrorOr<Time> copy_time_from_user(timeval const* tv_user)
|
||||
{
|
||||
timeval tv {};
|
||||
TRY(copy_from_user(&tv, tv_user, sizeof(timeval)));
|
||||
|
@ -55,13 +55,13 @@ KResultOr<Time> copy_time_from_user(timeval const* tv_user)
|
|||
}
|
||||
|
||||
template<>
|
||||
KResultOr<Time> copy_time_from_user<const timeval>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Time> copy_time_from_user<const timeval>(Userspace<timeval const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
KResultOr<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Time> copy_time_from_user<timeval>(Userspace<timeval*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
KResultOr<Time> copy_time_from_user<const timespec>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Time> copy_time_from_user<const timespec>(Userspace<timespec const*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
template<>
|
||||
KResultOr<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
ErrorOr<Time> copy_time_from_user<timespec>(Userspace<timespec*> src) { return copy_time_from_user(src.unsafe_userspace_ptr()); }
|
||||
|
||||
Optional<u32> user_atomic_fetch_add_relaxed(volatile u32* var, u32 val)
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ Optional<u32> user_atomic_fetch_xor_relaxed(volatile u32* var, u32 val)
|
|||
return Kernel::safe_atomic_fetch_xor_relaxed(var, val);
|
||||
}
|
||||
|
||||
KResult copy_to_user(void* dest_ptr, void const* src_ptr, size_t n)
|
||||
ErrorOr<void> copy_to_user(void* dest_ptr, void const* src_ptr, size_t n)
|
||||
{
|
||||
if (!Kernel::Memory::is_user_range(VirtualAddress(dest_ptr), n))
|
||||
return EFAULT;
|
||||
|
@ -175,10 +175,10 @@ KResult copy_to_user(void* dest_ptr, void const* src_ptr, size_t n)
|
|||
dbgln("copy_to_user({:p}, {:p}, {}) failed at {}", dest_ptr, src_ptr, n, VirtualAddress { fault_at });
|
||||
return EFAULT;
|
||||
}
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
KResult copy_from_user(void* dest_ptr, void const* src_ptr, size_t n)
|
||||
ErrorOr<void> copy_from_user(void* dest_ptr, void const* src_ptr, size_t n)
|
||||
{
|
||||
if (!Kernel::Memory::is_user_range(VirtualAddress(src_ptr), n))
|
||||
return EFAULT;
|
||||
|
@ -190,10 +190,10 @@ KResult copy_from_user(void* dest_ptr, void const* src_ptr, size_t n)
|
|||
dbgln("copy_from_user({:p}, {:p}, {}) failed at {}", dest_ptr, src_ptr, n, VirtualAddress { fault_at });
|
||||
return EFAULT;
|
||||
}
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
KResult memset_user(void* dest_ptr, int c, size_t n)
|
||||
ErrorOr<void> memset_user(void* dest_ptr, int c, size_t n)
|
||||
{
|
||||
bool is_user = Kernel::Memory::is_user_range(VirtualAddress(dest_ptr), n);
|
||||
if (!is_user)
|
||||
|
@ -204,7 +204,7 @@ KResult memset_user(void* dest_ptr, int c, size_t n)
|
|||
dbgln("memset_user({:p}, {}, {}) failed at {}", dest_ptr, c, n, VirtualAddress { fault_at });
|
||||
return EFAULT;
|
||||
}
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
#if defined(__clang__) && defined(ENABLE_KERNEL_LTO)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue