summaryrefslogtreecommitdiff
path: root/libc/include
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2022-10-04 06:43:59 +0000
committerSiva Chandra Reddy <sivachandra@google.com>2022-10-04 19:12:08 +0000
commite3638e83db086e77243d0673a4ce8a0b4b330d42 (patch)
tree8b24d0e259f9af3d6563304cad1b4d05a7262ca7 /libc/include
parentb39b805ad52ca5a843412f2b1ecf11989cddff90 (diff)
downloadllvm-e3638e83db086e77243d0673a4ce8a0b4b330d42.tar.gz
[libc] Add a minimal implementation of the POSIX fork function.
A very simple and minimal implementation of fork is added. Future changes will add more functionality to satisfy POSIX and Linux requirements. An implementation of wait and a few support macros in sys/wait.h have also been added to help with testing the fork function. Reviewed By: lntue, michaelrj Differential Revision: https://reviews.llvm.org/D135131
Diffstat (limited to 'libc/include')
-rw-r--r--libc/include/CMakeLists.txt11
-rw-r--r--libc/include/llvm-libc-macros/CMakeLists.txt8
-rw-r--r--libc/include/llvm-libc-macros/linux/CMakeLists.txt6
-rw-r--r--libc/include/llvm-libc-macros/linux/sys-wait-macros.h17
-rw-r--r--libc/include/llvm-libc-macros/sys-wait-macros.h16
-rw-r--r--libc/include/sys/wait.h.def18
6 files changed, 76 insertions, 0 deletions
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 70bf4d663f70..3998d7228e68 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -174,6 +174,7 @@ add_gen_header(
.llvm_libc_common_h
.llvm-libc-macros.file_seek_macros
.llvm-libc-macros.unistd_macros
+ .llvm-libc-types.off_t
.llvm-libc-types.pid_t
.llvm-libc-types.size_t
.llvm-libc-types.ssize_t
@@ -273,6 +274,16 @@ add_gen_header(
.llvm-libc-types.struct_utsname
)
+add_gen_header(
+ sys_wait
+ DEF_FILE sys/wait.h.def
+ GEN_HDR sys/wait.h
+ DEPENDS
+ .llvm_libc_common_h
+ .llvm-libc-macros.sys_wait_macros
+ .llvm-libc-types.pid_t
+)
+
if(NOT LLVM_LIBC_FULL_BUILD)
# We don't install headers in non-fullbuild mode.
return()
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index fbf8cef92dcd..740802cd4429 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -47,6 +47,14 @@ add_header(
)
add_header(
+ sys_wait_macros
+ HDR
+ sys-wait-macros.h
+ DEPENDS
+ .linux.sys_wait_macros
+)
+
+add_header(
time_macros
HDR
time-macros.h
diff --git a/libc/include/llvm-libc-macros/linux/CMakeLists.txt b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
index e0dcb7c9058b..cf6fe04d28d6 100644
--- a/libc/include/llvm-libc-macros/linux/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/linux/CMakeLists.txt
@@ -17,6 +17,12 @@ add_header(
)
add_header(
+ sys_wait_macros
+ HDR
+ sys-wait-macros.h
+)
+
+add_header(
time_macros
HDR
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..5b5ad22ecae1
--- /dev/null
+++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h
@@ -0,0 +1,17 @@
+//===-- 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
+
+// Wait status info macros
+#define WTERMSIG(status) (((status)&0x7F))
+#define WIFEXITED(status) (WTERMSIG(status) == 0)
+#define WEXITSTATUS(status) (((status)&0xFF00) >> 8)
+
+#endif // __LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H
diff --git a/libc/include/llvm-libc-macros/sys-wait-macros.h b/libc/include/llvm-libc-macros/sys-wait-macros.h
new file mode 100644
index 000000000000..ea58fccecaff
--- /dev/null
+++ b/libc/include/llvm-libc-macros/sys-wait-macros.h
@@ -0,0 +1,16 @@
+//===-- Macros defined in sys/wait.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_WAIT_MACROS_H
+#define __LLVM_LIBC_MACROS_SYS_WAIT_MACROS_H
+
+#ifdef __linux__
+#include "linux/sys-wait-macros.h"
+#endif
+
+#endif // __LLVM_LIBC_MACROS_SYS_WAIT_MACROS_H
diff --git a/libc/include/sys/wait.h.def b/libc/include/sys/wait.h.def
new file mode 100644
index 000000000000..b4fcce4d1652
--- /dev/null
+++ b/libc/include/sys/wait.h.def
@@ -0,0 +1,18 @@
+//===-- POSIX header 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_SYS_WAIT_H
+#define LLVM_LIBC_SYS_WAIT_H
+
+#include <__llvm-libc-common.h>
+
+#include <llvm-libc-macros/sys-wait-macros.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_SYS_WAIT_H