[libc-commits] [libc] 7d5dd43 - [libc] Add 'struct ucred' definition. (#213152)

via libc-commits libc-commits at lists.llvm.org
Fri Jul 31 07:15:08 PDT 2026


Author: Alexey Samsonov
Date: 2026-07-31T07:15:02-07:00
New Revision: 7d5dd438b286d4812a8d2e753262cb6db1c3be51

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

LOG: [libc] Add 'struct ucred' definition. (#213152)

This is a Linux extension that allows to obtain credentials of a peer
process connected to a socket, e.g. via passing `SO_PEERCRED` to
`getsockopt` function.

Added: 
    libc/include/llvm-libc-types/struct_ucred.h

Modified: 
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/include/sys/socket.yaml

Removed: 
    


################################################################################
diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 941c9c748bc0c..1c6c65fa29c23 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -858,6 +858,7 @@ add_header_macro(
     .llvm-libc-types.struct_msghdr
     .llvm-libc-types.struct_sockaddr
     .llvm-libc-types.struct_sockaddr_storage
+    .llvm-libc-types.struct_ucred
 )
 
 add_header_macro(

diff  --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 0854507a1fb59..3286ebe54d9a2 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -264,6 +264,7 @@ add_header(struct_sockaddr_un HDR struct_sockaddr_un.h DEPENDS .sa_family_t)
 add_header(struct_ifreq HDR struct_ifreq.h DEPENDS libc.include.llvm-libc-macros.net_if_macros .struct_sockaddr)
 add_header(struct_iovec HDR struct_iovec.h DEPENDS .size_t)
 add_header(struct_linger HDR struct_linger.h)
+add_header(struct_ucred HDR struct_ucred.h DEPENDS .pid_t .uid_t .gid_t)
 add_header(struct_cmsghdr HDR struct_cmsghdr.h DEPENDS .size_t)
 add_header(struct_msghdr HDR struct_msghdr.h DEPENDS .size_t .socklen_t .struct_iovec)
 add_header(struct_mmsghdr HDR struct_mmsghdr.h DEPENDS .struct_msghdr)

diff  --git a/libc/include/llvm-libc-types/struct_ucred.h b/libc/include/llvm-libc-types/struct_ucred.h
new file mode 100644
index 0000000000000..727e18f000421
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ucred.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 ucred.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_UCRED_H
+#define LLVM_LIBC_TYPES_STRUCT_UCRED_H
+
+#include "gid_t.h"
+#include "pid_t.h"
+#include "uid_t.h"
+
+// Credentials of a peer process connected to a socket.
+struct ucred {
+  pid_t pid;
+  uid_t uid;
+  gid_t gid;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_UCRED_H

diff  --git a/libc/include/sys/socket.yaml b/libc/include/sys/socket.yaml
index fb121fa805f3b..64a3a56603158 100644
--- a/libc/include/sys/socket.yaml
+++ b/libc/include/sys/socket.yaml
@@ -15,6 +15,9 @@ types:
   - type_name: struct_msghdr
   - type_name: struct_iovec
   - type_name: struct_linger
+  - type_name: struct_ucred
+    standards:
+      - linux
   - type_name: size_t
   - type_name: ssize_t
 enums: []


        


More information about the libc-commits mailing list