From 69ef2119253522e79a884b897b70df27317531cc Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sun, 12 Sep 2021 11:29:28 +0000 Subject: [PATCH] Kernel+LibC: Move errno definitions to Kernel/API/POSIX This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes. --- AK/Error.h | 2 +- Kernel/API/POSIX/errno.h | 97 +++++++++++++++++++ Kernel/Devices/FullDevice.cpp | 2 +- Kernel/FileSystem/Ext2FileSystem.cpp | 2 +- Kernel/FileSystem/InodeFile.cpp | 2 +- Kernel/FileSystem/OpenFileDescription.cpp | 2 +- Kernel/FileSystem/ProcFS.cpp | 2 +- Kernel/FileSystem/VirtualFileSystem.cpp | 2 +- Kernel/Graphics/FramebufferDevice.cpp | 2 +- Kernel/Graphics/GenericFramebufferDevice.cpp | 2 +- Kernel/Net/IPv4Socket.cpp | 2 +- Kernel/Net/LocalSocket.cpp | 2 +- Kernel/Net/Socket.cpp | 2 +- Kernel/Process.cpp | 2 +- Kernel/TTY/MasterPTY.cpp | 2 +- Kernel/TTY/PTYMultiplexer.cpp | 2 +- Kernel/TTY/TTY.cpp | 2 +- Kernel/UserOrKernelBuffer.h | 2 +- Userland/Libraries/LibC/errno.h | 2 +- .../LibC/{errno_numbers.h => errno_codes.h} | 85 +--------------- Userland/Libraries/LibC/grp.cpp | 2 +- Userland/Libraries/LibC/string.cpp | 84 +--------------- Userland/Utilities/syscall.cpp | 2 +- 23 files changed, 123 insertions(+), 183 deletions(-) create mode 100644 Kernel/API/POSIX/errno.h rename Userland/Libraries/LibC/{errno_numbers.h => errno_codes.h} (66%) diff --git a/AK/Error.h b/AK/Error.h index f1cf38face..831b2c2fb3 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -12,7 +12,7 @@ #include #if defined(__serenity__) && defined(KERNEL) -# include +# include #else # include #endif diff --git a/Kernel/API/POSIX/errno.h b/Kernel/API/POSIX/errno.h new file mode 100644 index 0000000000..65a8d74c1e --- /dev/null +++ b/Kernel/API/POSIX/errno.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, sin-ack + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#define ENUMERATE_ERRNO_CODES(E) \ + E(ESUCCESS, "Success (not an error)") \ + E(EPERM, "Operation not permitted") \ + E(ENOENT, "No such file or directory") \ + E(ESRCH, "No such process") \ + E(EINTR, "Interrupted syscall") \ + E(EIO, "I/O error") \ + E(ENXIO, "No such device or address") \ + E(E2BIG, "Argument list too long") \ + E(ENOEXEC, "Exec format error") \ + E(EBADF, "Bad fd number") \ + E(ECHILD, "No child processes") \ + E(EAGAIN, "Try again") \ + E(ENOMEM, "Out of memory") \ + E(EACCES, "Permission denied") \ + E(EFAULT, "Bad address") \ + E(ENOTBLK, "Block device required") \ + E(EBUSY, "Device or resource busy") \ + E(EEXIST, "File already exists") \ + E(EXDEV, "Cross-device link") \ + E(ENODEV, "No such device") \ + E(ENOTDIR, "Not a directory") \ + E(EISDIR, "Is a directory") \ + E(EINVAL, "Invalid argument") \ + E(ENFILE, "File table overflow") \ + E(EMFILE, "Too many open files") \ + E(ENOTTY, "Not a TTY") \ + E(ETXTBSY, "Text file busy") \ + E(EFBIG, "File too large") \ + E(ENOSPC, "No space left on device") \ + E(ESPIPE, "Illegal seek") \ + E(EROFS, "Read-only filesystem") \ + E(EMLINK, "Too many links") \ + E(EPIPE, "Broken pipe") \ + E(ERANGE, "Range error") \ + E(ENAMETOOLONG, "Name too long") \ + E(ELOOP, "Too many symlinks") \ + E(EOVERFLOW, "Overflow") \ + E(EOPNOTSUPP, "Operation not supported") \ + E(ENOSYS, "No such syscall") \ + E(ENOTIMPL, "Not implemented") \ + E(EAFNOSUPPORT, "Address family not supported") \ + E(ENOTSOCK, "Not a socket") \ + E(EADDRINUSE, "Address in use") \ + E(EWHYTHO, "Failed without setting an error code (bug!)") \ + E(ENOTEMPTY, "Directory not empty") \ + E(EDOM, "Math argument out of domain") \ + E(ECONNREFUSED, "Connection refused") \ + E(EHOSTDOWN, "Host is down") \ + E(EADDRNOTAVAIL, "Address not available") \ + E(EISCONN, "Already connected") \ + E(ECONNABORTED, "Connection aborted") \ + E(EALREADY, "Connection already in progress") \ + E(ECONNRESET, "Connection reset") \ + E(EDESTADDRREQ, "Destination address required") \ + E(EHOSTUNREACH, "Host unreachable") \ + E(EILSEQ, "Illegal byte sequence") \ + E(EMSGSIZE, "Message size") \ + E(ENETDOWN, "Network down") \ + E(ENETUNREACH, "Network unreachable") \ + E(ENETRESET, "Network reset") \ + E(ENOBUFS, "No buffer space") \ + E(ENOLCK, "No lock available") \ + E(ENOMSG, "No message") \ + E(ENOPROTOOPT, "No protocol option") \ + E(ENOTCONN, "Not connected") \ + E(ESHUTDOWN, "Transport endpoint has shutdown") \ + E(ETOOMANYREFS, "Too many references") \ + E(ESOCKTNOSUPPORT, "Socket type not supported") \ + E(EPROTONOSUPPORT, "Protocol not supported") \ + E(EDEADLK, "Resource deadlock would occur") \ + E(ETIMEDOUT, "Timed out") \ + E(EPROTOTYPE, "Wrong protocol type") \ + E(EINPROGRESS, "Operation in progress") \ + E(ENOTHREAD, "No such thread") \ + E(EPROTO, "Protocol error") \ + E(ENOTSUP, "Not supported") \ + E(EPFNOSUPPORT, "Protocol family not supported") \ + E(EDIRINTOSELF, "Cannot make directory a subdirectory of itself") \ + E(EDQUOT, "Quota exceeded") \ + E(ENOTRECOVERABLE, "State not recoverable") \ + E(EMAXERRNO, "The highest errno +1 :^)") + +enum ErrnoCode { +#define __ENUMERATE_ERRNO_CODE(c, s) c, + ENUMERATE_ERRNO_CODES(__ENUMERATE_ERRNO_CODE) +#undef __ENUMERATE_ERRNO_CODE +}; diff --git a/Kernel/Devices/FullDevice.cpp b/Kernel/Devices/FullDevice.cpp index 686303d0fd..122216bccb 100644 --- a/Kernel/Devices/FullDevice.cpp +++ b/Kernel/Devices/FullDevice.cpp @@ -5,10 +5,10 @@ */ #include +#include #include #include #include -#include namespace Kernel { diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 355f7ec6fe..8245a1fab8 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include namespace Kernel { diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index ad252f1d24..6ee7a5ac8e 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include #include namespace Kernel { diff --git a/Kernel/FileSystem/OpenFileDescription.cpp b/Kernel/FileSystem/OpenFileDescription.cpp index 5dfd3a4fc0..1143459f7d 100644 --- a/Kernel/FileSystem/OpenFileDescription.cpp +++ b/Kernel/FileSystem/OpenFileDescription.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include namespace Kernel { diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 1cecfd30f7..6b2f0715ff 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include namespace Kernel { diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 1c104efe4c..c8c6f19367 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include namespace Kernel { diff --git a/Kernel/Graphics/FramebufferDevice.cpp b/Kernel/Graphics/FramebufferDevice.cpp index 89f8de7242..6d41721871 100644 --- a/Kernel/Graphics/FramebufferDevice.cpp +++ b/Kernel/Graphics/FramebufferDevice.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include #include namespace Kernel { diff --git a/Kernel/Graphics/GenericFramebufferDevice.cpp b/Kernel/Graphics/GenericFramebufferDevice.cpp index 401bc169f8..848310d58f 100644 --- a/Kernel/Graphics/GenericFramebufferDevice.cpp +++ b/Kernel/Graphics/GenericFramebufferDevice.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #define MAX_RESOLUTION_WIDTH 4096 #define MAX_RESOLUTION_HEIGHT 2160 diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 17d1e07300..b0b03dc037 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -21,7 +22,6 @@ #include #include #include -#include #include namespace Kernel { diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index dbb14078e6..ea8adaf303 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include #include namespace Kernel { diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index b3187c585e..20b40318cc 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -13,7 +14,6 @@ #include #include #include -#include namespace Kernel { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 117cbb33bb..87af43fff2 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -17,6 +17,7 @@ #ifdef ENABLE_KERNEL_COVERAGE_COLLECTION # include #endif +#include #include #include #include @@ -34,7 +35,6 @@ #include #include #include -#include #include namespace Kernel { diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index d4b6c96804..0a7cdbb793 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include #include #include #include -#include #include #include diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp index 77578c3b1d..2a9a0eded6 100644 --- a/Kernel/TTY/PTYMultiplexer.cpp +++ b/Kernel/TTY/PTYMultiplexer.cpp @@ -5,12 +5,12 @@ */ #include +#include #include #include #include #include #include -#include namespace Kernel { diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index 7153d14772..281b4d65df 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -6,11 +6,11 @@ #include #include +#include #include #include #include #include -#include #include #include #define TTYDEFCHARS diff --git a/Kernel/UserOrKernelBuffer.h b/Kernel/UserOrKernelBuffer.h index bebd512f3f..4b9e47c767 100644 --- a/Kernel/UserOrKernelBuffer.h +++ b/Kernel/UserOrKernelBuffer.h @@ -9,10 +9,10 @@ #include #include +#include #include #include #include -#include namespace Kernel { diff --git a/Userland/Libraries/LibC/errno.h b/Userland/Libraries/LibC/errno.h index 449d6d2bdb..75b75ddf63 100644 --- a/Userland/Libraries/LibC/errno.h +++ b/Userland/Libraries/LibC/errno.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #define __RETURN_WITH_ERRNO(rc, good_ret, bad_ret) \ diff --git a/Userland/Libraries/LibC/errno_numbers.h b/Userland/Libraries/LibC/errno_codes.h similarity index 66% rename from Userland/Libraries/LibC/errno_numbers.h rename to Userland/Libraries/LibC/errno_codes.h index 1df0c97a13..f203c68911 100644 --- a/Userland/Libraries/LibC/errno_numbers.h +++ b/Userland/Libraries/LibC/errno_codes.h @@ -6,168 +6,89 @@ #pragma once -enum ErrnoCode { - EPERM = 1, +#include + +// NOTE: You can't define with a macro, so these have to be duplicated. #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 - EHOSTDOWN, #define EHOSTDOWN EHOSTDOWN - 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 - ESHUTDOWN, #define ESHUTDOWN ESHUTDOWN - ETOOMANYREFS, #define ETOOMANYREFS ETOOMANYREFS - EPROTONOSUPPORT, #define EPROTONOSUPPORT EPROTONOSUPPORT - ESOCKTNOSUPPORT, #define ESOCKTNOSUPPORT ESOCKTNOSUPPORT - 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 EDQUOT EDQUOT - EDQUOT, #define EDIRINTOSELF EDIRINTOSELF - ENOTRECOVERABLE, #define ENOTRECOVERABLE ENOTRECOVERABLE - EMAXERRNO, #define EMAXERRNO EMAXERRNO -}; #define EWOULDBLOCK EAGAIN #define ELAST EMAXERRNO diff --git a/Userland/Libraries/LibC/grp.cpp b/Userland/Libraries/LibC/grp.cpp index 6c22723407..9a4d55ca05 100644 --- a/Userland/Libraries/LibC/grp.cpp +++ b/Userland/Libraries/LibC/grp.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Userland/Libraries/LibC/string.cpp b/Userland/Libraries/LibC/string.cpp index d7ba75d14d..40410fde8e 100644 --- a/Userland/Libraries/LibC/string.cpp +++ b/Userland/Libraries/LibC/string.cpp @@ -264,87 +264,9 @@ char* strncat(char* dest, const char* src, size_t n) } const char* const sys_errlist[] = { - "Success (not an error)", - "Operation not permitted", - "No such file or directory", - "No such process", - "Interrupted syscall", - "I/O error", - "No such device or address", - "Argument list too long", - "Exec format error", - "Bad fd number", - "No child processes", - "Try again", - "Out of memory", - "Permission denied", - "Bad address", - "Block device required", - "Device or resource busy", - "File already exists", - "Cross-device link", - "No such device", - "Not a directory", - "Is a directory", - "Invalid argument", - "File table overflow", - "Too many open files", - "Not a TTY", - "Text file busy", - "File too large", - "No space left on device", - "Illegal seek", - "Read-only filesystem", - "Too many links", - "Broken pipe", - "Range error", - "Name too long", - "Too many symlinks", - "Overflow", - "Operation not supported", - "No such syscall", - "Not implemented", - "Address family not supported", - "Not a socket", - "Address in use", - "Failed without setting an error code (bug!)", - "Directory not empty", - "Math argument out of domain", - "Connection refused", - "Host is down", - "Address not available", - "Already connected", - "Connection aborted", - "Connection already in progress", - "Connection reset", - "Destination address required", - "Host unreachable", - "Illegal byte sequence", - "Message size", - "Network down", - "Network unreachable", - "Network reset", - "No buffer space", - "No lock available", - "No message", - "No protocol option", - "Not connected", - "Transport endpoint has shutdown", - "Too many references", - "Protocol not supported", - "Socket type not supported", - "Resource deadlock would occur", - "Timed out", - "Wrong protocol type", - "Operation in progress", - "No such thread", - "Protocol error", - "Not supported", - "Protocol family not supported", - "Cannot make directory a subdirectory of itself", - "Quota exceeded", - "State not recoverable", - "The highest errno +1 :^)", +#define __ENUMERATE_ERRNO_CODE(c, s) s, + ENUMERATE_ERRNO_CODES(__ENUMERATE_ERRNO_CODE) +#undef __ENUMERATE_ERRNO_CODE }; static_assert(array_size(sys_errlist) == (EMAXERRNO + 1)); diff --git a/Userland/Utilities/syscall.cpp b/Userland/Utilities/syscall.cpp index 4eaf603f7d..c59d121283 100644 --- a/Userland/Utilities/syscall.cpp +++ b/Userland/Utilities/syscall.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include