[libc-commits] [libc] 35a4fe4 - [libc] add headers sys/auxv sys/prctl and sys/time
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Oct 12 13:20:01 PDT 2022
Author: Michael Jones
Date: 2022-10-12T13:19:50-07:00
New Revision: 35a4fe4c0bf5f02c2eade1d97cfbda263a9285e1
URL: https://github.com/llvm/llvm-project/commit/35a4fe4c0bf5f02c2eade1d97cfbda263a9285e1
DIFF: https://github.com/llvm/llvm-project/commit/35a4fe4c0bf5f02c2eade1d97cfbda263a9285e1.diff
LOG: [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
Added:
libc/include/llvm-libc-macros/linux/sys-time-macros.h
libc/include/llvm-libc-macros/sys-auxv-macros.h
libc/include/llvm-libc-macros/sys-time-macros.h
libc/include/sys/auxv.h.def
libc/include/sys/prctl.h.def
libc/include/sys/time.h.def
Modified:
libc/config/linux/x86_64/headers.txt
libc/include/CMakeLists.txt
libc/include/llvm-libc-macros/CMakeLists.txt
libc/include/llvm-libc-macros/linux/CMakeLists.txt
libc/spec/gnu_ext.td
libc/spec/linux.td
Removed:
################################################################################
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 145143a4e6bf..d1c9a093b068 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -10,6 +10,7 @@ set(TARGET_PUBLIC_HEADERS
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 @@ set(TARGET_PUBLIC_HEADERS
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
index 4d77ddf27d59..35e84b7ec97e 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -228,6 +228,15 @@ add_gen_header(
# 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 @@ add_gen_header(
.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 @@ add_gen_header(
../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
index 2b69a3b60644..8e8dbae0d852 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -36,6 +36,12 @@ add_header(
stdlib-macros.h
)
+add_header(
+ sys_auxv_macros
+ HDR
+ sys-auxv-macros.h
+)
+
add_header(
sys_ioctl_macros
HDR
@@ -77,6 +83,14 @@ add_header(
.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
index 5857290f333a..52b826837027 100644
--- a/libc/include/llvm-libc-macros/linux/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
@@ -52,6 +52,12 @@ add_header(
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
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
diff --git a/libc/spec/gnu_ext.td b/libc/spec/gnu_ext.td
index 5c4c9e341233..ebadbb6f12c4 100644
--- a/libc/spec/gnu_ext.td
+++ b/libc/spec/gnu_ext.td
@@ -159,6 +159,14 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
]
>;
+ HeaderSpec SysAuxv = HeaderSpec<
+ "sys/auxv.h",
+ [], // Macros
+ [], // Types
+ [], // Enumerations
+ [] // Functions
+ >;
+
HeaderSpec SendFile = HeaderSpec<
"sys/sendfile.h",
[], // Macros
@@ -194,6 +202,7 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
PThread,
Sched,
SendFile,
+ SysAuxv,
StdIO,
String,
UniStd,
diff --git a/libc/spec/linux.td b/libc/spec/linux.td
index da6ceae66f76..c6835c217602 100644
--- 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 @@ def Linux : StandardSpec<"Linux"> {
[Macro<"MAP_ANONYMOUS">]
>;
+
+ HeaderSpec SysPrctl = HeaderSpec<
+ "sys/prctl.h",
+ [], // Macros
+ [], // Types
+ [], // Enumerations
+ [] // Functions
+ >;
+
HeaderSpec SysRandom = HeaderSpec<
"sys/random.h",
[
@@ -85,6 +96,20 @@ def Linux : StandardSpec<"Linux"> {
]
>;
+ 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 @@ def Linux : StandardSpec<"Linux"> {
let Headers = [
Errno,
SysMMan,
+ SysPrctl,
SysRandom,
+ SysTime,
Signal,
];
}
More information about the libc-commits
mailing list