diff options
author | Michael Jones <michaelrj@google.com> | 2022-10-11 15:30:07 -0700 |
---|---|---|
committer | Michael Jones <michaelrj@google.com> | 2022-10-12 13:19:50 -0700 |
commit | 35a4fe4c0bf5f02c2eade1d97cfbda263a9285e1 (patch) | |
tree | 004964b442c3b61af44e60104b3550c9514e07d5 /libc/include | |
parent | bb7069626c8db502c4e5dbe915eca42200fb25e2 (diff) | |
download | llvm-35a4fe4c0bf5f02c2eade1d97cfbda263a9285e1.tar.gz |
[libc] add headers sys/auxv sys/prctl and sys/time
These headers are uncommonly used, and from extensions, but some basic
support is needed. Macros have been added where available.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D135731
Diffstat (limited to 'libc/include')
-rw-r--r-- | libc/include/CMakeLists.txt | 27 | ||||
-rw-r--r-- | libc/include/llvm-libc-macros/CMakeLists.txt | 14 | ||||
-rw-r--r-- | libc/include/llvm-libc-macros/linux/CMakeLists.txt | 6 | ||||
-rw-r--r-- | libc/include/llvm-libc-macros/linux/sys-time-macros.h | 53 | ||||
-rw-r--r-- | libc/include/llvm-libc-macros/sys-auxv-macros.h | 43 | ||||
-rw-r--r-- | libc/include/llvm-libc-macros/sys-time-macros.h | 16 | ||||
-rw-r--r-- | libc/include/sys/auxv.h.def | 18 | ||||
-rw-r--r-- | libc/include/sys/prctl.h.def | 22 | ||||
-rw-r--r-- | libc/include/sys/time.h.def | 20 |
9 files changed, 219 insertions, 0 deletions
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt index 4d77ddf27d59..35e84b7ec97e 100644 --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -229,6 +229,15 @@ add_gen_header( 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 GEN_HDR sys/ioctl.h @@ -249,6 +258,14 @@ add_gen_header( ) 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 GEN_HDR sys/random.h @@ -302,6 +319,16 @@ add_gen_header( ) 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 GEN_HDR sys/utsname.h diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt index 2b69a3b60644..8e8dbae0d852 100644 --- a/libc/include/llvm-libc-macros/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/CMakeLists.txt @@ -37,6 +37,12 @@ add_header( ) add_header( + sys_auxv_macros + HDR + sys-auxv-macros.h +) + +add_header( sys_ioctl_macros HDR sys-ioctl-macros.h @@ -78,6 +84,14 @@ add_header( ) add_header( + sys_time_macros + HDR + sys-time-macros.h + DEPENDS + .linux.sys_time_macros +) + +add_header( sys_wait_macros HDR sys-wait-macros.h diff --git a/libc/include/llvm-libc-macros/linux/CMakeLists.txt b/libc/include/llvm-libc-macros/linux/CMakeLists.txt index 5857290f333a..52b826837027 100644 --- a/libc/include/llvm-libc-macros/linux/CMakeLists.txt +++ b/libc/include/llvm-libc-macros/linux/CMakeLists.txt @@ -53,6 +53,12 @@ add_header( ) add_header( + sys_time_macros + HDR + sys-time-macros.h +) + +add_header( unistd_macros HDR unistd-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..06ae43f0e005 --- /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 index 000000000000..a57c6018ea0a --- /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 index 000000000000..5254cab0ad22 --- /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 index 000000000000..504c2f68cb1e --- /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 <llvm-libc-macros/sys-auxv-macros.h> + +%%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 index 000000000000..3c29719837ca --- /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 <linux/prctl.h> + +// 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 index 000000000000..9a3bd7bb49f8 --- /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 <llvm-libc-types/struct_timeval.h> + +#include <llvm-libc-macros/sys-time-macros.h> + +%%public_api() + +#endif // LLVM_LIBC_SYS_TIME_H |