diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-07-26 03:47:25 -0700 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-27 01:23:37 +0430 |
commit | de9ff0af507f7630c8ffd937345dcff2291b6253 (patch) | |
tree | dcf4a99a1c71ddc6d8767bc3970bfa77428f3fa7 | |
parent | 46c9b1d81c22c6840733e821bc0859dda1d65e7d (diff) | |
download | serenity-de9ff0af507f7630c8ffd937345dcff2291b6253.zip |
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.
-rw-r--r-- | Kernel/Devices/HID/KeyboardDevice.cpp | 20 | ||||
-rw-r--r-- | Kernel/Devices/HID/KeyboardDevice.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/File.cpp | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/File.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeFile.cpp | 14 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeFile.h | 2 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.cpp | 50 | ||||
-rw-r--r-- | Kernel/Graphics/FramebufferDevice.h | 2 | ||||
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp | 42 | ||||
-rw-r--r-- | Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h | 2 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 88 | ||||
-rw-r--r-- | Kernel/Net/IPv4Socket.h | 2 | ||||
-rw-r--r-- | Kernel/TTY/MasterPTY.cpp | 6 | ||||
-rw-r--r-- | Kernel/TTY/MasterPTY.h | 2 | ||||
-rw-r--r-- | Kernel/TTY/TTY.cpp | 60 | ||||
-rw-r--r-- | Kernel/TTY/TTY.h | 4 |
16 files changed, 151 insertions, 151 deletions
diff --git a/Kernel/Devices/HID/KeyboardDevice.cpp b/Kernel/Devices/HID/KeyboardDevice.cpp index a95465228e..7d490f8595 100644 --- a/Kernel/Devices/HID/KeyboardDevice.cpp +++ b/Kernel/Devices/HID/KeyboardDevice.cpp @@ -311,38 +311,38 @@ KResultOr<size_t> KeyboardDevice::write(FileDescription&, u64, const UserOrKerne return 0; } -int KeyboardDevice::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) +KResult KeyboardDevice::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) { switch (request) { case KEYBOARD_IOCTL_GET_NUM_LOCK: { auto output = static_ptr_cast<bool*>(arg); if (!copy_to_user(output, &m_num_lock_on)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case KEYBOARD_IOCTL_SET_NUM_LOCK: { // In this case we expect the value to be a boolean and not a pointer. auto num_lock_value = static_cast<u8>(arg.ptr()); if (num_lock_value != 0 && num_lock_value != 1) - return -EINVAL; + return EINVAL; m_num_lock_on = !!num_lock_value; - return 0; + return KSuccess; } case KEYBOARD_IOCTL_GET_CAPS_LOCK: { auto output = static_ptr_cast<bool*>(arg); if (!copy_to_user(output, &m_caps_lock_on)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case KEYBOARD_IOCTL_SET_CAPS_LOCK: { auto caps_lock_value = static_cast<u8>(arg.ptr()); if (caps_lock_value != 0 && caps_lock_value != 1) - return -EINVAL; + return EINVAL; m_caps_lock_on = !!caps_lock_value; - return 0; + return KSuccess; } default: - return -EINVAL; + return EINVAL; }; } diff --git a/Kernel/Devices/HID/KeyboardDevice.h b/Kernel/Devices/HID/KeyboardDevice.h index 5bd43a9767..3269971a20 100644 --- a/Kernel/Devices/HID/KeyboardDevice.h +++ b/Kernel/Devices/HID/KeyboardDevice.h @@ -37,7 +37,7 @@ public: virtual mode_t required_mode() const override { return 0440; } // ^File - virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; + virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; virtual String device_name() const override { return String::formatted("keyboard{}", minor()); } diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index 29bc1fc5e9..355b6ed56d 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -35,9 +35,9 @@ KResult File::close() return KSuccess; } -int File::ioctl(FileDescription&, unsigned, Userspace<void*>) +KResult File::ioctl(FileDescription&, unsigned, Userspace<void*>) { - return -ENOTTY; + return ENOTTY; } KResultOr<Region*> File::mmap(Process&, FileDescription&, const Range&, u64, int, bool) diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index f51569897e..6410d1e1cb 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -87,7 +87,7 @@ public: virtual void did_seek(FileDescription&, off_t) { } virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) = 0; virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0; - virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg); + virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg); virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared); virtual KResult stat(::stat&) const { return EBADF; } diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index a0d657b88b..c7462ac42e 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -62,34 +62,34 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, u64 offset, con return nwritten; } -int InodeFile::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg) +KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg) { (void)description; switch (request) { case FIBMAP: { if (!Process::current()->is_superuser()) - return -EPERM; + return EPERM; auto user_block_number = static_ptr_cast<int*>(arg); int block_number = 0; if (!copy_from_user(&block_number, user_block_number)) - return -EFAULT; + return EFAULT; if (block_number < 0) - return -EINVAL; + return EINVAL; auto block_address = inode().get_block_address(block_number); if (block_address.is_error()) return block_address.error(); if (!copy_to_user(user_block_number, &block_address.value())) - return -EFAULT; + return EFAULT; - return 0; + return KSuccess; } default: - return -EINVAL; + return EINVAL; } } diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index 2fb6a38d17..5fe928a21d 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -32,7 +32,7 @@ public: virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override; - 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 KResult stat(::stat& buffer) const override { return inode().metadata().stat(buffer); } diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index 435868ccb3..822db73951 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -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; }; } diff --git a/Kernel/Graphics/FramebufferDevice.h b/Kernel/Graphics/FramebufferDevice.h index bde59ddbe3..033c248dbb 100644 --- a/Kernel/Graphics/FramebufferDevice.h +++ b/Kernel/Graphics/FramebufferDevice.h @@ -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 diff --git a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp index 126a1313a9..eb312811df 100644 --- a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp +++ b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.cpp @@ -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; }; } diff --git a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h index e7bbae8624..54b765a40c 100644 --- a/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h +++ b/Kernel/Graphics/VirtIOGPU/FrameBufferDevice.h @@ -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; } diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 9aa0fd61bc..a539b4c503 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -568,75 +568,75 @@ KResult IPv4Socket::getsockopt(FileDescription& description, int level, int opti } } -int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) +KResult IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) { REQUIRE_PROMISE(inet); - auto ioctl_route = [request, arg]() { + auto ioctl_route = [request, arg]() -> KResult { auto user_route = static_ptr_cast<rtentry*>(arg); rtentry route; if (!copy_from_user(&route, user_route)) - return -EFAULT; + return EFAULT; auto copied_ifname = copy_string_from_user(route.rt_dev, IFNAMSIZ); if (copied_ifname.is_null()) - return -EFAULT; + return EFAULT; auto adapter = NetworkingManagement::the().lookup_by_name(copied_ifname); if (!adapter) - return -ENODEV; + return ENODEV; switch (request) { case SIOCADDRT: if (!Process::current()->is_superuser()) - return -EPERM; + return EPERM; if (route.rt_gateway.sa_family != AF_INET) - return -EAFNOSUPPORT; + return EAFNOSUPPORT; if ((route.rt_flags & (RTF_UP | RTF_GATEWAY)) != (RTF_UP | RTF_GATEWAY)) - return -EINVAL; // FIXME: Find the correct value to return + return EINVAL; // FIXME: Find the correct value to return adapter->set_ipv4_gateway(IPv4Address(((sockaddr_in&)route.rt_gateway).sin_addr.s_addr)); - return 0; + return KSuccess; case SIOCDELRT: // FIXME: Support gateway deletion - return 0; + return KSuccess; } - return -EINVAL; + return EINVAL; }; - auto ioctl_arp = [request, arg]() { + auto ioctl_arp = [request, arg]() -> KResult { auto user_req = static_ptr_cast<arpreq*>(arg); arpreq arp_req; if (!copy_from_user(&arp_req, user_req)) - return -EFAULT; + return EFAULT; switch (request) { case SIOCSARP: if (!Process::current()->is_superuser()) - return -EPERM; + return EPERM; if (arp_req.arp_pa.sa_family != AF_INET) - return -EAFNOSUPPORT; + return EAFNOSUPPORT; update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateArp::Set); - return 0; + return KSuccess; case SIOCDARP: if (!Process::current()->is_superuser()) - return -EPERM; + return EPERM; if (arp_req.arp_pa.sa_family != AF_INET) - return -EAFNOSUPPORT; + return EAFNOSUPPORT; update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateArp::Delete); - return 0; + return KSuccess; } - return -EINVAL; + return EINVAL; }; - auto ioctl_interface = [request, arg]() { + auto ioctl_interface = [request, arg]() -> KResult { auto user_ifr = static_ptr_cast<ifreq*>(arg); ifreq ifr; if (!copy_from_user(&ifr, user_ifr)) - return -EFAULT; + return EFAULT; char namebuf[IFNAMSIZ + 1]; memcpy(namebuf, ifr.ifr_name, IFNAMSIZ); @@ -644,24 +644,24 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) auto adapter = NetworkingManagement::the().lookup_by_name(namebuf); if (!adapter) - return -ENODEV; + return ENODEV; switch (request) { case SIOCSIFADDR: if (!Process::current()->is_superuser()) - return -EPERM; + return EPERM; if (ifr.ifr_addr.sa_family != AF_INET) - return -EAFNOSUPPORT; + return EAFNOSUPPORT; adapter->set_ipv4_address(IPv4Address(((sockaddr_in&)ifr.ifr_addr).sin_addr.s_addr)); - return 0; + return KSuccess; case SIOCSIFNETMASK: if (!Process::current()->is_superuser()) - return -EPERM; + return EPERM; if (ifr.ifr_addr.sa_family != AF_INET) - return -EAFNOSUPPORT; + return EAFNOSUPPORT; adapter->set_ipv4_netmask(IPv4Address(((sockaddr_in&)ifr.ifr_netmask).sin_addr.s_addr)); - return 0; + return KSuccess; case SIOCGIFADDR: { auto ip4_addr = adapter->ipv4_address().to_u32(); @@ -669,8 +669,8 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) socket_address_in.sin_family = AF_INET; socket_address_in.sin_addr.s_addr = ip4_addr; if (!copy_to_user(user_ifr, &ifr)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case SIOCGIFNETMASK: { @@ -681,8 +681,8 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) socket_address_in.sin_addr.s_addr = ip4_netmask; if (!copy_to_user(user_ifr, &ifr)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case SIOCGIFHWADDR: { @@ -690,8 +690,8 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) ifr.ifr_hwaddr.sa_family = AF_INET; mac_address.copy_to(Bytes { ifr.ifr_hwaddr.sa_data, sizeof(ifr.ifr_hwaddr.sa_data) }); if (!copy_to_user(user_ifr, &ifr)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case SIOCGIFBRDADDR: { @@ -703,8 +703,8 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) socket_address_in.sin_family = AF_INET; socket_address_in.sin_addr.s_addr = broadcast_addr; if (!copy_to_user(user_ifr, &ifr)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case SIOCGIFMTU: { @@ -713,8 +713,8 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) ifr.ifr_addr.sa_family = AF_INET; ifr.ifr_metric = ip4_metric; if (!copy_to_user(user_ifr, &ifr)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case SIOCGIFFLAGS: { @@ -723,17 +723,17 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) ifr.ifr_addr.sa_family = AF_INET; ifr.ifr_flags = flags; if (!copy_to_user(user_ifr, &ifr)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case SIOCGIFCONF: { // FIXME: stub! - return -EINVAL; + return EINVAL; } } - return -EINVAL; + return EINVAL; }; switch (request) { @@ -757,7 +757,7 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) return ioctl_arp(); } - return -EINVAL; + return EINVAL; } KResult IPv4Socket::close() diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h index 1eed0a4d09..3d47160aba 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -46,7 +46,7 @@ public: virtual KResult setsockopt(int level, int option, Userspace<const void*>, socklen_t) override; virtual KResult getsockopt(FileDescription&, int level, int option, Userspace<void*>, Userspace<socklen_t*>) override; - virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; + virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; bool did_receive(const IPv4Address& peer_address, u16 peer_port, ReadonlyBytes, const Time&); diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index 6cf84f2c9f..2179d7c90f 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -106,14 +106,14 @@ KResult MasterPTY::close() return KSuccess; } -int MasterPTY::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg) +KResult MasterPTY::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg) { REQUIRE_PROMISE(tty); if (!m_slave) - return -EIO; + return EIO; if (request == TIOCSWINSZ || request == TIOCGPGRP) return m_slave->ioctl(description, request, arg); - return -EINVAL; + return EINVAL; } String MasterPTY::absolute_path(const FileDescription&) const diff --git a/Kernel/TTY/MasterPTY.h b/Kernel/TTY/MasterPTY.h index 96fcadea7a..a1c9274046 100644 --- a/Kernel/TTY/MasterPTY.h +++ b/Kernel/TTY/MasterPTY.h @@ -40,7 +40,7 @@ private: virtual bool can_write(const FileDescription&, size_t) const override; virtual KResult close() override; virtual bool is_master_pty() const override { return true; } - virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; + virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; virtual StringView class_name() const override { return "MasterPTY"; } RefPtr<SlavePTY> m_slave; diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index c5a7802133..db7962bdb1 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -360,9 +360,9 @@ void TTY::flush_input() evaluate_block_conditions(); } -int TTY::set_termios(const termios& t) +KResult TTY::set_termios(const termios& t) { - int rc = 0; + KResult rc = KSuccess; m_termios = t; dbgln_if(TTY_DEBUG, "{} set_termios: ECHO={}, ISIG={}, ICANON={}, ECHOE={}, ECHOK={}, ECHONL={}, ISTRIP={}, ICRNL={}, INLCR={}, IGNCR={}, OPOST={}, ONLCR={}", @@ -402,7 +402,7 @@ int TTY::set_termios(const termios& t) for (auto flag : unimplemented_iflags) { if (m_termios.c_iflag & flag.value) { dbgln("FIXME: iflag {} unimplemented", flag.name); - rc = -ENOTIMPL; + rc = ENOTIMPL; } } @@ -416,7 +416,7 @@ int TTY::set_termios(const termios& t) for (auto flag : unimplemented_oflags) { if (m_termios.c_oflag & flag.value) { dbgln("FIXME: oflag {} unimplemented", flag.name); - rc = -ENOTIMPL; + rc = ENOTIMPL; } } @@ -436,7 +436,7 @@ int TTY::set_termios(const termios& t) for (auto flag : unimplemented_cflags) { if (m_termios.c_cflag & flag.value) { dbgln("FIXME: cflag {} unimplemented", flag.name); - rc = -ENOTIMPL; + rc = ENOTIMPL; } } @@ -447,14 +447,14 @@ int TTY::set_termios(const termios& t) for (auto flag : unimplemented_lflags) { if (m_termios.c_lflag & flag.value) { dbgln("FIXME: lflag {} unimplemented", flag.name); - rc = -ENOTIMPL; + rc = ENOTIMPL; } } return rc; } -int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) +KResult TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) { REQUIRE_PROMISE(tty); auto& current_process = *Process::current(); @@ -473,42 +473,42 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) auto user_pgid = static_ptr_cast<pid_t*>(arg); auto pgid = this->pgid().value(); if (!copy_to_user(user_pgid, &pgid)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case TIOCSPGRP: { ProcessGroupID pgid = static_cast<pid_t>(arg.ptr()); if (pgid <= 0) - return -EINVAL; + return EINVAL; InterruptDisabler disabler; auto process_group = ProcessGroup::from_pgid(pgid); // Disallow setting a nonexistent PGID. if (!process_group) - return -EINVAL; + return EINVAL; auto process = Process::from_pid(ProcessID(pgid.value())); SessionID new_sid = process ? process->sid() : Process::get_sid_from_pgid(pgid); if (!new_sid || new_sid != current_process.sid()) - return -EPERM; + return EPERM; if (process && pgid != process->pgid()) - return -EPERM; + return EPERM; m_pg = process_group; if (process) { if (auto parent = Process::from_pid(process->ppid())) { m_original_process_parent = *parent; - return 0; + return KSuccess; } } m_original_process_parent = nullptr; - return 0; + return KSuccess; } case TCGETS: { user_termios = static_ptr_cast<termios*>(arg); if (!copy_to_user(user_termios, &m_termios)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; } case TCSETS: case TCSETSF: @@ -516,8 +516,8 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) user_termios = static_ptr_cast<termios*>(arg); termios termios; if (!copy_from_user(&termios, user_termios)) - return -EFAULT; - int rc = set_termios(termios); + return EFAULT; + auto rc = set_termios(termios); if (request == TCSETSF) flush_input(); return rc; @@ -528,9 +528,9 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) if (operation == TCIFLUSH || operation == TCIOFLUSH) { flush_input(); } else if (operation != TCOFLUSH) { - return -EINVAL; + return EINVAL; } - return 0; + return KSuccess; } case TIOCGWINSZ: user_winsize = static_ptr_cast<winsize*>(arg); @@ -540,30 +540,30 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg) ws.ws_xpixel = 0; ws.ws_ypixel = 0; if (!copy_to_user(user_winsize, &ws)) - return -EFAULT; - return 0; + return EFAULT; + return KSuccess; case TIOCSWINSZ: { user_winsize = static_ptr_cast<winsize*>(arg); winsize ws; if (!copy_from_user(&ws, user_winsize)) - return -EFAULT; + return EFAULT; if (ws.ws_col == m_columns && ws.ws_row == m_rows) - return 0; + return KSuccess; m_rows = ws.ws_row; m_columns = ws.ws_col; generate_signal(SIGWINCH); - return 0; + return KSuccess; } case TIOCSCTTY: current_process.set_tty(this); - return 0; + return KSuccess; case TIOCSTI: - return -EIO; + return EIO; case TIOCNOTTY: current_process.set_tty(nullptr); - return 0; + return KSuccess; } - return -EINVAL; + return EINVAL; } void TTY::set_size(unsigned short columns, unsigned short rows) diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h index 6d611b3332..678e835605 100644 --- a/Kernel/TTY/TTY.h +++ b/Kernel/TTY/TTY.h @@ -25,7 +25,7 @@ public: virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override; virtual bool can_read(const FileDescription&, size_t) const override; virtual bool can_write(const FileDescription&, size_t) const override; - virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override final; + virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override final; virtual String absolute_path(const FileDescription&) const override { return tty_name(); } virtual String const& tty_name() const = 0; @@ -40,7 +40,7 @@ public: return 0; } - int set_termios(const termios&); + KResult set_termios(const termios&); bool should_generate_signals() const { return m_termios.c_lflag & ISIG; } bool should_flush_on_signal() const { return !(m_termios.c_lflag & NOFLSH); } bool should_echo_input() const { return m_termios.c_lflag & ECHO; } |