diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt --- a/libc/config/linux/x86_64/headers.txt +++ b/libc/config/linux/x86_64/headers.txt @@ -10,6 +10,7 @@ libc.include.pthread libc.include.sched libc.include.signal + libc.include.spawn libc.include.stdio libc.include.stdlib libc.include.string @@ -17,12 +18,15 @@ libc.include.time libc.include.unistd + libc.include.sys_auxv libc.include.sys_ioctl libc.include.sys_mman + libc.include.sys_prctl libc.include.sys_random libc.include.sys_resource libc.include.sys_stat libc.include.sys_syscall + libc.include.sys_time libc.include.sys_utsname libc.include.sys_wait ) diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -228,6 +228,15 @@ # them. file(MAKE_DIRECTORY "sys") +add_gen_header( + sys_auxv + DEF_FILE sys/auxv.h.def + GEN_HDR sys/auxv.h + DEPENDS + .llvm_libc_common_h + .llvm-libc-macros.sys_auxv_macros +) + add_gen_header( sys_ioctl DEF_FILE sys/ioctl.h.def @@ -248,6 +257,14 @@ .llvm-libc-macros.sys_mman_macros ) +add_gen_header( + sys_prctl + DEF_FILE sys/prctl.h.def + GEN_HDR sys/prctl.h + DEPENDS + .llvm_libc_common_h +) + add_gen_header( sys_random DEF_FILE sys/random.h.def @@ -301,6 +318,16 @@ ../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc ) +add_gen_header( + sys_time + DEF_FILE sys/time.h.def + GEN_HDR sys/time.h + DEPENDS + .llvm_libc_common_h + .llvm-libc-types.struct_timeval + .llvm-libc-macros.sys_time_macros +) + add_gen_header( sys_utsname DEF_FILE sys/utsname.h.def diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt --- a/libc/include/llvm-libc-macros/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/CMakeLists.txt @@ -36,6 +36,12 @@ stdlib-macros.h ) +add_header( + sys_auxv_macros + HDR + sys-auxv-macros.h +) + add_header( sys_ioctl_macros HDR @@ -77,6 +83,14 @@ .linux.sys_resource_macros ) +add_header( + sys_time_macros + HDR + sys-time-macros.h + DEPENDS + .linux.sys_time_macros +) + add_header( sys_wait_macros HDR diff --git a/libc/include/llvm-libc-macros/linux/CMakeLists.txt b/libc/include/llvm-libc-macros/linux/CMakeLists.txt --- a/libc/include/llvm-libc-macros/linux/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/linux/CMakeLists.txt @@ -52,6 +52,12 @@ sys-stat-macros.h ) +add_header( + sys_time_macros + HDR + sys-time-macros.h +) + add_header( unistd_macros HDR 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 --- /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/sys-auxv-macros.h b/libc/include/llvm-libc-macros/sys-auxv-macros.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-auxv-macros.h @@ -0,0 +1,43 @@ +//===-- Macros defined in sys/auxv.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_AUXV_MACROS_H +#define __LLVM_LIBC_MACROS_AUXV_MACROS_H + +// Macros defining the aux vector indexes. +#define AT_NULL 0 +#define AT_IGNORE 1 +#define AT_EXECFD 2 +#define AT_PHDR 3 +#define AT_PHENT 4 +#define AT_PHNUM 5 +#define AT_PAGESZ 6 +#define AT_BASE 7 +#define AT_FLAGS 8 +#define AT_ENTRY 9 +#define AT_NOTELF 10 +#define AT_UID 11 +#define AT_EUID 12 +#define AT_GID 13 +#define AT_EGID 14 +#define AT_PLATFORM 15 +#define AT_HWCAP 16 +#define AT_CLKTCK 17 + +#define AT_SECURE 23 +#define AT_BASE_PLATFORM 24 +#define AT_RANDOM 25 +#define AT_HWCAP2 26 + +#define AT_EXECFN 31 + +#ifndef AT_MINSIGSTKSZ +#define AT_MINSIGSTKSZ 51 +#endif + +#endif // __LLVM_LIBC_MACROS_AUXV_MACROS_H diff --git a/libc/include/llvm-libc-macros/sys-time-macros.h b/libc/include/llvm-libc-macros/sys-time-macros.h new file mode 100644 --- /dev/null +++ b/libc/include/llvm-libc-macros/sys-time-macros.h @@ -0,0 +1,16 @@ +//===-- Macros defined in sys/time.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_SYS_TIME_MACROS_H +#define __LLVM_LIBC_MACROS_SYS_TIME_MACROS_H + +#ifdef __unix__ +#include "linux/sys-time-macros.h" +#endif + +#endif // __LLVM_LIBC_MACROS_SYS_TIME_MACROS_H diff --git a/libc/include/sys/auxv.h.def b/libc/include/sys/auxv.h.def new file mode 100644 --- /dev/null +++ b/libc/include/sys/auxv.h.def @@ -0,0 +1,18 @@ +//===-- GNU header auxv.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_SYS_AUXV_H +#define LLVM_LIBC_SYS_AUXV_H + +#include <__llvm-libc-common.h> + +#include + +%%public_api() + +#endif // LLVM_LIBC_SYS_AUXV_H diff --git a/libc/include/sys/prctl.h.def b/libc/include/sys/prctl.h.def new file mode 100644 --- /dev/null +++ b/libc/include/sys/prctl.h.def @@ -0,0 +1,22 @@ +//===-- Linux header prctl.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_SYS_PRCTL_H +#define LLVM_LIBC_SYS_PRCTL_H + +#include <__llvm-libc-common.h> + +// Process control is highly platform specific, so the platform usually defines +// the macros itself. +#include + +// TODO: Define the prctl macros. + +%%public_api() + +#endif // LLVM_LIBC_SYS_PRCTL_H diff --git a/libc/include/sys/time.h.def b/libc/include/sys/time.h.def new file mode 100644 --- /dev/null +++ b/libc/include/sys/time.h.def @@ -0,0 +1,20 @@ +//===-- Linux header 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_SYS_TIME_H +#define LLVM_LIBC_SYS_TIME_H + +#include <__llvm-libc-common.h> + +#include + +#include + +%%public_api() + +#endif // LLVM_LIBC_SYS_TIME_H diff --git a/libc/spec/gnu_ext.td b/libc/spec/gnu_ext.td --- a/libc/spec/gnu_ext.td +++ b/libc/spec/gnu_ext.td @@ -159,6 +159,14 @@ ] >; + HeaderSpec SysAuxv = HeaderSpec< + "sys/auxv.h", + [], // Macros + [], // Types + [], // Enumerations + [] // Functions + >; + HeaderSpec SendFile = HeaderSpec< "sys/sendfile.h", [], // Macros @@ -194,6 +202,7 @@ PThread, Sched, SendFile, + SysAuxv, StdIO, String, UniStd, diff --git a/libc/spec/linux.td b/libc/spec/linux.td --- a/libc/spec/linux.td +++ b/libc/spec/linux.td @@ -1,3 +1,5 @@ +def StructTimevalType : NamedType<"struct timeval">; + def Linux : StandardSpec<"Linux"> { HeaderSpec Errno = HeaderSpec< "errno.h", @@ -63,6 +65,15 @@ [Macro<"MAP_ANONYMOUS">] >; + + HeaderSpec SysPrctl = HeaderSpec< + "sys/prctl.h", + [], // Macros + [], // Types + [], // Enumerations + [] // Functions + >; + HeaderSpec SysRandom = HeaderSpec< "sys/random.h", [ @@ -85,6 +96,20 @@ ] >; + HeaderSpec SysTime = HeaderSpec< + "sys/time.h", + [ + Macro<"timeradd">, + Macro<"timersub">, + Macro<"timerclear">, + Macro<"timerisset">, + Macro<"timercmp">, + ], + [StructTimevalType], // Types + [], // Enumerations + [] // Functions + >; + HeaderSpec Signal = HeaderSpec< "signal.h", [ @@ -130,7 +155,9 @@ let Headers = [ Errno, SysMMan, + SysPrctl, SysRandom, + SysTime, Signal, ]; }