[libc-commits] [libc] [libc] Add more Linux-specific macro for fcntl and sched. (PR #213727)

via libc-commits libc-commits at lists.llvm.org
Mon Aug 3 10:53:38 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Alexey Samsonov (vonosmas)

<details>
<summary>Changes</summary>

* Add more `O_` flags (in particular, `O_LARGEFILE`) to fcntl-macros and group all creation/status flags (shared and arch-specific) together.
* Add Linux `CLONE_` flags to sched-macros (to be exposed from `<sched.h>`). Those are also provided in `<linux/sched.h>` kernel header, but the libc users often expect to find them in regular `<sched.h>` as those are passed to `clone()` syscall wrapper. Migrate internal Linux thread implementation to use our own header (instead of Linux kernel) for these macro.

---
Full diff: https://github.com/llvm/llvm-project/pull/213727.diff


4 Files Affected:

- (modified) libc/include/llvm-libc-macros/linux/fcntl-macros.h (+23-23) 
- (modified) libc/include/llvm-libc-macros/linux/sched-macros.h (+28) 
- (modified) libc/src/__support/threads/linux/CMakeLists.txt (+1) 
- (modified) libc/src/__support/threads/linux/thread.cpp (+1-1) 


``````````diff
diff --git a/libc/include/llvm-libc-macros/linux/fcntl-macros.h b/libc/include/llvm-libc-macros/linux/fcntl-macros.h
index 74d406f742f38..8dcc177434cec 100644
--- a/libc/include/llvm-libc-macros/linux/fcntl-macros.h
+++ b/libc/include/llvm-libc-macros/linux/fcntl-macros.h
@@ -9,35 +9,35 @@
 #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
+// File creation and file status flags.
+#define O_APPEND 000002000
+#define O_ASYNC 000020000
+#define O_CLOEXEC 002000000
+#define O_CREAT 000000100
+#define O_DSYNC 000010000
+#define O_EXCL 000000200
+#define O_NOATIME 001000000
+#define O_NOCTTY 000000400
+#define O_NONBLOCK 000004000
+#define O_NDELAY O_NONBLOCK
 #define O_PATH 010000000
+#define O_SYNC 004010000
+#define O_TRUNC 000001000
 
 #ifdef __aarch64__
-#define O_DIRECTORY 040000
+#define O_DIRECT 000200000
+#define O_DIRECTORY 000040000
+#define O_NOFOLLOW 000100000
+#define O_LARGEFILE 000040000
+#define O_TMPFILE 020040000
 #else
-#define O_DIRECTORY 00200000
+#define O_DIRECT 000040000
+#define O_DIRECTORY 000200000
+#define O_NOFOLLOW 000400000
+#define O_LARGEFILE 000100000
+#define O_TMPFILE 020200000
 #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
 
diff --git a/libc/include/llvm-libc-macros/linux/sched-macros.h b/libc/include/llvm-libc-macros/linux/sched-macros.h
index 28719b59d019a..c65d52d6f8c46 100644
--- a/libc/include/llvm-libc-macros/linux/sched-macros.h
+++ b/libc/include/llvm-libc-macros/linux/sched-macros.h
@@ -23,6 +23,34 @@
 #define SCHED_IDLE 5
 #define SCHED_DEADLINE 6
 
+// Linux-specific flags for clone.
+#define CLONE_CHILD_CLEARTID 0x00200000
+#define CLONE_CHILD_SETTID 0x01000000
+#define CLONE_CLEAR_SIGHAND 0x100000000
+#define CLONE_DETACHED 0x00400000
+#define CLONE_FILES 0x00000400
+#define CLONE_FS 0x00000200
+#define CLONE_INTO_CGROUP 0x200000000
+#define CLONE_IO 0x80000000
+#define CLONE_NEWCGROUP 0x02000000
+#define CLONE_NEWIPC 0x08000000
+#define CLONE_NEWNET 0x40000000
+#define CLONE_NEWNS 0x00020000
+#define CLONE_NEWPID 0x20000000
+#define CLONE_NEWUSER 0x10000000
+#define CLONE_NEWUTS 0x04000000
+#define CLONE_PARENT 0x00008000
+#define CLONE_PARENT_SETTID 0x00100000
+#define CLONE_PIDFD 0x00001000
+#define CLONE_PTRACE 0x00002000
+#define CLONE_SETTLS 0x00080000
+#define CLONE_SIGHAND 0x00000800
+#define CLONE_SYSVSEM 0x00040000
+#define CLONE_THREAD 0x00010000
+#define CLONE_UNTRACED 0x00800000
+#define CLONE_VFORK 0x00004000
+#define CLONE_VM 0x00000100
+
 #define CPU_SETSIZE __CPU_SETSIZE
 #define NCPUBITS __NCPUBITS
 #define CPU_AND_S(setsize, destset, srcset1, srcset2)                          \
diff --git a/libc/src/__support/threads/linux/CMakeLists.txt b/libc/src/__support/threads/linux/CMakeLists.txt
index 1124d1254ba76..14d57299dfd3f 100644
--- a/libc/src/__support/threads/linux/CMakeLists.txt
+++ b/libc/src/__support/threads/linux/CMakeLists.txt
@@ -34,6 +34,7 @@ add_object_library(
     libc.include.sys_syscall
     libc.hdr.fcntl_macros
     libc.hdr.errno_macros
+    libc.hdr.sched_macros
     libc.hdr.sys_mman_macros
     libc.src.errno.errno
     libc.src.__support.CPP.atomic
diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp
index 704916fff95e6..9142d8ff10b00 100644
--- a/libc/src/__support/threads/linux/thread.cpp
+++ b/libc/src/__support/threads/linux/thread.cpp
@@ -34,11 +34,11 @@
 
 #include "hdr/errno_macros.h"
 #include "hdr/fcntl_macros.h"
+#include "hdr/sched_macros.h" // For CLONE_* flags.
 #include "hdr/stdint_proxy.h"
 #include "hdr/sys_mman_macros.h" // For PROT_* and MAP_* definitions.
 #include <linux/param.h> // For EXEC_PAGESIZE.
 #include <linux/prctl.h> // For PR_SET_NAME
-#include <linux/sched.h> // For CLONE_* flags.
 #include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE_DECL {

``````````

</details>


https://github.com/llvm/llvm-project/pull/213727


More information about the libc-commits mailing list