(syscall_wrapper_refactor)=
LLVM-libc is transitioning to a centralized system for Linux syscalls. The goal is to move all direct syscall_impl calls into a dedicated directory: src/__support/OSUtil/linux/syscall_wrappers/.
This refactor provides several benefits:
ErrorOr<T> ensures that error conditions are handled explicitly.Each syscall should have its own header-only library in the syscall_wrappers directory. The wrapper function should return an ErrorOr<T>. Wrappers live in the linux_syscalls namespace to make call sites self-documenting and to clearly identify any leakage into OS-generic code.
src/__support/OSUtil/linux/syscall_wrappers/read.h):#include "hdr/types/ssize_t.h" #include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked #include "src/__support/common.h" #include "src/__support/error_or.h" #include "src/__support/macros/config.h" #include <sys/syscall.h> // For syscall numbers namespace LIBC_NAMESPACE_DECL { namespace linux_syscalls { LIBC_INLINE ErrorOr<ssize_t> read(int fd, void *buf, size_t count) { return syscall_checked<ssize_t>(SYS_read, fd, buf, count); } } // namespace linux_syscalls } // namespace LIBC_NAMESPACE_DECL
Cleanup Existing Implementation: If the syscall was previously implemented in OSUtil/linux/fcntl.cpp (or similar), remove the old implementation to replace it with the new wrapper.
Create the Wrapper: Add a new header file in src/__support/OSUtil/linux/syscall_wrappers/.
Update CMake: Add a add_header_library target for the new wrapper in src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt.
Refactor Entrypoints:
read.h).syscall_impl calls with linux_syscalls::<function_name>.DEPENDS in CMakeLists.txt to include the new wrapper target.