1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

Kernel: Modify the IOCTL API to return KResult

The kernel has been gradually moving towards KResult from just bare
int's, this change migrates the IOCTL paths.
This commit is contained in:
Brian Gianforcaro 2021-07-26 03:47:25 -07:00 committed by Ali Mohammad Pur
parent 46c9b1d81c
commit de9ff0af50
16 changed files with 151 additions and 151 deletions

View file

@ -143,7 +143,7 @@ size_t FramebufferDevice::framebuffer_size_in_bytes() const
return m_framebuffer_pitch * m_framebuffer_height;
}
int FramebufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
KResult FramebufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
{
REQUIRE_PROMISE(video);
switch (request) {
@ -151,26 +151,26 @@ int FramebufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
auto user_size = static_ptr_cast<size_t*>(arg);
size_t value = framebuffer_size_in_bytes();
if (!copy_to_user(user_size, &value))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_GET_BUFFER: {
auto user_index = static_ptr_cast<int*>(arg);
int value = m_y_offset == 0 ? 0 : 1;
if (!copy_to_user(user_index, &value))
return -EFAULT;
return EFAULT;
if (!m_graphics_adapter->double_framebuffering_capable())
return -ENOTIMPL;
return 0;
return ENOTIMPL;
return KSuccess;
}
case FB_IOCTL_SET_BUFFER: {
auto buffer = static_cast<int>(arg.ptr());
if (buffer != 0 && buffer != 1)
return -EINVAL;
return EINVAL;
if (!m_graphics_adapter->double_framebuffering_capable())
return -ENOTIMPL;
return ENOTIMPL;
m_graphics_adapter->set_y_offset(m_output_port_index, buffer == 0 ? 0 : m_framebuffer_height);
return 0;
return KSuccess;
}
case FB_IOCTL_GET_RESOLUTION: {
auto user_resolution = static_ptr_cast<FBResolution*>(arg);
@ -179,24 +179,24 @@ int FramebufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
resolution.width = m_framebuffer_width;
resolution.height = m_framebuffer_height;
if (!copy_to_user(user_resolution, &resolution))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_SET_RESOLUTION: {
auto user_resolution = static_ptr_cast<FBResolution*>(arg);
FBResolution resolution;
if (!copy_from_user(&resolution, user_resolution))
return -EFAULT;
return EFAULT;
if (resolution.width > MAX_RESOLUTION_WIDTH || resolution.height > MAX_RESOLUTION_HEIGHT)
return -EINVAL;
return EINVAL;
if (!m_graphics_adapter->modesetting_capable()) {
resolution.pitch = m_framebuffer_pitch;
resolution.width = m_framebuffer_width;
resolution.height = m_framebuffer_height;
if (!copy_to_user(user_resolution, &resolution))
return -EFAULT;
return -ENOTIMPL;
return EFAULT;
return ENOTIMPL;
}
if (!m_graphics_adapter->try_to_set_resolution(m_output_port_index, resolution.width, resolution.height)) {
@ -210,8 +210,8 @@ int FramebufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
resolution.width = m_framebuffer_width;
resolution.height = m_framebuffer_height;
if (!copy_to_user(user_resolution, &resolution))
return -EFAULT;
return -EINVAL;
return EFAULT;
return EINVAL;
}
m_framebuffer_width = resolution.width;
m_framebuffer_height = resolution.height;
@ -222,25 +222,25 @@ int FramebufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
resolution.width = m_framebuffer_width;
resolution.height = m_framebuffer_height;
if (!copy_to_user(user_resolution, &resolution))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_GET_BUFFER_OFFSET: {
auto user_buffer_offset = static_ptr_cast<FBBufferOffset*>(arg);
FBBufferOffset buffer_offset;
if (!copy_from_user(&buffer_offset, user_buffer_offset))
return -EFAULT;
return EFAULT;
if (buffer_offset.buffer_index != 0 && buffer_offset.buffer_index != 1)
return -EINVAL;
return EINVAL;
buffer_offset.offset = (size_t)buffer_offset.buffer_index * m_framebuffer_pitch * m_framebuffer_height;
if (!copy_to_user(user_buffer_offset, &buffer_offset))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_FLUSH_BUFFERS:
return -ENOTSUP;
return ENOTSUP;
default:
return -EINVAL;
return EINVAL;
};
}

View file

@ -22,7 +22,7 @@ class FramebufferDevice : public BlockDevice {
public:
static NonnullRefPtr<FramebufferDevice> create(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t);
virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override;
// ^Device

View file

@ -140,7 +140,7 @@ void FrameBufferDevice::set_buffer(int buffer_index)
buffer.dirty_rect = {};
}
int FrameBufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
KResult FrameBufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
{
REQUIRE_PROMISE(video);
switch (request) {
@ -148,20 +148,20 @@ int FrameBufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
auto out = static_ptr_cast<size_t*>(arg);
size_t value = m_buffer_size * 2;
if (!copy_to_user(out, &value))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_SET_RESOLUTION: {
auto user_resolution = static_ptr_cast<FBResolution*>(arg);
FBResolution resolution;
if (!copy_from_user(&resolution, user_resolution))
return -EFAULT;
return EFAULT;
if (!try_to_set_resolution(resolution.width, resolution.height))
return -EINVAL;
return EINVAL;
resolution.pitch = pitch();
if (!copy_to_user(user_resolution, &resolution))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_GET_RESOLUTION: {
auto user_resolution = static_ptr_cast<FBResolution*>(arg);
@ -170,33 +170,33 @@ int FrameBufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
resolution.width = width();
resolution.height = height();
if (!copy_to_user(user_resolution, &resolution))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
case FB_IOCTL_SET_BUFFER: {
auto buffer_index = static_cast<int>(arg.ptr());
if (!is_valid_buffer_index(buffer_index))
return -EINVAL;
return EINVAL;
if (m_last_set_buffer_index.exchange(buffer_index) != buffer_index && m_are_writes_active)
set_buffer(buffer_index);
return 0;
return KSuccess;
}
case FB_IOCTL_FLUSH_BUFFERS: {
auto user_flush_rects = static_ptr_cast<FBFlushRects*>(arg);
FBFlushRects flush_rects;
if (!copy_from_user(&flush_rects, user_flush_rects))
return -EFAULT;
return EFAULT;
if (!is_valid_buffer_index(flush_rects.buffer_index))
return -EINVAL;
return EINVAL;
if (Checked<unsigned>::multiplication_would_overflow(flush_rects.count, sizeof(FBRect)))
return -EFAULT;
return EFAULT;
if (m_are_writes_active && flush_rects.count > 0) {
auto& buffer = buffer_from_index(flush_rects.buffer_index);
MutexLocker locker(m_gpu.operation_lock());
for (unsigned i = 0; i < flush_rects.count; i++) {
FBRect user_dirty_rect;
if (!copy_from_user(&user_dirty_rect, &flush_rects.rects[i]))
return -EFAULT;
return EFAULT;
Protocol::Rect dirty_rect {
.x = user_dirty_rect.x,
.y = user_dirty_rect.y,
@ -222,22 +222,22 @@ int FrameBufferDevice::ioctl(FileDescription&, unsigned request, Userspace<void*
}
}
}
return 0;
return KSuccess;
}
case FB_IOCTL_GET_BUFFER_OFFSET: {
auto user_buffer_offset = static_ptr_cast<FBBufferOffset*>(arg);
FBBufferOffset buffer_offset;
if (!copy_from_user(&buffer_offset, user_buffer_offset))
return -EFAULT;
return EFAULT;
if (!is_valid_buffer_index(buffer_offset.buffer_index))
return -EINVAL;
return EINVAL;
buffer_offset.offset = (size_t)buffer_offset.buffer_index * m_buffer_size;
if (!copy_to_user(user_buffer_offset, &buffer_offset))
return -EFAULT;
return 0;
return EFAULT;
return KSuccess;
}
default:
return -EINVAL;
return EINVAL;
};
}

View file

@ -60,7 +60,7 @@ private:
void create_buffer(Buffer&, size_t, size_t);
void set_buffer(int);
virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override;
virtual bool can_read(const FileDescription&, size_t) const override { return true; }
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }