35 changes: 35 additions & 0 deletions libc/src/__support/StringUtil/tables/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${LIBC_TARGET_OS})
endif()

set(error_to_string_platform_dep "")
if(TARGET libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.error_table)
set(error_to_string_platform_dep
libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.error_table)
endif()

add_header_library(
error_table
HDRS
error_table.h
stdc_error_table.h
posix_error_table.h
DEPENDS
${error_to_string_platform_dep}
)

set(signal_to_string_platform_dep "")
if(TARGET libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.signal_table)
set(signal_to_string_platform_dep
libc.src.__support.StringUtil.tables.${LIBC_TARGET_OS}.signal_table)
endif()

add_header_library(
signal_table
HDRS
signal_table.h
stdc_signal_table.h
posix_signal_table.h
DEPENDS
${signal_to_string_platform_dep}
)
32 changes: 32 additions & 0 deletions libc/src/__support/StringUtil/tables/error_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===-- Map from error numbers to strings -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_ERROR_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_ERROR_TABLE_H

#include "src/__support/StringUtil/message_mapper.h"

#include "posix_error_table.h"
#include "stdc_error_table.h"

#ifdef __linux__
#include "linux/error_table.h"
#endif

namespace __llvm_libc::internal {

#ifdef __linux__
inline constexpr auto PLATFORM_ERRORS =
STDC_ERRORS + POSIX_ERRORS + LINUX_ERRORS;
#else
inline constexpr auto PLATFORM_ERRORS = STDC_ERRORS;
#endif

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_ERROR_TABLE_H
17 changes: 17 additions & 0 deletions libc/src/__support/StringUtil/tables/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_header_library(
error_table
HDRS
error_table.h
DEPENDS
libc.src.__support.StringUtil.message_mapper
libc.src.errno.errno
)

add_header_library(
signal_table
HDRS
signal_table.h
DEPENDS
libc.src.__support.StringUtil.message_mapper
libc.include.signal
)
76 changes: 76 additions & 0 deletions libc/src/__support/StringUtil/tables/linux/error_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//===-- Map from error numbers to strings on linux --------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H

#include "src/errno/libc_errno.h" // For error macros

#include "src/__support/CPP/array.h"
#include "src/__support/StringUtil/message_mapper.h"

namespace __llvm_libc::internal {

constexpr MsgTable<52> LINUX_ERRORS = {
MsgMapping(ENOTBLK, "Block device required"),
MsgMapping(ECHRNG, "Channel number out of range"),
MsgMapping(EL2NSYNC, "Level 2 not synchronized"),
MsgMapping(EL3HLT, "Level 3 halted"),
MsgMapping(EL3RST, "Level 3 reset"),
MsgMapping(ELNRNG, "Link number out of range"),
MsgMapping(EUNATCH, "Protocol driver not attached"),
MsgMapping(ENOCSI, "No CSI structure available"),
MsgMapping(EL2HLT, "Level 2 halted"),
MsgMapping(EBADE, "Invalid exchange"),
MsgMapping(EBADR, "Invalid request descriptor"),
MsgMapping(EXFULL, "Exchange full"),
MsgMapping(ENOANO, "No anode"),
MsgMapping(EBADRQC, "Invalid request code"),
MsgMapping(EBADSLT, "Invalid slot"),
MsgMapping(EBFONT, "Bad font file format"),
MsgMapping(ENONET, "Machine is not on the network"),
MsgMapping(ENOPKG, "Package not installed"),
MsgMapping(EREMOTE, "Object is remote"),
MsgMapping(EADV, "Advertise error"),
MsgMapping(ESRMNT, "Srmount error"),
MsgMapping(ECOMM, "Communication error on send"),
MsgMapping(EDOTDOT, "RFS specific error"),
MsgMapping(ENOTUNIQ, "Name not unique on network"),
MsgMapping(EBADFD, "File descriptor in bad state"),
MsgMapping(EREMCHG, "Remote address changed"),
MsgMapping(ELIBACC, "Can not access a needed shared library"),
MsgMapping(ELIBBAD, "Accessing a corrupted shared library"),
MsgMapping(ELIBSCN, ".lib section in a.out corrupted"),
MsgMapping(ELIBMAX, "Attempting to link in too many shared libraries"),
MsgMapping(ELIBEXEC, "Cannot exec a shared library directly"),
MsgMapping(ERESTART, "Interrupted system call should be restarted"),
MsgMapping(ESTRPIPE, "Streams pipe error"),
MsgMapping(EUSERS, "Too many users"),
MsgMapping(ESOCKTNOSUPPORT, "Socket type not supported"),
MsgMapping(EPFNOSUPPORT, "Protocol family not supported"),
MsgMapping(ESHUTDOWN, "Cannot send after transport endpoint shutdown"),
MsgMapping(ETOOMANYREFS, "Too many references: cannot splice"),
MsgMapping(EHOSTDOWN, "Host is down"),
MsgMapping(EUCLEAN, "Structure needs cleaning"),
MsgMapping(ENOTNAM, "Not a XENIX named type file"),
MsgMapping(ENAVAIL, "No XENIX semaphores available"),
MsgMapping(EISNAM, "Is a named type file"),
MsgMapping(EREMOTEIO, "Remote I/O error"),
MsgMapping(ENOMEDIUM, "No medium found"),
MsgMapping(EMEDIUMTYPE, "Wrong medium type"),
MsgMapping(ENOKEY, "Required key not available"),
MsgMapping(EKEYEXPIRED, "Key has expired"),
MsgMapping(EKEYREVOKED, "Key has been revoked"),
MsgMapping(EKEYREJECTED, "Key was rejected by service"),
MsgMapping(ERFKILL, "Operation not possible due to RF-kill"),
MsgMapping(EHWPOISON, "Memory page has hardware error"),
};

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
33 changes: 33 additions & 0 deletions libc/src/__support/StringUtil/tables/linux/signal_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===-- Map from signal numbers to strings on linux -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H

#include <signal.h>

#include "src/__support/StringUtil/message_mapper.h"

namespace __llvm_libc::internal {

// The array being larger than necessary isn't a problem. The MsgMappings will
// be set to their default state which maps 0 to an empty string. This will get
// filtered out in the MessageMapper building stage.
inline constexpr const MsgTable<3> LINUX_SIGNALS = {
#ifdef SIGSTKFLT
MsgMapping(SIGSTKFLT, "Stack fault"), // unused
#endif
MsgMapping(SIGWINCH, "Window changed"),
#ifdef SIGPWR
MsgMapping(SIGPWR, "Power failure"), // ignored
#endif
};

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H
100 changes: 100 additions & 0 deletions libc/src/__support/StringUtil/tables/posix_error_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//===-- Map from error numbers to strings in posix --------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERROR_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERROR_TABLE_H

#include "src/errno/libc_errno.h" // For error macros

#include "src/__support/CPP/array.h"
#include "src/__support/StringUtil/message_mapper.h"

namespace __llvm_libc::internal {

inline constexpr MsgTable<76> POSIX_ERRORS = {
MsgMapping(EPERM, "Operation not permitted"),
MsgMapping(ENOENT, "No such file or directory"),
MsgMapping(ESRCH, "No such process"),
MsgMapping(EINTR, "Interrupted system call"),
MsgMapping(EIO, "Input/output error"),
MsgMapping(ENXIO, "No such device or address"),
MsgMapping(E2BIG, "Argument list too long"),
MsgMapping(ENOEXEC, "Exec format error"),
MsgMapping(EBADF, "Bad file descriptor"),
MsgMapping(ECHILD, "No child processes"),
MsgMapping(EAGAIN, "Resource temporarily unavailable"),
MsgMapping(ENOMEM, "Cannot allocate memory"),
MsgMapping(EACCES, "Permission denied"),
MsgMapping(EFAULT, "Bad address"),
MsgMapping(EBUSY, "Device or resource busy"),
MsgMapping(EEXIST, "File exists"),
MsgMapping(EXDEV, "Invalid cross-device link"),
MsgMapping(ENODEV, "No such device"),
MsgMapping(ENOTDIR, "Not a directory"),
MsgMapping(EISDIR, "Is a directory"),
MsgMapping(EINVAL, "Invalid argument"),
MsgMapping(ENFILE, "Too many open files in system"),
MsgMapping(EMFILE, "Too many open files"),
MsgMapping(ENOTTY, "Inappropriate ioctl for device"),
MsgMapping(ETXTBSY, "Text file busy"),
MsgMapping(EFBIG, "File too large"),
MsgMapping(ENOSPC, "No space left on device"),
MsgMapping(ESPIPE, "Illegal seek"),
MsgMapping(EROFS, "Read-only file system"),
MsgMapping(EMLINK, "Too many links"),
MsgMapping(EPIPE, "Broken pipe"),
MsgMapping(EDEADLK, "Resource deadlock avoided"),
MsgMapping(ENAMETOOLONG, "File name too long"),
MsgMapping(ENOLCK, "No locks available"),
MsgMapping(ENOSYS, "Function not implemented"),
MsgMapping(ENOTEMPTY, "Directory not empty"),
MsgMapping(ELOOP, "Too many levels of symbolic links"),
MsgMapping(ENOMSG, "No message of desired type"),
MsgMapping(EIDRM, "Identifier removed"),
MsgMapping(ENOSTR, "Device not a stream"),
MsgMapping(ENODATA, "No data available"),
MsgMapping(ETIME, "Timer expired"),
MsgMapping(ENOSR, "Out of streams resources"),
MsgMapping(ENOLINK, "Link has been severed"),
MsgMapping(EPROTO, "Protocol error"),
MsgMapping(EMULTIHOP, "Multihop attempted"),
MsgMapping(EBADMSG, "Bad message"),
MsgMapping(EOVERFLOW, "Value too large for defined data type"),
MsgMapping(ENOTSOCK, "Socket operation on non-socket"),
MsgMapping(EDESTADDRREQ, "Destination address required"),
MsgMapping(EMSGSIZE, "Message too long"),
MsgMapping(EPROTOTYPE, "Protocol wrong type for socket"),
MsgMapping(ENOPROTOOPT, "Protocol not available"),
MsgMapping(EPROTONOSUPPORT, "Protocol not supported"),
MsgMapping(ENOTSUP, "Operation not supported"),
MsgMapping(EAFNOSUPPORT, "Address family not supported by protocol"),
MsgMapping(EADDRINUSE, "Address already in use"),
MsgMapping(EADDRNOTAVAIL, "Cannot assign requested address"),
MsgMapping(ENETDOWN, "Network is down"),
MsgMapping(ENETUNREACH, "Network is unreachable"),
MsgMapping(ENETRESET, "Network dropped connection on reset"),
MsgMapping(ECONNABORTED, "Software caused connection abort"),
MsgMapping(ECONNRESET, "Connection reset by peer"),
MsgMapping(ENOBUFS, "No buffer space available"),
MsgMapping(EISCONN, "Transport endpoint is already connected"),
MsgMapping(ENOTCONN, "Transport endpoint is not connected"),
MsgMapping(ETIMEDOUT, "Connection timed out"),
MsgMapping(ECONNREFUSED, "Connection refused"),
MsgMapping(EHOSTUNREACH, "No route to host"),
MsgMapping(EALREADY, "Operation already in progress"),
MsgMapping(EINPROGRESS, "Operation now in progress"),
MsgMapping(ESTALE, "Stale file handle"),
MsgMapping(EDQUOT, "Disk quota exceeded"),
MsgMapping(ECANCELED, "Operation canceled"),
MsgMapping(EOWNERDEAD, "Owner died"),
MsgMapping(ENOTRECOVERABLE, "State not recoverable"),
};

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_ERROR_TABLE_H
46 changes: 46 additions & 0 deletions libc/src/__support/StringUtil/tables/posix_signal_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===-- Map from signal numbers to strings in posix -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNAL_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNAL_TABLE_H

#include <signal.h>

#include "src/__support/CPP/array.h"
#include "src/__support/StringUtil/message_mapper.h"

namespace __llvm_libc::internal {

inline constexpr MsgTable<22> POSIX_SIGNALS = {
MsgMapping(SIGHUP, "Hangup"),
MsgMapping(SIGQUIT, "Quit"),
MsgMapping(SIGTRAP, "Trace/breakpoint trap"),
MsgMapping(SIGBUS, "Bus error"),
MsgMapping(SIGKILL, "Killed"),
MsgMapping(SIGUSR1, "User defined signal 1"),
MsgMapping(SIGUSR2, "User defined signal 2"),
MsgMapping(SIGPIPE, "Broken pipe"),
MsgMapping(SIGALRM, "Alarm clock"),
MsgMapping(SIGCHLD, "Child exited"),
MsgMapping(SIGCONT, "Continued"),
MsgMapping(SIGSTOP, "Stopped (signal)"),
MsgMapping(SIGTSTP, "Stopped"),
MsgMapping(SIGTTIN, "Stopped (tty input)"),
MsgMapping(SIGTTOU, "Stopped (tty output)"),
MsgMapping(SIGURG, "Urgent I/O condition"),
MsgMapping(SIGXCPU, "CPU time limit exceeded"),
MsgMapping(SIGXFSZ, "File size limit exceeded"),
MsgMapping(SIGVTALRM, "Virtual timer expired"),
MsgMapping(SIGPROF, "Profiling timer expired"),
MsgMapping(SIGPOLL, "I/O possible"),
MsgMapping(SIGSYS, "Bad system call"),
};

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_POSIX_SIGNAL_TABLE_H
32 changes: 32 additions & 0 deletions libc/src/__support/StringUtil/tables/signal_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===-- Map from signal numbers to strings ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_SIGNAL_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_SIGNAL_TABLE_H

#include "src/__support/StringUtil/message_mapper.h"

#include "posix_signal_table.h"
#include "stdc_signal_table.h"

#ifdef __linux__
#include "linux/signal_table.h"
#endif

namespace __llvm_libc::internal {

#ifdef __linux__
inline constexpr auto PLATFORM_SIGNALS =
STDC_SIGNALS + POSIX_SIGNALS + LINUX_SIGNALS;
#else
inline constexpr auto PLATFORM_SIGNALS = STDC_SIGNALS;
#endif

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_SIGNAL_TABLE_H
27 changes: 27 additions & 0 deletions libc/src/__support/StringUtil/tables/stdc_error_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Map from error numbers to strings in the c std ----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_ERROR_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_ERROR_TABLE_H

#include "src/errno/libc_errno.h" // For error macros

#include "src/__support/StringUtil/message_mapper.h"

namespace __llvm_libc::internal {

inline constexpr const MsgTable<4> STDC_ERRORS = {
MsgMapping(0, "Success"),
MsgMapping(EDOM, "Numerical argument out of domain"),
MsgMapping(ERANGE, "Numerical result out of range"),
MsgMapping(EILSEQ, "Invalid or incomplete multibyte or wide character"),
};

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_ERROR_TABLE_H
29 changes: 29 additions & 0 deletions libc/src/__support/StringUtil/tables/stdc_signal_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- Map from signal numbers to strings in the c std ---------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_SIGNAL_TABLE_H
#define LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_STDC_SIGNAL_TABLE_H

#include <signal.h>

#include "src/__support/StringUtil/message_mapper.h"

namespace __llvm_libc::internal {

inline constexpr const MsgTable<6> STDC_SIGNALS = {
MsgMapping(SIGINT, "Interrupt"),
MsgMapping(SIGILL, "Illegal instruction"),
MsgMapping(SIGABRT, "Aborted"),
MsgMapping(SIGFPE, "Floating point exception"),
MsgMapping(SIGSEGV, "Segmentation fault"),
MsgMapping(SIGTERM, "Terminated"),
};

} // namespace __llvm_libc::internal

#endif // LLVM_LIBC_SRC_SUPPORT_STRING_UTIL_TABLES_LINUX_SIGNAL_TABLE_H