[libc-commits] [libc] fa23e82 - [libc] Add <sys/user.h> for Linux-x86_64 (#220809)

via libc-commits libc-commits at lists.llvm.org
Thu Sep 3 08:23:03 PDT 2026


Author: Alexey Samsonov
Date: 2026-09-03T08:22:58-07:00
New Revision: fa23e82fa0715ed5db767bbf9f5b312f2a78834d

URL: https://github.com/llvm/llvm-project/commit/fa23e82fa0715ed5db767bbf9f5b312f2a78834d
DIFF: https://github.com/llvm/llvm-project/commit/fa23e82fa0715ed5db767bbf9f5b312f2a78834d.diff

LOG: [libc] Add <sys/user.h> for Linux-x86_64 (#220809)

This is a non-POSIX header, which is nevertheless provided in some
environments to give access to arch-specific information, such as
register sets. Linux `ptrace` man page for `PTRACE_GETREGS` flags
references `<sys/user.h>` explcitly :
https://man7.org/linux/man-pages/man2/ptrace.2.html

Users get to rely on that to explore the thread/process state
e.g. LeakSanitizer does it to collect live pointers that can be present
in the registers:

https://github.com/llvm/llvm-project/blob/3993ccd4f07a5feee69764efa5bc9b53a0ce19ae/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp#L41

Provide this header and define `user_regs_struct` struct on Linux
x86_64.

Added: 
    libc/include/llvm-libc-types/struct_user_regs_struct.h
    libc/include/llvm-libc-types/x86_64/struct_user_regs_struct.h
    libc/include/sys/user.yaml

Modified: 
    libc/config/linux/x86_64/headers.txt
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/include/llvm-libc-types/x86_64/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 1413b9775c1cb..ac06e5b5e742d 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -81,6 +81,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_uio
     libc.include.sys_un
     libc.include.sys_unistd
+    libc.include.sys_user
     libc.include.sys_utsname
     libc.include.sys_vfs
     libc.include.sys_wait

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 80f6f0e34ccc0..87b52bb756d11 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -1046,6 +1046,15 @@ add_header_macro(
     .llvm-libc-types.struct_sockaddr_un
 )
 
+add_header_macro(
+  sys_user
+  ../libc/include/sys/user.yaml
+  sys/user.h
+  DEPENDS
+    .llvm_libc_common_h
+    .llvm-libc-types.struct_user_regs_struct
+)
+
 add_header_macro(
   sys_vfs
   ../libc/include/sys/vfs.yaml

diff  --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 9bf17a14cee69..381098968d2ec 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -619,6 +619,7 @@ endif()
 
 add_type_header(mcontext_t HDR mcontext_t.h)
 add_type_header(ucontext_t HDR ucontext_t.h)
+add_type_header(struct_user_regs_struct HDR struct_user_regs_struct.h)
 
 # UEFI
 add_header(EFI_GUID HDR EFI_GUID.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)

diff  --git a/libc/include/llvm-libc-types/struct_user_regs_struct.h b/libc/include/llvm-libc-types/struct_user_regs_struct.h
new file mode 100644
index 0000000000000..a8a0fd7356d2f
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_user_regs_struct.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of type struct user_regs_struct.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_USER_REGS_STRUCT_H
+#define LLVM_LIBC_TYPES_STRUCT_USER_REGS_STRUCT_H
+
+#if defined(__x86_64__)
+#include "x86_64/struct_user_regs_struct.h"
+#else
+#error "struct user_regs_struct not available for your target architecture."
+#endif
+
+#endif // LLVM_LIBC_TYPES_STRUCT_USER_REGS_STRUCT_H

diff  --git a/libc/include/llvm-libc-types/x86_64/CMakeLists.txt b/libc/include/llvm-libc-types/x86_64/CMakeLists.txt
index a0b329365b1f1..ec5202f9881f0 100644
--- a/libc/include/llvm-libc-types/x86_64/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/x86_64/CMakeLists.txt
@@ -4,6 +4,12 @@ add_header(
     mcontext_t.h
 )
 
+add_header(
+  struct_user_regs_struct
+  HDR
+    struct_user_regs_struct.h
+)
+
 add_header(
   ucontext_t
   HDR

diff  --git a/libc/include/llvm-libc-types/x86_64/struct_user_regs_struct.h b/libc/include/llvm-libc-types/x86_64/struct_user_regs_struct.h
new file mode 100644
index 0000000000000..4a95ed44889c3
--- /dev/null
+++ b/libc/include/llvm-libc-types/x86_64/struct_user_regs_struct.h
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct user_regs_struct for x86_64.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_X86_64_STRUCT_USER_REGS_STRUCT_H
+#define LLVM_LIBC_TYPES_X86_64_STRUCT_USER_REGS_STRUCT_H
+
+struct user_regs_struct {
+  unsigned long long r15;
+  unsigned long long r14;
+  unsigned long long r13;
+  unsigned long long r12;
+  unsigned long long rbp;
+  unsigned long long rbx;
+  unsigned long long r11;
+  unsigned long long r10;
+  unsigned long long r9;
+  unsigned long long r8;
+  unsigned long long rax;
+  unsigned long long rcx;
+  unsigned long long rdx;
+  unsigned long long rsi;
+  unsigned long long rdi;
+  unsigned long long orig_rax;
+  unsigned long long rip;
+  unsigned long long cs;
+  unsigned long long eflags;
+  unsigned long long rsp;
+  unsigned long long ss;
+  unsigned long long fs_base;
+  unsigned long long gs_base;
+  unsigned long long ds;
+  unsigned long long es;
+  unsigned long long fs;
+  unsigned long long gs;
+};
+
+#endif // LLVM_LIBC_TYPES_X86_64_STRUCT_USER_REGS_STRUCT_H

diff  --git a/libc/include/sys/user.yaml b/libc/include/sys/user.yaml
new file mode 100644
index 0000000000000..8f3d209cfd8c1
--- /dev/null
+++ b/libc/include/sys/user.yaml
@@ -0,0 +1,5 @@
+header: sys/user.h
+standards:
+  - linux
+types:
+  - type_name: struct_user_regs_struct


        


More information about the libc-commits mailing list