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

via libc-commits libc-commits at lists.llvm.org
Tue Oct 20 10:47:54 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Aman Maurya (amanmaurya92)

<details>
<summary>Changes</summary>

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.

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


6 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h (+6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/lchown.h (+3-1) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/setgid.h (+6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/setregid.h (+6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/setreuid.h (+6) 
- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/setuid.h (+6) 


``````````diff
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/getegid.h
index 4451ce0993bcd..807d622b75af4 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 44bdefc30342c..c06cbd253d797 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 09a86b332a15e..44cd3d5912b2a 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 02ebc2187dc82..9ee5794715fe5 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 68f08b24d3f2c..4aa1243162584 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 8d99551b97396..ba911d1273ceb 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

``````````

</details>


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


More information about the libc-commits mailing list