diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -30,6 +30,8 @@ list(APPEND compile_options "-fno-rtti") list(APPEND compile_options "-Wall") list(APPEND compile_options "-Wextra") + list(APPEND compile_options "-Wconversion") + list(APPEND compile_options "-Wno-sign-conversion") list(APPEND compile_options "-Wimplicit-fallthrough") list(APPEND compile_options "-Wwrite-strings") list(APPEND compile_options "-Wextra-semi") diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h --- a/libc/src/__support/CPP/bit.h +++ b/libc/src/__support/CPP/bit.h @@ -48,6 +48,15 @@ #endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST) } +template +constexpr To bit_or_static_cast(const From &from) { + if constexpr (sizeof(To) == sizeof(From)) { + return bit_cast(from); + } else { + return static_cast(from); + } +} + } // namespace __llvm_libc::cpp #endif // LLVM_LIBC_SUPPORT_CPP_BIT_H diff --git a/libc/src/__support/File/linux/dir.cpp b/libc/src/__support/File/linux/dir.cpp --- a/libc/src/__support/File/linux/dir.cpp +++ b/libc/src/__support/File/linux/dir.cpp @@ -19,9 +19,10 @@ ErrorOr platform_opendir(const char *name) { int open_flags = O_RDONLY | O_DIRECTORY | O_CLOEXEC; #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, name, open_flags); + int fd = __llvm_libc::syscall_impl(SYS_open, name, open_flags); #elif defined(SYS_openat) - int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, name, open_flags); + int fd = + __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, name, open_flags); #else #error \ "SYS_open and SYS_openat syscalls not available to perform an open operation." @@ -35,8 +36,8 @@ ErrorOr platform_fetch_dirents(int fd, cpp::span buffer) { #ifdef SYS_getdents64 - long size = __llvm_libc::syscall_impl(SYS_getdents64, fd, buffer.data(), - buffer.size()); + long size = __llvm_libc::syscall_impl(SYS_getdents64, fd, buffer.data(), + buffer.size()); #else #error "getdents64 syscalls not available to perform a fetch dirents operation." #endif @@ -48,7 +49,7 @@ } int platform_closedir(int fd) { - long ret = __llvm_libc::syscall_impl(SYS_close, fd); + int ret = __llvm_libc::syscall_impl(SYS_close, fd); if (ret < 0) { return static_cast(-ret); } diff --git a/libc/src/__support/File/linux/file.cpp b/libc/src/__support/File/linux/file.cpp --- a/libc/src/__support/File/linux/file.cpp +++ b/libc/src/__support/File/linux/file.cpp @@ -44,7 +44,7 @@ FileIOResult write_func(File *f, const void *data, size_t size) { auto *lf = reinterpret_cast(f); - int ret = __llvm_libc::syscall_impl(SYS_write, lf->get_fd(), data, size); + int ret = __llvm_libc::syscall_impl(SYS_write, lf->get_fd(), data, size); if (ret < 0) { return {0, -ret}; } @@ -53,7 +53,7 @@ FileIOResult read_func(File *f, void *buf, size_t size) { auto *lf = reinterpret_cast(f); - int ret = __llvm_libc::syscall_impl(SYS_read, lf->get_fd(), buf, size); + int ret = __llvm_libc::syscall_impl(SYS_read, lf->get_fd(), buf, size); if (ret < 0) { return {0, -ret}; } @@ -64,16 +64,22 @@ auto *lf = reinterpret_cast(f); long result; #ifdef SYS_lseek - int ret = __llvm_libc::syscall_impl(SYS_lseek, lf->get_fd(), offset, whence); + int ret = + __llvm_libc::syscall_impl(SYS_lseek, lf->get_fd(), offset, whence); result = ret; #elif defined(SYS_llseek) - int ret = __llvm_libc::syscall_impl(SYS_llseek, lf->get_fd(), - (long)(((uint64_t)(offset)) >> 32), - (long)offset, &result, whence); + int ret = __llvm_libc::syscall_impl(SYS_llseek, lf->get_fd(), + (long)(((uint64_t)(offset)) >> 32), + (long)offset, &result, whence); + result = ret; +#elif defined(SYS_llseek) + int ret = __llvm_libc::syscall_impl(SYS_llseek, lf->get_fd(), + (long)(((uint64_t)(offset)) >> 32), + (long)offset, &result, whence); result = ret; #elif defined(SYS__llseek) - int ret = __llvm_libc::syscall_impl(SYS__llseek, lf->get_fd(), offset >> 32, - offset, &result, whence); + int ret = __llvm_libc::syscall_impl( + SYS__llseek, lf->get_fd(), offset >> 32, offset, &result, whence); #else #error "lseek, llseek and _llseek syscalls not available." #endif @@ -86,7 +92,7 @@ int close_func(File *f) { auto *lf = reinterpret_cast(f); - int ret = __llvm_libc::syscall_impl(SYS_close, lf->get_fd()); + int ret = __llvm_libc::syscall_impl(SYS_close, lf->get_fd()); if (ret < 0) { return -ret; } @@ -128,10 +134,11 @@ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, path, open_flags, OPEN_MODE); + int fd = + __llvm_libc::syscall_impl(SYS_open, path, open_flags, OPEN_MODE); #elif defined(SYS_openat) - int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, open_flags, - OPEN_MODE); + int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, + open_flags, OPEN_MODE); #else #error "open and openat syscalls not available." #endif diff --git a/libc/src/__support/OSUtil/darwin/quick_exit.h b/libc/src/__support/OSUtil/darwin/quick_exit.h --- a/libc/src/__support/OSUtil/darwin/quick_exit.h +++ b/libc/src/__support/OSUtil/darwin/quick_exit.h @@ -17,7 +17,7 @@ LIBC_INLINE void quick_exit(int status) { for (;;) { - __llvm_libc::syscall_impl(1 /* SYS_exit */, status); + __llvm_libc::syscall_impl(1 /* SYS_exit */, status); } } diff --git a/libc/src/__support/OSUtil/darwin/syscall.h b/libc/src/__support/OSUtil/darwin/syscall.h --- a/libc/src/__support/OSUtil/darwin/syscall.h +++ b/libc/src/__support/OSUtil/darwin/syscall.h @@ -9,6 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_DARWIN_SYSCALL_H #define LLVM_LIBC_SRC_SUPPORT_OSUTIL_DARWIN_SYSCALL_H +#include "src/__support/CPP/bit.h" #include "src/__support/common.h" #include "src/__support/macros/properties/architectures.h" @@ -20,10 +21,10 @@ namespace __llvm_libc { -template -LIBC_INLINE long syscall_impl(long __number, Ts... ts) { +template +LIBC_INLINE RET_TYPE syscall_impl(long __number, Ts... ts) { static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall"); - return syscall_impl(__number, (long)ts...); + return cpp::bit_or_static_cast(syscall_impl(__number, (long)ts...)); } } // namespace __llvm_libc diff --git a/libc/src/__support/OSUtil/linux/io.h b/libc/src/__support/OSUtil/linux/io.h --- a/libc/src/__support/OSUtil/linux/io.h +++ b/libc/src/__support/OSUtil/linux/io.h @@ -17,7 +17,8 @@ namespace __llvm_libc { LIBC_INLINE void write_to_stderr(cpp::string_view msg) { - __llvm_libc::syscall_impl(SYS_write, 2 /* stderr */, msg.data(), msg.size()); + __llvm_libc::syscall_impl(SYS_write, 2 /* stderr */, msg.data(), + msg.size()); } } // namespace __llvm_libc diff --git a/libc/src/__support/OSUtil/linux/quick_exit.h b/libc/src/__support/OSUtil/linux/quick_exit.h --- a/libc/src/__support/OSUtil/linux/quick_exit.h +++ b/libc/src/__support/OSUtil/linux/quick_exit.h @@ -19,8 +19,8 @@ LIBC_INLINE void quick_exit(int status) { for (;;) { - __llvm_libc::syscall_impl(SYS_exit_group, status); - __llvm_libc::syscall_impl(SYS_exit, status); + __llvm_libc::syscall_impl(SYS_exit_group, status); + __llvm_libc::syscall_impl(SYS_exit, status); } } diff --git a/libc/src/__support/OSUtil/linux/syscall.h b/libc/src/__support/OSUtil/linux/syscall.h --- a/libc/src/__support/OSUtil/linux/syscall.h +++ b/libc/src/__support/OSUtil/linux/syscall.h @@ -9,6 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H #define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H +#include "src/__support/CPP/bit.h" #include "src/__support/common.h" #include "src/__support/macros/properties/architectures.h" @@ -24,10 +25,10 @@ namespace __llvm_libc { -template -LIBC_INLINE long syscall_impl(long __number, Ts... ts) { +template +LIBC_INLINE RET_TYPE syscall_impl(long __number, Ts... ts) { static_assert(sizeof...(Ts) <= 6, "Too many arguments for syscall"); - return syscall_impl(__number, (long)ts...); + return cpp::bit_or_static_cast(syscall_impl(__number, (long)ts...)); } } // namespace __llvm_libc diff --git a/libc/src/__support/threads/linux/callonce.cpp b/libc/src/__support/threads/linux/callonce.cpp --- a/libc/src/__support/threads/linux/callonce.cpp +++ b/libc/src/__support/threads/linux/callonce.cpp @@ -34,10 +34,10 @@ func(); auto status = futex_word->exchange(FINISH); if (status == WAITING) { - __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &futex_word->val, - FUTEX_WAKE_PRIVATE, - INT_MAX, // Wake all waiters. - 0, 0, 0); + __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &futex_word->val, + FUTEX_WAKE_PRIVATE, + INT_MAX, // Wake all waiters. + 0, 0, 0); } return 0; } @@ -45,7 +45,7 @@ FutexWordType status = START; if (futex_word->compare_exchange_strong(status, WAITING) || status == WAITING) { - __llvm_libc::syscall_impl( + __llvm_libc::syscall_impl( FUTEX_SYSCALL_ID, &futex_word->val, FUTEX_WAIT_PRIVATE, WAITING, // Block only if status is still |WAITING|. 0, 0, 0); diff --git a/libc/src/__support/threads/linux/mutex.h b/libc/src/__support/threads/linux/mutex.h --- a/libc/src/__support/threads/linux/mutex.h +++ b/libc/src/__support/threads/linux/mutex.h @@ -76,9 +76,9 @@ // futex syscall will block if the futex data is still // `LockState::Waiting` (the 4th argument to the syscall function // below.) - __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &futex_word.val, - FUTEX_WAIT_PRIVATE, - FutexWordType(LockState::Waiting), 0, 0, 0); + __llvm_libc::syscall_impl( + FUTEX_SYSCALL_ID, &futex_word.val, FUTEX_WAIT_PRIVATE, + FutexWordType(LockState::Waiting), 0, 0, 0); was_waiting = true; // Once woken up/unblocked, try everything all over. continue; @@ -91,9 +91,9 @@ // we will wait for the futex to be woken up. Note again that the // following syscall will block only if the futex data is still // `LockState::Waiting`. - __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &futex_word, - FUTEX_WAIT_PRIVATE, - FutexWordType(LockState::Waiting), 0, 0, 0); + __llvm_libc::syscall_impl( + FUTEX_SYSCALL_ID, &futex_word, FUTEX_WAIT_PRIVATE, + FutexWordType(LockState::Waiting), 0, 0, 0); was_waiting = true; } continue; @@ -110,8 +110,8 @@ if (futex_word.compare_exchange_strong(mutex_status, FutexWordType(LockState::Free))) { // If any thread is waiting to be woken up, then do it. - __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &futex_word, - FUTEX_WAKE_PRIVATE, 1, 0, 0, 0); + __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &futex_word, + FUTEX_WAKE_PRIVATE, 1, 0, 0, 0); return MutexError::NONE; } diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp --- a/libc/src/__support/threads/linux/thread.cpp +++ b/libc/src/__support/threads/linux/thread.cpp @@ -92,14 +92,14 @@ // TODO: Maybe add MAP_STACK? Currently unimplemented on linux but helps // future-proof. - long mmap_result = - __llvm_libc::syscall_impl(MMAP_SYSCALL_NUMBER, - 0, // No special address - size, prot, - MAP_ANONYMOUS | MAP_PRIVATE, // Process private. - -1, // Not backed by any file - 0 // No offset - ); + long mmap_result = __llvm_libc::syscall_impl( + MMAP_SYSCALL_NUMBER, + 0, // No special address + size, prot, + MAP_ANONYMOUS | MAP_PRIVATE, // Process private. + -1, // Not backed by any file + 0 // No offset + ); if (mmap_result < 0 && (uintptr_t(mmap_result) >= UINTPTR_MAX - size)) return Error{int(-mmap_result)}; @@ -107,8 +107,8 @@ // Give read/write permissions to actual stack. // TODO: We are assuming stack growsdown here. long result = - __llvm_libc::syscall_impl(SYS_mprotect, mmap_result + guardsize, - stacksize, PROT_READ | PROT_WRITE); + __llvm_libc::syscall_impl(SYS_mprotect, mmap_result + guardsize, + stacksize, PROT_READ | PROT_WRITE); if (result != 0) return Error{int(-result)}; @@ -125,7 +125,7 @@ uintptr_t stackaddr = reinterpret_cast(stack); stackaddr -= guardsize; stack = reinterpret_cast(stackaddr); - __llvm_libc::syscall_impl(SYS_munmap, stack, stacksize + guardsize); + __llvm_libc::syscall_impl(SYS_munmap, stack, stacksize + guardsize); } struct Thread; @@ -299,7 +299,7 @@ // variables from this function will not be availalbe to the child thread. #if defined(LIBC_TARGET_ARCH_IS_X86_64) long register clone_result asm(CLONE_RESULT_REGISTER); - clone_result = __llvm_libc::syscall_impl( + clone_result = __llvm_libc::syscall_impl( SYS_clone, CLONE_SYSCALL_FLAGS, adjusted_stack, &attrib->tid, // The address where the child tid is written &clear_tid->val, // The futex where the child thread status is signalled @@ -308,7 +308,7 @@ #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) || \ defined(LIBC_TARGET_ARCH_IS_RISCV64) long register clone_result asm(CLONE_RESULT_REGISTER); - clone_result = __llvm_libc::syscall_impl( + clone_result = __llvm_libc::syscall_impl( SYS_clone, CLONE_SYSCALL_FLAGS, adjusted_stack, &attrib->tid, // The address where the child tid is written tls.tp, // The thread pointer value for the new thread. @@ -334,7 +334,7 @@ start_thread(); } else if (clone_result < 0) { cleanup_thread_resources(attrib); - return -clone_result; + return static_cast(-clone_result); } return 0; @@ -379,8 +379,8 @@ while (clear_tid->load() != 0) { // We cannot do a FUTEX_WAIT_PRIVATE here as the kernel does a // FUTEX_WAKE and not a FUTEX_WAKE_PRIVATE. - __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &clear_tid->val, FUTEX_WAIT, - CLEAR_TID_VALUE, nullptr); + __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &clear_tid->val, + FUTEX_WAIT, CLEAR_TID_VALUE, nullptr); } } @@ -408,7 +408,8 @@ if (*this == self) { // If we are setting the name of the current thread, then we can // use the syscall to set the name. - int retval = __llvm_libc::syscall_impl(SYS_prctl, PR_SET_NAME, name.data()); + int retval = + __llvm_libc::syscall_impl(SYS_prctl, PR_SET_NAME, name.data()); if (retval < 0) return -retval; else @@ -419,17 +420,17 @@ cpp::StringStream path_stream(path_name_buffer); construct_thread_name_file_path(path_stream, attrib->tid); #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, path_name_buffer, O_RDWR); + int fd = __llvm_libc::syscall_impl(SYS_open, path_name_buffer, O_RDWR); #else - int fd = - __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path_name_buffer, O_RDWR); + int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, + path_name_buffer, O_RDWR); #endif if (fd < 0) return -fd; int retval = - __llvm_libc::syscall_impl(SYS_write, fd, name.data(), name.size()); - __llvm_libc::syscall_impl(SYS_close, fd); + __llvm_libc::syscall_impl(SYS_write, fd, name.data(), name.size()); + __llvm_libc::syscall_impl(SYS_close, fd); if (retval < 0) return -retval; @@ -448,7 +449,8 @@ if (*this == self) { // If we are getting the name of the current thread, then we can // use the syscall to get the name. - int retval = __llvm_libc::syscall_impl(SYS_prctl, PR_GET_NAME, name_buffer); + int retval = + __llvm_libc::syscall_impl(SYS_prctl, PR_GET_NAME, name_buffer); if (retval < 0) return -retval; name << name_buffer << cpp::StringStream::ENDS; @@ -459,17 +461,17 @@ cpp::StringStream path_stream(path_name_buffer); construct_thread_name_file_path(path_stream, attrib->tid); #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, path_name_buffer, O_RDONLY); + int fd = __llvm_libc::syscall_impl(SYS_open, path_name_buffer, O_RDONLY); #else - int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path_name_buffer, - O_RDONLY); + int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, + path_name_buffer, O_RDONLY); #endif if (fd < 0) return -fd; int retval = - __llvm_libc::syscall_impl(SYS_read, fd, name_buffer, NAME_SIZE_MAX); - __llvm_libc::syscall_impl(SYS_close, fd); + __llvm_libc::syscall_impl(SYS_read, fd, name_buffer, NAME_SIZE_MAX); + __llvm_libc::syscall_impl(SYS_close, fd); if (retval < 0) return -retval; if (retval == NAME_SIZE_MAX) @@ -503,18 +505,18 @@ // Set the CLEAR_TID address to nullptr to prevent the kernel // from signalling at a non-existent futex location. - __llvm_libc::syscall_impl(SYS_set_tid_address, 0); + __llvm_libc::syscall_impl(SYS_set_tid_address, 0); // Return value for detached thread should be unused. We need to avoid // referencing `style` or `retval.*` because they may be stored on the stack // and we have deallocated our stack! - __llvm_libc::syscall_impl(SYS_exit, 0); + __llvm_libc::syscall_impl(SYS_exit, 0); __builtin_unreachable(); } if (style == ThreadStyle::POSIX) - __llvm_libc::syscall_impl(SYS_exit, retval.posix_retval); + __llvm_libc::syscall_impl(SYS_exit, retval.posix_retval); else - __llvm_libc::syscall_impl(SYS_exit, retval.stdc_retval); + __llvm_libc::syscall_impl(SYS_exit, retval.stdc_retval); __builtin_unreachable(); } diff --git a/libc/src/__support/threads/thread.cpp b/libc/src/__support/threads/thread.cpp --- a/libc/src/__support/threads/thread.cpp +++ b/libc/src/__support/threads/thread.cpp @@ -57,7 +57,7 @@ cpp::optional new_key(TSSDtor *dtor) { MutexLock lock(&mtx); - for (size_t i = 0; i < TSS_KEY_COUNT; ++i) { + for (unsigned int i = 0; i < TSS_KEY_COUNT; ++i) { TSSKeyUnit &u = units[i]; if (!u.active) { u = {dtor}; diff --git a/libc/src/fcntl/linux/creat.cpp b/libc/src/fcntl/linux/creat.cpp --- a/libc/src/fcntl/linux/creat.cpp +++ b/libc/src/fcntl/linux/creat.cpp @@ -19,11 +19,11 @@ LLVM_LIBC_FUNCTION(int, creat, (const char *path, int mode_flags)) { #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, path, - O_CREAT | O_WRONLY | O_TRUNC, mode_flags); + int fd = __llvm_libc::syscall_impl( + SYS_open, path, O_CREAT | O_WRONLY | O_TRUNC, mode_flags); #else - int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, - O_CREAT | O_WRONLY | O_TRUNC, mode_flags); + int fd = __llvm_libc::syscall_impl( + SYS_openat, AT_FDCWD, path, O_CREAT | O_WRONLY | O_TRUNC, mode_flags); #endif if (fd > 0) diff --git a/libc/src/fcntl/linux/open.cpp b/libc/src/fcntl/linux/open.cpp --- a/libc/src/fcntl/linux/open.cpp +++ b/libc/src/fcntl/linux/open.cpp @@ -30,10 +30,10 @@ } #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, path, flags, mode_flags); + int fd = __llvm_libc::syscall_impl(SYS_open, path, flags, mode_flags); #else - int fd = - __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, flags, mode_flags); + int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, flags, + mode_flags); #endif if (fd > 0) return fd; diff --git a/libc/src/fcntl/linux/openat.cpp b/libc/src/fcntl/linux/openat.cpp --- a/libc/src/fcntl/linux/openat.cpp +++ b/libc/src/fcntl/linux/openat.cpp @@ -29,7 +29,8 @@ va_end(varargs); } - int fd = __llvm_libc::syscall_impl(SYS_openat, dfd, path, flags, mode_flags); + int fd = + __llvm_libc::syscall_impl(SYS_openat, dfd, path, flags, mode_flags); if (fd > 0) return fd; diff --git a/libc/src/sched/linux/sched_get_priority_max.cpp b/libc/src/sched/linux/sched_get_priority_max.cpp --- a/libc/src/sched/linux/sched_get_priority_max.cpp +++ b/libc/src/sched/linux/sched_get_priority_max.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, sched_get_priority_max, (int policy)) { - long ret = __llvm_libc::syscall_impl(SYS_sched_get_priority_max, policy); + int ret = __llvm_libc::syscall_impl(SYS_sched_get_priority_max, policy); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_get_priority_min.cpp b/libc/src/sched/linux/sched_get_priority_min.cpp --- a/libc/src/sched/linux/sched_get_priority_min.cpp +++ b/libc/src/sched/linux/sched_get_priority_min.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, sched_get_priority_min, (int policy)) { - long ret = __llvm_libc::syscall_impl(SYS_sched_get_priority_min, policy); + int ret = __llvm_libc::syscall_impl(SYS_sched_get_priority_min, policy); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_getaffinity.cpp b/libc/src/sched/linux/sched_getaffinity.cpp --- a/libc/src/sched/linux/sched_getaffinity.cpp +++ b/libc/src/sched/linux/sched_getaffinity.cpp @@ -20,8 +20,8 @@ LLVM_LIBC_FUNCTION(int, sched_getaffinity, (pid_t tid, size_t cpuset_size, cpu_set_t *mask)) { - long ret = - __llvm_libc::syscall_impl(SYS_sched_getaffinity, tid, cpuset_size, mask); + int ret = __llvm_libc::syscall_impl(SYS_sched_getaffinity, tid, + cpuset_size, mask); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_getparam.cpp b/libc/src/sched/linux/sched_getparam.cpp --- a/libc/src/sched/linux/sched_getparam.cpp +++ b/libc/src/sched/linux/sched_getparam.cpp @@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, sched_getparam, (pid_t tid, struct sched_param *param)) { - long ret = __llvm_libc::syscall_impl(SYS_sched_getparam, tid, param); + int ret = __llvm_libc::syscall_impl(SYS_sched_getparam, tid, param); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_getscheduler.cpp b/libc/src/sched/linux/sched_getscheduler.cpp --- a/libc/src/sched/linux/sched_getscheduler.cpp +++ b/libc/src/sched/linux/sched_getscheduler.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, sched_getscheduler, (pid_t tid)) { - long ret = __llvm_libc::syscall_impl(SYS_sched_getscheduler, tid); + int ret = __llvm_libc::syscall_impl(SYS_sched_getscheduler, tid); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_rr_get_interval.cpp b/libc/src/sched/linux/sched_rr_get_interval.cpp --- a/libc/src/sched/linux/sched_rr_get_interval.cpp +++ b/libc/src/sched/linux/sched_rr_get_interval.cpp @@ -23,24 +23,24 @@ LLVM_LIBC_FUNCTION(int, sched_rr_get_interval, (pid_t tid, struct timespec *tp)) { #ifdef SYS_sched_rr_get_interval - long ret = __llvm_libc::syscall_impl(SYS_sched_rr_get_interval, tid, tp); + int ret = __llvm_libc::syscall_impl(SYS_sched_rr_get_interval, tid, tp); #elif defined(SYS_sched_rr_get_interval_time64) // The difference between the and SYS_sched_rr_get_interval // SYS_sched_rr_get_interval_time64 syscalls is the data type used for the // time interval parameter: the latter takes a struct __kernel_timespec - long ret; + int ret; if (tp) { struct __kernel_timespec ts32; - ret = - __llvm_libc::syscall_impl(SYS_sched_rr_get_interval_time64, tid, &ts32); + ret = __llvm_libc::syscall_impl(SYS_sched_rr_get_interval_time64, tid, + &ts32); if (ret == 0) { tp->tv_sec = ts32.tv_sec; tp->tv_nsec = ts32.tv_nsec; } } else // When tp is a nullptr, we still do the syscall to set ret and errno - ret = __llvm_libc::syscall_impl(SYS_sched_rr_get_interval_time64, tid, - nullptr); + ret = __llvm_libc::syscall_impl(SYS_sched_rr_get_interval_time64, tid, + nullptr); #else #error \ "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available." diff --git a/libc/src/sched/linux/sched_setaffinity.cpp b/libc/src/sched/linux/sched_setaffinity.cpp --- a/libc/src/sched/linux/sched_setaffinity.cpp +++ b/libc/src/sched/linux/sched_setaffinity.cpp @@ -19,8 +19,8 @@ LLVM_LIBC_FUNCTION(int, sched_setaffinity, (pid_t tid, size_t cpuset_size, const cpu_set_t *mask)) { - long ret = - __llvm_libc::syscall_impl(SYS_sched_setaffinity, tid, cpuset_size, mask); + int ret = __llvm_libc::syscall_impl(SYS_sched_setaffinity, tid, + cpuset_size, mask); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_setparam.cpp b/libc/src/sched/linux/sched_setparam.cpp --- a/libc/src/sched/linux/sched_setparam.cpp +++ b/libc/src/sched/linux/sched_setparam.cpp @@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, sched_setparam, (pid_t tid, const struct sched_param *param)) { - long ret = __llvm_libc::syscall_impl(SYS_sched_setparam, tid, param); + int ret = __llvm_libc::syscall_impl(SYS_sched_setparam, tid, param); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_setscheduler.cpp b/libc/src/sched/linux/sched_setscheduler.cpp --- a/libc/src/sched/linux/sched_setscheduler.cpp +++ b/libc/src/sched/linux/sched_setscheduler.cpp @@ -18,8 +18,8 @@ LLVM_LIBC_FUNCTION(int, sched_setscheduler, (pid_t tid, int policy, const struct sched_param *param)) { - long ret = - __llvm_libc::syscall_impl(SYS_sched_setscheduler, tid, policy, param); + int ret = __llvm_libc::syscall_impl(SYS_sched_setscheduler, tid, policy, + param); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sched/linux/sched_yield.cpp b/libc/src/sched/linux/sched_yield.cpp --- a/libc/src/sched/linux/sched_yield.cpp +++ b/libc/src/sched/linux/sched_yield.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, sched_yield, ()) { - long ret = __llvm_libc::syscall_impl(SYS_sched_yield); + int ret = __llvm_libc::syscall_impl(SYS_sched_yield); // As of writing this, yield() cannot fail if (ret < 0) { libc_errno = -ret; diff --git a/libc/src/signal/linux/__restore.cpp b/libc/src/signal/linux/__restore.cpp --- a/libc/src/signal/linux/__restore.cpp +++ b/libc/src/signal/linux/__restore.cpp @@ -19,6 +19,8 @@ __attribute__((no_sanitize("all"), hidden)); -extern "C" void __restore_rt() { __llvm_libc::syscall_impl(SYS_rt_sigreturn); } +extern "C" void __restore_rt() { + __llvm_libc::syscall_impl(SYS_rt_sigreturn); +} } // namespace __llvm_libc diff --git a/libc/src/signal/linux/kill.cpp b/libc/src/signal/linux/kill.cpp --- a/libc/src/signal/linux/kill.cpp +++ b/libc/src/signal/linux/kill.cpp @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, kill, (pid_t pid, int sig)) { - int ret = __llvm_libc::syscall_impl(SYS_kill, pid, sig); + int ret = __llvm_libc::syscall_impl(SYS_kill, pid, sig); // A negative return value indicates an error with the magnitude of the // value being the error code. diff --git a/libc/src/signal/linux/raise.cpp b/libc/src/signal/linux/raise.cpp --- a/libc/src/signal/linux/raise.cpp +++ b/libc/src/signal/linux/raise.cpp @@ -16,9 +16,9 @@ LLVM_LIBC_FUNCTION(int, raise, (int sig)) { ::sigset_t sigset; block_all_signals(sigset); - long pid = __llvm_libc::syscall_impl(SYS_getpid); - long tid = __llvm_libc::syscall_impl(SYS_gettid); - int ret = __llvm_libc::syscall_impl(SYS_tgkill, pid, tid, sig); + long pid = __llvm_libc::syscall_impl(SYS_getpid); + long tid = __llvm_libc::syscall_impl(SYS_gettid); + int ret = __llvm_libc::syscall_impl(SYS_tgkill, pid, tid, sig); restore_signals(sigset); return ret; } diff --git a/libc/src/signal/linux/sigaction.cpp b/libc/src/signal/linux/sigaction.cpp --- a/libc/src/signal/linux/sigaction.cpp +++ b/libc/src/signal/linux/sigaction.cpp @@ -34,7 +34,7 @@ } KernelSigaction kernel_old; - int ret = __llvm_libc::syscall_impl( + int ret = __llvm_libc::syscall_impl( SYS_rt_sigaction, signal, libc_new ? &kernel_new : nullptr, libc_old ? &kernel_old : nullptr, sizeof(sigset_t)); if (ret) { diff --git a/libc/src/signal/linux/sigaltstack.cpp b/libc/src/signal/linux/sigaltstack.cpp --- a/libc/src/signal/linux/sigaltstack.cpp +++ b/libc/src/signal/linux/sigaltstack.cpp @@ -34,7 +34,7 @@ } } - int ret = __llvm_libc::syscall_impl(SYS_sigaltstack, ss, oss); + int ret = __llvm_libc::syscall_impl(SYS_sigaltstack, ss, oss); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/signal/linux/signal_utils.h b/libc/src/signal/linux/signal_utils.h --- a/libc/src/signal/linux/signal_utils.h +++ b/libc/src/signal/linux/signal_utils.h @@ -44,7 +44,7 @@ LIBC_INLINE operator struct sigaction() const { struct sigaction sa; - sa.sa_flags = sa_flags; + sa.sa_flags = static_cast(sa_flags); sa.sa_mask = sa_mask; sa.sa_restorer = sa_restorer; if (sa_flags & SA_SIGINFO) @@ -96,13 +96,13 @@ LIBC_INLINE int block_all_signals(sigset_t &set) { sigset_t full = full_set(); - return __llvm_libc::syscall_impl(SYS_rt_sigprocmask, SIG_BLOCK, &full, &set, - sizeof(sigset_t)); + return __llvm_libc::syscall_impl(SYS_rt_sigprocmask, SIG_BLOCK, &full, + &set, sizeof(sigset_t)); } LIBC_INLINE int restore_signals(const sigset_t &set) { - return __llvm_libc::syscall_impl(SYS_rt_sigprocmask, SIG_SETMASK, &set, - nullptr, sizeof(sigset_t)); + return __llvm_libc::syscall_impl(SYS_rt_sigprocmask, SIG_SETMASK, &set, + nullptr, sizeof(sigset_t)); } } // namespace __llvm_libc diff --git a/libc/src/signal/linux/sigprocmask.cpp b/libc/src/signal/linux/sigprocmask.cpp --- a/libc/src/signal/linux/sigprocmask.cpp +++ b/libc/src/signal/linux/sigprocmask.cpp @@ -21,8 +21,8 @@ LLVM_LIBC_FUNCTION(int, sigprocmask, (int how, const sigset_t *__restrict set, sigset_t *__restrict oldset)) { - int ret = __llvm_libc::syscall_impl(SYS_rt_sigprocmask, how, set, oldset, - sizeof(sigset_t)); + int ret = __llvm_libc::syscall_impl(SYS_rt_sigprocmask, how, set, oldset, + sizeof(sigset_t)); if (!ret) return 0; diff --git a/libc/src/spawn/linux/posix_spawn.cpp b/libc/src/spawn/linux/posix_spawn.cpp --- a/libc/src/spawn/linux/posix_spawn.cpp +++ b/libc/src/spawn/linux/posix_spawn.cpp @@ -27,9 +27,9 @@ // to avoid duplicating the complete stack from the parent. A new stack will // be created on exec anyway so duplicating the full stack is unnecessary. #ifdef SYS_fork - return __llvm_libc::syscall_impl(SYS_fork); + return __llvm_libc::syscall_impl(SYS_fork); #elif defined(SYS_clone) - return __llvm_libc::syscall_impl(SYS_clone, SIGCHLD, 0); + return __llvm_libc::syscall_impl(SYS_clone, SIGCHLD, 0); #else #error "fork or clone syscalls not available." #endif @@ -37,9 +37,10 @@ cpp::optional open(const char *path, int oflags, mode_t mode) { #ifdef SYS_open - int fd = __llvm_libc::syscall_impl(SYS_open, path, oflags, mode); + int fd = __llvm_libc::syscall_impl(SYS_open, path, oflags, mode); #else - int fd = __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, oflags, mode); + int fd = + __llvm_libc::syscall_impl(SYS_openat, AT_FDCWD, path, oflags, mode); #endif if (fd > 0) return fd; @@ -49,14 +50,14 @@ return cpp::nullopt; } -void close(int fd) { __llvm_libc::syscall_impl(SYS_close, fd); } +void close(int fd) { __llvm_libc::syscall_impl(SYS_close, fd); } // We use dup3 if dup2 is not available, similar to our implementation of dup2 bool dup2(int fd, int newfd) { #ifdef SYS_dup2 - long ret = __llvm_libc::syscall_impl(SYS_dup2, fd, newfd); + int ret = __llvm_libc::syscall_impl(SYS_dup2, fd, newfd); #elif defined(SYS_dup3) - long ret = __llvm_libc::syscall_impl(SYS_dup3, fd, newfd, 0); + int ret = __llvm_libc::syscall_impl(SYS_dup3, fd, newfd, 0); #else #error "dup2 and dup3 syscalls not available." #endif @@ -67,8 +68,8 @@ // exit implementation which exits with code 127. void exit() { for (;;) { - __llvm_libc::syscall_impl(SYS_exit_group, 127); - __llvm_libc::syscall_impl(SYS_exit, 127); + __llvm_libc::syscall_impl(SYS_exit_group, 127); + __llvm_libc::syscall_impl(SYS_exit, 127); } } @@ -116,7 +117,7 @@ } } - if (__llvm_libc::syscall_impl(SYS_execve, path, argv, envp) < 0) + if (__llvm_libc::syscall_impl(SYS_execve, path, argv, envp) < 0) exit(); } diff --git a/libc/src/stdio/linux/remove.cpp b/libc/src/stdio/linux/remove.cpp --- a/libc/src/stdio/linux/remove.cpp +++ b/libc/src/stdio/linux/remove.cpp @@ -20,9 +20,10 @@ LLVM_LIBC_FUNCTION(int, remove, (const char *path)) { // We first try unlinking it as a file. If it is ia file, it will succeed. If // it fails with EISDIR, we will try unlinking it as a directory. - int ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, 0); + int ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, 0); if (ret == -EISDIR) - ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); + ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, + AT_REMOVEDIR); if (ret >= 0) return 0; libc_errno = -ret; diff --git a/libc/src/sys/mman/linux/madvise.cpp b/libc/src/sys/mman/linux/madvise.cpp --- a/libc/src/sys/mman/linux/madvise.cpp +++ b/libc/src/sys/mman/linux/madvise.cpp @@ -19,13 +19,13 @@ // This function is currently linux only. It has to be refactored suitably if // madvise is to be supported on non-linux operating systems also. LLVM_LIBC_FUNCTION(int, madvise, (void *addr, size_t size, int advice)) { - long ret_val = __llvm_libc::syscall_impl( + int ret = __llvm_libc::syscall_impl( SYS_madvise, reinterpret_cast(addr), size, advice); // A negative return value indicates an error with the magnitude of the // value being the error code. - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return -1; } diff --git a/libc/src/sys/mman/linux/mmap.cpp b/libc/src/sys/mman/linux/mmap.cpp --- a/libc/src/sys/mman/linux/mmap.cpp +++ b/libc/src/sys/mman/linux/mmap.cpp @@ -39,7 +39,7 @@ #error "mmap or mmap2 syscalls not available." #endif - long ret_val = + long ret = __llvm_libc::syscall_impl(syscall_number, reinterpret_cast(addr), size, prot, flags, fd, offset); @@ -52,12 +52,12 @@ // However, since a valid return address cannot be within the last page, a // return value corresponding to a location in the last page is an error // value. - if (ret_val < 0 && ret_val > -EXEC_PAGESIZE) { - libc_errno = -ret_val; + if (ret < 0 && ret > -EXEC_PAGESIZE) { + libc_errno = static_cast(-ret); return MAP_FAILED; } - return reinterpret_cast(ret_val); + return reinterpret_cast(ret); } } // namespace __llvm_libc diff --git a/libc/src/sys/mman/linux/mprotect.cpp b/libc/src/sys/mman/linux/mprotect.cpp --- a/libc/src/sys/mman/linux/mprotect.cpp +++ b/libc/src/sys/mman/linux/mprotect.cpp @@ -19,13 +19,13 @@ // This function is currently linux only. It has to be refactored suitably if // mprotect is to be supported on non-linux operating systems also. LLVM_LIBC_FUNCTION(int, mprotect, (void *addr, size_t size, int prot)) { - long ret_val = __llvm_libc::syscall_impl( + int ret = __llvm_libc::syscall_impl( SYS_mprotect, reinterpret_cast(addr), size, prot); // A negative return value indicates an error with the magnitude of the // value being the error code. - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return -1; } diff --git a/libc/src/sys/mman/linux/munmap.cpp b/libc/src/sys/mman/linux/munmap.cpp --- a/libc/src/sys/mman/linux/munmap.cpp +++ b/libc/src/sys/mman/linux/munmap.cpp @@ -19,13 +19,13 @@ // This function is currently linux only. It has to be refactored suitably if // mmap is to be supported on non-linux operating systems also. LLVM_LIBC_FUNCTION(int, munmap, (void *addr, size_t size)) { - long ret_val = - __llvm_libc::syscall_impl(SYS_munmap, reinterpret_cast(addr), size); + int ret = __llvm_libc::syscall_impl(SYS_munmap, + reinterpret_cast(addr), size); // A negative return value indicates an error with the magnitude of the // value being the error code. - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return -1; } diff --git a/libc/src/sys/mman/linux/posix_madvise.cpp b/libc/src/sys/mman/linux/posix_madvise.cpp --- a/libc/src/sys/mman/linux/posix_madvise.cpp +++ b/libc/src/sys/mman/linux/posix_madvise.cpp @@ -23,9 +23,9 @@ if (advice == POSIX_MADV_DONTNEED) { return 0; } - long ret_val = __llvm_libc::syscall_impl( + int ret = __llvm_libc::syscall_impl( SYS_madvise, reinterpret_cast(addr), size, advice); - return ret_val < 0 ? -ret_val : 0; + return ret < 0 ? -ret : 0; } } // namespace __llvm_libc diff --git a/libc/src/sys/random/linux/getrandom.cpp b/libc/src/sys/random/linux/getrandom.cpp --- a/libc/src/sys/random/linux/getrandom.cpp +++ b/libc/src/sys/random/linux/getrandom.cpp @@ -18,9 +18,10 @@ LLVM_LIBC_FUNCTION(ssize_t, getrandom, (void *buf, size_t buflen, unsigned int flags)) { - long ret = __llvm_libc::syscall_impl(SYS_getrandom, buf, buflen, flags); + ssize_t ret = + __llvm_libc::syscall_impl(SYS_getrandom, buf, buflen, flags); if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp --- a/libc/src/sys/resource/linux/getrlimit.cpp +++ b/libc/src/sys/resource/linux/getrlimit.cpp @@ -18,7 +18,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, getrlimit, (int res, struct rlimit *limits)) { - long ret = __llvm_libc::syscall_impl(SYS_prlimit64, 0, res, nullptr, limits); + int ret = + __llvm_libc::syscall_impl(SYS_prlimit64, 0, res, nullptr, limits); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp --- a/libc/src/sys/resource/linux/setrlimit.cpp +++ b/libc/src/sys/resource/linux/setrlimit.cpp @@ -18,7 +18,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, setrlimit, (int res, const struct rlimit *limits)) { - long ret = __llvm_libc::syscall_impl(SYS_prlimit64, 0, res, limits, nullptr); + int ret = + __llvm_libc::syscall_impl(SYS_prlimit64, 0, res, limits, nullptr); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sys/select/linux/select.cpp b/libc/src/sys/select/linux/select.cpp --- a/libc/src/sys/select/linux/select.cpp +++ b/libc/src/sys/select/linux/select.cpp @@ -54,11 +54,11 @@ } pselect6_sigset_t pss{nullptr, sizeof(sigset_t)}; #if SYS_pselect6 - long ret = __llvm_libc::syscall_impl(SYS_pselect6, nfds, read_set, write_set, - error_set, &ts, &pss); + int ret = __llvm_libc::syscall_impl(SYS_pselect6, nfds, read_set, + write_set, error_set, &ts, &pss); #elif defined(SYS_pselect6_time64) - long ret = __llvm_libc::syscall_impl(SYS_pselect6_time64, nfds, read_set, - write_set, error_set, &ts, &pss); + int ret = __llvm_libc::syscall_impl(SYS_pselect6_time64, nfds, read_set, + write_set, error_set, &ts, &pss); #else #error "SYS_pselect6 and SYS_pselect6_time64 syscalls not available." #endif diff --git a/libc/src/sys/sendfile/linux/sendfile.cpp b/libc/src/sys/sendfile/linux/sendfile.cpp --- a/libc/src/sys/sendfile/linux/sendfile.cpp +++ b/libc/src/sys/sendfile/linux/sendfile.cpp @@ -20,18 +20,18 @@ LLVM_LIBC_FUNCTION(ssize_t, sendfile, (int out_fd, int in_fd, off_t *offset, size_t count)) { #ifdef SYS_sendfile - long ret = - __llvm_libc::syscall_impl(SYS_sendfile, in_fd, out_fd, offset, count); + ssize_t ret = __llvm_libc::syscall_impl(SYS_sendfile, in_fd, out_fd, + offset, count); #elif defined(SYS_sendfile64) // Same as sendfile but can handle large offsets static_assert(sizeof(off_t) == 8); - long ret = - __llvm_libc::syscall_impl(SYS_sendfile64, in_fd, out_fd, offset, count); + ssize_t ret = __llvm_libc::syscall_impl(SYS_sendfile64, in_fd, + out_fd, offset, count); #else #error "sendfile and sendfile64 syscalls not available." #endif if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/sys/socket/linux/socket.cpp b/libc/src/sys/socket/linux/socket.cpp --- a/libc/src/sys/socket/linux/socket.cpp +++ b/libc/src/sys/socket/linux/socket.cpp @@ -20,11 +20,11 @@ LLVM_LIBC_FUNCTION(int, socket, (int domain, int type, int protocol)) { #ifdef SYS_socket - long ret = __llvm_libc::syscall_impl(SYS_socket, domain, type, protocol); + int ret = __llvm_libc::syscall_impl(SYS_socket, domain, type, protocol); #elif defined(SYS_socketcall) unsigned long sockcall_args[3] = {domain, type, protocol}; - long ret = - __llvm_libc::syscall_impl(SYS_socketcall, SYS_SOCKET, sockcall_args); + int ret = + __llvm_libc::syscall_impl(SYS_socketcall, SYS_SOCKET, sockcall_args); #else #error "socket and socketcall syscalls unavailable for this platform." #endif diff --git a/libc/src/sys/stat/linux/chmod.cpp b/libc/src/sys/stat/linux/chmod.cpp --- a/libc/src/sys/stat/linux/chmod.cpp +++ b/libc/src/sys/stat/linux/chmod.cpp @@ -20,9 +20,9 @@ LLVM_LIBC_FUNCTION(int, chmod, (const char *path, mode_t mode)) { #ifdef SYS_chmod - long ret = __llvm_libc::syscall_impl(SYS_chmod, path, mode); + int ret = __llvm_libc::syscall_impl(SYS_chmod, path, mode); #elif defined(SYS_fchmodat) - long ret = __llvm_libc::syscall_impl(SYS_fchmodat, AT_FDCWD, path, mode); + int ret = __llvm_libc::syscall_impl(SYS_fchmodat, AT_FDCWD, path, mode); #else #error "chmod and fchmodat syscalls not available." #endif diff --git a/libc/src/sys/stat/linux/fchmod.cpp b/libc/src/sys/stat/linux/fchmod.cpp --- a/libc/src/sys/stat/linux/fchmod.cpp +++ b/libc/src/sys/stat/linux/fchmod.cpp @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fchmod, (int fd, mode_t mode)) { - long ret = __llvm_libc::syscall_impl(SYS_fchmod, fd, mode); + int ret = __llvm_libc::syscall_impl(SYS_fchmod, fd, mode); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sys/stat/linux/fchmodat.cpp b/libc/src/sys/stat/linux/fchmodat.cpp --- a/libc/src/sys/stat/linux/fchmodat.cpp +++ b/libc/src/sys/stat/linux/fchmodat.cpp @@ -19,7 +19,8 @@ LLVM_LIBC_FUNCTION(int, fchmodat, (int dirfd, const char *path, mode_t mode, int flags)) { - long ret = __llvm_libc::syscall_impl(SYS_fchmodat, dirfd, path, mode, flags); + int ret = + __llvm_libc::syscall_impl(SYS_fchmodat, dirfd, path, mode, flags); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/sys/stat/linux/kernel_statx.h b/libc/src/sys/stat/linux/kernel_statx.h --- a/libc/src/sys/stat/linux/kernel_statx.h +++ b/libc/src/sys/stat/linux/kernel_statx.h @@ -73,8 +73,8 @@ struct stat *__restrict statbuf) { // We make a statx syscall and copy out the result into the |statbuf|. ::statx_buf xbuf; - long ret = __llvm_libc::syscall_impl(SYS_statx, dirfd, path, flags, - ::STATX_BASIC_STATS_MASK, &xbuf); + int ret = __llvm_libc::syscall_impl(SYS_statx, dirfd, path, flags, + ::STATX_BASIC_STATS_MASK, &xbuf); if (ret < 0) return -ret; diff --git a/libc/src/sys/stat/linux/mkdir.cpp b/libc/src/sys/stat/linux/mkdir.cpp --- a/libc/src/sys/stat/linux/mkdir.cpp +++ b/libc/src/sys/stat/linux/mkdir.cpp @@ -20,9 +20,9 @@ LLVM_LIBC_FUNCTION(int, mkdir, (const char *path, mode_t mode)) { #ifdef SYS_mkdir - long ret = __llvm_libc::syscall_impl(SYS_mkdir, path, mode); + int ret = __llvm_libc::syscall_impl(SYS_mkdir, path, mode); #elif defined(SYS_mkdirat) - long ret = __llvm_libc::syscall_impl(SYS_mkdirat, AT_FDCWD, path, mode); + int ret = __llvm_libc::syscall_impl(SYS_mkdirat, AT_FDCWD, path, mode); #else #error "mkdir and mkdirat syscalls not available." #endif diff --git a/libc/src/sys/stat/linux/mkdirat.cpp b/libc/src/sys/stat/linux/mkdirat.cpp --- a/libc/src/sys/stat/linux/mkdirat.cpp +++ b/libc/src/sys/stat/linux/mkdirat.cpp @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, mkdirat, (int dfd, const char *path, mode_t mode)) { #ifdef SYS_mkdirat - long ret = __llvm_libc::syscall_impl(SYS_mkdirat, dfd, path, mode); + int ret = __llvm_libc::syscall_impl(SYS_mkdirat, dfd, path, mode); #else #error "mkdirat syscall not available." #endif diff --git a/libc/src/sys/utsname/linux/uname.cpp b/libc/src/sys/utsname/linux/uname.cpp --- a/libc/src/sys/utsname/linux/uname.cpp +++ b/libc/src/sys/utsname/linux/uname.cpp @@ -18,7 +18,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, uname, (struct utsname * name)) { - long ret = __llvm_libc::syscall_impl(SYS_uname, name); + int ret = __llvm_libc::syscall_impl(SYS_uname, name); if (ret >= 0) return 1; diff --git a/libc/src/sys/wait/wait4Impl.h b/libc/src/sys/wait/wait4Impl.h --- a/libc/src/sys/wait/wait4Impl.h +++ b/libc/src/sys/wait/wait4Impl.h @@ -27,7 +27,8 @@ LIBC_INLINE ErrorOr wait4impl(pid_t pid, int *wait_status, int options, struct rusage *usage) { #if SYS_wait4 - pid = __llvm_libc::syscall_impl(SYS_wait4, pid, wait_status, options, usage); + pid = __llvm_libc::syscall_impl(SYS_wait4, pid, wait_status, options, + usage); #elif defined(SYS_waitid) int idtype = P_PID; if (pid == -1) { @@ -42,8 +43,8 @@ options |= WEXITED; siginfo_t info; - pid = - __llvm_libc::syscall_impl(SYS_waitid, idtype, pid, &info, options, usage); + pid = __llvm_libc::syscall_impl(SYS_waitid, idtype, pid, &info, + options, usage); if (pid >= 0) pid = info.si_pid; diff --git a/libc/src/termios/linux/tcdrain.cpp b/libc/src/termios/linux/tcdrain.cpp --- a/libc/src/termios/linux/tcdrain.cpp +++ b/libc/src/termios/linux/tcdrain.cpp @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, tcdrain, (int fd)) { - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 1); + int ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 1); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/termios/linux/tcflow.cpp b/libc/src/termios/linux/tcflow.cpp --- a/libc/src/termios/linux/tcflow.cpp +++ b/libc/src/termios/linux/tcflow.cpp @@ -19,7 +19,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, tcflow, (int fd, int action)) { - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCXONC, action); + int ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCXONC, action); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/termios/linux/tcflush.cpp b/libc/src/termios/linux/tcflush.cpp --- a/libc/src/termios/linux/tcflush.cpp +++ b/libc/src/termios/linux/tcflush.cpp @@ -19,7 +19,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, tcflush, (int fd, int queue_selector)) { - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCFLSH, queue_selector); + int ret = + __llvm_libc::syscall_impl(SYS_ioctl, fd, TCFLSH, queue_selector); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/termios/linux/tcgetattr.cpp b/libc/src/termios/linux/tcgetattr.cpp --- a/libc/src/termios/linux/tcgetattr.cpp +++ b/libc/src/termios/linux/tcgetattr.cpp @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, tcgetattr, (int fd, struct termios *t)) { __llvm_libc::kernel_termios kt; - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCGETS, &kt); + int ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCGETS, &kt); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/termios/linux/tcgetsid.cpp b/libc/src/termios/linux/tcgetsid.cpp --- a/libc/src/termios/linux/tcgetsid.cpp +++ b/libc/src/termios/linux/tcgetsid.cpp @@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(pid_t, tcgetsid, (int fd)) { pid_t sid; - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TIOCGSID, &sid); + int ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TIOCGSID, &sid); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/termios/linux/tcsendbreak.cpp b/libc/src/termios/linux/tcsendbreak.cpp --- a/libc/src/termios/linux/tcsendbreak.cpp +++ b/libc/src/termios/linux/tcsendbreak.cpp @@ -22,7 +22,7 @@ // POSIX leaves the behavior for non-zero duration implementation dependent. // Which means that the behavior can be the same as it is when duration is // zero. So, we just pass zero to the syscall. - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 0); + int ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, TCSBRK, 0); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/termios/linux/tcsetattr.cpp b/libc/src/termios/linux/tcsetattr.cpp --- a/libc/src/termios/linux/tcsetattr.cpp +++ b/libc/src/termios/linux/tcsetattr.cpp @@ -51,7 +51,7 @@ kt.c_cc[i] = 0; } - long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, cmd, &kt); + int ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, cmd, &kt); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/threads/linux/CndVar.h b/libc/src/threads/linux/CndVar.h --- a/libc/src/threads/linux/CndVar.h +++ b/libc/src/threads/linux/CndVar.h @@ -84,8 +84,8 @@ } } - __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &waiter.futex_word.val, - FUTEX_WAIT, WS_Waiting, 0, 0, 0); + __llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &waiter.futex_word.val, + FUTEX_WAIT, WS_Waiting, 0, 0, 0); // At this point, if locking |m| fails, we can simply return as the // queued up waiter would have been removed from the queue. @@ -109,7 +109,7 @@ qmtx.futex_word = FutexWordType(Mutex::LockState::Free); - __llvm_libc::syscall_impl( + __llvm_libc::syscall_impl( FUTEX_SYSCALL_ID, &qmtx.futex_word.val, FUTEX_WAKE_OP, 1, 1, &first->futex_word.val, FUTEX_OP(FUTEX_OP_SET, WS_Signalled, FUTEX_OP_CMP_EQ, WS_Waiting)); @@ -126,7 +126,7 @@ // atomically update the waiter status to WS_Signalled before waking // up the waiter. A dummy location is used for the other futex of // FUTEX_WAKE_OP. - __llvm_libc::syscall_impl( + __llvm_libc::syscall_impl( FUTEX_SYSCALL_ID, &dummy_futex_word, FUTEX_WAKE_OP, 1, 1, &waiter->futex_word.val, FUTEX_OP(FUTEX_OP_SET, WS_Signalled, FUTEX_OP_CMP_EQ, WS_Waiting)); diff --git a/libc/src/time/clock_gettime.cpp b/libc/src/time/clock_gettime.cpp --- a/libc/src/time/clock_gettime.cpp +++ b/libc/src/time/clock_gettime.cpp @@ -21,21 +21,21 @@ LLVM_LIBC_FUNCTION(int, clock_gettime, (clockid_t clockid, struct timespec *tp)) { #if SYS_clock_gettime - long ret_val = - __llvm_libc::syscall_impl(SYS_clock_gettime, static_cast(clockid), - reinterpret_cast(tp)); + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime, + static_cast(clockid), + reinterpret_cast(tp)); #elif defined(SYS_clock_gettime64) - long ret_val = - __llvm_libc::syscall_impl(SYS_clock_gettime64, static_cast(clockid), - reinterpret_cast(tp)); + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime64, + static_cast(clockid), + reinterpret_cast(tp)); #else #error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available." #endif // A negative return value indicates an error with the magnitude of the // value being the error code. - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return -1; } diff --git a/libc/src/time/gettimeofday.cpp b/libc/src/time/gettimeofday.cpp --- a/libc/src/time/gettimeofday.cpp +++ b/libc/src/time/gettimeofday.cpp @@ -23,11 +23,11 @@ return 0; struct timespec tp; #if SYS_clock_gettime - long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime, + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime, static_cast(CLOCK_REALTIME), reinterpret_cast(&tp)); #elif defined(SYS_clock_gettime64) - long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime64, + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime64, static_cast(CLOCK_REALTIME), reinterpret_cast(&tp)); #else @@ -35,12 +35,12 @@ #endif // A negative return value indicates an error with the magnitude of the // value being the error code. - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return -1; } tv->tv_sec = tp.tv_sec; - tv->tv_usec = tp.tv_nsec / 1000; + tv->tv_usec = static_cast(tp.tv_nsec / 1000); return 0; } diff --git a/libc/src/time/linux/clock.cpp b/libc/src/time/linux/clock.cpp --- a/libc/src/time/linux/clock.cpp +++ b/libc/src/time/linux/clock.cpp @@ -21,17 +21,17 @@ LLVM_LIBC_FUNCTION(clock_t, clock, ()) { struct timespec ts; #if SYS_clock_gettime - long ret_val = __llvm_libc::syscall_impl( + int ret = __llvm_libc::syscall_impl( SYS_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, reinterpret_cast(&ts)); #elif defined(SYS_clock_gettime64) - long ret_val = - __llvm_libc::syscall_impl(SYS_clock_gettime64, CLOCK_PROCESS_CPUTIME_ID, - reinterpret_cast(&ts)); + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime64, + CLOCK_PROCESS_CPUTIME_ID, + reinterpret_cast(&ts)); #else #error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available." #endif - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return clock_t(-1); } diff --git a/libc/src/time/linux/time.cpp b/libc/src/time/linux/time.cpp --- a/libc/src/time/linux/time.cpp +++ b/libc/src/time/linux/time.cpp @@ -21,16 +21,16 @@ // TODO: Use the Linux VDSO to fetch the time and avoid the syscall. struct timespec ts; #if SYS_clock_gettime - long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime, CLOCK_REALTIME, + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime, CLOCK_REALTIME, reinterpret_cast(&ts)); #elif defined(SYS_clock_gettime64) - long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime64, CLOCK_REALTIME, + int ret = __llvm_libc::syscall_impl(SYS_clock_gettime64, CLOCK_REALTIME, reinterpret_cast(&ts)); #else #error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available." #endif - if (ret_val < 0) { - libc_errno = -ret_val; + if (ret < 0) { + libc_errno = -ret; return -1; } diff --git a/libc/src/time/nanosleep.cpp b/libc/src/time/nanosleep.cpp --- a/libc/src/time/nanosleep.cpp +++ b/libc/src/time/nanosleep.cpp @@ -20,9 +20,10 @@ LLVM_LIBC_FUNCTION(int, nanosleep, (const struct timespec *req, struct timespec *rem)) { #if SYS_nanosleep - int ret = __llvm_libc::syscall_impl(SYS_nanosleep, req, rem); + int ret = __llvm_libc::syscall_impl(SYS_nanosleep, req, rem); #elif defined(SYS_clock_nanosleep_time64) - int ret = __llvm_libc::syscall_impl(SYS_clock_nanosleep_time64, req, rem); + int ret = + __llvm_libc::syscall_impl(SYS_clock_nanosleep_time64, req, rem); #else #error "SYS_nanosleep and SYS_clock_nanosleep_time64 syscalls not available." #endif diff --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp --- a/libc/src/time/time_utils.cpp +++ b/libc/src/time/time_utils.cpp @@ -131,16 +131,19 @@ // All the data (years, month and remaining days) was calculated from // March, 2000. Thus adjust the data to be from January, 1900. - tm->tm_year = years + 2000 - TimeConstants::TIME_YEAR_BASE; - tm->tm_mon = months + 2; - tm->tm_mday = remainingDays + 1; - tm->tm_wday = wday; - tm->tm_yday = yday; - - tm->tm_hour = remainingSeconds / TimeConstants::SECONDS_PER_HOUR; - tm->tm_min = remainingSeconds / TimeConstants::SECONDS_PER_MIN % - TimeConstants::SECONDS_PER_MIN; - tm->tm_sec = remainingSeconds % TimeConstants::SECONDS_PER_MIN; + tm->tm_year = static_cast(years + 2000 - TimeConstants::TIME_YEAR_BASE); + tm->tm_mon = static_cast(months + 2); + tm->tm_mday = static_cast(remainingDays + 1); + tm->tm_wday = static_cast(wday); + tm->tm_yday = static_cast(yday); + + tm->tm_hour = + static_cast(remainingSeconds / TimeConstants::SECONDS_PER_HOUR); + tm->tm_min = + static_cast(remainingSeconds / TimeConstants::SECONDS_PER_MIN % + TimeConstants::SECONDS_PER_MIN); + tm->tm_sec = + static_cast(remainingSeconds % TimeConstants::SECONDS_PER_MIN); // TODO(rtenneti): Need to handle timezone and update of tm_isdst. tm->tm_isdst = 0; diff --git a/libc/src/unistd/linux/access.cpp b/libc/src/unistd/linux/access.cpp --- a/libc/src/unistd/linux/access.cpp +++ b/libc/src/unistd/linux/access.cpp @@ -19,9 +19,10 @@ LLVM_LIBC_FUNCTION(int, access, (const char *path, int mode)) { #ifdef SYS_access - long ret = __llvm_libc::syscall_impl(SYS_access, path, mode); + int ret = __llvm_libc::syscall_impl(SYS_access, path, mode); #elif defined(SYS_faccessat) - long ret = __llvm_libc::syscall_impl(SYS_faccessat, AT_FDCWD, path, mode, 0); + int ret = + __llvm_libc::syscall_impl(SYS_faccessat, AT_FDCWD, path, mode, 0); #else #error "access and faccessat syscalls not available." #endif diff --git a/libc/src/unistd/linux/chdir.cpp b/libc/src/unistd/linux/chdir.cpp --- a/libc/src/unistd/linux/chdir.cpp +++ b/libc/src/unistd/linux/chdir.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, chdir, (const char *path)) { - long ret = __llvm_libc::syscall_impl(SYS_chdir, path); + int ret = __llvm_libc::syscall_impl(SYS_chdir, path); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/close.cpp b/libc/src/unistd/linux/close.cpp --- a/libc/src/unistd/linux/close.cpp +++ b/libc/src/unistd/linux/close.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, close, (int fd)) { - long ret = __llvm_libc::syscall_impl(SYS_close, fd); + int ret = __llvm_libc::syscall_impl(SYS_close, fd); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/dup.cpp b/libc/src/unistd/linux/dup.cpp --- a/libc/src/unistd/linux/dup.cpp +++ b/libc/src/unistd/linux/dup.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, dup, (int fd)) { - long ret = __llvm_libc::syscall_impl(SYS_dup, fd); + int ret = __llvm_libc::syscall_impl(SYS_dup, fd); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/dup2.cpp b/libc/src/unistd/linux/dup2.cpp --- a/libc/src/unistd/linux/dup2.cpp +++ b/libc/src/unistd/linux/dup2.cpp @@ -20,7 +20,7 @@ LLVM_LIBC_FUNCTION(int, dup2, (int oldfd, int newfd)) { #ifdef SYS_dup2 // If dup2 syscall is available, we make use of directly. - long ret = __llvm_libc::syscall_impl(SYS_dup2, oldfd, newfd); + int ret = __llvm_libc::syscall_impl(SYS_dup2, oldfd, newfd); #elif defined(SYS_dup3) // If dup2 syscall is not available, we try using the dup3 syscall. However, // dup3 fails if oldfd is the same as newfd. So, we handle that case @@ -28,11 +28,11 @@ if (oldfd == newfd) { // Check if oldfd is actually a valid file descriptor. #if SYS_fcntl - long ret = __llvm_libc::syscall_impl(SYS_fcntl, oldfd, F_GETFD); + int ret = __llvm_libc::syscall_impl(SYS_fcntl, oldfd, F_GETFD); #elif defined(SYS_fcntl64) // Same as fcntl but can handle large offsets static_assert(sizeof(off_t) == 8); - long ret = __llvm_libc::syscall_impl(SYS_fcntl64, oldfd, F_GETFD); + int ret = __llvm_libc::syscall_impl(SYS_fcntl64, oldfd, F_GETFD); #else #error "SYS_fcntl and SYS_fcntl64 syscalls not available." #endif @@ -41,7 +41,7 @@ libc_errno = -ret; return -1; } - long ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, 0); + int ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, 0); #else #error "dup2 and dup3 syscalls not available." #endif diff --git a/libc/src/unistd/linux/dup3.cpp b/libc/src/unistd/linux/dup3.cpp --- a/libc/src/unistd/linux/dup3.cpp +++ b/libc/src/unistd/linux/dup3.cpp @@ -18,7 +18,7 @@ LLVM_LIBC_FUNCTION(int, dup3, (int oldfd, int newfd, int flags)) { // If dup2 syscall is available, we make use of directly. - long ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, flags); + int ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, flags); if (ret >= 0) return ret; libc_errno = -ret; diff --git a/libc/src/unistd/linux/execv.cpp b/libc/src/unistd/linux/execv.cpp --- a/libc/src/unistd/linux/execv.cpp +++ b/libc/src/unistd/linux/execv.cpp @@ -18,8 +18,8 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, execv, (const char *path, char *const argv[])) { - long ret = - __llvm_libc::syscall_impl(SYS_execve, path, argv, __llvm_libc::environ); + int ret = __llvm_libc::syscall_impl(SYS_execve, path, argv, + __llvm_libc::environ); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/execve.cpp b/libc/src/unistd/linux/execve.cpp --- a/libc/src/unistd/linux/execve.cpp +++ b/libc/src/unistd/linux/execve.cpp @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, execve, (const char *path, char *const argv[], char *const envp[])) { - long ret = __llvm_libc::syscall_impl(SYS_execve, path, argv, envp); + int ret = __llvm_libc::syscall_impl(SYS_execve, path, argv, envp); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/fchdir.cpp b/libc/src/unistd/linux/fchdir.cpp --- a/libc/src/unistd/linux/fchdir.cpp +++ b/libc/src/unistd/linux/fchdir.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fchdir, (int fd)) { - long ret = __llvm_libc::syscall_impl(SYS_fchdir, fd); + int ret = __llvm_libc::syscall_impl(SYS_fchdir, fd); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/fork.cpp b/libc/src/unistd/linux/fork.cpp --- a/libc/src/unistd/linux/fork.cpp +++ b/libc/src/unistd/linux/fork.cpp @@ -25,9 +25,9 @@ LLVM_LIBC_FUNCTION(pid_t, fork, (void)) { invoke_prepare_callbacks(); #ifdef SYS_fork - pid_t ret = __llvm_libc::syscall_impl(SYS_fork); + pid_t ret = __llvm_libc::syscall_impl(SYS_fork); #elif defined(SYS_clone) - pid_t ret = __llvm_libc::syscall_impl(SYS_clone, SIGCHLD, 0); + pid_t ret = __llvm_libc::syscall_impl(SYS_clone, SIGCHLD, 0); #else #error "fork and clone syscalls not available." #endif @@ -36,14 +36,14 @@ // The child is created with a single thread whose self object will be a // copy of parent process' thread which called fork. So, we have to fix up // the child process' self object with the new process' tid. - self.attrib->tid = __llvm_libc::syscall_impl(SYS_gettid); + self.attrib->tid = __llvm_libc::syscall_impl(SYS_gettid); invoke_child_callbacks(); return 0; } if (ret < 0) { // Error case, a child process was not created. - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } diff --git a/libc/src/unistd/linux/fsync.cpp b/libc/src/unistd/linux/fsync.cpp --- a/libc/src/unistd/linux/fsync.cpp +++ b/libc/src/unistd/linux/fsync.cpp @@ -17,7 +17,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(int, fsync, (int fd)) { - long ret = __llvm_libc::syscall_impl(SYS_fsync, fd); + int ret = __llvm_libc::syscall_impl(SYS_fsync, fd); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/ftruncate.cpp b/libc/src/unistd/linux/ftruncate.cpp --- a/libc/src/unistd/linux/ftruncate.cpp +++ b/libc/src/unistd/linux/ftruncate.cpp @@ -20,12 +20,12 @@ LLVM_LIBC_FUNCTION(int, ftruncate, (int fd, off_t len)) { #ifdef SYS_ftruncate - int ret = __llvm_libc::syscall_impl(SYS_ftruncate, fd, len); + int ret = __llvm_libc::syscall_impl(SYS_ftruncate, fd, len); #elif defined(SYS_ftruncate64) // Same as ftruncate but can handle large offsets static_assert(sizeof(off_t) == 8); - int ret = __llvm_libc::syscall_impl(SYS_ftruncate64, fd, (long)len, - (long)(((uint64_t)(len)) >> 32)); + int ret = __llvm_libc::syscall_impl(SYS_ftruncate64, fd, (long)len, + (long)(((uint64_t)(len)) >> 32)); #else #error "ftruncate and ftruncate64 syscalls not available." #endif diff --git a/libc/src/unistd/linux/getcwd.cpp b/libc/src/unistd/linux/getcwd.cpp --- a/libc/src/unistd/linux/getcwd.cpp +++ b/libc/src/unistd/linux/getcwd.cpp @@ -22,7 +22,7 @@ namespace { bool getcwd_syscall(char *buf, size_t size) { - int ret = __llvm_libc::syscall_impl(SYS_getcwd, buf, size); + int ret = __llvm_libc::syscall_impl(SYS_getcwd, buf, size); if (ret < 0) { libc_errno = -ret; return false; diff --git a/libc/src/unistd/linux/geteuid.cpp b/libc/src/unistd/linux/geteuid.cpp --- a/libc/src/unistd/linux/geteuid.cpp +++ b/libc/src/unistd/linux/geteuid.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(uid_t, geteuid, ()) { - return __llvm_libc::syscall_impl(SYS_geteuid); + return __llvm_libc::syscall_impl(SYS_geteuid); } } // namespace __llvm_libc diff --git a/libc/src/unistd/linux/getpid.cpp b/libc/src/unistd/linux/getpid.cpp --- a/libc/src/unistd/linux/getpid.cpp +++ b/libc/src/unistd/linux/getpid.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(pid_t, getpid, ()) { - return __llvm_libc::syscall_impl(SYS_getpid); + return __llvm_libc::syscall_impl(SYS_getpid); } } // namespace __llvm_libc diff --git a/libc/src/unistd/linux/getppid.cpp b/libc/src/unistd/linux/getppid.cpp --- a/libc/src/unistd/linux/getppid.cpp +++ b/libc/src/unistd/linux/getppid.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(pid_t, getppid, ()) { - return __llvm_libc::syscall_impl(SYS_getppid); + return __llvm_libc::syscall_impl(SYS_getppid); } } // namespace __llvm_libc diff --git a/libc/src/unistd/linux/getuid.cpp b/libc/src/unistd/linux/getuid.cpp --- a/libc/src/unistd/linux/getuid.cpp +++ b/libc/src/unistd/linux/getuid.cpp @@ -16,7 +16,7 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(uid_t, getuid, ()) { - return __llvm_libc::syscall_impl(SYS_getuid); + return __llvm_libc::syscall_impl(SYS_getuid); } } // namespace __llvm_libc diff --git a/libc/src/unistd/linux/isatty.cpp b/libc/src/unistd/linux/isatty.cpp --- a/libc/src/unistd/linux/isatty.cpp +++ b/libc/src/unistd/linux/isatty.cpp @@ -22,7 +22,8 @@ int line_d_val = INIT_VAL; // This gets the line dicipline of the terminal. When called on something that // isn't a terminal it doesn't change line_d_val and returns -1. - int result = __llvm_libc::syscall_impl(SYS_ioctl, fd, TIOCGETD, &line_d_val); + int result = + __llvm_libc::syscall_impl(SYS_ioctl, fd, TIOCGETD, &line_d_val); if (result == 0) return 1; diff --git a/libc/src/unistd/linux/link.cpp b/libc/src/unistd/linux/link.cpp --- a/libc/src/unistd/linux/link.cpp +++ b/libc/src/unistd/linux/link.cpp @@ -19,10 +19,10 @@ LLVM_LIBC_FUNCTION(int, link, (const char *path1, const char *path2)) { #ifdef SYS_link - long ret = __llvm_libc::syscall_impl(SYS_link, path1, path2); + int ret = __llvm_libc::syscall_impl(SYS_link, path1, path2); #elif defined(SYS_linkat) - long ret = __llvm_libc::syscall_impl(SYS_linkat, AT_FDCWD, path1, AT_FDCWD, - path2, 0); + int ret = __llvm_libc::syscall_impl(SYS_linkat, AT_FDCWD, path1, + AT_FDCWD, path2, 0); #else #error "link or linkat syscalls not available." #endif diff --git a/libc/src/unistd/linux/linkat.cpp b/libc/src/unistd/linux/linkat.cpp --- a/libc/src/unistd/linux/linkat.cpp +++ b/libc/src/unistd/linux/linkat.cpp @@ -20,8 +20,8 @@ LLVM_LIBC_FUNCTION(int, linkat, (int fd1, const char *path1, int fd2, const char *path2, int flags)) { - long ret = - __llvm_libc::syscall_impl(SYS_linkat, fd1, path1, fd2, path2, flags); + int ret = + __llvm_libc::syscall_impl(SYS_linkat, fd1, path1, fd2, path2, flags); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/lseek.cpp b/libc/src/unistd/linux/lseek.cpp --- a/libc/src/unistd/linux/lseek.cpp +++ b/libc/src/unistd/linux/lseek.cpp @@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(off_t, lseek, (int fd, off_t offset, int whence)) { off_t result; #ifdef SYS_lseek - long ret = __llvm_libc::syscall_impl(SYS_lseek, fd, offset, whence); + int ret = __llvm_libc::syscall_impl(SYS_lseek, fd, offset, whence); result = ret; #elif defined(SYS_llseek) long ret = __llvm_libc::syscall_impl(SYS_llseek, fd, @@ -29,8 +29,8 @@ (long)offset, &result, whence); result = ret; #elif defined(SYS__llseek) - long ret = __llvm_libc::syscall_impl(SYS__llseek, fd, offset >> 32, offset, - &result, whence); + int ret = __llvm_libc::syscall_impl(SYS__llseek, fd, offset >> 32, + offset, &result, whence); #else #error "lseek, llseek and _llseek syscalls not available." #endif diff --git a/libc/src/unistd/linux/pread.cpp b/libc/src/unistd/linux/pread.cpp --- a/libc/src/unistd/linux/pread.cpp +++ b/libc/src/unistd/linux/pread.cpp @@ -21,14 +21,15 @@ (int fd, void *buf, size_t count, off_t offset)) { #ifdef LIBC_TARGET_ARCH_IS_RISCV32 static_assert(sizeof(off_t) == 8); - long ret = - __llvm_libc::syscall_impl(SYS_pread64, fd, buf, count, (long)offset, - (long)(((uint64_t)(offset)) >> 32)); + ssize_t ret = __llvm_libc::syscall_impl( + SYS_pread64, fd, buf, count, (long)offset, + (long)(((uint64_t)(offset)) >> 32)); #else - long ret = __llvm_libc::syscall_impl(SYS_pread64, fd, buf, count, offset); + ssize_t ret = + __llvm_libc::syscall_impl(SYS_pread64, fd, buf, count, offset); #endif if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/unistd/linux/pwrite.cpp b/libc/src/unistd/linux/pwrite.cpp --- a/libc/src/unistd/linux/pwrite.cpp +++ b/libc/src/unistd/linux/pwrite.cpp @@ -21,14 +21,15 @@ (int fd, const void *buf, size_t count, off_t offset)) { #ifdef LIBC_TARGET_ARCH_IS_RISCV32 static_assert(sizeof(off_t) == 8); - long ret = - __llvm_libc::syscall_impl(SYS_pwrite64, fd, buf, count, (long)offset, - (long)(((uint64_t)(offset)) >> 32)); + ssize_t ret = __llvm_libc::syscall_impl( + SYS_pwrite64, fd, buf, count, (long)offset, + (long)(((uint64_t)(offset)) >> 32)); #else - long ret = __llvm_libc::syscall_impl(SYS_pwrite64, fd, buf, count, offset); + ssize_t ret = + __llvm_libc::syscall_impl(SYS_pwrite64, fd, buf, count, offset); #endif if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/unistd/linux/read.cpp b/libc/src/unistd/linux/read.cpp --- a/libc/src/unistd/linux/read.cpp +++ b/libc/src/unistd/linux/read.cpp @@ -17,9 +17,9 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) { - long ret = __llvm_libc::syscall_impl(SYS_read, fd, buf, count); + ssize_t ret = __llvm_libc::syscall_impl(SYS_read, fd, buf, count); if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/unistd/linux/readlink.cpp b/libc/src/unistd/linux/readlink.cpp --- a/libc/src/unistd/linux/readlink.cpp +++ b/libc/src/unistd/linux/readlink.cpp @@ -21,15 +21,16 @@ (const char *__restrict path, char *__restrict buf, size_t bufsize)) { #ifdef SYS_readlink - ssize_t ret = __llvm_libc::syscall_impl(SYS_readlink, path, buf, bufsize); -#elif defined(SYS_readlinkat) ssize_t ret = - __llvm_libc::syscall_impl(SYS_readlinkat, AT_FDCWD, path, buf, bufsize); + __llvm_libc::syscall_impl(SYS_readlink, path, buf, bufsize); +#elif defined(SYS_readlinkat) + ssize_t ret = __llvm_libc::syscall_impl(SYS_readlinkat, AT_FDCWD, + path, buf, bufsize); #else #error "readlink or readlinkat syscalls not available." #endif if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/unistd/linux/readlinkat.cpp b/libc/src/unistd/linux/readlinkat.cpp --- a/libc/src/unistd/linux/readlinkat.cpp +++ b/libc/src/unistd/linux/readlinkat.cpp @@ -20,10 +20,10 @@ LLVM_LIBC_FUNCTION(ssize_t, readlinkat, (int fd, const char *__restrict path, char *__restrict buf, size_t bufsize)) { - ssize_t ret = - __llvm_libc::syscall_impl(SYS_readlinkat, fd, path, buf, bufsize); + ssize_t ret = __llvm_libc::syscall_impl(SYS_readlinkat, fd, path, + buf, bufsize); if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/unistd/linux/rmdir.cpp b/libc/src/unistd/linux/rmdir.cpp --- a/libc/src/unistd/linux/rmdir.cpp +++ b/libc/src/unistd/linux/rmdir.cpp @@ -19,10 +19,10 @@ LLVM_LIBC_FUNCTION(int, rmdir, (const char *path)) { #ifdef SYS_rmdir - long ret = __llvm_libc::syscall_impl(SYS_rmdir, path); + int ret = __llvm_libc::syscall_impl(SYS_rmdir, path); #elif defined(SYS_unlinkat) - long ret = - __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); + int ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, + AT_REMOVEDIR); #else #error "rmdir and unlinkat syscalls not available." #endif diff --git a/libc/src/unistd/linux/symlink.cpp b/libc/src/unistd/linux/symlink.cpp --- a/libc/src/unistd/linux/symlink.cpp +++ b/libc/src/unistd/linux/symlink.cpp @@ -19,9 +19,10 @@ LLVM_LIBC_FUNCTION(int, symlink, (const char *path1, const char *path2)) { #ifdef SYS_symlink - long ret = __llvm_libc::syscall_impl(SYS_symlink, path1, path2); + int ret = __llvm_libc::syscall_impl(SYS_symlink, path1, path2); #elif defined(SYS_symlinkat) - long ret = __llvm_libc::syscall_impl(SYS_symlinkat, path1, AT_FDCWD, path2); + int ret = + __llvm_libc::syscall_impl(SYS_symlinkat, path1, AT_FDCWD, path2); #else #error "symlink or symlinkat syscalls not available." #endif diff --git a/libc/src/unistd/linux/symlinkat.cpp b/libc/src/unistd/linux/symlinkat.cpp --- a/libc/src/unistd/linux/symlinkat.cpp +++ b/libc/src/unistd/linux/symlinkat.cpp @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, symlinkat, (const char *path1, int fd, const char *path2)) { - long ret = __llvm_libc::syscall_impl(SYS_symlinkat, path1, fd, path2); + int ret = __llvm_libc::syscall_impl(SYS_symlinkat, path1, fd, path2); if (ret < 0) { libc_errno = -ret; return -1; diff --git a/libc/src/unistd/linux/syscall.cpp b/libc/src/unistd/linux/syscall.cpp --- a/libc/src/unistd/linux/syscall.cpp +++ b/libc/src/unistd/linux/syscall.cpp @@ -19,12 +19,12 @@ LLVM_LIBC_FUNCTION(long, __llvm_libc_syscall, (long number, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6)) { - long ret = - __llvm_libc::syscall_impl(number, arg1, arg2, arg3, arg4, arg5, arg6); + long ret = __llvm_libc::syscall_impl(number, arg1, arg2, arg3, arg4, + arg5, arg6); // Syscalls may return large positive values that overflow, but will never // return values between -4096 and -1 if (static_cast(ret) > -4096UL) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/src/unistd/linux/truncate.cpp b/libc/src/unistd/linux/truncate.cpp --- a/libc/src/unistd/linux/truncate.cpp +++ b/libc/src/unistd/linux/truncate.cpp @@ -20,12 +20,12 @@ LLVM_LIBC_FUNCTION(int, truncate, (const char *path, off_t len)) { #ifdef SYS_truncate - int ret = __llvm_libc::syscall_impl(SYS_truncate, path, len); + int ret = __llvm_libc::syscall_impl(SYS_truncate, path, len); #elif defined(SYS_truncate64) // Same as truncate but can handle large offsets static_assert(sizeof(off_t) == 8); - int ret = __llvm_libc::syscall_impl(SYS_truncate64, path, (long)len, - (long)(((uint64_t)(len)) >> 32)); + int ret = __llvm_libc::syscall_impl(SYS_truncate64, path, (long)len, + (long)(((uint64_t)(len)) >> 32)); #else #error "truncate and truncate64 syscalls not available." #endif diff --git a/libc/src/unistd/linux/unlink.cpp b/libc/src/unistd/linux/unlink.cpp --- a/libc/src/unistd/linux/unlink.cpp +++ b/libc/src/unistd/linux/unlink.cpp @@ -19,9 +19,9 @@ LLVM_LIBC_FUNCTION(int, unlink, (const char *path)) { #ifdef SYS_unlink - long ret = __llvm_libc::syscall_impl(SYS_unlink, path); + int ret = __llvm_libc::syscall_impl(SYS_unlink, path); #elif defined(SYS_unlinkat) - long ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, 0); + int ret = __llvm_libc::syscall_impl(SYS_unlinkat, AT_FDCWD, path, 0); #else #error "unlink and unlinkat syscalls not available." #endif diff --git a/libc/src/unistd/linux/unlinkat.cpp b/libc/src/unistd/linux/unlinkat.cpp --- a/libc/src/unistd/linux/unlinkat.cpp +++ b/libc/src/unistd/linux/unlinkat.cpp @@ -19,7 +19,7 @@ LLVM_LIBC_FUNCTION(int, unlinkat, (int dfd, const char *path, int flags)) { #ifdef SYS_unlinkat - long ret = __llvm_libc::syscall_impl(SYS_unlinkat, dfd, path, flags); + int ret = __llvm_libc::syscall_impl(SYS_unlinkat, dfd, path, flags); #else #error "unlinkat syscalls not available." #endif diff --git a/libc/src/unistd/linux/write.cpp b/libc/src/unistd/linux/write.cpp --- a/libc/src/unistd/linux/write.cpp +++ b/libc/src/unistd/linux/write.cpp @@ -17,9 +17,9 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(ssize_t, write, (int fd, const void *buf, size_t count)) { - long ret = __llvm_libc::syscall_impl(SYS_write, fd, buf, count); + ssize_t ret = __llvm_libc::syscall_impl(SYS_write, fd, buf, count); if (ret < 0) { - libc_errno = -ret; + libc_errno = static_cast(-ret); return -1; } return ret; diff --git a/libc/startup/linux/aarch64/start.cpp b/libc/startup/linux/aarch64/start.cpp --- a/libc/startup/linux/aarch64/start.cpp +++ b/libc/startup/linux/aarch64/start.cpp @@ -69,13 +69,13 @@ // We cannot call the mmap function here as the functions set errno on // failure. Since errno is implemented via a thread local variable, we cannot // use errno before TLS is setup. - long mmap_ret_val = __llvm_libc::syscall_impl( + long mmap_ret_val = __llvm_libc::syscall_impl( MMAP_SYSCALL_NUMBER, nullptr, alloc_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // We cannot check the return value with MAP_FAILED as that is the return // of the mmap function and not the mmap syscall. if (mmap_ret_val < 0 && static_cast(mmap_ret_val) > -app.pageSize) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl(SYS_exit, 1); uintptr_t thread_ptr = uintptr_t(reinterpret_cast(mmap_ret_val)); uintptr_t tls_addr = thread_ptr + size_of_pointers + padding; __llvm_libc::inline_memcpy(reinterpret_cast(tls_addr), @@ -89,7 +89,7 @@ void cleanup_tls(uintptr_t addr, uintptr_t size) { if (size == 0) return; - __llvm_libc::syscall_impl(SYS_munmap, addr, size); + __llvm_libc::syscall_impl(SYS_munmap, addr, size); } static void set_thread_ptr(uintptr_t val) { __arm_wsr64("tpidr_el0", val); } @@ -134,10 +134,10 @@ }; __attribute__((noinline)) static void do_start() { - auto tid = __llvm_libc::syscall_impl(SYS_gettid); + auto tid = __llvm_libc::syscall_impl(SYS_gettid); if (tid <= 0) - __llvm_libc::syscall_impl(SYS_exit, 1); - __llvm_libc::main_thread_attrib.tid = tid; + __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::main_thread_attrib.tid = static_cast(tid); // After the argv array, is a 8-byte long NULL value before the array of env // values. The end of the env values is marked by another 8-byte long NULL @@ -200,10 +200,12 @@ __llvm_libc::atexit(&__llvm_libc::call_fini_array_callbacks); __llvm_libc::call_init_array_callbacks( - app.args->argc, reinterpret_cast(app.args->argv), + static_cast(app.args->argc), + reinterpret_cast(app.args->argv), reinterpret_cast(env_ptr)); - int retval = main(app.args->argc, reinterpret_cast(app.args->argv), + int retval = main(static_cast(app.args->argc), + reinterpret_cast(app.args->argv), reinterpret_cast(env_ptr)); // TODO: TLS cleanup should be done after all other atexit callbacks diff --git a/libc/startup/linux/riscv64/start.cpp b/libc/startup/linux/riscv64/start.cpp --- a/libc/startup/linux/riscv64/start.cpp +++ b/libc/startup/linux/riscv64/start.cpp @@ -56,13 +56,13 @@ // We cannot call the mmap function here as the functions set errno on // failure. Since errno is implemented via a thread local variable, we cannot // use errno before TLS is setup. - long mmap_ret_val = __llvm_libc::syscall_impl( + long mmap_ret_val = __llvm_libc::syscall_impl( MMAP_SYSCALL_NUMBER, nullptr, alloc_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // We cannot check the return value with MAP_FAILED as that is the return // of the mmap function and not the mmap syscall. if (mmap_ret_val < 0 && static_cast(mmap_ret_val) > -app.pageSize) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl(SYS_exit, 1); uintptr_t thread_ptr = uintptr_t(reinterpret_cast(mmap_ret_val)); uintptr_t tls_addr = thread_ptr + size_of_pointers + padding; __llvm_libc::inline_memcpy(reinterpret_cast(tls_addr), @@ -76,7 +76,7 @@ void cleanup_tls(uintptr_t addr, uintptr_t size) { if (size == 0) return; - __llvm_libc::syscall_impl(SYS_munmap, addr, size); + __llvm_libc::syscall_impl(SYS_munmap, addr, size); } static void set_thread_ptr(uintptr_t val) { @@ -127,10 +127,10 @@ ".option norelax\n\t" "lla gp, __global_pointer$\n\t" ".option pop\n\t"); - auto tid = __llvm_libc::syscall_impl(SYS_gettid); + auto tid = __llvm_libc::syscall_impl(SYS_gettid); if (tid <= 0) - __llvm_libc::syscall_impl(SYS_exit, 1); - __llvm_libc::main_thread_attrib.tid = tid; + __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::main_thread_attrib.tid = static_cast(tid); // After the argv array, is a 8-byte long NULL value before the array of env // values. The end of the env values is marked by another 8-byte long NULL @@ -193,10 +193,12 @@ __llvm_libc::atexit(&__llvm_libc::call_fini_array_callbacks); __llvm_libc::call_init_array_callbacks( - app.args->argc, reinterpret_cast(app.args->argv), + static_cast(app.args->argc), + reinterpret_cast(app.args->argv), reinterpret_cast(env_ptr)); - int retval = main(app.args->argc, reinterpret_cast(app.args->argv), + int retval = main(static_cast(app.args->argc), + reinterpret_cast(app.args->argv), reinterpret_cast(env_ptr)); // TODO: TLS cleanup should be done after all other atexit callbacks diff --git a/libc/startup/linux/x86_64/start.cpp b/libc/startup/linux/x86_64/start.cpp --- a/libc/startup/linux/x86_64/start.cpp +++ b/libc/startup/linux/x86_64/start.cpp @@ -59,13 +59,13 @@ // We cannot call the mmap function here as the functions set errno on // failure. Since errno is implemented via a thread local variable, we cannot // use errno before TLS is setup. - long mmapRetVal = __llvm_libc::syscall_impl( + long mmapRetVal = __llvm_libc::syscall_impl( mmapSyscallNumber, nullptr, tlsSizeWithAddr, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); // We cannot check the return value with MAP_FAILED as that is the return // of the mmap function and not the mmap syscall. if (mmapRetVal < 0 && static_cast(mmapRetVal) > -app.pageSize) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl(SYS_exit, 1); uintptr_t *tlsAddr = reinterpret_cast(mmapRetVal); // x86_64 TLS faces down from the thread pointer with the first entry @@ -84,7 +84,7 @@ void cleanup_tls(uintptr_t addr, uintptr_t size) { if (size == 0) return; - __llvm_libc::syscall_impl(SYS_munmap, addr, size); + __llvm_libc::syscall_impl(SYS_munmap, addr, size); } // Sets the thread pointer to |val|. Returns true on success, false on failure. @@ -152,10 +152,10 @@ __asm__ __volatile__("andq $0xfffffffffffffff0, %rsp\n\t"); __asm__ __volatile__("andq $0xfffffffffffffff0, %rbp\n\t"); - auto tid = __llvm_libc::syscall_impl(SYS_gettid); + auto tid = __llvm_libc::syscall_impl(SYS_gettid); if (tid <= 0) - __llvm_libc::syscall_impl(SYS_exit, 1); - __llvm_libc::main_thread_attrib.tid = tid; + __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::main_thread_attrib.tid = static_cast(tid); // After the argv array, is a 8-byte long NULL value before the array of env // values. The end of the env values is marked by another 8-byte long NULL @@ -205,7 +205,7 @@ __llvm_libc::TLSDescriptor tls; __llvm_libc::init_tls(tls); if (tls.size != 0 && !__llvm_libc::set_thread_ptr(tls.tp)) - __llvm_libc::syscall_impl(SYS_exit, 1); + __llvm_libc::syscall_impl(SYS_exit, 1); __llvm_libc::self.attrib = &__llvm_libc::main_thread_attrib; __llvm_libc::main_thread_attrib.atexit_callback_mgr = @@ -218,10 +218,12 @@ __llvm_libc::atexit(&__llvm_libc::call_fini_array_callbacks); __llvm_libc::call_init_array_callbacks( - app.args->argc, reinterpret_cast(app.args->argv), + static_cast(app.args->argc), + reinterpret_cast(app.args->argv), reinterpret_cast(env_ptr)); - int retval = main(app.args->argc, reinterpret_cast(app.args->argv), + int retval = main(static_cast(app.args->argc), + reinterpret_cast(app.args->argv), reinterpret_cast(env_ptr)); // TODO: TLS cleanup should be done after all other atexit callbacks diff --git a/libc/test/src/__support/OSUtil/linux/x86_64/syscall_test.cpp b/libc/test/src/__support/OSUtil/linux/x86_64/syscall_test.cpp --- a/libc/test/src/__support/OSUtil/linux/x86_64/syscall_test.cpp +++ b/libc/test/src/__support/OSUtil/linux/x86_64/syscall_test.cpp @@ -16,29 +16,30 @@ using __llvm_libc::cpp::function; - function f([](long n) { return __llvm_libc::syscall_impl(n); }); + function f( + [](long n) { return __llvm_libc::syscall_impl(n); }); function f1( - [](long n, long a1) { return __llvm_libc::syscall_impl(n, a1); }); + [](long n, long a1) { return __llvm_libc::syscall_impl(n, a1); }); function f2([](long n, long a1, long a2) { - return __llvm_libc::syscall_impl(n, a1, a2); + return __llvm_libc::syscall_impl(n, a1, a2); }); function f3( [](long n, long a1, long a2, long a3) { - return __llvm_libc::syscall_impl(n, a1, a2, a3); + return __llvm_libc::syscall_impl(n, a1, a2, a3); }); function f4( [](long n, long a1, long a2, long a3, long a4) { - return __llvm_libc::syscall_impl(n, a1, a2, a3, a4); + return __llvm_libc::syscall_impl(n, a1, a2, a3, a4); }); function f5( [](long n, long a1, long a2, long a3, long a4, long a5) { - return __llvm_libc::syscall_impl(n, a1, a2, a3, a4, a5); + return __llvm_libc::syscall_impl(n, a1, a2, a3, a4, a5); }); function f6( [](long n, long a1, long a2, long a3, long a4, long a5, long a6) { - return __llvm_libc::syscall_impl(n, a1, a2, a3, a4, a5, a6); + return __llvm_libc::syscall_impl(n, a1, a2, a3, a4, a5, a6); }); function not_long_type( - [](long n, void *a1) { return __llvm_libc::syscall_impl(n, a1); }); + [](long n, void *a1) { return __llvm_libc::syscall_impl(n, a1); }); } diff --git a/libc/test/src/sched/affinity_test.cpp b/libc/test/src/sched/affinity_test.cpp --- a/libc/test/src/sched/affinity_test.cpp +++ b/libc/test/src/sched/affinity_test.cpp @@ -19,7 +19,7 @@ cpu_set_t mask; libc_errno = 0; using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; - pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); + pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); ASSERT_GT(tid, pid_t(0)); // We just get and set the same mask. ASSERT_THAT(__llvm_libc::sched_getaffinity(tid, sizeof(cpu_set_t), &mask), @@ -30,7 +30,7 @@ TEST(LlvmLibcSchedAffinityTest, BadMask) { using __llvm_libc::testing::ErrnoSetterMatcher::Fails; - pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); + pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); libc_errno = 0; ASSERT_THAT(__llvm_libc::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr), diff --git a/libc/test/src/sched/cpu_count_test.cpp b/libc/test/src/sched/cpu_count_test.cpp --- a/libc/test/src/sched/cpu_count_test.cpp +++ b/libc/test/src/sched/cpu_count_test.cpp @@ -19,7 +19,7 @@ cpu_set_t mask; libc_errno = 0; using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; - pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); + pid_t tid = __llvm_libc::syscall_impl(SYS_gettid); ASSERT_GT(tid, pid_t(0)); ASSERT_THAT(__llvm_libc::sched_getaffinity(tid, sizeof(cpu_set_t), &mask), Succeeds(0)); diff --git a/libc/test/src/signal/kill_test.cpp b/libc/test/src/signal/kill_test.cpp --- a/libc/test/src/signal/kill_test.cpp +++ b/libc/test/src/signal/kill_test.cpp @@ -18,12 +18,12 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; TEST(LlvmLibcKillTest, TargetSelf) { - pid_t parent_pid = __llvm_libc::syscall_impl(SYS_getpid); + pid_t parent_pid = __llvm_libc::syscall_impl(SYS_getpid); ASSERT_THAT(__llvm_libc::kill(parent_pid, 0), Succeeds(0)); EXPECT_DEATH( [] { - pid_t child_pid = __llvm_libc::syscall_impl(SYS_getpid); + pid_t child_pid = __llvm_libc::syscall_impl(SYS_getpid); __llvm_libc::kill(child_pid, SIGKILL); }, WITH_SIGNAL(SIGKILL));