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

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


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

<details>
<summary>Changes</summary>

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.


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


1 Files Affected:

- (modified) libc/src/__support/OSUtil/linux/syscall_wrappers/execve.h (+3-6) 


``````````diff
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

``````````

</details>


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


More information about the libc-commits mailing list