[libc][cleanup] Fix most conversion warnings

This patch is large, but is almost entirely just adding casts to calls
to syscall_impl. Much of the work was done programatically, with human
checking when the syntax or types got confusing.

Reviewed By: mcgrathr

Differential Revision: https://reviews.llvm.org/D156950
This commit is contained in:
Michael Jones 2023-08-02 16:30:26 -07:00
parent f6267d3b98
commit f0a3954ef1
110 changed files with 382 additions and 332 deletions

View File

@ -50,6 +50,15 @@ LIBC_INLINE constexpr To bit_cast(const From &from) {
#endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
}
template <class To, class From>
LIBC_INLINE constexpr To bit_or_static_cast(const From &from) {
if constexpr (sizeof(To) == sizeof(From)) {
return bit_cast<To>(from);
} else {
return static_cast<To>(from);
}
}
} // namespace __llvm_libc::cpp
#endif // LLVM_LIBC_SUPPORT_CPP_BIT_H

View File

@ -19,9 +19,10 @@ namespace __llvm_libc {
ErrorOr<int> 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<int>(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<int>(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<int> platform_opendir(const char *name) {
ErrorOr<size_t> platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer) {
#ifdef SYS_getdents64
long size = __llvm_libc::syscall_impl(SYS_getdents64, fd, buffer.data(),
buffer.size());
long size = __llvm_libc::syscall_impl<long>(SYS_getdents64, fd, buffer.data(),
buffer.size());
#else
#error "getdents64 syscalls not available to perform a fetch dirents operation."
#endif
@ -48,7 +49,7 @@ ErrorOr<size_t> platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer) {
}
int platform_closedir(int fd) {
long ret = __llvm_libc::syscall_impl(SYS_close, fd);
int ret = __llvm_libc::syscall_impl<int>(SYS_close, fd);
if (ret < 0) {
return static_cast<int>(-ret);
}

View File

@ -44,7 +44,7 @@ namespace {
FileIOResult write_func(File *f, const void *data, size_t size) {
auto *lf = reinterpret_cast<LinuxFile *>(f);
int ret = __llvm_libc::syscall_impl(SYS_write, lf->get_fd(), data, size);
int ret = __llvm_libc::syscall_impl<int>(SYS_write, lf->get_fd(), data, size);
if (ret < 0) {
return {0, -ret};
}
@ -53,7 +53,7 @@ FileIOResult write_func(File *f, const void *data, size_t size) {
FileIOResult read_func(File *f, void *buf, size_t size) {
auto *lf = reinterpret_cast<LinuxFile *>(f);
int ret = __llvm_libc::syscall_impl(SYS_read, lf->get_fd(), buf, size);
int ret = __llvm_libc::syscall_impl<int>(SYS_read, lf->get_fd(), buf, size);
if (ret < 0) {
return {0, -ret};
}
@ -64,16 +64,22 @@ ErrorOr<long> seek_func(File *f, long offset, int whence) {
auto *lf = reinterpret_cast<LinuxFile *>(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<int>(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<int>(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<int>(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<int>(
SYS__llseek, lf->get_fd(), offset >> 32, offset, &result, whence);
#else
#error "lseek, llseek and _llseek syscalls not available."
#endif
@ -86,7 +92,7 @@ ErrorOr<long> seek_func(File *f, long offset, int whence) {
int close_func(File *f) {
auto *lf = reinterpret_cast<LinuxFile *>(f);
int ret = __llvm_libc::syscall_impl(SYS_close, lf->get_fd());
int ret = __llvm_libc::syscall_impl<int>(SYS_close, lf->get_fd());
if (ret < 0) {
return -ret;
}
@ -128,10 +134,11 @@ ErrorOr<File *> openfile(const char *path, const char *mode) {
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<int>(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<int>(SYS_openat, AT_FDCWD, path,
open_flags, OPEN_MODE);
#else
#error "open and openat syscalls not available."
#endif

View File

@ -17,7 +17,7 @@ namespace __llvm_libc {
LIBC_INLINE void quick_exit(int status) {
for (;;) {
__llvm_libc::syscall_impl(1 /* SYS_exit */, status);
__llvm_libc::syscall_impl<long>(1 /* SYS_exit */, status);
}
}

View File

@ -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 <typename... Ts>
LIBC_INLINE long syscall_impl(long __number, Ts... ts) {
template <typename R, typename... Ts>
LIBC_INLINE R 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<R>(syscall_impl(__number, (long)ts...));
}
} // namespace __llvm_libc

View File

@ -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<long>(SYS_write, 2 /* stderr */, msg.data(),
msg.size());
}
} // namespace __llvm_libc

View File

@ -19,8 +19,8 @@ namespace __llvm_libc {
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<long>(SYS_exit_group, status);
__llvm_libc::syscall_impl<long>(SYS_exit, status);
}
}

View File

@ -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 <typename... Ts>
LIBC_INLINE long syscall_impl(long __number, Ts... ts) {
template <typename R, typename... Ts>
LIBC_INLINE R 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<R>(syscall_impl(__number, (long)ts...));
}
} // namespace __llvm_libc

View File

@ -34,10 +34,10 @@ int callonce(CallOnceFlag *flag, CallOnceCallback *func) {
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<long>(FUTEX_SYSCALL_ID, &futex_word->val,
FUTEX_WAKE_PRIVATE,
INT_MAX, // Wake all waiters.
0, 0, 0);
}
return 0;
}
@ -45,7 +45,7 @@ int callonce(CallOnceFlag *flag, CallOnceCallback *func) {
FutexWordType status = START;
if (futex_word->compare_exchange_strong(status, WAITING) ||
status == WAITING) {
__llvm_libc::syscall_impl(
__llvm_libc::syscall_impl<long>(
FUTEX_SYSCALL_ID, &futex_word->val, FUTEX_WAIT_PRIVATE,
WAITING, // Block only if status is still |WAITING|.
0, 0, 0);

View File

@ -76,9 +76,9 @@ public:
// 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<long>(
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 @@ public:
// 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<long>(
FUTEX_SYSCALL_ID, &futex_word, FUTEX_WAIT_PRIVATE,
FutexWordType(LockState::Waiting), 0, 0, 0);
was_waiting = true;
}
continue;
@ -110,8 +110,8 @@ public:
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<long>(FUTEX_SYSCALL_ID, &futex_word,
FUTEX_WAKE_PRIVATE, 1, 0, 0, 0);
return MutexError::NONE;
}

View File

@ -92,14 +92,14 @@ LIBC_INLINE ErrorOr<void *> alloc_stack(size_t stacksize, size_t guardsize) {
// 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<long>(
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 @@ LIBC_INLINE ErrorOr<void *> alloc_stack(size_t stacksize, size_t guardsize) {
// 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<long>(SYS_mprotect, mmap_result + guardsize,
stacksize, PROT_READ | PROT_WRITE);
if (result != 0)
return Error{int(-result)};
@ -125,7 +125,7 @@ free_stack(void *stack, size_t stacksize, size_t guardsize) {
uintptr_t stackaddr = reinterpret_cast<uintptr_t>(stack);
stackaddr -= guardsize;
stack = reinterpret_cast<void *>(stackaddr);
__llvm_libc::syscall_impl(SYS_munmap, stack, stacksize + guardsize);
__llvm_libc::syscall_impl<long>(SYS_munmap, stack, stacksize + guardsize);
}
struct Thread;
@ -299,7 +299,7 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
// 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<long>(
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 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
#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<long>(
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 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
start_thread();
} else if (clone_result < 0) {
cleanup_thread_resources(attrib);
return -clone_result;
return static_cast<int>(-clone_result);
}
return 0;
@ -379,8 +379,8 @@ void Thread::wait() {
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<long>(FUTEX_SYSCALL_ID, &clear_tid->val,
FUTEX_WAIT, CLEAR_TID_VALUE, nullptr);
}
}
@ -408,7 +408,8 @@ int Thread::set_name(const cpp::string_view &name) {
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<int>(SYS_prctl, PR_SET_NAME, name.data());
if (retval < 0)
return -retval;
else
@ -419,17 +420,17 @@ int Thread::set_name(const cpp::string_view &name) {
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<int>(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<int>(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<int>(SYS_write, fd, name.data(), name.size());
__llvm_libc::syscall_impl<long>(SYS_close, fd);
if (retval < 0)
return -retval;
@ -448,7 +449,8 @@ int Thread::get_name(cpp::StringStream &name) const {
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<int>(SYS_prctl, PR_GET_NAME, name_buffer);
if (retval < 0)
return -retval;
name << name_buffer << cpp::StringStream::ENDS;
@ -459,17 +461,17 @@ int Thread::get_name(cpp::StringStream &name) const {
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<int>(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<int>(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<int>(SYS_read, fd, name_buffer, NAME_SIZE_MAX);
__llvm_libc::syscall_impl<long>(SYS_close, fd);
if (retval < 0)
return -retval;
if (retval == NAME_SIZE_MAX)
@ -503,18 +505,18 @@ void thread_exit(ThreadReturnValue retval, ThreadStyle style) {
// 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<long>(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<long>(SYS_exit, 0);
__builtin_unreachable();
}
if (style == ThreadStyle::POSIX)
__llvm_libc::syscall_impl(SYS_exit, retval.posix_retval);
__llvm_libc::syscall_impl<long>(SYS_exit, retval.posix_retval);
else
__llvm_libc::syscall_impl(SYS_exit, retval.stdc_retval);
__llvm_libc::syscall_impl<long>(SYS_exit, retval.stdc_retval);
__builtin_unreachable();
}

View File

@ -57,7 +57,7 @@ public:
cpp::optional<unsigned int> 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};

View File

@ -19,11 +19,11 @@ namespace __llvm_libc {
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<int>(
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<int>(
SYS_openat, AT_FDCWD, path, O_CREAT | O_WRONLY | O_TRUNC, mode_flags);
#endif
if (fd > 0)

View File

@ -30,10 +30,10 @@ LLVM_LIBC_FUNCTION(int, open, (const char *path, int flags, ...)) {
}
#ifdef SYS_open
int fd = __llvm_libc::syscall_impl(SYS_open, path, flags, mode_flags);
int fd = __llvm_libc::syscall_impl<int>(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<int>(SYS_openat, AT_FDCWD, path, flags,
mode_flags);
#endif
if (fd > 0)
return fd;

View File

@ -29,7 +29,8 @@ LLVM_LIBC_FUNCTION(int, openat, (int dfd, const char *path, int flags, ...)) {
va_end(varargs);
}
int fd = __llvm_libc::syscall_impl(SYS_openat, dfd, path, flags, mode_flags);
int fd =
__llvm_libc::syscall_impl<int>(SYS_openat, dfd, path, flags, mode_flags);
if (fd > 0)
return fd;

View File

@ -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<int>(SYS_sched_get_priority_max, policy);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_sched_get_priority_min, policy);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -20,8 +20,8 @@ namespace __llvm_libc {
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<int>(SYS_sched_getaffinity, tid,
cpuset_size, mask);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -18,7 +18,7 @@ namespace __llvm_libc {
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<int>(SYS_sched_getparam, tid, param);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_sched_getscheduler, tid);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -23,24 +23,24 @@ namespace __llvm_libc {
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<int>(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<int>(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<int>(SYS_sched_rr_get_interval_time64, tid,
nullptr);
#else
#error \
"sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."

View File

@ -19,8 +19,8 @@ namespace __llvm_libc {
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<int>(SYS_sched_setaffinity, tid,
cpuset_size, mask);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -18,7 +18,7 @@ namespace __llvm_libc {
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<int>(SYS_sched_setparam, tid, param);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -18,8 +18,8 @@ namespace __llvm_libc {
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<int>(SYS_sched_setscheduler, tid, policy,
param);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_sched_yield);
// As of writing this, yield() cannot fail
if (ret < 0) {
libc_errno = -ret;

View File

@ -19,6 +19,8 @@ extern "C" void __restore_rt()
__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<long>(SYS_rt_sigreturn);
}
} // namespace __llvm_libc

View File

@ -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<int>(SYS_kill, pid, sig);
// A negative return value indicates an error with the magnitude of the
// value being the error code.

View File

@ -16,9 +16,9 @@ namespace __llvm_libc {
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<long>(SYS_getpid);
long tid = __llvm_libc::syscall_impl<long>(SYS_gettid);
int ret = __llvm_libc::syscall_impl<int>(SYS_tgkill, pid, tid, sig);
restore_signals(sigset);
return ret;
}

View File

@ -34,7 +34,7 @@ LLVM_LIBC_FUNCTION(int, sigaction,
}
KernelSigaction kernel_old;
int ret = __llvm_libc::syscall_impl(
int ret = __llvm_libc::syscall_impl<int>(
SYS_rt_sigaction, signal, libc_new ? &kernel_new : nullptr,
libc_old ? &kernel_old : nullptr, sizeof(sigset_t));
if (ret) {

View File

@ -34,7 +34,7 @@ LLVM_LIBC_FUNCTION(int, sigaltstack,
}
}
int ret = __llvm_libc::syscall_impl(SYS_sigaltstack, ss, oss);
int ret = __llvm_libc::syscall_impl<int>(SYS_sigaltstack, ss, oss);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -44,7 +44,7 @@ struct KernelSigaction {
LIBC_INLINE operator struct sigaction() const {
struct sigaction sa;
sa.sa_flags = sa_flags;
sa.sa_flags = static_cast<int>(sa_flags);
sa.sa_mask = sa_mask;
sa.sa_restorer = sa_restorer;
if (sa_flags & SA_SIGINFO)
@ -96,13 +96,13 @@ LIBC_INLINE constexpr bool delete_signal(sigset_t &set, int signal) {
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<int>(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<int>(SYS_rt_sigprocmask, SIG_SETMASK, &set,
nullptr, sizeof(sigset_t));
}
} // namespace __llvm_libc

View File

@ -21,8 +21,8 @@ namespace __llvm_libc {
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<int>(SYS_rt_sigprocmask, how, set, oldset,
sizeof(sigset_t));
if (!ret)
return 0;

View File

@ -27,9 +27,9 @@ pid_t fork() {
// 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<pid_t>(SYS_fork);
#elif defined(SYS_clone)
return __llvm_libc::syscall_impl(SYS_clone, SIGCHLD, 0);
return __llvm_libc::syscall_impl<pid_t>(SYS_clone, SIGCHLD, 0);
#else
#error "fork or clone syscalls not available."
#endif
@ -37,9 +37,10 @@ pid_t fork() {
cpp::optional<int> 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<int>(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<int>(SYS_openat, AT_FDCWD, path, oflags, mode);
#endif
if (fd > 0)
return fd;
@ -49,14 +50,14 @@ cpp::optional<int> open(const char *path, int oflags, mode_t mode) {
return cpp::nullopt;
}
void close(int fd) { __llvm_libc::syscall_impl(SYS_close, fd); }
void close(int fd) { __llvm_libc::syscall_impl<long>(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<int>(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<int>(SYS_dup3, fd, newfd, 0);
#else
#error "dup2 and dup3 syscalls not available."
#endif
@ -67,8 +68,8 @@ bool dup2(int fd, int newfd) {
// 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<long>(SYS_exit_group, 127);
__llvm_libc::syscall_impl<long>(SYS_exit, 127);
}
}
@ -116,7 +117,7 @@ void child_process(const char *__restrict path,
}
}
if (__llvm_libc::syscall_impl(SYS_execve, path, argv, envp) < 0)
if (__llvm_libc::syscall_impl<long>(SYS_execve, path, argv, envp) < 0)
exit();
}

View File

@ -20,9 +20,10 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_unlinkat, AT_FDCWD, path,
AT_REMOVEDIR);
if (ret >= 0)
return 0;
libc_errno = -ret;

View File

@ -34,11 +34,10 @@ LIBC_INLINE void funlockfile(FILE *f) {
reinterpret_cast<__llvm_libc::File *>(f)->unlock();
}
LIBC_INLINE int fwrite_unlocked(const void *ptr, size_t size, size_t nmemb,
FILE *f) {
return static_cast<int>(
reinterpret_cast<__llvm_libc::File *>(f)->write_unlocked(ptr,
size * nmemb));
LIBC_INLINE size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb,
FILE *f) {
return reinterpret_cast<__llvm_libc::File *>(f)->write_unlocked(ptr,
size * nmemb);
}
#else // defined(LIBC_COPT_PRINTF_USE_SYSTEM_FILE)
LIBC_INLINE int ferror_unlocked(::FILE *f) { return ::ferror_unlocked(f); }
@ -47,8 +46,8 @@ LIBC_INLINE void flockfile(::FILE *f) { ::flockfile(f); }
LIBC_INLINE void funlockfile(::FILE *f) { ::funlockfile(f); }
LIBC_INLINE int fwrite_unlocked(const void *ptr, size_t size, size_t nmemb,
::FILE *f) {
LIBC_INLINE size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb,
::FILE *f) {
return ::fwrite_unlocked(ptr, size, nmemb, f);
}
#endif // LIBC_COPT_PRINTF_USE_SYSTEM_FILE

View File

@ -19,13 +19,13 @@ namespace __llvm_libc {
// 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<int>(
SYS_madvise, reinterpret_cast<long>(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;
}

View File

@ -39,7 +39,7 @@ LLVM_LIBC_FUNCTION(void *, mmap,
#error "mmap or mmap2 syscalls not available."
#endif
long ret_val =
long ret =
__llvm_libc::syscall_impl(syscall_number, reinterpret_cast<long>(addr),
size, prot, flags, fd, offset);
@ -52,12 +52,12 @@ LLVM_LIBC_FUNCTION(void *, mmap,
// 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<int>(-ret);
return MAP_FAILED;
}
return reinterpret_cast<void *>(ret_val);
return reinterpret_cast<void *>(ret);
}
} // namespace __llvm_libc

View File

@ -19,13 +19,13 @@ namespace __llvm_libc {
// 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<int>(
SYS_mprotect, reinterpret_cast<long>(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;
}

View File

@ -19,13 +19,13 @@ namespace __llvm_libc {
// 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<long>(addr), size);
int ret = __llvm_libc::syscall_impl<int>(SYS_munmap,
reinterpret_cast<long>(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;
}

View File

@ -23,9 +23,9 @@ LLVM_LIBC_FUNCTION(int, posix_madvise, (void *addr, size_t size, int advice)) {
if (advice == POSIX_MADV_DONTNEED) {
return 0;
}
long ret_val = __llvm_libc::syscall_impl(
int ret = __llvm_libc::syscall_impl<int>(
SYS_madvise, reinterpret_cast<long>(addr), size, advice);
return ret_val < 0 ? -ret_val : 0;
return ret < 0 ? -ret : 0;
}
} // namespace __llvm_libc

View File

@ -18,9 +18,10 @@ namespace __llvm_libc {
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<ssize_t>(SYS_getrandom, buf, buflen, flags);
if (ret < 0) {
libc_errno = -ret;
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;

View File

@ -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<int>(SYS_prlimit64, 0, res, nullptr, limits);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_prlimit64, 0, res, limits, nullptr);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -54,11 +54,11 @@ LLVM_LIBC_FUNCTION(int, select,
}
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<int>(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<int>(SYS_pselect6_time64, nfds, read_set,
write_set, error_set, &ts, &pss);
#else
#error "SYS_pselect6 and SYS_pselect6_time64 syscalls not available."
#endif

View File

@ -20,18 +20,18 @@ namespace __llvm_libc {
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<ssize_t>(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<ssize_t>(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<int>(-ret);
return -1;
}
return ret;

View File

@ -20,11 +20,11 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_socketcall, SYS_SOCKET, sockcall_args);
#else
#error "socket and socketcall syscalls unavailable for this platform."
#endif

View File

@ -20,9 +20,9 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_fchmodat, AT_FDCWD, path, mode);
#else
#error "chmod and fchmodat syscalls not available."
#endif

View File

@ -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<int>(SYS_fchmod, fd, mode);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -19,7 +19,8 @@ namespace __llvm_libc {
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<int>(SYS_fchmodat, dirfd, path, mode, flags);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -73,8 +73,8 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
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<int>(SYS_statx, dirfd, path, flags,
::STATX_BASIC_STATS_MASK, &xbuf);
if (ret < 0)
return -ret;

View File

@ -20,9 +20,9 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_mkdirat, AT_FDCWD, path, mode);
#else
#error "mkdir and mkdirat syscalls not available."
#endif

View File

@ -19,7 +19,7 @@ namespace __llvm_libc {
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<int>(SYS_mkdirat, dfd, path, mode);
#else
#error "mkdirat syscall not available."
#endif

View File

@ -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<int>(SYS_uname, name);
if (ret >= 0)
return 1;

View File

@ -27,7 +27,8 @@ namespace internal {
LIBC_INLINE ErrorOr<pid_t> 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<pid_t>(SYS_wait4, pid, wait_status, options,
usage);
#elif defined(SYS_waitid)
int idtype = P_PID;
if (pid == -1) {
@ -42,8 +43,8 @@ LIBC_INLINE ErrorOr<pid_t> wait4impl(pid_t pid, int *wait_status, int options,
options |= WEXITED;
siginfo_t info;
pid =
__llvm_libc::syscall_impl(SYS_waitid, idtype, pid, &info, options, usage);
pid = __llvm_libc::syscall_impl<pid_t>(SYS_waitid, idtype, pid, &info,
options, usage);
if (pid >= 0)
pid = info.si_pid;

View File

@ -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<int>(SYS_ioctl, fd, TCSBRK, 1);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_ioctl, fd, TCXONC, action);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_ioctl, fd, TCFLSH, queue_selector);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -21,7 +21,7 @@ namespace __llvm_libc {
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<int>(SYS_ioctl, fd, TCGETS, &kt);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -20,7 +20,7 @@ namespace __llvm_libc {
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<int>(SYS_ioctl, fd, TIOCGSID, &sid);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(pid_t, tcsendbreak, (int fd, int /* unused duration */)) {
// 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<int>(SYS_ioctl, fd, TCSBRK, 0);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -51,7 +51,7 @@ LLVM_LIBC_FUNCTION(int, tcsetattr,
kt.c_cc[i] = 0;
}
long ret = __llvm_libc::syscall_impl(SYS_ioctl, fd, cmd, &kt);
int ret = __llvm_libc::syscall_impl<int>(SYS_ioctl, fd, cmd, &kt);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -84,8 +84,8 @@ struct CndVar {
}
}
__llvm_libc::syscall_impl(FUTEX_SYSCALL_ID, &waiter.futex_word.val,
FUTEX_WAIT, WS_Waiting, 0, 0, 0);
__llvm_libc::syscall_impl<long>(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 @@ struct CndVar {
qmtx.futex_word = FutexWordType(Mutex::LockState::Free);
__llvm_libc::syscall_impl(
__llvm_libc::syscall_impl<long>(
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 @@ struct CndVar {
// 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<long>(
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));

View File

@ -21,21 +21,21 @@ namespace __llvm_libc {
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<long>(clockid),
reinterpret_cast<long>(tp));
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime,
static_cast<long>(clockid),
reinterpret_cast<long>(tp));
#elif defined(SYS_clock_gettime64)
long ret_val =
__llvm_libc::syscall_impl(SYS_clock_gettime64, static_cast<long>(clockid),
reinterpret_cast<long>(tp));
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime64,
static_cast<long>(clockid),
reinterpret_cast<long>(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;
}

View File

@ -23,11 +23,11 @@ LLVM_LIBC_FUNCTION(int, gettimeofday,
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<int>(SYS_clock_gettime,
static_cast<long>(CLOCK_REALTIME),
reinterpret_cast<long>(&tp));
#elif defined(SYS_clock_gettime64)
long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime64,
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime64,
static_cast<long>(CLOCK_REALTIME),
reinterpret_cast<long>(&tp));
#else
@ -35,12 +35,12 @@ LLVM_LIBC_FUNCTION(int, gettimeofday,
#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<suseconds_t>(tp.tv_nsec / 1000);
return 0;
}

View File

@ -21,17 +21,17 @@ namespace __llvm_libc {
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<int>(
SYS_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, reinterpret_cast<long>(&ts));
#elif defined(SYS_clock_gettime64)
long ret_val =
__llvm_libc::syscall_impl(SYS_clock_gettime64, CLOCK_PROCESS_CPUTIME_ID,
reinterpret_cast<long>(&ts));
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime64,
CLOCK_PROCESS_CPUTIME_ID,
reinterpret_cast<long>(&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);
}

View File

@ -21,16 +21,16 @@ LLVM_LIBC_FUNCTION(time_t, time, (time_t * tp)) {
// 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<int>(SYS_clock_gettime, CLOCK_REALTIME,
reinterpret_cast<long>(&ts));
#elif defined(SYS_clock_gettime64)
long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime64, CLOCK_REALTIME,
int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime64, CLOCK_REALTIME,
reinterpret_cast<long>(&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;
}

View File

@ -20,9 +20,10 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_clock_nanosleep_time64, req, rem);
#else
#error "SYS_nanosleep and SYS_clock_nanosleep_time64 syscalls not available."
#endif

View File

@ -131,16 +131,19 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) {
// 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_year = static_cast<int>(years + 2000 - TimeConstants::TIME_YEAR_BASE);
tm->tm_mon = static_cast<int>(months + 2);
tm->tm_mday = static_cast<int>(remainingDays + 1);
tm->tm_wday = static_cast<int>(wday);
tm->tm_yday = static_cast<int>(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_hour =
static_cast<int>(remainingSeconds / TimeConstants::SECONDS_PER_HOUR);
tm->tm_min =
static_cast<int>(remainingSeconds / TimeConstants::SECONDS_PER_MIN %
TimeConstants::SECONDS_PER_MIN);
tm->tm_sec =
static_cast<int>(remainingSeconds % TimeConstants::SECONDS_PER_MIN);
// TODO(rtenneti): Need to handle timezone and update of tm_isdst.
tm->tm_isdst = 0;

View File

@ -19,9 +19,10 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_faccessat, AT_FDCWD, path, mode, 0);
#else
#error "access and faccessat syscalls not available."
#endif

View File

@ -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<int>(SYS_chdir, path);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_close, fd);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_dup, fd);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -20,7 +20,7 @@ namespace __llvm_libc {
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<int>(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 @@ LLVM_LIBC_FUNCTION(int, dup2, (int oldfd, int newfd)) {
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<int>(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<int>(SYS_fcntl64, oldfd, F_GETFD);
#else
#error "SYS_fcntl and SYS_fcntl64 syscalls not available."
#endif
@ -41,7 +41,7 @@ LLVM_LIBC_FUNCTION(int, dup2, (int oldfd, int newfd)) {
libc_errno = -ret;
return -1;
}
long ret = __llvm_libc::syscall_impl(SYS_dup3, oldfd, newfd, 0);
int ret = __llvm_libc::syscall_impl<int>(SYS_dup3, oldfd, newfd, 0);
#else
#error "dup2 and dup3 syscalls not available."
#endif

View File

@ -18,7 +18,7 @@ namespace __llvm_libc {
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<int>(SYS_dup3, oldfd, newfd, flags);
if (ret >= 0)
return ret;
libc_errno = -ret;

View File

@ -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<int>(SYS_execve, path, argv,
__llvm_libc::environ);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -19,7 +19,7 @@ namespace __llvm_libc {
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<int>(SYS_execve, path, argv, envp);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -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<int>(SYS_fchdir, fd);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -25,9 +25,9 @@ namespace __llvm_libc {
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<pid_t>(SYS_fork);
#elif defined(SYS_clone)
pid_t ret = __llvm_libc::syscall_impl(SYS_clone, SIGCHLD, 0);
pid_t ret = __llvm_libc::syscall_impl<pid_t>(SYS_clone, SIGCHLD, 0);
#else
#error "fork and clone syscalls not available."
#endif
@ -36,14 +36,14 @@ LLVM_LIBC_FUNCTION(pid_t, fork, (void)) {
// 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<pid_t>(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<int>(-ret);
return -1;
}

View File

@ -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<int>(SYS_fsync, fd);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -20,12 +20,12 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_ftruncate64, fd, (long)len,
(long)(((uint64_t)(len)) >> 32));
#else
#error "ftruncate and ftruncate64 syscalls not available."
#endif

View File

@ -22,7 +22,7 @@ namespace __llvm_libc {
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<int>(SYS_getcwd, buf, size);
if (ret < 0) {
libc_errno = -ret;
return false;

View File

@ -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<uid_t>(SYS_geteuid);
}
} // namespace __llvm_libc

View File

@ -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<pid_t>(SYS_getpid);
}
} // namespace __llvm_libc

View File

@ -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<pid_t>(SYS_getppid);
}
} // namespace __llvm_libc

View File

@ -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<uid_t>(SYS_getuid);
}
} // namespace __llvm_libc

View File

@ -22,7 +22,8 @@ LLVM_LIBC_FUNCTION(int, isatty, (int fd)) {
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<int>(SYS_ioctl, fd, TIOCGETD, &line_d_val);
if (result == 0)
return 1;

View File

@ -19,10 +19,10 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_linkat, AT_FDCWD, path1,
AT_FDCWD, path2, 0);
#else
#error "link or linkat syscalls not available."
#endif

View File

@ -20,8 +20,8 @@ namespace __llvm_libc {
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<int>(SYS_linkat, fd1, path1, fd2, path2, flags);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -21,7 +21,7 @@ namespace __llvm_libc {
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<int>(SYS_lseek, fd, offset, whence);
result = ret;
#elif defined(SYS_llseek)
long ret = __llvm_libc::syscall_impl(SYS_llseek, fd,
@ -29,8 +29,8 @@ LLVM_LIBC_FUNCTION(off_t, lseek, (int fd, off_t offset, int whence)) {
(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<int>(SYS__llseek, fd, offset >> 32,
offset, &result, whence);
#else
#error "lseek, llseek and _llseek syscalls not available."
#endif

View File

@ -21,14 +21,15 @@ LLVM_LIBC_FUNCTION(ssize_t, pread,
(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<ssize_t>(
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<ssize_t>(SYS_pread64, fd, buf, count, offset);
#endif
if (ret < 0) {
libc_errno = -ret;
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;

View File

@ -21,14 +21,15 @@ LLVM_LIBC_FUNCTION(ssize_t, pwrite,
(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<ssize_t>(
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<ssize_t>(SYS_pwrite64, fd, buf, count, offset);
#endif
if (ret < 0) {
libc_errno = -ret;
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;

View File

@ -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<ssize_t>(SYS_read, fd, buf, count);
if (ret < 0) {
libc_errno = -ret;
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;

View File

@ -21,15 +21,16 @@ LLVM_LIBC_FUNCTION(ssize_t, readlink,
(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<ssize_t>(SYS_readlink, path, buf, bufsize);
#elif defined(SYS_readlinkat)
ssize_t ret = __llvm_libc::syscall_impl<ssize_t>(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<int>(-ret);
return -1;
}
return ret;

View File

@ -20,10 +20,10 @@ namespace __llvm_libc {
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<ssize_t>(SYS_readlinkat, fd, path,
buf, bufsize);
if (ret < 0) {
libc_errno = -ret;
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;

View File

@ -19,10 +19,10 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_unlinkat, AT_FDCWD, path,
AT_REMOVEDIR);
#else
#error "rmdir and unlinkat syscalls not available."
#endif

View File

@ -19,9 +19,10 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_symlinkat, path1, AT_FDCWD, path2);
#else
#error "symlink or symlinkat syscalls not available."
#endif

View File

@ -19,7 +19,7 @@ namespace __llvm_libc {
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<int>(SYS_symlinkat, path1, fd, path2);
if (ret < 0) {
libc_errno = -ret;
return -1;

View File

@ -19,12 +19,12 @@ namespace __llvm_libc {
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<long>(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<unsigned long>(ret) > -4096UL) {
libc_errno = -ret;
libc_errno = static_cast<int>(-ret);
return -1;
}
return ret;

View File

@ -20,12 +20,12 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_truncate64, path, (long)len,
(long)(((uint64_t)(len)) >> 32));
#else
#error "truncate and truncate64 syscalls not available."
#endif

View File

@ -19,9 +19,9 @@ namespace __llvm_libc {
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<int>(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<int>(SYS_unlinkat, AT_FDCWD, path, 0);
#else
#error "unlink and unlinkat syscalls not available."
#endif

Some files were not shown because too many files have changed in this diff Show More