[libc-commits] [libc] [libc] Simplify execve syscall error handling (PR #242601)

Connector Switch via libc-commits libc-commits at lists.llvm.org
Fri Nov 13 22:57:05 PST 2026


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/242601

Use syscall_checked<int> in the execve wrapper instead of converting syscall errors by hand. Keep the existing preference for SYS_execve and the SYS_execveat fallback, with the same arguments and ErrorOr<int> interface.

Validated successful execution, error returns, environment forwarding, and errno preservation for both syscall paths.


>From e259fca9fcda2ca77b720acc70309a61dd804426 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Sat, 14 Nov 2026 14:56:26 +0800
Subject: [PATCH] [libc] Simplify execve syscall error handling

---
 .../src/__support/OSUtil/linux/syscall_wrappers/execve.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h
index 9c88b7603e8083..9bc327f8b47cd1 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h
@@ -15,7 +15,7 @@
 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_EXECVE_H
 
 #include "hdr/fcntl_macros.h"
-#include "src/__support/OSUtil/linux/syscall.h" // syscall_impl
+#include "src/__support/OSUtil/linux/syscall.h" // syscall_checked
 #include "src/__support/common.h"
 #include "src/__support/error_or.h"
 #include "src/__support/macros/config.h"
@@ -27,15 +27,12 @@ namespace linux_syscalls {
 LIBC_INLINE ErrorOr<int> execve(const char *path, char *const argv[],
                                 char *const envp[]) {
 #if defined(SYS_execve)
-  int ret = syscall_impl<int>(SYS_execve, path, argv, envp);
+  return syscall_checked<int>(SYS_execve, path, argv, envp);
 #elif defined(SYS_execveat)
-  int ret = syscall_impl<int>(SYS_execveat, AT_FDCWD, path, argv, envp, 0);
+  return syscall_checked<int>(SYS_execveat, AT_FDCWD, path, argv, envp, 0);
 #else
 #error "execve and execveat syscalls not available."
 #endif
-  if (ret < 0)
-    return Error(-ret);
-  return ret;
 }
 
 } // namespace linux_syscalls



More information about the libc-commits mailing list