[libc-commits] [libc] [libc] Add 32-bit fallback syscall branches to UID/GID syscall wrappers (PR #233926)

Aman Maurya via libc-commits libc-commits at lists.llvm.org
Tue Oct 20 10:46:25 PDT 2026


https://github.com/amanmaurya92 created https://github.com/llvm/llvm-project/pull/233926

Add 32-bit fallback branches (SYS_*32) to existing Linux syscall wrappers for:
- setuid (SYS_setuid32)
- setgid (SYS_setgid32)
- setreuid (SYS_setreuid32)
- setregid (SYS_setregid32)
- getegid (SYS_getegid32)
- lchown (SYS_lchown32)

This matches the pattern used in setgroups, setresuid, and setresgid on 32-bit Linux architectures.

Follow-up requested by @labath in #233088.

>From 6c5af0e98b2a65e24538fa39fb138c7ee52b8d58 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Tue, 20 Oct 2026 22:31:23 +0530
Subject: [PATCH] [libc] Add 32-bit fallback syscall branches to UID/GID
 syscall wrappers

Add SYS_*32 fallback checks alongside SYS_* syscall numbers for:

- setuid (SYS_setuid32)

- setgid (SYS_setgid32)

- setreuid (SYS_setreuid32)

- setregid (SYS_setregid32)

- getegid (SYS_getegid32)

- lchown (SYS_lchown32)

This aligns these wrappers with setgroups, setresuid, and setresgid on 32-bit Linux platforms.
---
 libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h  | 6 ++++++
 libc/src/__support/OSUtil/linux/syscall_wrappers/lchown.h   | 4 +++-
 libc/src/__support/OSUtil/linux/syscall_wrappers/setgid.h   | 6 ++++++
 libc/src/__support/OSUtil/linux/syscall_wrappers/setregid.h | 6 ++++++
 libc/src/__support/OSUtil/linux/syscall_wrappers/setreuid.h | 6 ++++++
 libc/src/__support/OSUtil/linux/syscall_wrappers/setuid.h   | 6 ++++++
 6 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h
index 4451ce0993bcd8..807d622b75af42 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h
@@ -25,7 +25,13 @@ namespace linux_syscalls {
 
 LIBC_INLINE gid_t getegid() {
   // getegid is expected to always succeed, thus no error checking here.
+#if defined(SYS_getegid32)
+  return syscall_impl<gid_t>(SYS_getegid32);
+#elif defined(SYS_getegid)
   return syscall_impl<gid_t>(SYS_getegid);
+#else
+#error "SYS_getegid and SYS_getegid32 syscalls not available."
+#endif
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/lchown.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/lchown.h
index 44bdefc30342c1..c06cbd253d7977 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/lchown.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/lchown.h
@@ -30,10 +30,12 @@ LIBC_INLINE ErrorOr<int> lchown(const char *path, uid_t owner, gid_t group) {
 #if defined(SYS_fchownat)
   return syscall_checked<int>(SYS_fchownat, AT_FDCWD, path, owner, group,
                               AT_SYMLINK_NOFOLLOW);
+#elif defined(SYS_lchown32)
+  return syscall_checked<int>(SYS_lchown32, path, owner, group);
 #elif defined(SYS_lchown)
   return syscall_checked<int>(SYS_lchown, path, owner, group);
 #else
-#error "fchownat and lchown syscalls not available."
+#error "fchownat, lchown32, and lchown syscalls not available."
 #endif
 }
 
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setgid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setgid.h
index 09a86b332a15eb..44cd3d5912b2ae 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/setgid.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setgid.h
@@ -25,7 +25,13 @@ namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> setgid(gid_t gid) {
+#if defined(SYS_setgid32)
+  return syscall_checked<int>(SYS_setgid32, gid);
+#elif defined(SYS_setgid)
   return syscall_checked<int>(SYS_setgid, gid);
+#else
+#error "SYS_setgid and SYS_setgid32 syscalls not available."
+#endif
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setregid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setregid.h
index 02ebc2187dc82e..9ee5794715fe52 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/setregid.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setregid.h
@@ -25,7 +25,13 @@ namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> setregid(gid_t rgid, gid_t egid) {
+#if defined(SYS_setregid32)
+  return syscall_checked<int>(SYS_setregid32, rgid, egid);
+#elif defined(SYS_setregid)
   return syscall_checked<int>(SYS_setregid, rgid, egid);
+#else
+#error "SYS_setregid and SYS_setregid32 syscalls not available."
+#endif
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setreuid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setreuid.h
index 68f08b24d3f2ce..4aa12431625848 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/setreuid.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setreuid.h
@@ -25,7 +25,13 @@ namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> setreuid(uid_t ruid, uid_t euid) {
+#if defined(SYS_setreuid32)
+  return syscall_checked<int>(SYS_setreuid32, ruid, euid);
+#elif defined(SYS_setreuid)
   return syscall_checked<int>(SYS_setreuid, ruid, euid);
+#else
+#error "SYS_setreuid and SYS_setreuid32 syscalls not available."
+#endif
 }
 
 } // namespace linux_syscalls
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/setuid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/setuid.h
index 8d99551b973961..ba911d1273cebe 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/setuid.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/setuid.h
@@ -25,7 +25,13 @@ namespace LIBC_NAMESPACE_DECL {
 namespace linux_syscalls {
 
 LIBC_INLINE ErrorOr<int> setuid(uid_t uid) {
+#if defined(SYS_setuid32)
+  return syscall_checked<int>(SYS_setuid32, uid);
+#elif defined(SYS_setuid)
   return syscall_checked<int>(SYS_setuid, uid);
+#else
+#error "SYS_setuid and SYS_setuid32 syscalls not available."
+#endif
 }
 
 } // namespace linux_syscalls



More information about the libc-commits mailing list