diff options
Diffstat (limited to 'libc/include/llvm-libc-macros/linux')
16 files changed, 854 insertions, 0 deletions
diff --git a/libc/include/llvm-libc-macros/linux/error-number-macros.h b/libc/include/llvm-libc-macros/linux/error-number-macros.h new file mode 100644 index 000000000000..9a7304fa161a --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/error-number-macros.h @@ -0,0 +1,32 @@ +#ifndef LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H + +#ifndef ECANCELED +#define ECANCELED 125 +#endif // ECANCELED + +#ifndef EOWNERDEAD +#define EOWNERDEAD 130 +#endif // EOWNERDEAD + +#ifndef ENOTRECOVERABLE +#define ENOTRECOVERABLE 131 +#endif // ENOTRECOVERABLE + +#ifndef ERFKILL +#define ERFKILL 132 +#endif // ERFKILL + +#ifndef EHWPOISON +#define EHWPOISON 133 +#endif // EHWPOISON + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 95 +#endif + +#ifndef ENOTSUP +#define ENOTSUP EOPNOTSUPP +#endif + +#endif // LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/fcntl-macros.h b/libc/include/llvm-libc-macros/linux/fcntl-macros.h new file mode 100644 index 000000000000..aec8a0d2da0b --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/fcntl-macros.h @@ -0,0 +1,105 @@ +//===-- Definition of macros from fcntl.h ---------------------------------===// +// +// 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_MACROS_LINUX_FCNTL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_FCNTL_MACROS_H + +// File creation flags +#define O_CLOEXEC 02000000 +#define O_CREAT 00000100 +#define O_PATH 010000000 + +#ifdef __aarch64__ +#define O_DIRECTORY 040000 +#else +#define O_DIRECTORY 00200000 +#endif + +#define O_EXCL 00000200 +#define O_NOCTTY 00000400 + +#ifdef __aarch64__ +#define O_NOFOLLOW 0100000 +#else +#define O_NOFOLLOW 00400000 +#endif + +#define O_TRUNC 00001000 +#define O_TMPFILE (020000000 | O_DIRECTORY) + +// File status flags +#define O_APPEND 00002000 +#define O_DSYNC 00010000 +#define O_NONBLOCK 00004000 +#define O_SYNC 04000000 | O_DSYNC + +// File access mode mask +#define O_ACCMODE 00000003 + +// File access mode flags +#define O_RDONLY 00000000 +#define O_RDWR 00000002 +#define O_WRONLY 00000001 + +// Special directory FD to indicate that the path argument to +// openat is relative to the current directory. +#define AT_FDCWD -100 + +// Special flag to the function unlinkat to indicate that it +// has to perform the equivalent of "rmdir" on the path argument. +#define AT_REMOVEDIR 0x200 + +// Special flag for functions like lstat to convey that symlinks +// should not be followed. +#define AT_SYMLINK_NOFOLLOW 0x100 + +// Allow empty relative pathname. +#define AT_EMPTY_PATH 0x1000 + +// Values of SYS_fcntl commands. +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 +#define F_GETLK 5 +#define F_SETLK 6 +#define F_SETLKW 7 +#define F_SETOWN 8 +#define F_GETOWN 9 +#define F_SETSIG 10 +#define F_GETSIG 11 +#define F_GETLK64 12 +#define F_SETLK64 13 +#define F_SETLKW64 14 +#define F_SETOWN_EX 15 +#define F_GETOWN_EX 16 + +// Open File Description Locks. +#define F_OFD_GETLK 36 +#define F_OFD_SETLK 37 +#define F_OFD_SETLKW 38 + +// Close on succesful +#define F_CLOEXEC 1 + +// Close on execute for fcntl. +#define FD_CLOEXEC 1 + +#define F_RDLCK 0 +#define F_WRLCK 1 +#define F_UNLCK 2 + +// For Large File Support +#if defined(_LARGEFILE64_SOURCE) +#define F_GETLK F_GETLK64 +#define F_SETLK F_SETLK64 +#define F_SETLKW F_SETLKW64 +#endif + +#endif // LLVM_LIBC_MACROS_LINUX_FCNTL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/poll-macros.h b/libc/include/llvm-libc-macros/linux/poll-macros.h new file mode 100644 index 000000000000..d6724c5ee321 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/poll-macros.h @@ -0,0 +1,65 @@ +//===-- Macros defined in poll.h header file ------------------------------===// +// +// 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_MACROS_LINUX_POLL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H + +// From asm-generic/poll.h, redefined here to avoid redeclaring struct pollfd. +#ifndef POLLIN +#define POLLIN 0x0001 +#endif + +#ifndef POLLPRI +#define POLLPRI 0x0002 +#endif + +#ifndef POLLOUT +#define POLLOUT 0x0004 +#endif + +#ifndef POLLERR +#define POLLERR 0x0008 +#endif + +#ifndef POLLHUP +#define POLLHUP 0x0010 +#endif + +#ifndef POLLNVAL +#define POLLNVAL 0x0020 +#endif + +#ifndef POLLRDNORM +#define POLLRDNORM 0x0040 +#endif + +#ifndef POLLRDBAND +#define POLLRDBAND 0x0080 +#endif + +#ifndef POLLWRNORM +#define POLLWRNORM 0x0100 +#endif + +#ifndef POLLWRBAND +#define POLLWRBAND 0x0200 +#endif + +#ifndef POLLMSG +#define POLLMSG 0x0400 +#endif + +#ifndef POLLREMOVE +#define POLLREMOVE 0x1000 +#endif + +#ifndef POLLRDHUP +#define POLLRDHUP 0x2000 +#endif + +#endif // LLVM_LIBC_MACROS_LINUX_POLL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sched-macros.h b/libc/include/llvm-libc-macros/linux/sched-macros.h new file mode 100644 index 000000000000..597789bb4ce2 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sched-macros.h @@ -0,0 +1,37 @@ +//===-- Definition of macros from sched.h ---------------------------------===// +// +// 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_MACROS_LINUX_SCHED_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H + +// Definitions of SCHED_* macros must match was linux as at: +// https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/sched.h + +// Posix required +#define SCHED_OTHER 0 +#define SCHED_FIFO 1 +#define SCHED_RR 2 + +// Linux extentions +#define SCHED_BATCH 3 +#define SCHED_ISO 4 // Not yet implemented, reserved. +#define SCHED_IDLE 5 +#define SCHED_DEADLINE 6 + +#define CPU_SETSIZE __CPU_SETSIZE +#define NCPUBITS __NCPUBITS +#define CPU_COUNT_S(setsize, set) __sched_getcpucount(setsize, set) +#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t), set) +#define CPU_ZERO_S(setsize, set) __sched_setcpuzero(setsize, set) +#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t), set) +#define CPU_SET_S(cpu, setsize, set) __sched_setcpuset(cpu, setsize, set) +#define CPU_SET(cpu, setsize, set) CPU_SET_S(cpu, sizeof(cpt_set_t), set) +#define CPU_ISSET_S(cpu, setsize, set) __sched_getcpuisset(cpu, setsize, set) +#define CPU_ISSET(cpu, setsize, set) CPU_ISSET_S(cpu, sizeof(cpt_set_t), set) + +#endif // LLVM_LIBC_MACROS_LINUX_SCHED_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/signal-macros.h b/libc/include/llvm-libc-macros/linux/signal-macros.h new file mode 100644 index 000000000000..d220241a3820 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/signal-macros.h @@ -0,0 +1,101 @@ +//===-- Definition of Linux signal number macros --------------------------===// +// +// 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_MACROS_LINUX_SIGNAL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SIGNAL_MACROS_H + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGIOT 6 +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL SIGIO +#define SIGPWR 30 +#define SIGSYS 31 + +// Max signal number +#define NSIG 64 + +// SIGRTMIN is current set to the minimum usable from user mode programs. If +// the libc itself uses some of these signal numbers for private operations, +// then it has to be adjusted in future to reflect that. +#define SIGRTMIN 32 + +#define SIGRTMAX NSIG + +// The kernel sigset is stored as an array of long values. Each bit of this +// array corresponds to a signal, adjusted by 1. That is, bit 0 corresponds +// to signal number 1, bit 1 corresponds to signal number 2 and so on. The +// below macro denotes the size of that array (in number of long words and +// not bytes). +#define __NSIGSET_WORDS (NSIG / (sizeof(unsigned long) * 8)) + +#define SIG_BLOCK 0 // For blocking signals +#define SIG_UNBLOCK 1 // For unblocking signals +#define SIG_SETMASK 2 // For setting signal mask + +// Flag values to be used for setting sigaction.sa_flags. +#define SA_NOCLDSTOP 0x00000001 +#define SA_NOCLDWAIT 0x00000002 +#define SA_SIGINFO 0x00000004 +#define SA_RESTART 0x10000000 +#define SA_RESTORER 0x04000000 +#define SA_ONSTACK 0x08000000 + +// Signal stack flags +#define SS_ONSTACK 0x1 +#define SS_DISABLE 0x2 + +#if defined(__x86_64__) || defined(__i386__) || defined(__riscv) +#define MINSIGSTKSZ 2048 +#define SIGSTKSZ 8192 +#elif defined(__aarch64__) +#define MINSIGSTKSZ 5120 +#define SIGSTKSZ 16384 +#else +#error "Signal stack sizes not defined for your platform." +#endif + +#define SIG_DFL ((void (*)(int))0) +#define SIG_IGN ((void (*)(int))1) +#define SIG_ERR ((void (*)(int))(-1)) + +// SIGCHLD si_codes +#define CLD_EXITED 1 // child has exited +#define CLD_KILLED 2 // child was killed +#define CLD_DUMPED 3 // child terminated abnormally +#define CLD_TRAPPED 4 // traced child has trapped +#define CLD_STOPPED 5 // child has stopped +#define CLD_CONTINUED 6 // stopped child has continued + +#endif // LLVM_LIBC_MACROS_LINUX_SIGNAL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-epoll-macros.h b/libc/include/llvm-libc-macros/linux/sys-epoll-macros.h new file mode 100644 index 000000000000..f73d690908fd --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-epoll-macros.h @@ -0,0 +1,40 @@ +//===-- Macros defined in sys/epoll.h header file -------------------------===// +// +// 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_MACROS_LINUX_SYS_EPOLL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H + +#include "fcntl-macros.h" + +// These are also defined in <linux/eventpoll.h> but that also contains a +// different definition of the epoll_event struct that is different from the +// userspace version. + +#define EPOLL_CLOEXEC O_CLOEXEC + +#define EPOLL_CTL_ADD 1 +#define EPOLL_CTL_DEL 2 +#define EPOLL_CTL_MOD 3 + +#define EPOLLIN 0x1 +#define EPOLLPRI 0x2 +#define EPOLLOUT 0x4 +#define EPOLLERR 0x8 +#define EPOLLHUP 0x10 +#define EPOLLRDNORM 0x40 +#define EPOLLRDBAND 0x80 +#define EPOLLWRNORM 0x100 +#define EPOLLWRBAND 0x200 +#define EPOLLMSG 0x400 +#define EPOLLRDHUP 0x2000 +#define EPOLLEXCLUSIVE 0x10000000 +#define EPOLLWAKEUP 0x20000000 +#define EPOLLONESHOT 0x40000000 +#define EPOLLET 0x80000000 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_EPOLL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h b/libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h new file mode 100644 index 000000000000..41226080084c --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-ioctl-macros.h @@ -0,0 +1,20 @@ +//===-- Definition of macros from sys/ioctl.h -----------------------------===// +// +// 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_MACROS_LINUX_SYS_IOCTL_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_IOCTL_MACROS_H + +// TODO (michaelrj): Finish defining these macros. +// Just defining this macro for the moment since it's all that we need right +// now. The other macros are mostly just constants, but there's some complexity +// around the definitions of macros like _IO, _IOR, _IOW, and _IOWR that I don't +// think is worth digging into right now. +#define TIOCGETD 0x5424 +#define FIONREAD 0x541B + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_IOCTL_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-random-macros.h b/libc/include/llvm-libc-macros/linux/sys-random-macros.h new file mode 100644 index 000000000000..9261e87bdbf6 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-random-macros.h @@ -0,0 +1,17 @@ +//===-- Definition of macros from sys/random.h ----------------------------===// +// +// 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_MACROS_LINUX_SYS_RANDOM_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_RANDOM_MACROS_H + +// Getrandom flags +#define GRND_RANDOM 0x0001 +#define GRND_NONBLOCK 0x0002 +#define GRND_INSECURE 0x0004 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_RANDOM_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-resource-macros.h b/libc/include/llvm-libc-macros/linux/sys-resource-macros.h new file mode 100644 index 000000000000..c9d93c30c35a --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-resource-macros.h @@ -0,0 +1,31 @@ +//===-- Macros defined in sys/resource.h header file ----------------------===// +// +// 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_MACROS_LINUX_SYS_RESOURCE_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_RESOURCE_MACROS_H + +#define RLIMIT_CPU 0 +#define RLIMIT_FSIZE 1 +#define RLIMIT_DATA 2 +#define RLIMIT_STACK 3 +#define RLIMIT_CORE 4 +#define RLIMIT_RSS 5 +#define RLIMIT_NPROC 6 +#define RLIMIT_NOFILE 7 +#define RLIMIT_MEMLOCK 8 +#define RLIMIT_AS 9 +#define RLIMIT_LOCKS 10 +#define RLIMIT_SIGPENDING 11 +#define RLIMIT_MSGQUEUE 12 +#define RLIMIT_NICE 13 +#define RLIMIT_RTPRIO 14 +#define RLIMIT_RTTIME 15 + +#define RLIM_INFINITY (~0UL) + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_RESOURCE_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-socket-macros.h b/libc/include/llvm-libc-macros/linux/sys-socket-macros.h new file mode 100644 index 000000000000..f335200a103b --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-socket-macros.h @@ -0,0 +1,28 @@ +//===-- Definition of macros from sys/socket.h ----------------------------===// +// +// 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_MACROS_LINUX_SYS_SOCKET_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_SOCKET_MACROS_H + +// IEEE Std 1003.1-2017 - basedefs/sys_socket.h.html +// Macro values come from the Linux syscall interface. + +#define AF_UNSPEC 0 // Unspecified +#define AF_UNIX 1 // Unix domain sockets +#define AF_LOCAL 1 // POSIX name for AF_UNIX +#define AF_INET 2 // Internet IPv4 Protocol +#define AF_INET6 10 // IP version 6 + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +#define SOCK_RAW 3 +#define SOCK_RDM 4 +#define SOCK_SEQPACKET 5 +#define SOCK_PACKET 10 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_SOCKET_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-stat-macros.h b/libc/include/llvm-libc-macros/linux/sys-stat-macros.h new file mode 100644 index 000000000000..3013121d0f3c --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-stat-macros.h @@ -0,0 +1,48 @@ +//===-- Definition of macros from sys/stat.h ------------------------------===// +// +// 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_MACROS_LINUX_SYS_STAT_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H + +// Definitions from linux/stat.h +#define S_IFMT 0170000 +#define S_IFSOCK 0140000 +#define S_IFLNK 0120000 +#define S_IFREG 0100000 +#define S_IFBLK 0060000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 + +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 + +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 + +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_STAT_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-time-macros.h b/libc/include/llvm-libc-macros/linux/sys-time-macros.h new file mode 100644 index 000000000000..e97819594adc --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-time-macros.h @@ -0,0 +1,53 @@ +//===-- Definition of macros from sys/time.h ------------------------------===// +// +// 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_MACROS_LINUX_SYS_TIME_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H + +// Add two timevals and put the result in timeval_ptr_result. If the resulting +// usec value is greater than 999,999 then the microseconds are turned into full +// seconds (1,000,000 is subtracted from usec and 1 is added to sec). +#define timeradd(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \ + (timeval_ptr_result)->tv_sec = \ + (timeval_ptr_a)->tv_sec + (timeval_ptr_b)->tv_sec + \ + (((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 ? 1 \ + : 0); \ + (timeval_ptr_result)->tv_usec = \ + (timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec - \ + (((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 \ + ? 1000000 \ + : 0); + +// Subtract two timevals and put the result in timeval_ptr_result. If the +// resulting usec value is less than 0 then 1,000,000 is added to usec and 1 is +// subtracted from sec. +#define timersub(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \ + (timeval_ptr_result)->tv_sec = \ + (timeval_ptr_a)->tv_sec - (timeval_ptr_b)->tv_sec - \ + (((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1 : 0); \ + (timeval_ptr_result)->tv_usec = \ + (timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec + \ + (((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1000000 \ + : 0); + +// Reset a timeval to the epoch. +#define timerclear(timeval_ptr) \ + (timeval_ptr)->tv_sec = 0; \ + (timeval_ptr)->tv_usec = 0; + +// Determine if a timeval is set to the epoch. +#define timerisset(timeval_ptr) \ + (timeval_ptr)->tv_sec != 0 || (timeval_ptr)->tv_usec != 0; + +// Compare two timevals using CMP. +#define timercmp(timeval_ptr_a, timeval_ptr_b, CMP) \ + (((timeval_ptr_a)->tv_sec == (timeval_ptr_b)->tv_sec) \ + ? ((timeval_ptr_a)->tv_usec CMP(timeval_ptr_b)->tv_usec) \ + : ((timeval_ptr_a)->tv_sec CMP(timeval_ptr_b)->tv_sec)) + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h new file mode 100644 index 000000000000..d01cfa71ba39 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h @@ -0,0 +1,27 @@ +//===-- Definition of macros from sys/wait.h ------------------------------===// +// +// 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_MACROS_LINUX_SYS_WAIT_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H + +#include <linux/wait.h> + +#define WCOREDUMP(status) ((status) & WCOREFLAG) +#define WEXITSTATUS(status) (((status) & 0xff00) >> 8) +#define WIFCONTINUED(status) ((status) == 0xffff) +#define WIFEXITED(status) (WTERMSIG(status) == 0) +#define WIFSIGNALED(status) ((WTERMSIG(status) + 1) >= 2) +#define WIFSTOPPED(status) (WTERMSIG(status) == 0x7f) +#define WSTOPSIG(status) WEXITSTATUS(status) +#define WTERMSIG(status) ((status) & 0x7f) + +#define WCOREFLAG 0x80 +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | 0x7f) + +#endif // LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/termios-macros.h b/libc/include/llvm-libc-macros/linux/termios-macros.h new file mode 100644 index 000000000000..668cfe27abaa --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/termios-macros.h @@ -0,0 +1,167 @@ +//===-- Definition of macros from termios.h -------------------------------===// +// +// 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_MACROS_LINUX_TERMIOS_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_TERMIOS_MACROS_H + +// Below are generic definitions of symbolic bit-masks, modes etc. They serve +// most architectures including x86_64, aarch64 but have to be adjusted for few +// architectures MIPS. + +#define NCCS 32 + +// Bit-masks for the c_iflag field of struct termios. +#define IGNBRK 0000001 // Ignore break condition +#define BRKINT 0000002 // Signal interrupt on break +#define IGNPAR 0000004 // Ignore characters with parity errors +#define PARMRK 0000010 // Mark parity and framing errors +#define INPCK 0000020 // Enable input parity check +#define ISTRIP 0000040 // Strip 8th bit off characters +#define INLCR 0000100 // Map NL to CR on input +#define IGNCR 0000200 // Ignore CR +#define ICRNL 0000400 // Map CR to NL on input +#define IUCLC 0001000 // Map uppercase characters to lowercase on input +#define IXON 0002000 // Enable start/stop output control +#define IXANY 0004000 // Enable any character to restart output +#define IXOFF 0010000 // Enable start/stop input control +#define IMAXBEL 0020000 // Ring bell when input queue is full +#define IUTF8 0040000 // Input is UTF8 (not in POSIX) + +// Bit-masks for the c_oflag field of struct termios. +#define OPOST 0000001 // Post-process output +#define OLCUC 0000002 // Map lowercase characters to uppercase on output +#define ONLCR 0000004 // Map NL to CR-NL on output +#define OCRNL 0000010 // Map CR to NL on output +#define ONOCR 0000020 // No CR output at column 0 +#define ONLRET 0000040 // NL performs CR function +#define OFILL 0000100 // Use fill characters for delay +#define OFDEL 0000200 // Fill is DEL +#define NLDLY 0000400 // Select newline delays +#define NL0 0000000 // Newline type 0 +#define NL1 0000400 // Newline type 1 +#define CRDLY 0003000 // Select carriage-return delays +#define CR0 0000000 // Carriage-return delay type 0 +#define CR1 0001000 // Carriage-return delay type 1 +#define CR2 0002000 // Carriage-return delay type 2 +#define CR3 0003000 // Carriage-return delay type 3 +#define TABDLY 0014000 // Select horizontal-tab delays +#define TAB0 0000000 // Horizontal-tab delay type 0 +#define TAB1 0004000 // Horizontal-tab delay type 1 +#define TAB2 0010000 // Horizontal-tab delay type 2 +#define TAB3 0014000 // Expand tabs to spaces +#define BSDLY 0020000 // Select backspace delays +#define BS0 0000000 // Backspace-delay type 0 +#define BS1 0020000 // Backspace-delay type 1 +#define FFDLY 0100000 // Select form-feed delays +#define FF0 0000000 // Form-feed delay type 0 +#define FF1 0100000 // Form-feed delay type 1 +#define VTDLY 0040000 // Select vertical-tab delays +#define VT0 0000000 // Vertical-tab delay type 0 +#define VT1 0040000 // Vertical-tab delay type 1 +#define XTABS 0014000 + +// Symbolic subscripts for the c_cc array. +#define VINTR 0 +#define VQUIT 1 +#define VERASE 2 +#define VKILL 3 +#define VEOF 4 +#define VTIME 5 +#define VMIN 6 +#define VSWTC 7 +#define VSTART 8 +#define VSTOP 9 +#define VSUSP 10 +#define VEOL 11 +#define VREPRINT 12 +#define VDISCARD 13 +#define VWERASE 14 +#define VLNEXT 15 +#define VEOL2 16 + +// Baud rate related definitions +#define CBAUD 000000010017 // Baud speed mask +#define CBAUDX 000000010000 // Extra baud speed mask +#define CIBAUD 002003600000 +#define CMSPAR 010000000000 +#define CRTSCTS 020000000000 +// Baud rates with values representable by the speed_t type. +#define B0 0000000 // Implies hang-up +// A symbol B<NN+> below indicates a baud rate of <NN+>. +#define B50 0000001 +#define B75 0000002 +#define B110 0000003 +#define B134 0000004 +#define B150 0000005 +#define B200 0000006 +#define B300 0000007 +#define B600 0000010 +#define B1200 0000011 +#define B1800 0000012 +#define B2400 0000013 +#define B4800 0000014 +#define B9600 0000015 +#define B19200 0000016 +#define B38400 0000017 +// Extra baud rates +#define B57600 0010001 +#define B115200 0010002 +#define B230400 0010003 +#define B460800 0010004 +#define B500000 0010005 +#define B576000 0010006 +#define B921600 0010007 +#define B1000000 0010010 +#define B1152000 0010011 +#define B1500000 0010012 +#define B2000000 0010013 +#define B2500000 0010014 +#define B3000000 0010015 +#define B3500000 0010016 +#define B4000000 0010017 + +// Control mode bits for use in the c_cflag field of struct termios. +#define CSIZE 0000060 // Mask for character size bits +#define CS5 0000000 +#define CS6 0000020 +#define CS7 0000040 +#define CS8 0000060 +#define CSTOPB 0000100 // Send two bits, else one +#define CREAD 0000200 // Enable receiver +#define PARENB 0000400 // Parity enable +#define PARODD 0001000 // Odd parity, else even +#define HUPCL 0002000 // Hang up on last close +#define CLOCAL 0004000 // Ignore modem status lines + +// Local mode bits for use in the c_lflag field of struct termios. +#define ISIG 0000001 // Enable signals +#define ICANON 0000002 // Canonical input (erase and kill processing) +#define ECHO 0000010 // Enable echo +#define ECHOE 0000020 // Echo erase character as error-correcting backspace +#define ECHOK 0000040 // Echo KILL +#define ECHONL 0000100 // Echo NL +#define NOFLSH 0000200 // Disable flush after interrupt or quit +#define TOSTOP 0000400 // Send SIGTTOU for background output + +// Attribute selection +#define TCSANOW 0 // Change attributes immediately +#define TCSADRAIN 1 // Change attributes when output has drained +#define TCSAFLUSH 2 // Same as TCSADRAIN and flush pending Output + +// Symbolic constants for use with tcflush function. +#define TCIFLUSH 0 // Flush pending input +#define TCIOFLUSH 1 // Flush pending input and unstransmitted output +#define TCOFLUSH 2 // Flush unstransmitted output + +// Symbolic constantf for use with tcflow function. +#define TCOOFF 0 // Transmit a STOP character, intended to suspend input data +#define TCOON 1 // Transmit a START character, intended to restart input data +#define TCIOFF 2 // Suspend output +#define TCION 3 // Restart output + +#endif // LLVM_LIBC_MACROS_LINUX_TERMIOS_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/time-macros.h b/libc/include/llvm-libc-macros/linux/time-macros.h new file mode 100644 index 000000000000..407a1eb30eea --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/time-macros.h @@ -0,0 +1,26 @@ +//===-- Definition of macros from time.h ---------------------------------===// +// +// 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_MACROS_LINUX_TIME_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_TIME_MACROS_H + +// clock type macros +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 1 +#define CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOCK_THREAD_CPUTIME_ID 3 +#define CLOCK_MONOTONIC_RAW 4 +#define CLOCK_REALTIME_COARSE 5 +#define CLOCK_MONOTONIC_COARSE 6 +#define CLOCK_BOOTTIME 7 +#define CLOCK_REALTIME_ALARM 8 +#define CLOCK_BOOTTIME_ALARM 9 + +#define CLOCKS_PER_SEC 1000000 + +#endif // LLVM_LIBC_MACROS_LINUX_TIME_MACROS_H diff --git a/libc/include/llvm-libc-macros/linux/unistd-macros.h b/libc/include/llvm-libc-macros/linux/unistd-macros.h new file mode 100644 index 000000000000..a4c8e3cd91f7 --- /dev/null +++ b/libc/include/llvm-libc-macros/linux/unistd-macros.h @@ -0,0 +1,57 @@ +//===-- Definition of macros from unistd.h --------------------------------===// +// +// 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_MACROS_LINUX_UNISTD_MACROS_H +#define LLVM_LIBC_MACROS_LINUX_UNISTD_MACROS_H + +// Values for mode argument to the access(...) function. +#define F_OK 0 +#define X_OK 1 +#define W_OK 2 +#define R_OK 4 + +#define _SC_PAGESIZE 1 +#define _SC_PAGE_SIZE _SC_PAGESIZE + +#define _PC_FILESIZEBITS 0 +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_2_SYMLINKS 7 +#define _PC_ALLOC_SIZE_MIN 8 +#define _PC_REC_INCR_XFER_SIZE 9 +#define _PC_REC_MAX_XFER_SIZE 10 +#define _PC_REC_MIN_XFER_SIZE 11 +#define _PC_REC_XFER_ALIGN 12 +#define _PC_SYMLINK_MAX 13 +#define _PC_CHOWN_RESTRICTED 14 +#define _PC_NO_TRUNC 15 +#define _PC_VDISABLE 16 +#define _PC_ASYNC_IO 17 +#define _PC_PRIO_IO 18 +#define _PC_SYNC_IO 19 + +// TODO: Move these limit macros to a separate file +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_NO_TRUNC 1 +#define _POSIX_VDISABLE '\0' + +// Macro to set up the call to the __llvm_libc_syscall function +// This is to prevent the call from having fewer than 6 arguments, since six +// arguments are always passed to the syscall. Unnecessary arguments are +// ignored. +#define __syscall_helper(sysno, arg1, arg2, arg3, arg4, arg5, arg6, ...) \ + __llvm_libc_syscall((long)(sysno), (long)(arg1), (long)(arg2), (long)(arg3), \ + (long)(arg4), (long)(arg5), (long)(arg6)) +#define syscall(...) __syscall_helper(__VA_ARGS__, 0, 1, 2, 3, 4, 5, 6) + +#endif // LLVM_LIBC_MACROS_LINUX_UNISTD_MACROS_H |
