summaryrefslogtreecommitdiff
path: root/Kernel/UserOrKernelBuffer.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-07 12:09:52 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-07 13:53:14 +0200
commitb4811324183cc64bd671f93c889fa5e6590e0182 (patch)
tree083ec95329a20fbcf74f78ce8ea2bf3c9a4055b8 /Kernel/UserOrKernelBuffer.h
parent7bf88444993a72f588ce3bd849042c3420e222a7 (diff)
downloadserenity-b4811324183cc64bd671f93c889fa5e6590e0182.zip
Kernel: Make UserOrKernelBuffer return KResult from read/write/memset
This allows us to simplify a whole bunch of call sites with TRY(). :^)
Diffstat (limited to 'Kernel/UserOrKernelBuffer.h')
-rw-r--r--Kernel/UserOrKernelBuffer.h23
1 files changed, 11 insertions, 12 deletions
diff --git a/Kernel/UserOrKernelBuffer.h b/Kernel/UserOrKernelBuffer.h
index 555262f10f..1f348f3742 100644
--- a/Kernel/UserOrKernelBuffer.h
+++ b/Kernel/UserOrKernelBuffer.h
@@ -55,28 +55,29 @@ public:
}
KResultOr<NonnullOwnPtr<KString>> try_copy_into_kstring(size_t) const;
- [[nodiscard]] bool write(const void* src, size_t offset, size_t len);
- [[nodiscard]] bool write(const void* src, size_t len)
+ KResult write(const void* src, size_t offset, size_t len);
+ KResult write(const void* src, size_t len)
{
return write(src, 0, len);
}
- [[nodiscard]] bool write(ReadonlyBytes bytes)
+ KResult write(ReadonlyBytes bytes)
{
return write(bytes.data(), bytes.size());
}
- [[nodiscard]] bool read(void* dest, size_t offset, size_t len) const;
- [[nodiscard]] bool read(void* dest, size_t len) const
+ KResult read(void* dest, size_t offset, size_t len) const;
+ KResult read(void* dest, size_t len) const
{
return read(dest, 0, len);
}
- [[nodiscard]] bool read(Bytes bytes) const
+
+ KResult read(Bytes bytes) const
{
return read(bytes.data(), bytes.size());
}
- [[nodiscard]] bool memset(int value, size_t offset, size_t len);
- [[nodiscard]] bool memset(int value, size_t len)
+ KResult memset(int value, size_t offset, size_t len);
+ KResult memset(int value, size_t len)
{
return memset(value, 0, len);
}
@@ -104,8 +105,7 @@ public:
return copied_or_error.error();
auto copied = copied_or_error.value();
VERIFY(copied <= to_copy);
- if (!write(buffer, nwritten, copied))
- return EFAULT;
+ TRY(write(buffer, nwritten, copied));
nwritten += copied;
if (copied < to_copy)
break;
@@ -134,8 +134,7 @@ public:
size_t nread = 0;
while (nread < len) {
auto to_copy = min(sizeof(buffer), len - nread);
- if (!read(buffer, nread, to_copy))
- return EFAULT;
+ TRY(read(buffer, nread, to_copy));
ReadonlyBytes read_only_bytes { buffer, to_copy };
KResultOr<size_t> copied_or_error = f(read_only_bytes);
if (copied_or_error.is_error())