diff --git a/Kernel/Console.cpp b/Kernel/Console.cpp index 7c2ff7a3831ce7..4efe2fec790ba1 100644 --- a/Kernel/Console.cpp +++ b/Kernel/Console.cpp @@ -83,7 +83,7 @@ Kernel::KResultOr Console::write(Kernel::FileDescription&, size_t, const return (ssize_t)bytes_count; }); if (nread < 0) - return Kernel::KResult(nread); + return Kernel::KResult((ErrnoCode)-nread); return (size_t)nread; } diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index 44afeb24b13423..034922f373d6bf 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -179,12 +179,12 @@ KResultOr BXVGADevice::mmap(Process& process, FileDescription&, Virtual { REQUIRE_PROMISE(video); if (!shared) - return KResult(-ENODEV); + return ENODEV; ASSERT(offset == 0); ASSERT(size == framebuffer_size_in_bytes()); auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes()); if (!vmobject) - return KResult(-ENOMEM); + return ENOMEM; return process.allocate_region_with_vmobject( preferred_vaddr, framebuffer_size_in_bytes(), diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index 0d43d7a9509cab..cbe5ca0d1d9ba3 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -50,7 +50,7 @@ KResultOr FullDevice::read(FileDescription&, size_t, UserOrKernelBuffer& { ssize_t count = min(static_cast(PAGE_SIZE), size); if (!buffer.memset(0, count)) - return KResult(-EFAULT); + return EFAULT; return count; } @@ -58,7 +58,7 @@ KResultOr FullDevice::write(FileDescription&, size_t, const UserOrKernel { if (size == 0) return 0; - return KResult(-ENOSPC); + return ENOSPC; } } diff --git a/Kernel/Devices/KeyboardDevice.cpp b/Kernel/Devices/KeyboardDevice.cpp index d6974aaa2789dd..2c244b179427f3 100644 --- a/Kernel/Devices/KeyboardDevice.cpp +++ b/Kernel/Devices/KeyboardDevice.cpp @@ -386,7 +386,7 @@ KResultOr KeyboardDevice::read(FileDescription&, size_t, UserOrKernelBuf return (ssize_t)data_bytes; }); if (n < 0) - return KResult(n); + return KResult((ErrnoCode)-n); ASSERT((size_t)n == sizeof(Event)); nread += sizeof(Event); diff --git a/Kernel/Devices/MBVGADevice.cpp b/Kernel/Devices/MBVGADevice.cpp index 3ae439a6890617..38ee00f0473844 100644 --- a/Kernel/Devices/MBVGADevice.cpp +++ b/Kernel/Devices/MBVGADevice.cpp @@ -55,12 +55,12 @@ KResultOr MBVGADevice::mmap(Process& process, FileDescription&, Virtual { REQUIRE_PROMISE(video); if (!shared) - return KResult(-ENODEV); + return ENODEV; ASSERT(offset == 0); ASSERT(size == framebuffer_size_in_bytes()); auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes()); if (!vmobject) - return KResult(-ENOMEM); + return ENOMEM; return process.allocate_region_with_vmobject( preferred_vaddr, framebuffer_size_in_bytes(), diff --git a/Kernel/Devices/PS2MouseDevice.cpp b/Kernel/Devices/PS2MouseDevice.cpp index ee53c540a6e152..89d42c39b4cbde 100644 --- a/Kernel/Devices/PS2MouseDevice.cpp +++ b/Kernel/Devices/PS2MouseDevice.cpp @@ -288,7 +288,7 @@ KResultOr PS2MouseDevice::read(FileDescription&, size_t, UserOrKernelBuf #endif size_t bytes_read_from_packet = min(remaining_space_in_buffer, sizeof(MousePacket)); if (!buffer.write(&packet, nread, bytes_read_from_packet)) - return KResult(-EFAULT); + return EFAULT; nread += bytes_read_from_packet; remaining_space_in_buffer -= bytes_read_from_packet; diff --git a/Kernel/Devices/RandomDevice.cpp b/Kernel/Devices/RandomDevice.cpp index fa625d0ecf45b5..728e5456b4aeef 100644 --- a/Kernel/Devices/RandomDevice.cpp +++ b/Kernel/Devices/RandomDevice.cpp @@ -50,7 +50,7 @@ KResultOr RandomDevice::read(FileDescription&, size_t, UserOrKernelBuffe return (ssize_t)data_size; }); if (!success) - return KResult(-EFAULT); + return EFAULT; return size; } diff --git a/Kernel/Devices/SB16.cpp b/Kernel/Devices/SB16.cpp index c0430c725939b6..c9d1abb7c5150b 100644 --- a/Kernel/Devices/SB16.cpp +++ b/Kernel/Devices/SB16.cpp @@ -236,11 +236,11 @@ KResultOr SB16::write(FileDescription&, size_t, const UserOrKernelBuffer if (!m_dma_region) { auto page = MM.allocate_supervisor_physical_page(); if (!page) - return KResult(-ENOMEM); + return ENOMEM; auto vmobject = AnonymousVMObject::create_with_physical_page(*page); m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Region::Access::Write); if (!m_dma_region) - return KResult(-ENOMEM); + return ENOMEM; } #ifdef SB16_DEBUG @@ -249,7 +249,7 @@ KResultOr SB16::write(FileDescription&, size_t, const UserOrKernelBuffer ASSERT(length <= PAGE_SIZE); const int BLOCK_SIZE = 32 * 1024; if (length > BLOCK_SIZE) { - return KResult(-ENOSPC); + return ENOSPC; } u8 mode = (u8)SampleFormat::Signed | (u8)SampleFormat::Stereo; @@ -257,7 +257,7 @@ KResultOr SB16::write(FileDescription&, size_t, const UserOrKernelBuffer const int sample_rate = 44100; set_sample_rate(sample_rate); if (!data.read(m_dma_region->vaddr().as_ptr(), length)) - return KResult(-EFAULT); + return EFAULT; dma_start(length); // 16-bit single-cycle output. diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp index a54a8bed3e2a66..9801c6b83d1670 100644 --- a/Kernel/Devices/SerialDevice.cpp +++ b/Kernel/Devices/SerialDevice.cpp @@ -59,7 +59,7 @@ KResultOr SerialDevice::read(FileDescription&, size_t, UserOrKernelBuffe return (ssize_t)data_size; }); if (nwritten < 0) - return KResult(nwritten); + return KResult((ErrnoCode)-nwritten); return size; } @@ -83,7 +83,7 @@ KResultOr SerialDevice::write(FileDescription&, size_t, const UserOrKern return (ssize_t)data_size; }); if (nread < 0) - return KResult(nread); + return KResult((ErrnoCode)-nread); return (size_t)nread; } diff --git a/Kernel/Devices/ZeroDevice.cpp b/Kernel/Devices/ZeroDevice.cpp index ac326434d0c6a8..f0b0302f6428a7 100644 --- a/Kernel/Devices/ZeroDevice.cpp +++ b/Kernel/Devices/ZeroDevice.cpp @@ -48,7 +48,7 @@ KResultOr ZeroDevice::read(FileDescription&, size_t, UserOrKernelBuffer& { ssize_t count = min(static_cast(PAGE_SIZE), size); if (!buffer.memset(0, count)) - return KResult(-EFAULT); + return EFAULT; return count; } diff --git a/Kernel/FileSystem/AnonymousFile.cpp b/Kernel/FileSystem/AnonymousFile.cpp index 3b2059e633b5c1..a0fa76fd426fb0 100644 --- a/Kernel/FileSystem/AnonymousFile.cpp +++ b/Kernel/FileSystem/AnonymousFile.cpp @@ -42,10 +42,10 @@ AnonymousFile::~AnonymousFile() KResultOr AnonymousFile::mmap(Process& process, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared) { if (offset != 0) - return KResult(-EINVAL); + return EINVAL; if (size != m_vmobject->size()) - return KResult(-EINVAL); + return EINVAL; return process.allocate_region_with_vmobject(preferred_vaddr, size, m_vmobject, offset, {}, prot, shared); } diff --git a/Kernel/FileSystem/AnonymousFile.h b/Kernel/FileSystem/AnonymousFile.h index 66b6c331e528dc..d95fc5fcb006e0 100644 --- a/Kernel/FileSystem/AnonymousFile.h +++ b/Kernel/FileSystem/AnonymousFile.h @@ -46,8 +46,8 @@ class AnonymousFile final : public File { virtual String absolute_path(const FileDescription&) const override { return ":anonymous-file:"; } virtual bool can_read(const FileDescription&, size_t) const override { return false; } virtual bool can_write(const FileDescription&, size_t) const override { return false; } - virtual KResultOr read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override { return KResult(-ENOTSUP); } - virtual KResultOr write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t) override { return KResult(-ENOTSUP); } + virtual KResultOr read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override { return ENOTSUP; } + virtual KResultOr write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t) override { return ENOTSUP; } explicit AnonymousFile(NonnullRefPtr); diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index b4937d92941cf9..7496fc728ee664 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -169,7 +169,7 @@ KResult BlockBasedFS::write_block(unsigned index, const UserOrKernelBuffer& data return result; } if (!data.read(entry.data + offset, count)) - return KResult(-EFAULT); + return EFAULT; cache().mark_dirty(entry); entry.has_data = true; @@ -261,7 +261,7 @@ KResult BlockBasedFS::read_block(unsigned index, UserOrKernelBuffer* buffer, siz entry.has_data = true; } if (buffer && !buffer->write(entry.data + offset, count)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; } @@ -269,7 +269,7 @@ KResult BlockBasedFS::read_blocks(unsigned index, unsigned count, UserOrKernelBu { ASSERT(m_logical_block_size); if (!count) - return KResult(-EINVAL); + return EINVAL; if (count == 1) return read_block(index, &buffer, block_size(), 0, allow_cache); auto out = buffer; diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index 123f5e45c82cec..149a73edb10f2e 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -124,17 +124,17 @@ ssize_t DevFSInode::write_bytes(off_t, ssize_t, const UserOrKernelBuffer&, FileD KResultOr> DevFSInode::create_child(const String&, mode_t, dev_t, uid_t, gid_t) { - return KResult(-EROFS); + return EROFS; } KResult DevFSInode::add_child(Inode&, const StringView&, mode_t) { - return KResult(-EROFS); + return EROFS; } KResult DevFSInode::remove_child(const StringView&) { - return KResult(-EROFS); + return EROFS; } KResultOr DevFSInode::directory_entry_count() const @@ -144,17 +144,17 @@ KResultOr DevFSInode::directory_entry_count() const KResult DevFSInode::chmod(mode_t) { - return KResult(-EPERM); + return EPERM; } KResult DevFSInode::chown(uid_t, gid_t) { - return KResult(-EPERM); + return EPERM; } KResult DevFSInode::truncate(u64) { - return KResult(-EPERM); + return EPERM; } String DevFSLinkInode::name() const @@ -221,7 +221,7 @@ InodeMetadata DevFSDirectoryInode::metadata() const KResult DevFSDirectoryInode::traverse_as_directory(Function) const { LOCKER(m_lock); - return KResult(-EINVAL); + return EINVAL; } RefPtr DevFSDirectoryInode::lookup(StringView) { @@ -288,10 +288,10 @@ KResultOr> DevFSRootDirectoryInode::create_child(const Stri if (metadata.is_directory()) { for (auto& folder : m_subfolders) { if (folder.name() == name) - return KResult(-EEXIST); + return EEXIST; } if (name != "pts") - return KResult(-EROFS); + return EROFS; auto new_directory_inode = adopt(*new DevFSPtsDirectoryInode(m_parent_fs)); m_subfolders.append(new_directory_inode); m_parent_fs.m_nodes.append(new_directory_inode); @@ -300,7 +300,7 @@ KResultOr> DevFSRootDirectoryInode::create_child(const Stri if (metadata.is_symlink()) { for (auto& link : m_links) { if (link.name() == name) - return KResult(-EEXIST); + return EEXIST; } dbgln("DevFS: Success on create new symlink"); auto new_link_inode = adopt(*new DevFSLinkInode(m_parent_fs, name)); @@ -308,7 +308,7 @@ KResultOr> DevFSRootDirectoryInode::create_child(const Stri m_parent_fs.m_nodes.append(new_link_inode); return new_link_inode; } - return KResult(-EROFS); + return EROFS; } DevFSRootDirectoryInode::~DevFSRootDirectoryInode() diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index 3c781e73cd37d0..103e842d1552d1 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -143,7 +143,7 @@ InodeMetadata DevPtsFSInode::metadata() const KResult DevPtsFSInode::traverse_as_directory(Function callback) const { if (identifier().index() > 1) - return KResult(-ENOTDIR); + return ENOTDIR; callback({ ".", identifier(), 0 }); callback({ "..", identifier(), 0 }); @@ -187,27 +187,27 @@ void DevPtsFSInode::flush_metadata() KResult DevPtsFSInode::add_child(Inode&, const StringView&, mode_t) { - return KResult(-EROFS); + return EROFS; } KResultOr> DevPtsFSInode::create_child(const String&, mode_t, dev_t, uid_t, gid_t) { - return KResult(-EROFS); + return EROFS; } KResult DevPtsFSInode::remove_child(const StringView&) { - return KResult(-EROFS); + return EROFS; } KResult DevPtsFSInode::chmod(mode_t) { - return KResult(-EPERM); + return EPERM; } KResult DevPtsFSInode::chown(uid_t, gid_t) { - return KResult(-EPERM); + return EPERM; } } diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index a9b349a8e2bd1d..fac8a5feb7e8af 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -233,7 +233,7 @@ Ext2FS::BlockListShape Ext2FS::compute_block_list_shape(unsigned blocks) const return {}; } -bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2inode, const Vector& blocks) +KResult Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2inode, const Vector& blocks) { LOCKER(m_lock); @@ -241,7 +241,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in e2inode.i_blocks = 0; memset(e2inode.i_block, 0, sizeof(e2inode.i_block)); write_ext2_inode(inode_index, e2inode); - return true; + return KSuccess; } // NOTE: There is a mismatch between i_blocks and blocks.size() since i_blocks includes meta blocks and blocks.size() does not. @@ -279,7 +279,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in } if (!remaining_blocks) - return true; + return KSuccess; const unsigned entries_per_block = EXT2_ADDR_PER_BLOCK(&super_block()); @@ -315,12 +315,13 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in stream.fill_to_end(0); auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data()); - int err = write_block(e2inode.i_block[EXT2_IND_BLOCK], buffer, stream.size()); - ASSERT(err >= 0); + auto result = write_block(e2inode.i_block[EXT2_IND_BLOCK], buffer, stream.size()); + if (result.is_error()) + return result; } if (!remaining_blocks) - return true; + return KSuccess; bool dind_block_dirty = false; @@ -356,9 +357,8 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in auto buffer = UserOrKernelBuffer::for_kernel_buffer(dind_block_contents.data()); auto result = read_block(e2inode.i_block[EXT2_DIND_BLOCK], &buffer, block_size()); if (result.is_error()) { - // FIXME: Propagate the error dbgln("Ext2FS: write_block_list_for_inode had error: {}", result.error()); - return false; + return result; } } auto* dind_block_as_pointers = (unsigned*)dind_block_contents.data(); @@ -384,9 +384,8 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in auto buffer = UserOrKernelBuffer::for_kernel_buffer(ind_block_contents.data()); auto result = read_block(indirect_block_index, &buffer, block_size()); if (result.is_error()) { - // FIXME: Propagate the error dbgln("Ext2FS: write_block_list_for_inode had error: {}", result.error()); - return false; + return result; } } auto* ind_block_as_pointers = (unsigned*)ind_block_contents.data(); @@ -432,7 +431,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in } if (!remaining_blocks) - return true; + return KSuccess; // FIXME: Implement! dbgln("we don't know how to write tind ext2fs blocks yet!"); @@ -799,7 +798,7 @@ KResult Ext2FSInode::resize(u64 new_size) if (blocks_needed_after > blocks_needed_before) { u32 additional_blocks_needed = blocks_needed_after - blocks_needed_before; if (additional_blocks_needed > fs().super_block().s_free_blocks_count) - return KResult(-ENOSPC); + return ENOSPC; } Vector block_list; @@ -825,9 +824,9 @@ KResult Ext2FSInode::resize(u64 new_size) } } - int err = fs().write_block_list_for_inode(index(), m_raw_inode, block_list); - if (err < 0) - return KResult(err); + auto result = fs().write_block_list_for_inode(index(), m_raw_inode, block_list); + if (result.is_error()) + return result; m_raw_inode.i_size = new_size; set_metadata_dirty(true); @@ -844,7 +843,7 @@ KResult Ext2FSInode::resize(u64 new_size) while (bytes_to_clear) { auto nwritten = write_bytes(clear_from, min(sizeof(zero_buffer), bytes_to_clear), UserOrKernelBuffer::for_kernel_buffer(zero_buffer), nullptr); if (nwritten < 0) - return KResult(-nwritten); + return KResult((ErrnoCode)-nwritten); ASSERT(nwritten != 0); bytes_to_clear -= nwritten; clear_from += nwritten; @@ -1056,7 +1055,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode ASSERT(is_directory()); if (name.length() > EXT2_NAME_LEN) - return KResult(-ENAMETOOLONG); + return ENAMETOOLONG; #ifdef EXT2_DEBUG dbgln("Ext2FSInode::add_child: Adding inode {} with name '{}' and mode {:o} to directory {}", child.index(), name, mode, index()); @@ -1078,7 +1077,7 @@ KResult Ext2FSInode::add_child(Inode& child, const StringView& name, mode_t mode if (name_already_exists) { dbgln("Ext2FSInode::add_child: Name '{}' already exists in inode {}", name, index()); - return KResult(-EEXIST); + return EEXIST; } result = child.increment_link_count(); @@ -1104,7 +1103,7 @@ KResult Ext2FSInode::remove_child(const StringView& name) auto it = m_lookup_cache.find(name); if (it == m_lookup_cache.end()) - return KResult(-ENOENT); + return ENOENT; auto child_inode_index = (*it).value; InodeIdentifier child_id { fsid(), child_inode_index }; @@ -1125,7 +1124,7 @@ KResult Ext2FSInode::remove_child(const StringView& name) bool success = write_directory(entries); if (!success) { // FIXME: Plumb error from write_directory(). - return KResult(-EIO); + return EIO; } m_lookup_cache.remove(name); @@ -1487,10 +1486,10 @@ KResultOr> Ext2FS::create_inode(InodeIdentifier parent_id, ASSERT(parent_inode); if (static_cast(*parent_inode).m_raw_inode.i_links_count == 0) - return KResult(-ENOENT); + return ENOENT; if (name.length() > EXT2_NAME_LEN) - return KResult(-ENAMETOOLONG); + return ENAMETOOLONG; #ifdef EXT2_DEBUG dbgln("Ext2FS: Adding inode '{}' (mode {:o}) to parent directory {}", name, mode, parent_inode->index()); @@ -1499,14 +1498,14 @@ KResultOr> Ext2FS::create_inode(InodeIdentifier parent_id, size_t needed_blocks = ceil_div(static_cast(size), block_size()); if ((size_t)needed_blocks > super_block().s_free_blocks_count) { dbgln("Ext2FS: create_inode: not enough free blocks"); - return KResult(-ENOSPC); + return ENOSPC; } // NOTE: This doesn't commit the inode allocation just yet! auto inode_id = find_a_free_inode(0, size); if (!inode_id) { klog() << "Ext2FS: create_inode: allocate_inode failed"; - return KResult(-ENOSPC); + return ENOSPC; } auto blocks = allocate_blocks(group_index_from_inode(inode_id), needed_blocks); @@ -1537,8 +1536,9 @@ KResultOr> Ext2FS::create_inode(InodeIdentifier parent_id, else if (is_block_device(mode)) e2inode.i_block[1] = dev; - success = write_block_list_for_inode(inode_id, e2inode, blocks); - ASSERT(success); + auto result = write_block_list_for_inode(inode_id, e2inode, blocks); + if (result.is_error()) + return result; #ifdef EXT2_DEBUG dbgln("Ext2FS: writing initial metadata for inode {}", inode_id); @@ -1554,8 +1554,9 @@ KResultOr> Ext2FS::create_inode(InodeIdentifier parent_id, // If we've already computed a block list, no sense in throwing it away. static_cast(*inode).m_block_list = move(blocks); - auto result = parent_inode->add_child(*inode, name, mode); - ASSERT(result.is_success()); + result = parent_inode->add_child(*inode, name, mode); + if (result.is_error()) + return result; return inode.release_nonnull(); } @@ -1632,9 +1633,9 @@ KResult Ext2FSInode::increment_link_count() { LOCKER(m_lock); if (fs().is_readonly()) - return KResult(-EROFS); + return EROFS; if (m_raw_inode.i_links_count == max_link_count) - return KResult(-EMLINK); + return EMLINK; ++m_raw_inode.i_links_count; set_metadata_dirty(true); return KSuccess; @@ -1644,7 +1645,7 @@ KResult Ext2FSInode::decrement_link_count() { LOCKER(m_lock); if (fs().is_readonly()) - return KResult(-EROFS); + return EROFS; ASSERT(m_raw_inode.i_links_count); --m_raw_inode.i_links_count; if (ref_count() == 1 && m_raw_inode.i_links_count == 0) @@ -1730,7 +1731,7 @@ KResult Ext2FS::prepare_to_unmount() const for (auto& it : m_inode_cache) { if (it.value->ref_count() > 1) - return KResult(-EBUSY); + return EBUSY; } m_inode_cache.clear(); diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index 575c15bf6ca60e..6302a8690cd891 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -148,7 +148,7 @@ class Ext2FS final : public BlockBasedFS { Vector block_list_for_inode_impl(const ext2_inode&, bool include_block_list_blocks = false) const; Vector block_list_for_inode(const ext2_inode&, bool include_block_list_blocks = false) const; - bool write_block_list_for_inode(InodeIndex, ext2_inode&, const Vector&); + KResult write_block_list_for_inode(InodeIndex, ext2_inode&, const Vector&); bool get_inode_allocation_state(InodeIndex) const; bool set_inode_allocation_state(InodeIndex, bool); diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index 5b20d339fa689d..13148d1f91131b 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -61,7 +61,7 @@ int File::ioctl(FileDescription&, unsigned, FlatPtr) KResultOr File::mmap(Process&, FileDescription&, VirtualAddress, size_t, size_t, int, bool) { - return KResult(-ENODEV); + return ENODEV; } } diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index f00f5b8f3e0d04..b36bde45cd1bbd 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -115,13 +115,13 @@ class File virtual KResultOr write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t) = 0; virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg); virtual KResultOr mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared); - virtual KResult stat(::stat&) const { return KResult(-EBADF); } + virtual KResult stat(::stat&) const { return EBADF; } virtual String absolute_path(const FileDescription&) const = 0; - virtual KResult truncate(u64) { return KResult(-EINVAL); } - virtual KResult chown(FileDescription&, uid_t, gid_t) { return KResult(-EBADF); } - virtual KResult chmod(FileDescription&, mode_t) { return KResult(-EBADF); } + virtual KResult truncate(u64) { return EINVAL; } + virtual KResult chown(FileDescription&, uid_t, gid_t) { return EBADF; } + virtual KResult chmod(FileDescription&, mode_t) { return EBADF; } virtual const char* class_name() const = 0; diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 7923c66f27ac6d..f623508eabdcfb 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -82,7 +82,7 @@ KResultOr> Inode::read_entire(FileDescription* descriptio auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer); nread = read_bytes(offset, sizeof(buffer), buf, description); if (nread < 0) - return KResult(nread); + return KResult((ErrnoCode)-nread); ASSERT(nread <= (ssize_t)sizeof(buffer)); if (nread <= 0) break; @@ -93,12 +93,12 @@ KResultOr> Inode::read_entire(FileDescription* descriptio } if (nread < 0) { klog() << "Inode::read_entire: ERROR: " << nread; - return KResult(nread); + return KResult((ErrnoCode)-nread); } auto entire_file = builder.build(); if (!entire_file) - return KResult(-ENOMEM); + return ENOMEM; return entire_file.release_nonnull(); } @@ -168,12 +168,12 @@ int Inode::set_mtime(time_t) KResult Inode::increment_link_count() { - return KResult(-ENOTIMPL); + return ENOTIMPL; } KResult Inode::decrement_link_count() { - return KResult(-ENOTIMPL); + return ENOTIMPL; } void Inode::set_shared_vmobject(SharedInodeVMObject& vmobject) @@ -271,7 +271,7 @@ KResult Inode::prepare_to_write_data() // We should funnel everything through an interface at the VFS layer so this can happen from a single place. LOCKER(m_lock); if (fs().is_readonly()) - return KResult(-EROFS); + return EROFS; auto metadata = this->metadata(); if (metadata.is_setuid() || metadata.is_setgid()) { dbgln("Inode::prepare_to_write_data(): Stripping SUID/SGID bits from {}", identifier()); diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 58a3f2459e479f..3cade1cf5faa15 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -52,7 +52,7 @@ KResultOr InodeFile::read(FileDescription& description, size_t offset, U evaluate_block_conditions(); } if (nread < 0) - return KResult(nread); + return KResult((ErrnoCode)-nread); return nread; } @@ -65,7 +65,7 @@ KResultOr InodeFile::write(FileDescription& description, size_t offset, evaluate_block_conditions(); } if (nwritten < 0) - return KResult(nwritten); + return KResult((ErrnoCode)-nwritten); return nwritten; } @@ -78,7 +78,7 @@ KResultOr InodeFile::mmap(Process& process, FileDescription& descriptio else vmobject = PrivateInodeVMObject::create_with_inode(inode()); if (!vmobject) - return KResult(-ENOMEM); + return ENOMEM; return process.allocate_region_with_vmobject(preferred_vaddr, size, *vmobject, offset, description.absolute_path(), prot, shared); } @@ -95,8 +95,8 @@ KResult InodeFile::truncate(u64 size) if (truncate_result.is_error()) return truncate_result; int mtime_result = m_inode->set_mtime(kgettimeofday().tv_sec); - if (mtime_result != 0) - return KResult(mtime_result); + if (mtime_result < 0) + return KResult((ErrnoCode)-mtime_result); return KSuccess; } diff --git a/Kernel/FileSystem/InodeMetadata.h b/Kernel/FileSystem/InodeMetadata.h index 44cc8d5504797a..f4fe654626f540 100644 --- a/Kernel/FileSystem/InodeMetadata.h +++ b/Kernel/FileSystem/InodeMetadata.h @@ -106,7 +106,7 @@ struct InodeMetadata { KResult stat(stat& buffer) const { if (!is_valid()) - return KResult(-EIO); + return EIO; buffer.st_rdev = encoded_device(major_device, minor_device); buffer.st_ino = inode.index(); buffer.st_mode = mode; diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index 09580bbaffc3c2..c54b3fef764ab7 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -77,14 +77,14 @@ KResultOr InodeWatcher::read(FileDescription&, size_t, UserOrKernelBuffe return (ssize_t)data_bytes; }); if (nwritten < 0) - return KResult(nwritten); + return KResult((ErrnoCode)-nwritten); evaluate_block_conditions(); return bytes_to_write; } KResultOr InodeWatcher::write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t) { - return KResult(-EIO); + return EIO; } String InodeWatcher::absolute_path(const FileDescription&) const diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index 52051bd2535820..5b6b30bcf8649e 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -532,7 +532,7 @@ KResult Plan9FS::post_message(Message& message, RefPtr comple if (!description.can_write()) { auto unblock_flags = Thread::FileBlocker::BlockFlags::None; if (Thread::current()->block({}, description, unblock_flags).was_interrupted()) - return KResult(-EINTR); + return EINTR; } auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast(data)); auto nwritten_or_error = description.write(data_buffer, size); @@ -553,7 +553,7 @@ KResult Plan9FS::do_read(u8* data, size_t size) if (!description.can_read()) { auto unblock_flags = Thread::FileBlocker::BlockFlags::None; if (Thread::current()->block({}, description, unblock_flags).was_interrupted()) - return KResult(-EINTR); + return EINTR; } auto data_buffer = UserOrKernelBuffer::for_kernel_buffer(data); auto nread_or_error = description.read(data_buffer, size); @@ -561,7 +561,7 @@ KResult Plan9FS::do_read(u8* data, size_t size) return nread_or_error.error(); auto nread = nread_or_error.value(); if (nread == 0) - return KResult(-EIO); + return EIO; data += nread; size -= nread; } @@ -582,7 +582,7 @@ KResult Plan9FS::read_and_dispatch_one_message() auto buffer = KBuffer::try_create_with_size(header.size, Region::Access::Read | Region::Access::Write); if (!buffer) - return KResult(-ENOMEM); + return ENOMEM; // Copy the already read header into the buffer. memcpy(buffer->data(), &header, sizeof(header)); result = do_read(buffer->data() + sizeof(header), header.size - sizeof(header)); @@ -622,11 +622,11 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message) if (result.is_error()) return result; if (Thread::current()->block({}, *this, message, completion).was_interrupted()) - return KResult(-EINTR); + return EINTR; if (completion->result.is_error()) { dbgln("Plan9FS: Message was aborted with error {}", completion->result.error()); - return KResult(-EIO); + return EIO; } auto reply_type = message.type(); @@ -635,7 +635,7 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message) // Contains a numerical Linux errno; hopefully our errno numbers match. u32 error_code; message >> error_code; - return KResult(-error_code); + return KResult((ErrnoCode)error_code); } else if (reply_type == Message::Type::Rerror) { // Contains an error message. We could attempt to parse it, but for now // we simply return -EIO instead. In 9P200.u, it can also contain a @@ -643,12 +643,12 @@ KResult Plan9FS::post_message_and_wait_for_a_reply(Message& message) StringView error_name; message >> error_name; dbgln("Plan9FS: Received error name {}", error_name); - return KResult(-EIO); + return EIO; } else if ((u8)reply_type != (u8)request_type + 1) { // Other than those error messages. we only expect the matching reply // message type. dbgln("Plan9FS: Received unexpected message type {} in response to {}", (u8)reply_type, (u8)request_type); - return KResult(-EIO); + return EIO; } else { return KSuccess; } @@ -944,7 +944,7 @@ KResult Plan9FSInode::traverse_as_directory(Function Plan9FSInode::lookup(StringView name) KResultOr> Plan9FSInode::create_child(const String&, mode_t, dev_t, uid_t, gid_t) { // TODO - return KResult(-ENOTIMPL); + return ENOTIMPL; } KResult Plan9FSInode::add_child(Inode&, const StringView&, mode_t) { // TODO - return KResult(-ENOTIMPL); + return ENOTIMPL; } KResult Plan9FSInode::remove_child(const StringView&) { // TODO - return KResult(-ENOTIMPL); + return ENOTIMPL; } KResult Plan9FSInode::chmod(mode_t) { // TODO - return KResult(-ENOTIMPL); + return ENOTIMPL; } KResult Plan9FSInode::chown(uid_t, gid_t) { // TODO - return KResult(-ENOTIMPL); + return ENOTIMPL; } KResult Plan9FSInode::truncate(u64 new_size) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index f1f877b3cf4f54..36dc4ff1c01ea9 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -1073,14 +1073,14 @@ KResult ProcFSInode::refresh_data(FileDescription& description) const } KBufferBuilder builder(buffer, true); if (!read_callback(identifier(), builder)) - return KResult(-ENOENT); + return ENOENT; // We don't use builder.build() here, which would steal our buffer // and turn it into an OwnPtr. Instead, just flush to the buffer so // that we can read all the data that was written. if (!builder.flush()) - return KResult(-ENOMEM); + return ENOMEM; if (!buffer) - return KResult(-ENOMEM); + return ENOMEM; return KSuccess; } @@ -1220,7 +1220,7 @@ KResult ProcFSInode::traverse_as_directory(Function __FI_PID_Start && entry.proc_file_type < __FI_PID_End) { if (entry.proc_file_type == FI_PID_exe && !process->executable()) @@ -1278,7 +1278,7 @@ KResult ProcFSInode::traverse_as_directory(Functionmax_open_file_descriptors(); ++i) { auto description = process->file_description(i); if (!description) @@ -1293,7 +1293,7 @@ KResult ProcFSInode::traverse_as_directory(Functionfor_each_thread([&](Thread& thread) -> IterationDecision { int tid = thread.tid().value(); char name[16]; @@ -1478,7 +1478,7 @@ KResultOr> ProcFSInode::resolve_as_link(Custody& base, Re auto proc_file_type = to_proc_file_type(identifier()); auto process = Process::from_pid(pid); if (!process) - return KResult(-ENOENT); + return ENOENT; if (to_proc_parent_directory(identifier()) == PDI_PID_fd) { if (out_parent) @@ -1486,7 +1486,7 @@ KResultOr> ProcFSInode::resolve_as_link(Custody& base, Re int fd = to_fd(identifier()); auto description = process->file_description(fd); if (!description) - return KResult(-ENOENT); + return ENOENT; auto proxy_inode = ProcFSProxyInode::create(const_cast(fs()), *description); return Custody::create(&base, "", proxy_inode, base.mount_flags()); } @@ -1511,7 +1511,7 @@ KResultOr> ProcFSInode::resolve_as_link(Custody& base, Re } if (!res) - return KResult(-ENOENT); + return ENOENT; return *res; } @@ -1559,21 +1559,21 @@ InodeMetadata ProcFSProxyInode::metadata() const KResultOr> ProcFSProxyInode::create_child(const String& name, mode_t mode, dev_t dev, uid_t uid, gid_t gid) { if (!m_fd->inode()) - return KResult(-EINVAL); + return EINVAL; return m_fd->inode()->create_child(name, mode, dev, uid, gid); } KResult ProcFSProxyInode::add_child(Inode& child, const StringView& name, mode_t mode) { if (!m_fd->inode()) - return KResult(-EINVAL); + return EINVAL; return m_fd->inode()->add_child(child, name, mode); } KResult ProcFSProxyInode::remove_child(const StringView& name) { if (!m_fd->inode()) - return KResult(-EINVAL); + return EINVAL; return m_fd->inode()->remove_child(name); } @@ -1587,23 +1587,23 @@ RefPtr ProcFSProxyInode::lookup(StringView name) KResultOr ProcFSProxyInode::directory_entry_count() const { if (!m_fd->inode()) - return KResult(-EINVAL); + return EINVAL; return m_fd->inode()->directory_entry_count(); } KResultOr> ProcFSInode::create_child(const String&, mode_t, dev_t, uid_t, gid_t) { - return KResult(-EPERM); + return EPERM; } KResult ProcFSInode::add_child(Inode&, const StringView&, mode_t) { - return KResult(-EPERM); + return EPERM; } KResult ProcFSInode::remove_child([[maybe_unused]] const StringView& name) { - return KResult(-EPERM); + return EPERM; } KResultOr ProcFSInode::directory_entry_count() const @@ -1623,7 +1623,7 @@ KResultOr ProcFSInode::directory_entry_count() const KResult ProcFSInode::chmod(mode_t) { - return KResult(-EPERM); + return EPERM; } ProcFS::ProcFS() @@ -1673,6 +1673,6 @@ ProcFS::ProcFSDirectoryEntry* ProcFS::get_directory_entry(InodeIdentifier identi KResult ProcFSInode::chown(uid_t, gid_t) { - return KResult(-EPERM); + return EPERM; } } diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h index 36554b1de190b0..2ccdb7904aba27 100644 --- a/Kernel/FileSystem/ProcFS.h +++ b/Kernel/FileSystem/ProcFS.h @@ -139,8 +139,8 @@ class ProcFSProxyInode final : public Inode { virtual KResult add_child(Inode&, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; virtual KResultOr directory_entry_count() const override; - virtual KResult chmod(mode_t) override { return KResult(-EINVAL); } - virtual KResult chown(uid_t, gid_t) override { return KResult(-EINVAL); } + virtual KResult chmod(mode_t) override { return EINVAL; } + virtual KResult chown(uid_t, gid_t) override { return EINVAL; } virtual KResultOr> resolve_as_link(Custody&, RefPtr*, int, int) const override { ASSERT_NOT_REACHED(); } virtual FileDescription* preopen_fd() override { return m_fd; } diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index 207c18f65701c8..ac8cef0605ed36 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -134,7 +134,7 @@ KResult TmpFSInode::traverse_as_directory(Function> TmpFSInode::create_child(const String& name, mod // TODO: Support creating devices on TmpFS. if (dev != 0) - return KResult(-ENOTSUP); + return ENOTSUP; struct timeval now; kgettimeofday(now); @@ -305,7 +305,7 @@ KResult TmpFSInode::add_child(Inode& child, const StringView& name, mode_t) ASSERT(child.fsid() == fsid()); if (name.length() > NAME_MAX) - return KResult(-ENAMETOOLONG); + return ENAMETOOLONG; m_children.set(name, { name, static_cast(child) }); did_add_child(child.identifier()); @@ -322,7 +322,7 @@ KResult TmpFSInode::remove_child(const StringView& name) auto it = m_children.find(name); if (it == m_children.end()) - return KResult(-ENOENT); + return ENOENT; auto child_id = it->value.inode->identifier(); m_children.remove(it); did_remove_child(child_id); @@ -339,7 +339,7 @@ KResult TmpFSInode::truncate(u64 size) else if (!m_content) { m_content = KBuffer::try_create_with_size(size); if (!m_content) - return KResult(-ENOMEM); + return ENOMEM; } else if (static_cast(size) < m_content->capacity()) { size_t prev_size = m_metadata.size; m_content->set_size(size); @@ -349,7 +349,7 @@ KResult TmpFSInode::truncate(u64 size) size_t prev_size = m_metadata.size; auto tmp = KBuffer::try_create_with_size(size); if (!tmp) - return KResult(-ENOMEM); + return ENOMEM; memcpy(tmp->data(), m_content->data(), prev_size); m_content = move(tmp); } diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 06726ee936cc6a..ff98c64df8adad 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -107,7 +107,7 @@ KResult VFS::remount(Custody& mount_point, int new_flags) Mount* mount = find_mount_for_guest(mount_point.inode()); if (!mount) - return KResult(-ENODEV); + return ENODEV; mount->set_flags(new_flags); return KSuccess; @@ -133,7 +133,7 @@ KResult VFS::unmount(Inode& guest_inode) } dbg() << "VFS: Nothing mounted on inode " << guest_inode.identifier(); - return KResult(-ENODEV); + return ENODEV; } bool VFS::mount_root(FS& file_system) @@ -230,16 +230,16 @@ KResult VFS::utime(StringView path, Custody& base, time_t atime, time_t mtime) auto& inode = custody.inode(); auto current_process = Process::current(); if (!current_process->is_superuser() && inode.metadata().uid != current_process->euid()) - return KResult(-EACCES); + return EACCES; if (custody.is_readonly()) - return KResult(-EROFS); + return EROFS; int error = inode.set_atime(atime); - if (error) - return KResult(error); + if (error < 0) + return KResult((ErrnoCode)-error); error = inode.set_mtime(mtime); - if (error) - return KResult(error); + if (error < 0) + return KResult((ErrnoCode)-error); return KSuccess; } @@ -254,20 +254,20 @@ KResultOr VFS::lookup_metadata(StringView path, Custody& base, in KResultOr> VFS::open(StringView path, int options, mode_t mode, Custody& base, Optional owner) { if ((options & O_CREAT) && (options & O_DIRECTORY)) - return KResult(-EINVAL); + return EINVAL; RefPtr parent_custody; auto custody_or_error = resolve_path(path, base, &parent_custody, options); if (options & O_CREAT) { if (!parent_custody) - return KResult(-ENOENT); + return ENOENT; if (custody_or_error.is_error()) { if (custody_or_error.error() != -ENOENT) return custody_or_error.error(); return create(path, options, mode, *parent_custody, move(owner)); } if (options & O_EXCL) - return KResult(-EEXIST); + return EEXIST; } if (custody_or_error.is_error()) return custody_or_error.error(); @@ -277,24 +277,24 @@ KResultOr> VFS::open(StringView path, int options auto metadata = inode.metadata(); if ((options & O_DIRECTORY) && !metadata.is_directory()) - return KResult(-ENOTDIR); + return ENOTDIR; bool should_truncate_file = false; auto current_process = Process::current(); if ((options & O_RDONLY) && !metadata.may_read(*current_process)) - return KResult(-EACCES); + return EACCES; if (options & O_WRONLY) { if (!metadata.may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (metadata.is_directory()) - return KResult(-EISDIR); + return EISDIR; should_truncate_file = options & O_TRUNC; } if (options & O_EXEC) { if (!metadata.may_execute(*current_process) || (custody.mount_flags() & MS_NOEXEC)) - return KResult(-EACCES); + return EACCES; } if (auto preopen_fd = inode.preopen_fd()) @@ -321,15 +321,15 @@ KResultOr> VFS::open(StringView path, int options description->set_original_inode({}, inode); return description; } - return KResult(-EINVAL); + return EINVAL; } if (metadata.is_device()) { if (custody.mount_flags() & MS_NODEV) - return KResult(-EACCES); + return EACCES; auto device = Device::get_device(metadata.major_device, metadata.minor_device); if (device == nullptr) { - return KResult(-ENODEV); + return ENODEV; } auto descriptor_or_error = device->open(options); if (descriptor_or_error.is_error()) @@ -341,7 +341,7 @@ KResultOr> VFS::open(StringView path, int options // Check for read-only FS. Do this after handling preopen FD and devices, // but before modifying the inode in any way. if ((options & O_WRONLY) && custody.is_readonly()) - return KResult(-EROFS); + return EROFS; if (should_truncate_file) { KResult result = inode.truncate(0); @@ -360,22 +360,22 @@ KResultOr> VFS::open(StringView path, int options KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base) { if (!is_regular_file(mode) && !is_block_device(mode) && !is_character_device(mode) && !is_fifo(mode) && !is_socket(mode)) - return KResult(-EINVAL); + return EINVAL; RefPtr parent_custody; auto existing_file_or_error = resolve_path(path, base, &parent_custody); if (!existing_file_or_error.is_error()) - return KResult(-EEXIST); + return EEXIST; if (!parent_custody) - return KResult(-ENOENT); + return ENOENT; if (existing_file_or_error.error() != -ENOENT) return existing_file_or_error.error(); auto& parent_inode = parent_custody->inode(); auto current_process = Process::current(); if (!parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (parent_custody->is_readonly()) - return KResult(-EROFS); + return EROFS; LexicalPath p(path); dbgln("VFS::mknod: '{}' mode={} dev={} in {}", p.basename(), mode, dev, parent_inode.identifier()); @@ -396,9 +396,9 @@ KResultOr> VFS::create(StringView path, int optio auto& parent_inode = parent_custody.inode(); auto current_process = Process::current(); if (!parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (parent_custody.is_readonly()) - return KResult(-EROFS); + return EROFS; LexicalPath p(path); #ifdef VFS_DEBUG @@ -431,18 +431,18 @@ KResult VFS::mkdir(StringView path, mode_t mode, Custody& base) RefPtr parent_custody; auto result = resolve_path(path, base, &parent_custody); if (!result.is_error()) - return KResult(-EEXIST); + return EEXIST; if (!parent_custody) - return KResult(-ENOENT); + return ENOENT; if (result.error() != -ENOENT) return result.error(); auto& parent_inode = parent_custody->inode(); auto current_process = Process::current(); if (!parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (parent_custody->is_readonly()) - return KResult(-EROFS); + return EROFS; LexicalPath p(path); #ifdef VFS_DEBUG @@ -462,17 +462,17 @@ KResult VFS::access(StringView path, int mode, Custody& base) auto current_process = Process::current(); if (mode & R_OK) { if (!metadata.may_read(*current_process)) - return KResult(-EACCES); + return EACCES; } if (mode & W_OK) { if (!metadata.may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (custody.is_readonly()) - return KResult(-EROFS); + return EROFS; } if (mode & X_OK) { if (!metadata.may_execute(*current_process)) - return KResult(-EACCES); + return EACCES; } return KSuccess; } @@ -485,9 +485,9 @@ KResultOr> VFS::open_directory(StringView path, Custody& auto& custody = *inode_or_error.value(); auto& inode = custody.inode(); if (!inode.is_directory()) - return KResult(-ENOTDIR); + return ENOTDIR; if (!inode.metadata().may_execute(*Process::current())) - return KResult(-EACCES); + return EACCES; return custody; } @@ -497,9 +497,9 @@ KResult VFS::chmod(Custody& custody, mode_t mode) auto current_process = Process::current(); if (current_process->euid() != inode.metadata().uid && !current_process->is_superuser()) - return KResult(-EPERM); + return EPERM; if (custody.is_readonly()) - return KResult(-EROFS); + return EROFS; // Only change the permission bits. mode = (inode.mode() & ~07777u) | (mode & 07777u); @@ -535,27 +535,27 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) auto& new_parent_inode = new_parent_custody->inode(); if (&old_parent_inode.fs() != &new_parent_inode.fs()) - return KResult(-EXDEV); + return EXDEV; for (auto* new_ancestor = new_parent_custody.ptr(); new_ancestor; new_ancestor = new_ancestor->parent()) { if (&old_inode == &new_ancestor->inode()) - return KResult(-EDIRINTOSELF); + return EDIRINTOSELF; } auto current_process = Process::current(); if (!new_parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (!old_parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (old_parent_inode.metadata().is_sticky()) { if (!current_process->is_superuser() && old_inode.metadata().uid != current_process->euid()) - return KResult(-EACCES); + return EACCES; } if (old_parent_custody->is_readonly() || new_parent_custody->is_readonly()) - return KResult(-EROFS); + return EROFS; auto new_basename = LexicalPath(new_path).basename(); @@ -567,10 +567,10 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base) return KSuccess; if (new_parent_inode.metadata().is_sticky()) { if (!current_process->is_superuser() && new_inode.metadata().uid != current_process->euid()) - return KResult(-EACCES); + return EACCES; } if (new_inode.is_directory() && !old_inode.is_directory()) - return KResult(-EISDIR); + return EISDIR; auto result = new_parent_inode.remove_child(new_basename); if (result.is_error()) return result; @@ -594,24 +594,24 @@ KResult VFS::chown(Custody& custody, uid_t a_uid, gid_t a_gid) auto current_process = Process::current(); if (current_process->euid() != metadata.uid && !current_process->is_superuser()) - return KResult(-EPERM); + return EPERM; uid_t new_uid = metadata.uid; gid_t new_gid = metadata.gid; if (a_uid != (uid_t)-1) { if (current_process->euid() != a_uid && !current_process->is_superuser()) - return KResult(-EPERM); + return EPERM; new_uid = a_uid; } if (a_gid != (gid_t)-1) { if (!current_process->in_group(a_gid) && !current_process->is_superuser()) - return KResult(-EPERM); + return EPERM; new_gid = a_gid; } if (custody.is_readonly()) - return KResult(-EROFS); + return EROFS; dbgln("VFS::chown(): inode {} <- uid={} gid={}", inode.identifier(), new_uid, new_gid); @@ -662,27 +662,27 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base) RefPtr parent_custody; auto new_custody_or_error = resolve_path(new_path, base, &parent_custody); if (!new_custody_or_error.is_error()) - return KResult(-EEXIST); + return EEXIST; if (!parent_custody) - return KResult(-ENOENT); + return ENOENT; auto& parent_inode = parent_custody->inode(); if (parent_inode.fsid() != old_inode.fsid()) - return KResult(-EXDEV); + return EXDEV; if (!parent_inode.metadata().may_write(*Process::current())) - return KResult(-EACCES); + return EACCES; if (old_inode.is_directory()) - return KResult(-EPERM); + return EPERM; if (parent_custody->is_readonly()) - return KResult(-EROFS); + return EROFS; if (!hard_link_allowed(old_inode)) - return KResult(-EPERM); + return EPERM; return parent_inode.add_child(old_inode, LexicalPath(new_path).basename(), old_inode.mode()); } @@ -697,7 +697,7 @@ KResult VFS::unlink(StringView path, Custody& base) auto& inode = custody.inode(); if (inode.is_directory()) - return KResult(-EISDIR); + return EISDIR; // We have just checked that the inode is not a directory, and thus it's not // the root. So it should have a parent. Note that this would be invalidated @@ -707,15 +707,15 @@ KResult VFS::unlink(StringView path, Custody& base) auto& parent_inode = parent_custody->inode(); auto current_process = Process::current(); if (!parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (parent_inode.metadata().is_sticky()) { if (!current_process->is_superuser() && inode.metadata().uid != current_process->euid()) - return KResult(-EACCES); + return EACCES; } if (parent_custody->is_readonly()) - return KResult(-EROFS); + return EROFS; auto result = parent_inode.remove_child(LexicalPath(path).basename()); if (result.is_error()) @@ -729,17 +729,17 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base) RefPtr parent_custody; auto existing_custody_or_error = resolve_path(linkpath, base, &parent_custody); if (!existing_custody_or_error.is_error()) - return KResult(-EEXIST); + return EEXIST; if (!parent_custody) - return KResult(-ENOENT); + return ENOENT; if (existing_custody_or_error.error() != -ENOENT) return existing_custody_or_error.error(); auto& parent_inode = parent_custody->inode(); auto current_process = Process::current(); if (!parent_inode.metadata().may_write(*current_process)) - return KResult(-EACCES); + return EACCES; if (parent_custody->is_readonly()) - return KResult(-EROFS); + return EROFS; LexicalPath p(linkpath); dbgln("VFS::symlink: '{}' (-> '{}') in {}", p.basename(), target, parent_inode.identifier()); @@ -750,7 +750,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base) auto target_buffer = UserOrKernelBuffer::for_kernel_buffer(const_cast((const u8*)target.characters_without_null_termination())); ssize_t nwritten = inode->write_bytes(0, target.length(), target_buffer, nullptr); if (nwritten < 0) - return KResult(nwritten); + return KResult((ErrnoCode)-nwritten); return KSuccess; } @@ -768,20 +768,20 @@ KResult VFS::rmdir(StringView path, Custody& base) // FIXME: We should return ENOTEMPTY if the last component of the path is ".." if (!inode.is_directory()) - return KResult(-ENOTDIR); + return ENOTDIR; if (!parent_custody) - return KResult(-EBUSY); + return EBUSY; auto& parent_inode = parent_custody->inode(); auto parent_metadata = parent_inode.metadata(); if (!parent_metadata.may_write(*Process::current())) - return KResult(-EACCES); + return EACCES; if (parent_metadata.is_sticky()) { if (!Process::current()->is_superuser() && inode.metadata().uid != Process::current()->euid()) - return KResult(-EACCES); + return EACCES; } KResultOr dir_count_result = inode.directory_entry_count(); @@ -789,10 +789,10 @@ KResult VFS::rmdir(StringView path, Custody& base) return dir_count_result.result(); if (dir_count_result.value() != 2) - return KResult(-ENOTEMPTY); + return ENOTEMPTY; if (custody.is_readonly()) - return KResult(-EROFS); + return EROFS; auto result = inode.remove_child("."); if (result.is_error()) @@ -882,27 +882,27 @@ KResult VFS::validate_path_against_process_veil(StringView path, int options) // FIXME: Figure out a nicer way to do this. if (String(path).contains("/..")) - return KResult(-EINVAL); + return EINVAL; auto* unveiled_path = find_matching_unveiled_path(path); if (!unveiled_path) { dbgln("Rejecting path '{}' since it hasn't been unveiled.", path); dump_backtrace(); - return KResult(-ENOENT); + return ENOENT; } if (options & O_CREAT) { if (!(unveiled_path->permissions() & UnveilAccess::CreateOrRemove)) { dbgln("Rejecting path '{}' since it hasn't been unveiled with 'c' permission.", path); dump_backtrace(); - return KResult(-EACCES); + return EACCES; } } if (options & O_UNLINK_INTERNAL) { if (!(unveiled_path->permissions() & UnveilAccess::CreateOrRemove)) { dbgln("Rejecting path '{}' for unlink since it hasn't been unveiled with 'c' permission.", path); dump_backtrace(); - return KResult(-EACCES); + return EACCES; } return KSuccess; } @@ -911,13 +911,13 @@ KResult VFS::validate_path_against_process_veil(StringView path, int options) if (!(unveiled_path->permissions() & (UnveilAccess::Read | UnveilAccess::Browse))) { dbgln("Rejecting path '{}' since it hasn't been unveiled with 'r' or 'b' permissions.", path); dump_backtrace(); - return KResult(-EACCES); + return EACCES; } } else { if (!(unveiled_path->permissions() & UnveilAccess::Read)) { dbgln("Rejecting path '{}' since it hasn't been unveiled with 'r' permission.", path); dump_backtrace(); - return KResult(-EACCES); + return EACCES; } } } @@ -925,14 +925,14 @@ KResult VFS::validate_path_against_process_veil(StringView path, int options) if (!(unveiled_path->permissions() & UnveilAccess::Write)) { dbgln("Rejecting path '{}' since it hasn't been unveiled with 'w' permission.", path); dump_backtrace(); - return KResult(-EACCES); + return EACCES; } } if (options & O_EXEC) { if (!(unveiled_path->permissions() & UnveilAccess::Execute)) { dbgln("Rejecting path '{}' since it hasn't been unveiled with 'x' permission.", path); dump_backtrace(); - return KResult(-EACCES); + return EACCES; } } return KSuccess; @@ -970,10 +970,10 @@ static bool safe_to_follow_symlink(const Inode& inode, const InodeMetadata& pare KResultOr> VFS::resolve_path_without_veil(StringView path, Custody& base, RefPtr* out_parent, int options, int symlink_recursion_level) { if (symlink_recursion_level >= symlink_recursion_limit) - return KResult(-ELOOP); + return ELOOP; if (path.is_empty()) - return KResult(-EINVAL); + return EINVAL; auto parts = path.split_view('/', true); auto current_process = Process::current(); @@ -985,10 +985,10 @@ KResultOr> VFS::resolve_path_without_veil(StringView path Custody& parent = custody; auto parent_metadata = parent.inode().metadata(); if (!parent_metadata.is_directory()) - return KResult(-ENOTDIR); + return ENOTDIR; // Ensure the current user is allowed to resolve paths inside this directory. if (!parent_metadata.may_execute(*current_process)) - return KResult(-EACCES); + return EACCES; auto& part = parts[i]; bool have_more_parts = i + 1 < parts.size(); @@ -1011,7 +1011,7 @@ KResultOr> VFS::resolve_path_without_veil(StringView path // does not exist yet. *out_parent = have_more_parts ? nullptr : &parent; } - return KResult(-ENOENT); + return ENOENT; } int mount_flags_for_child = parent.mount_flags(); @@ -1028,13 +1028,13 @@ KResultOr> VFS::resolve_path_without_veil(StringView path if (child_inode->metadata().is_symlink()) { if (!have_more_parts) { if (options & O_NOFOLLOW) - return KResult(-ELOOP); + return ELOOP; if (options & O_NOFOLLOW_NOERROR) break; } if (!safe_to_follow_symlink(*child_inode, parent_metadata)) - return KResult(-EACCES); + return EACCES; auto symlink_target = child_inode->resolve_as_link(parent, out_parent, options, symlink_recursion_level + 1); if (symlink_target.is_error() || !have_more_parts) diff --git a/Kernel/KResult.h b/Kernel/KResult.h index 2629b25551388e..48e348b9fa61ab 100644 --- a/Kernel/KResult.h +++ b/Kernel/KResult.h @@ -27,6 +27,8 @@ #pragma once #include +#include +#include #include namespace Kernel { @@ -37,10 +39,9 @@ enum KSuccessTag { class [[nodiscard]] KResult { public: - ALWAYS_INLINE explicit KResult(int negative_e) - : m_error(negative_e) + KResult(ErrnoCode error) + : m_error(-error) { - ASSERT(negative_e <= 0); } KResult(KSuccessTag) : m_error(0) @@ -69,6 +70,12 @@ class alignas(T) [[nodiscard]] KResultOr { { } + KResultOr(ErrnoCode error) + : m_error(error) + , m_is_error(true) + { + } + ALWAYS_INLINE KResultOr(T&& value) { new (&m_storage) T(move(value)); diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index bcc1272897c93a..8700fc3ac73967 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -61,7 +61,7 @@ KResultOr> IPv4Socket::create(int type, int protocol) return UDPSocket::create(protocol); if (type == SOCK_RAW) return adopt(*new IPv4Socket(type, protocol)); - return KResult(-EINVAL); + return EINVAL; } IPv4Socket::IPv4Socket(int type, int protocol) @@ -102,20 +102,20 @@ KResult IPv4Socket::bind(Userspace user_address, socklen_t addr { ASSERT(setup_state() == SetupState::Unstarted); if (address_size != sizeof(sockaddr_in)) - return KResult(-EINVAL); + return EINVAL; sockaddr_in address; if (!copy_from_user(&address, user_address, sizeof(sockaddr_in))) - return KResult(-EFAULT); + return EFAULT; if (address.sin_family != AF_INET) - return KResult(-EINVAL); + return EINVAL; auto requested_local_port = ntohs(address.sin_port); if (!Process::current()->is_superuser()) { if (requested_local_port < 1024) { dbgln("UID {} attempted to bind {} to port {}", Process::current()->uid(), class_name(), requested_local_port); - return KResult(-EACCES); + return EACCES; } } @@ -134,7 +134,7 @@ KResult IPv4Socket::listen(size_t backlog) LOCKER(lock()); int rc = allocate_local_port_if_needed(); if (rc < 0) - return KResult(-EADDRINUSE); + return EADDRINUSE; set_backlog(backlog); m_role = Role::Listener; @@ -150,19 +150,19 @@ KResult IPv4Socket::listen(size_t backlog) KResult IPv4Socket::connect(FileDescription& description, Userspace address, socklen_t address_size, ShouldBlock should_block) { if (address_size != sizeof(sockaddr_in)) - return KResult(-EINVAL); + return EINVAL; u16 sa_family_copy; auto* user_address = reinterpret_cast(address.unsafe_userspace_ptr()); if (!copy_from_user(&sa_family_copy, &user_address->sa_family, sizeof(u16))) - return KResult(-EFAULT); + return EFAULT; if (sa_family_copy != AF_INET) - return KResult(-EINVAL); + return EINVAL; if (m_role == Role::Connected) - return KResult(-EISCONN); + return EISCONN; sockaddr_in safe_address; if (!copy_from_user(&safe_address, (const sockaddr_in*)user_address, sizeof(sockaddr_in))) - return KResult(-EFAULT); + return EFAULT; m_peer_address = IPv4Address((const u8*)&safe_address.sin_addr.s_addr); m_peer_port = ntohs(safe_address.sin_port); @@ -200,16 +200,16 @@ KResultOr IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& LOCKER(lock()); if (addr && addr_length != sizeof(sockaddr_in)) - return KResult(-EINVAL); + return EINVAL; if (addr) { sockaddr_in ia; if (!copy_from_user(&ia, Userspace(addr.ptr()))) - return KResult(-EFAULT); + return EFAULT; if (ia.sin_family != AF_INET) { klog() << "sendto: Bad address family: " << ia.sin_family << " is not AF_INET!"; - return KResult(-EAFNOSUPPORT); + return EAFNOSUPPORT; } m_peer_address = IPv4Address((const u8*)&ia.sin_addr.s_addr); @@ -218,7 +218,7 @@ KResultOr IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& auto routing_decision = route_to(m_peer_address, m_local_address, bound_interface()); if (routing_decision.is_zero()) - return KResult(-EHOSTUNREACH); + return EHOSTUNREACH; if (m_local_address.to_u32() == 0) m_local_address = routing_decision.adapter->ipv4_address(); @@ -234,7 +234,7 @@ KResultOr IPv4Socket::sendto(FileDescription&, const UserOrKernelBuffer& if (type() == SOCK_RAW) { int err = routing_decision.adapter->send_ipv4(routing_decision.next_hop, m_peer_address, (IPv4Protocol)protocol(), data, data_length, m_ttl); if (err < 0) - return KResult(err); + return KResult((ErrnoCode)-err); return data_length; } @@ -251,7 +251,7 @@ KResultOr IPv4Socket::receive_byte_buffered(FileDescription& description if (protocol_is_disconnected()) return 0; if (!description.is_blocking()) - return KResult(-EAGAIN); + return EAGAIN; locker.unlock(); auto unblocked_flags = Thread::FileDescriptionBlocker::BlockFlags::None; @@ -260,10 +260,10 @@ KResultOr IPv4Socket::receive_byte_buffered(FileDescription& description if (!((u32)unblocked_flags & (u32)Thread::FileDescriptionBlocker::BlockFlags::Read)) { if (res.was_interrupted()) - return KResult(-EINTR); + return EINTR; // Unblocked due to timeout. - return KResult(-EAGAIN); + return EAGAIN; } } @@ -287,7 +287,7 @@ KResultOr IPv4Socket::receive_packet_buffered(FileDescription& descripti if (protocol_is_disconnected()) return 0; if (!description.is_blocking()) - return KResult(-EAGAIN); + return EAGAIN; } if (!m_receive_queue.is_empty()) { @@ -311,10 +311,10 @@ KResultOr IPv4Socket::receive_packet_buffered(FileDescription& descripti if (!((u32)unblocked_flags & (u32)Thread::FileDescriptionBlocker::BlockFlags::Read)) { if (res.was_interrupted()) - return KResult(-EINTR); + return EINTR; // Unblocked due to timeout. - return KResult(-EAGAIN); + return EAGAIN; } ASSERT(m_can_read); ASSERT(!m_receive_queue.is_empty()); @@ -339,18 +339,18 @@ KResultOr IPv4Socket::receive_packet_buffered(FileDescription& descripti out_addr.sin_family = AF_INET; Userspace dest_addr = addr.ptr(); if (!copy_to_user(dest_addr, &out_addr)) - return KResult(-EFAULT); + return EFAULT; socklen_t out_length = sizeof(sockaddr_in); ASSERT(addr_length); if (!copy_to_user(addr_length, &out_length)) - return KResult(-EFAULT); + return EFAULT; } if (type() == SOCK_RAW) { size_t bytes_written = min(packet.data.value().size(), buffer_length); if (!buffer.write(packet.data.value().data(), bytes_written)) - return KResult(-EFAULT); + return EFAULT; return bytes_written; } @@ -362,9 +362,9 @@ KResultOr IPv4Socket::recvfrom(FileDescription& description, UserOrKerne if (user_addr_length) { socklen_t addr_length; if (!copy_from_user(&addr_length, user_addr_length.unsafe_userspace_ptr())) - return KResult(-EFAULT); + return EFAULT; if (addr_length < sizeof(sockaddr_in)) - return KResult(-EINVAL); + return EINVAL; } #ifdef IPV4_SOCKET_DEBUG @@ -464,17 +464,17 @@ KResult IPv4Socket::setsockopt(int level, int option, Userspace use switch (option) { case IP_TTL: { if (user_value_size < sizeof(int)) - return KResult(-EINVAL); + return EINVAL; int value; if (!copy_from_user(&value, static_ptr_cast(user_value))) - return KResult(-EFAULT); + return EFAULT; if (value < 0 || value > 255) - return KResult(-EINVAL); + return EINVAL; m_ttl = value; return KSuccess; } default: - return KResult(-ENOPROTOOPT); + return ENOPROTOOPT; } } @@ -485,20 +485,20 @@ KResult IPv4Socket::getsockopt(FileDescription& description, int level, int opti socklen_t size; if (!copy_from_user(&size, value_size.unsafe_userspace_ptr())) - return KResult(-EFAULT); + return EFAULT; switch (option) { case IP_TTL: if (size < sizeof(int)) - return KResult(-EINVAL); + return EINVAL; if (!copy_to_user(static_ptr_cast(value), (int*)&m_ttl)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(int); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; default: - return KResult(-ENOPROTOOPT); + return ENOPROTOOPT; } } diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 3ffc3708771821..6f50ebe4ae3840 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -102,14 +102,14 @@ KResult LocalSocket::bind(Userspace user_address, socklen_t add { ASSERT(setup_state() == SetupState::Unstarted); if (address_size != sizeof(sockaddr_un)) - return KResult(-EINVAL); + return EINVAL; sockaddr_un address; if (!copy_from_user(&address, user_address, sizeof(sockaddr_un))) - return KResult(-EFAULT); + return EFAULT; if (address.sun_family != AF_LOCAL) - return KResult(-EINVAL); + return EINVAL; auto path = String(address.sun_path, strnlen(address.sun_path, sizeof(address.sun_path))); @@ -122,7 +122,7 @@ KResult LocalSocket::bind(Userspace user_address, socklen_t add auto result = VFS::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current()->current_directory(), owner); if (result.is_error()) { if (result.error() == -EEXIST) - return KResult(-EADDRINUSE); + return EADDRINUSE; return result.error(); } @@ -130,7 +130,7 @@ KResult LocalSocket::bind(Userspace user_address, socklen_t add ASSERT(file->inode()); if (!file->inode()->bind_socket(*this)) - return KResult(-EADDRINUSE); + return EADDRINUSE; m_file = move(file); @@ -143,20 +143,20 @@ KResult LocalSocket::connect(FileDescription& description, Userspace(address.unsafe_userspace_ptr()); if (!copy_from_user(&sa_family_copy, &user_address->sa_family, sizeof(u16))) - return KResult(-EFAULT); + return EFAULT; if (sa_family_copy != AF_LOCAL) - return KResult(-EINVAL); + return EINVAL; if (is_connected()) - return KResult(-EISCONN); + return EISCONN; const auto& local_address = *reinterpret_cast(user_address); char safe_address[sizeof(local_address.sun_path) + 1] = { 0 }; if (!copy_from_user(&safe_address[0], &local_address.sun_path[0], sizeof(safe_address) - 1)) - return KResult(-EFAULT); + return EFAULT; safe_address[sizeof(safe_address) - 1] = '\0'; #ifdef DEBUG_LOCAL_SOCKET @@ -165,13 +165,13 @@ KResult LocalSocket::connect(FileDescription& description, Userspacecurrent_directory()); if (description_or_error.is_error()) - return KResult(-ECONNREFUSED); + return ECONNREFUSED; m_file = move(description_or_error.value()); ASSERT(m_file->inode()); if (!m_file->inode()->socket()) - return KResult(-ECONNREFUSED); + return ECONNREFUSED; m_address.sun_family = sa_family_copy; memcpy(m_address.sun_path, safe_address, sizeof(m_address.sun_path)); @@ -194,7 +194,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspaceblock({}, description, unblock_flags).was_interrupted()) { set_connect_side_role(Role::None); - return KResult(-EINTR); + return EINTR; } #ifdef DEBUG_LOCAL_SOCKET @@ -203,7 +203,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace LocalSocket::sendto(FileDescription& description, const UserOrKernelBuffer& data, size_t data_size, int, Userspace, socklen_t) { if (!has_attached_peer(description)) - return KResult(-EPIPE); + return EPIPE; auto* socket_buffer = send_buffer_for(description); if (!socket_buffer) - return KResult(-EINVAL); + return EINVAL; ssize_t nwritten = socket_buffer->write(data, data_size); if (nwritten > 0) Thread::current()->did_unix_socket_write(nwritten); @@ -320,17 +320,17 @@ KResultOr LocalSocket::recvfrom(FileDescription& description, UserOrKern { auto* socket_buffer = receive_buffer_for(description); if (!socket_buffer) - return KResult(-EINVAL); + return EINVAL; if (!description.is_blocking()) { if (socket_buffer->is_empty()) { if (!has_attached_peer(description)) return 0; - return KResult(-EAGAIN); + return EAGAIN; } } else if (!can_read(description, 0)) { auto unblock_flags = Thread::FileDescriptionBlocker::BlockFlags::None; if (Thread::current()->block({}, description, unblock_flags).was_interrupted()) - return KResult(-EINTR); + return EINTR; } if (!has_attached_peer(description) && socket_buffer->is_empty()) return 0; @@ -380,31 +380,31 @@ KResult LocalSocket::getsockopt(FileDescription& description, int level, int opt socklen_t size; if (!copy_from_user(&size, value_size.unsafe_userspace_ptr())) - return KResult(-EFAULT); + return EFAULT; switch (option) { case SO_PEERCRED: { if (size < sizeof(ucred)) - return KResult(-EINVAL); + return EINVAL; switch (role(description)) { case Role::Accepted: if (!copy_to_user(static_ptr_cast(value), &m_origin)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(ucred); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; case Role::Connected: if (!copy_to_user(static_ptr_cast(value), &m_acceptor)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(ucred); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; case Role::Connecting: - return KResult(-ENOTCONN); + return ENOTCONN; default: - return KResult(-EINVAL); + return EINVAL; } break; } @@ -429,7 +429,7 @@ KResult LocalSocket::chown(FileDescription&, uid_t uid, gid_t gid) auto current_process = Process::current(); if (!current_process->is_superuser() && (current_process->euid() != uid || !current_process->in_group(gid))) - return KResult(-EPERM); + return EPERM; m_prebind_uid = uid; m_prebind_gid = gid; @@ -461,11 +461,11 @@ KResult LocalSocket::sendfd(const FileDescription& socket_description, FileDescr LOCKER(lock()); auto role = this->role(socket_description); if (role != Role::Connected && role != Role::Accepted) - return KResult(-EINVAL); + return EINVAL; auto& queue = sendfd_queue_for(socket_description); // FIXME: Figure out how we should limit this properly. if (queue.size() > 16) - return KResult(-EBUSY); + return EBUSY; queue.append(move(passing_description)); return KSuccess; } @@ -475,11 +475,11 @@ KResultOr> LocalSocket::recvfd(const FileDescript LOCKER(lock()); auto role = this->role(socket_description); if (role != Role::Connected && role != Role::Accepted) - return KResult(-EINVAL); + return EINVAL; auto& queue = recvfd_queue_for(socket_description); if (queue.is_empty()) { // FIXME: Figure out the perfect error code for this. - return KResult(-EAGAIN); + return EAGAIN; } return queue.take_first(); } diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index bc86bb0afd7da5..f17934e656cc73 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -46,7 +46,7 @@ KResultOr> Socket::create(int domain, int type, int protoc case AF_INET: return IPv4Socket::create(type & SOCK_TYPE_MASK, protocol); default: - return KResult(-EAFNOSUPPORT); + return EAFNOSUPPORT; } } @@ -99,7 +99,7 @@ KResult Socket::queue_connection_from(NonnullRefPtr peer) #endif LOCKER(m_lock); if (m_pending.size() >= m_backlog) - return KResult(-ECONNREFUSED); + return ECONNREFUSED; m_pending.append(peer); evaluate_block_conditions(); return KSuccess; @@ -111,26 +111,26 @@ KResult Socket::setsockopt(int level, int option, Userspace user_va switch (option) { case SO_SNDTIMEO: if (user_value_size != sizeof(timeval)) - return KResult(-EINVAL); + return EINVAL; if (!copy_from_user(&m_send_timeout, static_ptr_cast(user_value))) - return KResult(-EFAULT); + return EFAULT; return KSuccess; case SO_RCVTIMEO: if (user_value_size != sizeof(timeval)) - return KResult(-EINVAL); + return EINVAL; if (!copy_from_user(&m_receive_timeout, static_ptr_cast(user_value))) - return KResult(-EFAULT); + return EFAULT; return KSuccess; case SO_BINDTODEVICE: { if (user_value_size != IFNAMSIZ) - return KResult(-EINVAL); + return EINVAL; auto user_string = static_ptr_cast(user_value); auto ifname = copy_string_from_user(user_string, user_value_size); if (ifname.is_null()) - return KResult(-EFAULT); + return EFAULT; auto device = NetworkAdapter::lookup_by_name(ifname); if (!device) - return KResult(-ENODEV); + return ENODEV; m_bound_interface = device; return KSuccess; } @@ -139,18 +139,18 @@ KResult Socket::setsockopt(int level, int option, Userspace user_va return KSuccess; case SO_TIMESTAMP: if (user_value_size != sizeof(int)) - return KResult(-EINVAL); + return EINVAL; if (!copy_from_user(&m_timestamp, static_ptr_cast(user_value))) - return KResult(-EFAULT); + return EFAULT; if (m_timestamp && (domain() != AF_INET || type() == SOCK_STREAM)) { // FIXME: Support SO_TIMESTAMP for more protocols? m_timestamp = 0; - return KResult(-ENOTSUP); + return ENOTSUP; } return KSuccess; default: dbgln("setsockopt({}) at SOL_SOCKET not implemented.", option); - return KResult(-ENOPROTOOPT); + return ENOPROTOOPT; } } @@ -158,76 +158,76 @@ KResult Socket::getsockopt(FileDescription&, int level, int option, Userspace(value), &m_send_timeout)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(timeval); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; case SO_RCVTIMEO: if (size < sizeof(timeval)) - return KResult(-EINVAL); + return EINVAL; if (!copy_to_user(static_ptr_cast(value), &m_receive_timeout)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(timeval); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; case SO_ERROR: { if (size < sizeof(int)) - return KResult(-EINVAL); + return EINVAL; dbgln("getsockopt(SO_ERROR): FIXME!"); int errno = 0; if (!copy_to_user(static_ptr_cast(value), &errno)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(int); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; } case SO_BINDTODEVICE: if (size < IFNAMSIZ) - return KResult(-EINVAL); + return EINVAL; if (m_bound_interface) { const auto& name = m_bound_interface->name(); auto length = name.length() + 1; if (!copy_to_user(static_ptr_cast(value), name.characters(), length)) - return KResult(-EFAULT); + return EFAULT; size = length; if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; } else { size = 0; if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; - return KResult(-EFAULT); + return EFAULT; } case SO_TIMESTAMP: if (size < sizeof(int)) - return KResult(-EINVAL); + return EINVAL; if (!copy_to_user(static_ptr_cast(value), &m_timestamp)) - return KResult(-EFAULT); + return EFAULT; size = sizeof(int); if (!copy_to_user(value_size, &size)) - return KResult(-EFAULT); + return EFAULT; return KSuccess; default: dbgln("setsockopt({}) at SOL_SOCKET not implemented.", option); - return KResult(-ENOPROTOOPT); + return ENOPROTOOPT; } } @@ -250,9 +250,9 @@ KResult Socket::shutdown(int how) { LOCKER(lock()); if (type() == SOCK_STREAM && !is_connected()) - return KResult(-ENOTCONN); + return ENOTCONN; if (m_role == Role::Listener) - return KResult(-ENOTCONN); + return ENOTCONN; if (!m_shut_down_for_writing && (how & SHUT_WR)) shut_down_for_writing(); if (!m_shut_down_for_reading && (how & SHUT_RD)) diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index 638602b8e67471..08bda1251fb202 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -177,7 +177,7 @@ KResultOr TCPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, Use #endif ASSERT(buffer_size >= payload_size); if (!buffer.write(tcp_packet.payload(), payload_size)) - return KResult(-EFAULT); + return EFAULT; return payload_size; } @@ -185,7 +185,7 @@ KResultOr TCPSocket::protocol_send(const UserOrKernelBuffer& data, size_ { int err = send_tcp_packet(TCPFlags::PUSH | TCPFlags::ACK, &data, data_length); if (err < 0) - return KResult(err); + return KResult((ErrnoCode)-err); return data_length; } @@ -354,7 +354,7 @@ KResult TCPSocket::protocol_bind() if (has_specific_local_address() && !m_adapter) { m_adapter = NetworkAdapter::from_ipv4_address(local_address()); if (!m_adapter) - return KResult(-EADDRNOTAVAIL); + return EADDRNOTAVAIL; } return KSuccess; @@ -364,7 +364,7 @@ KResult TCPSocket::protocol_listen() { LOCKER(sockets_by_tuple().lock()); if (sockets_by_tuple().resource().contains(tuple())) - return KResult(-EADDRINUSE); + return EADDRINUSE; sockets_by_tuple().resource().set(tuple(), this); set_direction(Direction::Passive); set_state(State::Listen); @@ -378,7 +378,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh auto routing_decision = route_to(peer_address(), local_address()); if (routing_decision.is_zero()) - return KResult(-EHOSTUNREACH); + return EHOSTUNREACH; if (!has_specific_local_address()) set_local_address(routing_decision.adapter->ipv4_address()); @@ -390,7 +390,7 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh set_setup_state(SetupState::InProgress); int err = send_tcp_packet(TCPFlags::SYN); if (err < 0) - return KResult(err); + return KResult((ErrnoCode)-err); m_state = State::SynSent; m_role = Role::Connecting; m_direction = Direction::Outgoing; @@ -401,17 +401,17 @@ KResult TCPSocket::protocol_connect(FileDescription& description, ShouldBlock sh locker.unlock(); auto unblock_flags = Thread::FileBlocker::BlockFlags::None; if (Thread::current()->block({}, description, unblock_flags).was_interrupted()) - return KResult(-EINTR); + return EINTR; locker.lock(); ASSERT(setup_state() == SetupState::Completed); if (has_error()) { // TODO: check unblock_flags m_role = Role::None; - return KResult(-ECONNREFUSED); + return ECONNREFUSED; } return KSuccess; } - return KResult(-EINPROGRESS); + return EINPROGRESS; } int TCPSocket::protocol_allocate_local_port() diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index 01242faa2b3906..a96808c39aa5d8 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -86,7 +86,7 @@ KResultOr UDPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, Use ASSERT(udp_packet.length() >= sizeof(UDPPacket)); // FIXME: This should be rejected earlier. ASSERT(buffer_size >= (udp_packet.length() - sizeof(UDPPacket))); if (!buffer.write(udp_packet.payload(), udp_packet.length() - sizeof(UDPPacket))) - return KResult(-EFAULT); + return EFAULT; return udp_packet.length() - sizeof(UDPPacket); } @@ -94,7 +94,7 @@ KResultOr UDPSocket::protocol_send(const UserOrKernelBuffer& data, size_ { auto routing_decision = route_to(peer_address(), local_address(), bound_interface()); if (routing_decision.is_zero()) - return KResult(-EHOSTUNREACH); + return EHOSTUNREACH; const size_t buffer_size = sizeof(UDPPacket) + data_length; alignas(UDPPacket) u8 buffer[buffer_size]; @@ -105,7 +105,7 @@ KResultOr UDPSocket::protocol_send(const UserOrKernelBuffer& data, size_ udp_packet.set_destination_port(peer_port()); udp_packet.set_length(buffer_size); if (!data.read(udp_packet.payload(), data_length)) - return KResult(-EFAULT); + return EFAULT; routing_decision.adapter->send_ipv4(routing_decision.next_hop, peer_address(), IPv4Protocol::UDP, UserOrKernelBuffer::for_kernel_buffer(buffer), buffer_size, ttl()); return data_length; @@ -146,7 +146,7 @@ KResult UDPSocket::protocol_bind() { LOCKER(sockets_by_port().lock()); if (sockets_by_port().resource().contains(local_port())) - return KResult(-EADDRINUSE); + return EADDRINUSE; sockets_by_port().resource().set(local_port(), this); return KSuccess; } diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index ec61c1ee271531..941e14efb52782 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -51,7 +51,7 @@ KResult PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2) KResult PerformanceEventBuffer::append_with_eip_and_ebp(u32 eip, u32 ebp, int type, FlatPtr arg1, FlatPtr arg2) { if (count() >= capacity()) - return KResult(-ENOBUFS); + return ENOBUFS; PerformanceEvent event; event.type = type; @@ -67,7 +67,7 @@ KResult PerformanceEventBuffer::append_with_eip_and_ebp(u32 eip, u32 ebp, int ty event.data.free.ptr = arg1; break; default: - return KResult(-EINVAL); + return EINVAL; } auto current_thread = Thread::current(); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index c8102c16461d5c..e76bdd31679fb2 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -148,10 +148,10 @@ KResultOr Process::allocate_region(const Range& range, const String& na ASSERT(range.is_valid()); auto vmobject = AnonymousVMObject::create_with_size(range.size(), strategy); if (!vmobject) - return KResult(-ENOMEM); + return ENOMEM; auto region = Region::create_user_accessible(this, range, vmobject.release_nonnull(), 0, name, prot_to_region_access_flags(prot)); if (!region->map(page_directory())) - return KResult(-ENOMEM); + return ENOMEM; return &add_region(move(region)); } @@ -159,7 +159,7 @@ KResultOr Process::allocate_region(VirtualAddress vaddr, size_t size, c { auto range = allocate_range(vaddr, size); if (!range.is_valid()) - return KResult(-ENOMEM); + return ENOMEM; return allocate_region(range, name, prot, strategy); } @@ -169,21 +169,21 @@ KResultOr Process::allocate_region_with_vmobject(const Range& range, No size_t end_in_vmobject = offset_in_vmobject + range.size(); if (end_in_vmobject <= offset_in_vmobject) { dbgln("allocate_region_with_vmobject: Overflow (offset + size)"); - return KResult(-EINVAL); + return EINVAL; } if (offset_in_vmobject >= vmobject->size()) { dbgln("allocate_region_with_vmobject: Attempt to allocate a region with an offset past the end of its VMObject."); - return KResult(-EINVAL); + return EINVAL; } if (end_in_vmobject > vmobject->size()) { dbgln("allocate_region_with_vmobject: Attempt to allocate a region with an end past the end of its VMObject."); - return KResult(-EINVAL); + return EINVAL; } offset_in_vmobject &= PAGE_MASK; auto& region = add_region(Region::create_user_accessible(this, range, move(vmobject), offset_in_vmobject, name, prot_to_region_access_flags(prot), true, shared)); if (!region.map(page_directory())) { // FIXME: What is an appropriate error code here, really? - return KResult(-ENOMEM); + return ENOMEM; } return ®ion; } @@ -192,7 +192,7 @@ KResultOr Process::allocate_region_with_vmobject(VirtualAddress vaddr, { auto range = allocate_range(vaddr, size); if (!range.is_valid()) - return KResult(-ENOMEM); + return ENOMEM; return allocate_region_with_vmobject(range, move(vmobject), offset_in_vmobject, name, prot, shared); } @@ -573,12 +573,12 @@ Custody& Process::current_directory() KResultOr Process::get_syscall_path_argument(const char* user_path, size_t path_length) const { if (path_length == 0) - return KResult(-EINVAL); + return EINVAL; if (path_length > PATH_MAX) - return KResult(-ENAMETOOLONG); + return ENAMETOOLONG; auto copied_string = copy_string_from_user(user_path, path_length); if (copied_string.is_null()) - return KResult(-EFAULT); + return EFAULT; return copied_string; } @@ -819,7 +819,7 @@ KResult Process::send_signal(u8 signal, Process* sender) receiver_thread->send_signal(signal, sender); return KSuccess; } - return KResult(-ESRCH); + return ESRCH; } RefPtr Process::create_kernel_thread(void (*entry)(void*), void* entry_data, u32 priority, const String& name, u32 affinity, bool joinable) diff --git a/Kernel/Ptrace.cpp b/Kernel/Ptrace.cpp index 90b65e03702d83..e39b3de21bd044 100644 --- a/Kernel/Ptrace.cpp +++ b/Kernel/Ptrace.cpp @@ -38,7 +38,7 @@ KResultOr handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P ScopedSpinLock scheduler_lock(g_scheduler_lock); if (params.request == PT_TRACE_ME) { if (Process::current()->tracer()) - return KResult(-EBUSY); + return EBUSY; caller.set_wait_for_tracer_at_next_execve(true); return KSuccess; @@ -49,23 +49,23 @@ KResultOr handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P // long it is not the main thread. Alternatively, if this is desired, then the // bug is that this prevents PT_ATTACH to the main thread from another thread. if (params.tid == caller.pid().value()) - return KResult(-EINVAL); + return EINVAL; auto peer = Thread::from_tid(params.tid); if (!peer) - return KResult(-ESRCH); + return ESRCH; if ((peer->process().uid() != caller.euid()) || (peer->process().uid() != peer->process().euid())) // Disallow tracing setuid processes - return KResult(-EACCES); + return EACCES; if (!peer->process().is_dumpable()) - return KResult(-EACCES); + return EACCES; auto& peer_process = peer->process(); if (params.request == PT_ATTACH) { if (peer_process.tracer()) { - return KResult(-EBUSY); + return EBUSY; } peer_process.start_tracing_from(caller.pid()); ScopedSpinLock lock(peer->get_lock()); @@ -78,13 +78,13 @@ KResultOr handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P auto* tracer = peer_process.tracer(); if (!tracer) - return KResult(-EPERM); + return EPERM; if (tracer->tracer_pid() != caller.pid()) - return KResult(-EBUSY); + return EBUSY; if (peer->state() == Thread::State::Running) - return KResult(-EBUSY); + return EBUSY; scheduler_lock.unlock(); @@ -105,25 +105,25 @@ KResultOr handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P case PT_GETREGS: { if (!tracer->has_regs()) - return KResult(-EINVAL); + return EINVAL; auto* regs = reinterpret_cast(params.addr); if (!copy_to_user(regs, &tracer->regs())) - return KResult(-EFAULT); + return EFAULT; break; } case PT_SETREGS: { if (!tracer->has_regs()) - return KResult(-EINVAL); + return EINVAL; PtraceRegisters regs; if (!copy_from_user(®s, (const PtraceRegisters*)params.addr)) - return KResult(-EFAULT); + return EFAULT; auto& peer_saved_registers = peer->get_register_dump_from_stack(); // Verify that the saved registers are in usermode context if ((peer_saved_registers.cs & 0x03) != 3) - return KResult(-EFAULT); + return EFAULT; tracer->set_regs(regs); copy_ptrace_registers_into_kernel_registers(peer_saved_registers, regs); @@ -133,24 +133,24 @@ KResultOr handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P case PT_PEEK: { Kernel::Syscall::SC_ptrace_peek_params peek_params; if (!copy_from_user(&peek_params, reinterpret_cast(params.addr))) - return KResult(-EFAULT); + return EFAULT; if (!is_user_address(VirtualAddress { peek_params.address })) - return KResult(-EFAULT); + return EFAULT; auto result = peer->process().peek_user_data(Userspace { (FlatPtr)peek_params.address }); if (result.is_error()) return result.error(); if (!copy_to_user(peek_params.out_data, &result.value())) - return KResult(-EFAULT); + return EFAULT; break; } case PT_POKE: if (!is_user_address(VirtualAddress { params.addr })) - return KResult(-EFAULT); + return EFAULT; return peer->process().poke_user_data(Userspace { (FlatPtr)params.addr }, params.data); default: - return KResult(-EINVAL); + return EINVAL; } return KSuccess; diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp index 9dcb17ea38ae28..210b14603c8710 100644 --- a/Kernel/Storage/StorageDevice.cpp +++ b/Kernel/Storage/StorageDevice.cpp @@ -73,13 +73,13 @@ KResultOr StorageDevice::read(FileDescription&, size_t offset, UserOrKer auto read_request = make_request(AsyncBlockDeviceRequest::Read, index, whole_blocks, outbuf, whole_blocks * block_size()); auto result = read_request->wait(); if (result.wait_result().was_interrupted()) - return KResult(-EINTR); + return EINTR; switch (result.request_result()) { case AsyncDeviceRequest::Failure: case AsyncDeviceRequest::Cancelled: - return KResult(-EIO); + return EIO; case AsyncDeviceRequest::MemoryFault: - return KResult(-EFAULT); + return EFAULT; default: break; } @@ -93,12 +93,12 @@ KResultOr StorageDevice::read(FileDescription&, size_t offset, UserOrKer auto read_request = make_request(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size()); auto result = read_request->wait(); if (result.wait_result().was_interrupted()) - return KResult(-EINTR); + return EINTR; switch (result.request_result()) { case AsyncDeviceRequest::Failure: return pos; case AsyncDeviceRequest::Cancelled: - return KResult(-EIO); + return EIO; case AsyncDeviceRequest::MemoryFault: // This should never happen, we're writing to a kernel buffer! ASSERT_NOT_REACHED(); @@ -106,7 +106,7 @@ KResultOr StorageDevice::read(FileDescription&, size_t offset, UserOrKer break; } if (!outbuf.write(data.data(), pos, remaining)) - return KResult(-EFAULT); + return EFAULT; } return pos + remaining; @@ -140,13 +140,13 @@ KResultOr StorageDevice::write(FileDescription&, size_t offset, const Us auto write_request = make_request(AsyncBlockDeviceRequest::Write, index, whole_blocks, inbuf, whole_blocks * block_size()); auto result = write_request->wait(); if (result.wait_result().was_interrupted()) - return KResult(-EINTR); + return EINTR; switch (result.request_result()) { case AsyncDeviceRequest::Failure: case AsyncDeviceRequest::Cancelled: - return KResult(-EIO); + return EIO; case AsyncDeviceRequest::MemoryFault: - return KResult(-EFAULT); + return EFAULT; default: break; } @@ -165,12 +165,12 @@ KResultOr StorageDevice::write(FileDescription&, size_t offset, const Us auto read_request = make_request(AsyncBlockDeviceRequest::Read, index + whole_blocks, 1, data_buffer, block_size()); auto result = read_request->wait(); if (result.wait_result().was_interrupted()) - return KResult(-EINTR); + return EINTR; switch (result.request_result()) { case AsyncDeviceRequest::Failure: return pos; case AsyncDeviceRequest::Cancelled: - return KResult(-EIO); + return EIO; case AsyncDeviceRequest::MemoryFault: // This should never happen, we're writing to a kernel buffer! ASSERT_NOT_REACHED(); @@ -180,18 +180,18 @@ KResultOr StorageDevice::write(FileDescription&, size_t offset, const Us } if (!inbuf.read(data.data(), pos, remaining)) - return KResult(-EFAULT); + return EFAULT; { auto write_request = make_request(AsyncBlockDeviceRequest::Write, index + whole_blocks, 1, data_buffer, block_size()); auto result = write_request->wait(); if (result.wait_result().was_interrupted()) - return KResult(-EINTR); + return EINTR; switch (result.request_result()) { case AsyncDeviceRequest::Failure: return pos; case AsyncDeviceRequest::Cancelled: - return KResult(-EIO); + return EIO; case AsyncDeviceRequest::MemoryFault: // This should never happen, we're writing to a kernel buffer! ASSERT_NOT_REACHED(); diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 7865480c96d228..347e587e7fa7a2 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -149,7 +149,7 @@ KResultOr Process::load_elf_object(FileDescription& object_ auto vmobject = SharedInodeVMObject::create_with_inode(inode); if (vmobject->writable_mappings()) { dbgln("Refusing to execute a write-mapped program"); - return KResult(-ETXTBSY); + return ETXTBSY; } size_t executable_size = inode.size(); @@ -157,13 +157,13 @@ KResultOr Process::load_elf_object(FileDescription& object_ auto executable_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_ROUND_UP(executable_size), "ELF loading", Region::Access::Read); if (!executable_region) { dbgln("Could not allocate memory for ELF loading"); - return KResult(-ENOMEM); + return ENOMEM; } auto elf_image = ELF::Image(executable_region->vaddr().as_ptr(), executable_size); if (!elf_image.is_valid()) - return KResult(-ENOEXEC); + return ENOEXEC; Region* master_tls_region { nullptr }; size_t master_tls_size = 0; @@ -181,7 +181,7 @@ KResultOr Process::load_elf_object(FileDescription& object_ if (!elf_image.is_within_image(program_header.raw_data(), program_header.size_in_image())) { dbgln("Shenanigans! ELF PT_TLS header sneaks outside of executable."); - ph_load_result = KResult(-ENOEXEC); + ph_load_result = ENOEXEC; return IterationDecision::Break; } @@ -195,7 +195,7 @@ KResultOr Process::load_elf_object(FileDescription& object_ master_tls_alignment = program_header.alignment(); if (!copy_to_user(master_tls_region->vaddr().as_ptr(), program_header.raw_data(), program_header.size_in_image())) { - ph_load_result = KResult(-EFAULT); + ph_load_result = EFAULT; return IterationDecision::Break; } return IterationDecision::Continue; @@ -210,7 +210,7 @@ KResultOr Process::load_elf_object(FileDescription& object_ if (!elf_image.is_within_image(program_header.raw_data(), program_header.size_in_image())) { dbgln("Shenanigans! Writable ELF PT_LOAD header sneaks outside of executable."); - ph_load_result = KResult(-ENOEXEC); + ph_load_result = ENOEXEC; return IterationDecision::Break; } @@ -236,7 +236,7 @@ KResultOr Process::load_elf_object(FileDescription& object_ auto page_offset = program_header.vaddr(); page_offset.mask(~PAGE_MASK); if (!copy_to_user((u8*)region_or_error.value()->vaddr().as_ptr() + page_offset.get(), program_header.raw_data(), program_header.size_in_image())) { - ph_load_result = KResult(-EFAULT); + ph_load_result = EFAULT; return IterationDecision::Break; } return IterationDecision::Continue; @@ -269,7 +269,7 @@ KResultOr Process::load_elf_object(FileDescription& object_ if (!elf_image.entry().offset(load_offset).get()) { dbgln("do_exec: Failure loading program, entry pointer is invalid! {})", elf_image.entry().offset(load_offset)); - return KResult(-ENOEXEC); + return ENOEXEC; } auto stack_region_or_error = allocate_region(VirtualAddress(), Thread::default_userspace_stack_size, "Stack (Main thread)", PROT_READ | PROT_WRITE, AllocationStrategy::Reserve); @@ -299,7 +299,7 @@ KResultOr Process::load(NonnullRefPtr main { auto page_directory = PageDirectory::create_for_userspace(*this); if (!page_directory) - return KResult(-ENOMEM); + return ENOMEM; // Need to make sure we don't swap contexts in the middle ScopedCritical critical; @@ -366,12 +366,12 @@ static KResultOr get_required_load_range(FileDescription& pro auto region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_ROUND_UP(executable_size), "ELF memory range calculation", Region::Access::Read); if (!region) { dbgln("Could not allocate memory for ELF"); - return KResult(-ENOMEM); + return ENOMEM; } auto elf_image = ELF::Image(region->vaddr().as_ptr(), executable_size); if (!elf_image.is_valid()) { - return -EINVAL; + return EINVAL; } RequiredLoadRange range {}; @@ -688,7 +688,7 @@ static KResultOr> find_shebang_interpreter_for_executable(const c return interpreter_words; } - return KResult(-ENOEXEC); + return ENOEXEC; } KResultOr> Process::find_elf_interpreter_for_executable(const String& path, const Elf32_Ehdr& main_program_header, int nread, size_t file_size) @@ -698,7 +698,7 @@ KResultOr> Process::find_elf_interpreter_for_executable( String interpreter_path; if (!ELF::validate_program_headers(main_program_header, file_size, (const u8*)&main_program_header, nread, &interpreter_path)) { dbgln("exec({}): File has invalid ELF Program headers", path); - return KResult(-ENOEXEC); + return ENOEXEC; } if (!interpreter_path.is_empty()) { @@ -719,34 +719,34 @@ KResultOr> Process::find_elf_interpreter_for_executable( // Validate the program interpreter as a valid elf binary. // If your program interpreter is a #! file or something, it's time to stop playing games :) if (interp_metadata.size < (int)sizeof(Elf32_Ehdr)) - return KResult(-ENOEXEC); + return ENOEXEC; char first_page[PAGE_SIZE] = {}; auto first_page_buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)&first_page); auto nread_or_error = interpreter_description->read(first_page_buffer, sizeof(first_page)); if (nread_or_error.is_error()) - return KResult(-ENOEXEC); + return ENOEXEC; nread = nread_or_error.value(); if (nread < (int)sizeof(Elf32_Ehdr)) - return KResult(-ENOEXEC); + return ENOEXEC; auto elf_header = (Elf32_Ehdr*)first_page; if (!ELF::validate_elf_header(*elf_header, interp_metadata.size)) { dbgln("exec({}): Interpreter ({}) has invalid ELF header", path, interpreter_description->absolute_path()); - return KResult(-ENOEXEC); + return ENOEXEC; } // Not using KResultOr here because we'll want to do the same thing in userspace in the RTLD String interpreter_interpreter_path; if (!ELF::validate_program_headers(*elf_header, interp_metadata.size, (u8*)first_page, nread, &interpreter_interpreter_path)) { dbgln("exec({}): Interpreter ({}) has invalid ELF Program headers", path, interpreter_description->absolute_path()); - return KResult(-ENOEXEC); + return ENOEXEC; } if (!interpreter_interpreter_path.is_empty()) { dbgln("exec({}): Interpreter ({}) has its own interpreter ({})! No thank you!", path, interpreter_description->absolute_path(), interpreter_interpreter_path); - return KResult(-ELOOP); + return ELOOP; } return interpreter_description; @@ -754,7 +754,7 @@ KResultOr> Process::find_elf_interpreter_for_executable( if (main_program_header.e_type == ET_REL) { // We can't exec an ET_REL, that's just an object file from the compiler - return KResult(-ENOEXEC); + return ENOEXEC; } if (main_program_header.e_type == ET_DYN) { // If it's ET_DYN with no PT_INTERP, then it's a dynamic executable responsible @@ -817,12 +817,12 @@ int Process::exec(String path, Vector arguments, Vector environm // #2) ELF32 for i386 if (nread_or_error.value() < (int)sizeof(Elf32_Ehdr)) - return KResult(-ENOEXEC); + return ENOEXEC; auto main_program_header = (Elf32_Ehdr*)first_page; if (!ELF::validate_elf_header(*main_program_header, metadata.size)) { dbgln("exec({}): File has invalid ELF header", path); - return KResult(-ENOEXEC); + return ENOEXEC; } auto elf_result = find_elf_interpreter_for_executable(path, *main_program_header, nread_or_error.value(), metadata.size); diff --git a/Kernel/Syscalls/kill.cpp b/Kernel/Syscalls/kill.cpp index a8de14ee86ec9e..33d8c1643c1833 100644 --- a/Kernel/Syscalls/kill.cpp +++ b/Kernel/Syscalls/kill.cpp @@ -33,10 +33,10 @@ KResult Process::do_kill(Process& process, int signal) // FIXME: Allow sending SIGCONT to everyone in the process group. // FIXME: Should setuid processes have some special treatment here? if (!is_superuser() && m_euid != process.m_uid && m_uid != process.m_uid) - return KResult(-EPERM); + return EPERM; if (process.is_kernel_process() && signal == SIGKILL) { klog() << "attempted to send SIGKILL to kernel process " << process.name().characters() << "(" << process.pid().value() << ")"; - return KResult(-EPERM); + return EPERM; } if (signal != 0) return process.send_signal(signal, this); @@ -72,7 +72,7 @@ KResult Process::do_killpg(ProcessGroupID pgrp, int signal) }); if (group_was_empty) - return KResult(-ESRCH); + return ESRCH; if (any_succeeded) return KSuccess; return error; diff --git a/Kernel/Syscalls/ptrace.cpp b/Kernel/Syscalls/ptrace.cpp index a4b82edfaa878b..26e91fcaae25fa 100644 --- a/Kernel/Syscalls/ptrace.cpp +++ b/Kernel/Syscalls/ptrace.cpp @@ -42,7 +42,7 @@ int Process::sys$ptrace(Userspace user_params) if (!copy_from_user(¶ms, user_params)) return -EFAULT; auto result = Ptrace::handle_syscall(params, *this); - return result.is_error() ? result.error() : result.value(); + return result.is_error() ? result.error().error() : result.value(); } /** @@ -64,7 +64,7 @@ KResultOr Process::peek_user_data(Userspace address) ProcessPagingScope scope(*this); if (!copy_from_user(&result, address)) { dbgln("Invalid address for peek_user_data: {}", address.ptr()); - return KResult(-EFAULT); + return EFAULT; } return result; @@ -75,7 +75,7 @@ KResult Process::poke_user_data(Userspace address, u32 data) Range range = { VirtualAddress(address), sizeof(u32) }; auto* region = find_region_containing(range); if (!region) - return KResult(-EFAULT); + return EFAULT; ProcessPagingScope scope(*this); if (region->is_shared()) { // If the region is shared, we change its vmobject to a PrivateInodeVMObject @@ -98,7 +98,7 @@ KResult Process::poke_user_data(Userspace address, u32 data) if (!copy_to_user(address, &data)) { dbgln("poke_user_data: Bad address {:p}", address.ptr()); - return KResult(-EFAULT); + return EFAULT; } return KSuccess; diff --git a/Kernel/Syscalls/waitid.cpp b/Kernel/Syscalls/waitid.cpp index 6a7953ca4e70e7..ea6fb3248a4844 100644 --- a/Kernel/Syscalls/waitid.cpp +++ b/Kernel/Syscalls/waitid.cpp @@ -38,12 +38,12 @@ KResultOr Process::do_waitid(idtype_t idtype, int id, int options) case P_PGID: break; default: - return KResult(-EINVAL); + return EINVAL; } KResultOr result = KResult(KSuccess); if (Thread::current()->block({}, options, idtype, id, result).was_interrupted()) - return KResult(-EINTR); + return EINTR; ASSERT(!result.is_error() || (options & WNOHANG) || result.error() != KSuccess); return result; } diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index eca9f4c2faefb1..538b4716992f49 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -75,7 +75,7 @@ KResultOr MasterPTY::read(FileDescription&, size_t, UserOrKernelBuffer& KResultOr MasterPTY::write(FileDescription&, size_t, const UserOrKernelBuffer& buffer, size_t size) { if (!m_slave) - return KResult(-EIO); + return EIO; m_slave->on_master_write(buffer, size); return size; } diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp index 7a9789c5440c1d..3ccf768b6d9572 100644 --- a/Kernel/TTY/PTYMultiplexer.cpp +++ b/Kernel/TTY/PTYMultiplexer.cpp @@ -59,7 +59,7 @@ KResultOr> PTYMultiplexer::open(int options) { LOCKER(m_lock); if (m_freelist.is_empty()) - return KResult(-EBUSY); + return EBUSY; auto master_index = m_freelist.take_last(); auto master = adopt(*new MasterPTY(master_index)); #ifdef PTMX_DEBUG diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index 4375eef40c2fba..bde26f6da77145 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -58,7 +58,7 @@ KResultOr TTY::read(FileDescription&, size_t, UserOrKernelBuffer& buffer if (Process::current()->pgid() != pgid()) { // FIXME: Should we propagate this error path somehow? [[maybe_unused]] auto rc = Process::current()->send_signal(SIGTTIN, nullptr); - return KResult(-EINTR); + return EINTR; } if (m_input_buffer.size() < static_cast(size)) @@ -95,7 +95,7 @@ KResultOr TTY::read(FileDescription&, size_t, UserOrKernelBuffer& buffer }); } if (nwritten < 0) - return KResult(nwritten); + return KResult((ErrnoCode)-nwritten); if (nwritten > 0 || need_evaluate_block_conditions) evaluate_block_conditions(); return (size_t)nwritten; @@ -105,7 +105,7 @@ KResultOr TTY::write(FileDescription&, size_t, const UserOrKernelBuffer& { if (m_termios.c_lflag & TOSTOP && Process::current()->pgid() != pgid()) { [[maybe_unused]] auto rc = Process::current()->send_signal(SIGTTOU, nullptr); - return KResult(-EINTR); + return EINTR; } on_tty_write(buffer, size); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 210835c19282a8..761fcb33a8732d 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -748,11 +748,11 @@ class Thread KResult try_join(AddBlockerHandler add_blocker) { if (Thread::current() == this) - return KResult(-EDEADLK); + return EDEADLK; ScopedSpinLock lock(m_lock); if (!m_is_joinable || state() == Dead) - return KResult(-EINVAL); + return EINVAL; add_blocker(); diff --git a/Kernel/ThreadBlockers.cpp b/Kernel/ThreadBlockers.cpp index 7e3d023b34a43a..d1e8b2cbb567bf 100644 --- a/Kernel/ThreadBlockers.cpp +++ b/Kernel/ThreadBlockers.cpp @@ -611,7 +611,7 @@ Thread::WaitBlocker::WaitBlocker(int wait_options, idtype_t id_type, pid_t id, K case P_PID: { m_waitee = Process::from_pid(m_waitee_id); if (!m_waitee || m_waitee->ppid() != Process::current()->pid()) { - m_result = KResult(-ECHILD); + m_result = ECHILD; m_error = true; return; } @@ -620,7 +620,7 @@ Thread::WaitBlocker::WaitBlocker(int wait_options, idtype_t id_type, pid_t id, K case P_PGID: { m_waitee_group = ProcessGroup::from_pgid(m_waitee_id); if (!m_waitee_group) { - m_result = KResult(-ECHILD); + m_result = ECHILD; m_error = true; return; } @@ -670,7 +670,7 @@ void Thread::WaitBlocker::do_was_disowned() { ASSERT(!m_did_unblock); m_did_unblock = true; - m_result = KResult(-ECHILD); + m_result = ECHILD; } void Thread::WaitBlocker::do_set_result(const siginfo_t& result) diff --git a/Userland/Libraries/LibC/errno_numbers.h b/Userland/Libraries/LibC/errno_numbers.h index fc067b171da8ef..f1b618a6f31584 100644 --- a/Userland/Libraries/LibC/errno_numbers.h +++ b/Userland/Libraries/LibC/errno_numbers.h @@ -26,78 +26,155 @@ #pragma once -#define EPERM 1 -#define ENOENT 2 -#define ESRCH 3 -#define EINTR 4 -#define EIO 5 -#define ENXIO 6 -#define E2BIG 7 -#define ENOEXEC 8 -#define EBADF 9 -#define ECHILD 10 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EFAULT 14 -#define ENOTBLK 15 -#define EBUSY 16 -#define EEXIST 17 -#define EXDEV 18 -#define ENODEV 19 -#define ENOTDIR 20 -#define EISDIR 21 -#define EINVAL 22 -#define ENFILE 23 -#define EMFILE 24 -#define ENOTTY 25 -#define ETXTBSY 26 -#define EFBIG 27 -#define ENOSPC 28 -#define ESPIPE 29 -#define EROFS 30 -#define EMLINK 31 -#define EPIPE 32 -#define ERANGE 33 -#define ENAMETOOLONG 34 -#define ELOOP 35 -#define EOVERFLOW 36 -#define EOPNOTSUPP 37 -#define ENOSYS 38 -#define ENOTIMPL 39 -#define EAFNOSUPPORT 40 -#define ENOTSOCK 41 -#define EADDRINUSE 42 -#define EWHYTHO 43 -#define ENOTEMPTY 44 -#define EDOM 45 -#define ECONNREFUSED 46 -#define EADDRNOTAVAIL 47 -#define EISCONN 48 -#define ECONNABORTED 49 -#define EALREADY 50 -#define ECONNRESET 51 -#define EDESTADDRREQ 52 -#define EHOSTUNREACH 53 -#define EILSEQ 54 -#define EMSGSIZE 55 -#define ENETDOWN 56 -#define ENETUNREACH 57 -#define ENETRESET 58 -#define ENOBUFS 59 -#define ENOLCK 60 -#define ENOMSG 61 -#define ENOPROTOOPT 62 -#define ENOTCONN 63 -#define EWOULDBLOCK 64 -#define EPROTONOSUPPORT 65 -#define EDEADLK 66 -#define ETIMEDOUT 67 -#define EPROTOTYPE 68 -#define EINPROGRESS 69 -#define ENOTHREAD 70 -#define EPROTO 71 -#define ENOTSUP 72 -#define EPFNOSUPPORT 73 -#define EDIRINTOSELF 74 -#define EMAXERRNO 75 +enum ErrnoCode { + EPERM = 1, +#define EPERM EPERM + ENOENT, +#define ENOENT ENOENT + ESRCH, +#define ESRCH ESRCH + EINTR, +#define EINTR EINTR + EIO, +#define EIO EIO + ENXIO, +#define ENXIO ENXIO + E2BIG, +#define E2BIG E2BIG + ENOEXEC, +#define ENOEXEC ENOEXEC + EBADF, +#define EBADF EBADF + ECHILD, +#define ECHILD ECHILD + EAGAIN, +#define EAGAIN EAGAIN + ENOMEM, +#define ENOMEM ENOMEM + EACCES, +#define EACCES EACCES + EFAULT, +#define EFAULT EFAULT + ENOTBLK, +#define ENOTBLK ENOTBLK + EBUSY, +#define EBUSY EBUSY + EEXIST, +#define EEXIST EEXIST + EXDEV, +#define EXDEV EXDEV + ENODEV, +#define ENODEV ENODEV + ENOTDIR, +#define ENOTDIR ENOTDIR + EISDIR, +#define EISDIR EISDIR + EINVAL, +#define EINVAL EINVAL + ENFILE, +#define ENFILE ENFILE + EMFILE, +#define EMFILE EMFILE + ENOTTY, +#define ENOTTY ENOTTY + ETXTBSY, +#define ETXTBSY ETXTBSY + EFBIG, +#define EFBIG EFBIG + ENOSPC, +#define ENOSPC ENOSPC + ESPIPE, +#define ESPIPE ESPIPE + EROFS, +#define EROFS EROFS + EMLINK, +#define EMLINK EMLINK + EPIPE, +#define EPIPE EPIPE + ERANGE, +#define ERANGE ERANGE + ENAMETOOLONG, +#define ENAMETOOLONG ENAMETOOLONG + ELOOP, +#define ELOOP ELOOP + EOVERFLOW, +#define EOVERFLOW EOVERFLOW + EOPNOTSUPP, +#define EOPNOTSUPP EOPNOTSUPP + ENOSYS, +#define ENOSYS ENOSYS + ENOTIMPL, +#define ENOTIMPL ENOTIMPL + EAFNOSUPPORT, +#define EAFNOSUPPORT EAFNOSUPPORT + ENOTSOCK, +#define ENOTSOCK ENOTSOCK + EADDRINUSE, +#define EADDRINUSE EADDRINUSE + EWHYTHO, +#define EWHYTHO EWHYTHO + ENOTEMPTY, +#define ENOTEMPTY ENOTEMPTY + EDOM, +#define EDOM EDOM + ECONNREFUSED, +#define ECONNREFUSED ECONNREFUSED + EADDRNOTAVAIL, +#define EADDRNOTAVAIL EADDRNOTAVAIL + EISCONN, +#define EISCONN EISCONN + ECONNABORTED, +#define ECONNABORTED ECONNABORTED + EALREADY, +#define EALREADY EALREADY + ECONNRESET, +#define ECONNRESET ECONNRESET + EDESTADDRREQ, +#define EDESTADDRREQ EDESTADDRREQ + EHOSTUNREACH, +#define EHOSTUNREACH EHOSTUNREACH + EILSEQ, +#define EILSEQ EILSEQ + EMSGSIZE, +#define EMSGSIZE EMSGSIZE + ENETDOWN, +#define ENETDOWN ENETDOWN + ENETUNREACH, +#define ENETUNREACH ENETUNREACH + ENETRESET, +#define ENETRESET ENETRESET + ENOBUFS, +#define ENOBUFS ENOBUFS + ENOLCK, +#define ENOLCK ENOLCK + ENOMSG, +#define ENOMSG ENOMSG + ENOPROTOOPT, +#define ENOPROTOOPT ENOPROTOOPT + ENOTCONN, +#define ENOTCONN ENOTCONN + EWOULDBLOCK, +#define EWOULDBLOCK EWOULDBLOCK + EPROTONOSUPPORT, +#define EPROTONOSUPPORT EPROTONOSUPPORT + EDEADLK, +#define EDEADLK EDEADLK + ETIMEDOUT, +#define ETIMEDOUT ETIMEDOUT + EPROTOTYPE, +#define EPROTOTYPE EPROTOTYPE + EINPROGRESS, +#define EINPROGRESS EINPROGRESS + ENOTHREAD, +#define ENOTHREAD ENOTHREAD + EPROTO, +#define EPROTO EPROTO + ENOTSUP, +#define ENOTSUP ENOTSUP + EPFNOSUPPORT, +#define EPFNOSUPPORT EPFNOSUPPORT + EDIRINTOSELF, +#define EDIRINTOSELF EDIRINTOSELF + EMAXERRNO, +#define EMAXERRNO EMAXERRNO +};