summaryrefslogtreecommitdiff
path: root/Kernel/Devices/RandomDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Devices/RandomDevice.cpp')
-rw-r--r--Kernel/Devices/RandomDevice.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp
index 5c6b7eb22b..fa625d0ecf 100644
--- a/Kernel/Devices/RandomDevice.cpp
+++ b/Kernel/Devices/RandomDevice.cpp
@@ -43,13 +43,18 @@ bool RandomDevice::can_read(const FileDescription&, size_t) const
return true;
}
-KResultOr<size_t> RandomDevice::read(FileDescription&, size_t, u8* buffer, size_t size)
+KResultOr<size_t> RandomDevice::read(FileDescription&, size_t, UserOrKernelBuffer& buffer, size_t size)
{
- get_good_random_bytes(buffer, size);
+ bool success = buffer.write_buffered<256>(size, [&](u8* data, size_t data_size) {
+ get_good_random_bytes(data, data_size);
+ return (ssize_t)data_size;
+ });
+ if (!success)
+ return KResult(-EFAULT);
return size;
}
-KResultOr<size_t> RandomDevice::write(FileDescription&, size_t, const u8*, size_t size)
+KResultOr<size_t> RandomDevice::write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t size)
{
// FIXME: Use input for entropy? I guess that could be a neat feature?
return min(static_cast<size_t>(PAGE_SIZE), size);