[libc][NFC] Port raw syscall users to existing syscall_wrappers (#208039)
Several call sites still invoked syscall_impl directly (or carried their own SYS_* fallback ladders) for syscalls that already have a wrapper in src/__support/OSUtil/linux/syscall_wrappers. This PR removes these syscalls in favor of the syscall_wrappers.
This commit is contained in:
parent
db1f902cd6
commit
f04bf4791a
23 changed files with 111 additions and 148 deletions
|
|
@ -11,12 +11,13 @@ add_object_library(
|
|||
libc.hdr.sys_stat_macros
|
||||
libc.hdr.types.FILE
|
||||
libc.hdr.types.off_t
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.CPP.new
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.close
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.lseek
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.open
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.read
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.write
|
||||
libc.src.__support.error_or
|
||||
libc.src.__support.File.file
|
||||
libc.src.errno.errno
|
||||
|
|
@ -33,6 +34,7 @@ add_object_library(
|
|||
libc.hdr.sys_stat_macros
|
||||
libc.src.__support.OSUtil.linux.stat.kernel_statx_types
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.close
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.open
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.fcntl
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.statx
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "hdr/fcntl_macros.h" // For open flags
|
||||
#include "hdr/sys_stat_macros.h" // For S_ISDIR
|
||||
#include "src/__support/OSUtil/linux/stat/kernel_statx_types.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/fcntl.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/statx.h"
|
||||
|
|
@ -42,9 +43,9 @@ ErrorOr<size_t> platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer) {
|
|||
}
|
||||
|
||||
int platform_closedir(int fd) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_close, fd);
|
||||
if (ret < 0)
|
||||
return static_cast<int>(-ret);
|
||||
auto ret = linux_syscalls::close(fd);
|
||||
if (!ret)
|
||||
return ret.error();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,36 +14,34 @@
|
|||
#include "hdr/types/off_t.h"
|
||||
#include "src/__support/CPP/new.h"
|
||||
#include "src/__support/File/file.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/fcntl.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/lseek.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/read.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/write.h"
|
||||
#include "src/__support/alloc-checker.h"
|
||||
#include "src/__support/libc_errno.h" // For error macros
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
#include <sys/syscall.h> // For syscall numbers
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
FileIOResult linux_file_write(File *f, const void *data, size_t size) {
|
||||
auto *lf = reinterpret_cast<LinuxFile *>(f);
|
||||
int ret =
|
||||
LIBC_NAMESPACE::syscall_impl<int>(SYS_write, lf->get_fd(), data, size);
|
||||
if (ret < 0) {
|
||||
return {0, -ret};
|
||||
auto ret = linux_syscalls::write(lf->get_fd(), data, size);
|
||||
if (!ret) {
|
||||
return {0, ret.error()};
|
||||
}
|
||||
return ret;
|
||||
return static_cast<size_t>(ret.value());
|
||||
}
|
||||
|
||||
FileIOResult linux_file_read(File *f, void *buf, size_t size) {
|
||||
auto *lf = reinterpret_cast<LinuxFile *>(f);
|
||||
int ret =
|
||||
LIBC_NAMESPACE::syscall_impl<int>(SYS_read, lf->get_fd(), buf, size);
|
||||
if (ret < 0) {
|
||||
return {0, -ret};
|
||||
auto ret = linux_syscalls::read(lf->get_fd(), buf, size);
|
||||
if (!ret) {
|
||||
return {0, ret.error()};
|
||||
}
|
||||
return ret;
|
||||
return static_cast<size_t>(ret.value());
|
||||
}
|
||||
|
||||
ErrorOr<off_t> linux_file_seek(File *f, off_t offset, int whence) {
|
||||
|
|
@ -54,9 +52,9 @@ ErrorOr<off_t> linux_file_seek(File *f, off_t offset, int whence) {
|
|||
int linux_file_close(File *f) {
|
||||
File::remove_file(f);
|
||||
auto *lf = reinterpret_cast<LinuxFile *>(f);
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_close, lf->get_fd());
|
||||
if (ret < 0) {
|
||||
return -ret;
|
||||
auto ret = linux_syscalls::close(lf->get_fd());
|
||||
if (!ret) {
|
||||
return ret.error();
|
||||
}
|
||||
delete lf;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -25,12 +25,15 @@ add_header_library(
|
|||
HDRS
|
||||
auxv.h
|
||||
DEPENDS
|
||||
libc.hdr.errno_macros
|
||||
libc.hdr.fcntl_macros
|
||||
libc.hdr.sys_auxv_macros
|
||||
libc.hdr.sys_mman_macros
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.close
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.mmap
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.munmap
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.open
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.read
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.common
|
||||
libc.src.__support.CPP.optional
|
||||
|
|
|
|||
|
|
@ -9,12 +9,15 @@
|
|||
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AUXV_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_AUXV_H
|
||||
|
||||
#include "hdr/errno_macros.h" // For EINTR
|
||||
#include "hdr/fcntl_macros.h" // For open flags
|
||||
#include "hdr/sys_auxv_macros.h" // For AT_ macros
|
||||
#include "hdr/sys_mman_macros.h" // For mmap flags
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/mmap.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/munmap.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/read.h"
|
||||
#include "src/__support/OSUtil/syscall.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/threads/callonce.h"
|
||||
|
|
@ -122,18 +125,20 @@ LIBC_INLINE void Vector::fallback_initialize_unsync() {
|
|||
uint8_t *cursor = reinterpret_cast<uint8_t *>(vector);
|
||||
bool has_error = false;
|
||||
while (avaiable_size != 0) {
|
||||
long bytes_read =
|
||||
syscall_impl<long>(SYS_read, fd.value(), cursor, avaiable_size);
|
||||
if (bytes_read <= 0) {
|
||||
if (bytes_read == -EINTR)
|
||||
ErrorOr<ssize_t> bytes_read =
|
||||
linux_syscalls::read(fd.value(), cursor, avaiable_size);
|
||||
if (!bytes_read.has_value()) {
|
||||
if (bytes_read.error() == EINTR)
|
||||
continue;
|
||||
has_error = bytes_read < 0;
|
||||
has_error = true;
|
||||
break;
|
||||
}
|
||||
avaiable_size -= bytes_read;
|
||||
cursor += bytes_read;
|
||||
if (bytes_read.value() == 0)
|
||||
break;
|
||||
avaiable_size -= bytes_read.value();
|
||||
cursor += bytes_read.value();
|
||||
}
|
||||
syscall_impl<long>(SYS_close, fd.value());
|
||||
linux_syscalls::close(fd.value());
|
||||
if (has_error) {
|
||||
linux_syscalls::munmap(vector, AUXV_MMAP_SIZE);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -41,10 +41,13 @@ add_object_library(
|
|||
libc.src.__support.CPP.string_view
|
||||
libc.src.__support.common
|
||||
libc.src.__support.error_or
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.close
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.mmap
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.mprotect
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.munmap
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.open
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.read
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.write
|
||||
libc.src.__support.threads.thread_common
|
||||
COMPILE_OPTIONS
|
||||
${libc_opt_high_flag}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,13 @@
|
|||
#include "src/__support/CPP/atomic.h"
|
||||
#include "src/__support/CPP/string_view.h"
|
||||
#include "src/__support/CPP/stringstream.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/mmap.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/mprotect.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/munmap.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/read.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/write.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/error_or.h"
|
||||
|
|
@ -435,13 +438,13 @@ int Thread::set_name(const cpp::string_view &name) {
|
|||
if (!fd)
|
||||
return fd.error();
|
||||
|
||||
int retval = LIBC_NAMESPACE::syscall_impl<int>(SYS_write, fd.value(),
|
||||
name.data(), name.size());
|
||||
LIBC_NAMESPACE::syscall_impl<long>(SYS_close, fd.value());
|
||||
auto write_result =
|
||||
linux_syscalls::write(fd.value(), name.data(), name.size());
|
||||
linux_syscalls::close(fd.value());
|
||||
|
||||
if (retval < 0)
|
||||
return -retval;
|
||||
else if (retval != int(name.size()))
|
||||
if (!write_result)
|
||||
return write_result.error();
|
||||
else if (write_result.value() != static_cast<ssize_t>(name.size()))
|
||||
return EIO;
|
||||
else
|
||||
return 0;
|
||||
|
|
@ -471,11 +474,12 @@ int Thread::get_name(cpp::StringStream &name) const {
|
|||
if (!fd)
|
||||
return fd.error();
|
||||
|
||||
int retval = LIBC_NAMESPACE::syscall_impl<int>(SYS_read, fd.value(),
|
||||
name_buffer, NAME_SIZE_MAX);
|
||||
LIBC_NAMESPACE::syscall_impl<long>(SYS_close, fd.value());
|
||||
if (retval < 0)
|
||||
return -retval;
|
||||
auto read_result =
|
||||
linux_syscalls::read(fd.value(), name_buffer, NAME_SIZE_MAX);
|
||||
linux_syscalls::close(fd.value());
|
||||
if (!read_result)
|
||||
return read_result.error();
|
||||
int retval = static_cast<int>(read_result.value());
|
||||
if (retval == NAME_SIZE_MAX)
|
||||
return ERANGE;
|
||||
if (name_buffer[retval - 1] == '\n')
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ add_entrypoint_object(
|
|||
libc.hdr.types.cpu_set_t
|
||||
libc.hdr.types.pid_t
|
||||
libc.hdr.types.size_t
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.CPP.span
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.sched_getaffinity
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
#include "src/sched/sched_getaffinity.h"
|
||||
|
||||
#include "hdr/stdint_proxy.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/CPP/span.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/sched_getaffinity.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/libc_errno.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
|
@ -17,18 +18,19 @@
|
|||
#include "hdr/types/cpu_set_t.h"
|
||||
#include "hdr/types/pid_t.h"
|
||||
#include "hdr/types/size_t.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, sched_getaffinity,
|
||||
(pid_t tid, size_t cpuset_size, cpu_set_t *mask)) {
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_sched_getaffinity, tid,
|
||||
cpuset_size, mask);
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
auto result = linux_syscalls::sched_getaffinity(
|
||||
tid, cpp::span<unsigned char>(reinterpret_cast<unsigned char *>(mask),
|
||||
cpuset_size));
|
||||
if (!result) {
|
||||
libc_errno = result.error();
|
||||
return -1;
|
||||
}
|
||||
int ret = result.value();
|
||||
if (size_t(ret) < cpuset_size) {
|
||||
// This means that only |ret| bytes in |mask| have been set. We will have to
|
||||
// zero out the remaining bytes.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ add_entrypoint_object(
|
|||
libc.include.spawn
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.close
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.dup2
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.open
|
||||
libc.src.spawn.file_actions
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/spawn/posix_spawn.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/close.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/dup2.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/open.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
|
|
@ -40,8 +41,6 @@ pid_t fork() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void close(int fd) { LIBC_NAMESPACE::syscall_impl<long>(SYS_close, fd); }
|
||||
|
||||
// All exits from child_process are error exits. So, we use a simple
|
||||
// exit implementation which exits with code 127.
|
||||
void exit() {
|
||||
|
|
@ -75,7 +74,7 @@ void child_process(const char *__restrict path,
|
|||
if (actual_fd != open_act->fd) {
|
||||
bool dup2_result =
|
||||
linux_syscalls::dup2(actual_fd, open_act->fd).has_value();
|
||||
close(actual_fd); // The old fd is not needed anymore.
|
||||
linux_syscalls::close(actual_fd); // The old fd is not needed anymore.
|
||||
if (!dup2_result)
|
||||
exit();
|
||||
}
|
||||
|
|
@ -83,7 +82,7 @@ void child_process(const char *__restrict path,
|
|||
}
|
||||
case BaseSpawnFileAction::CLOSE: {
|
||||
auto *close_act = reinterpret_cast<SpawnFileCloseAction *>(act);
|
||||
close(close_act->fd);
|
||||
linux_syscalls::close(close_act->fd);
|
||||
break;
|
||||
}
|
||||
case BaseSpawnFileAction::DUP2: {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ add_entrypoint_object(
|
|||
HDRS
|
||||
../remove.h
|
||||
DEPENDS
|
||||
libc.hdr.errno_macros
|
||||
libc.hdr.fcntl_macros
|
||||
libc.include.unistd
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.unlinkat
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,26 +8,25 @@
|
|||
|
||||
#include "src/stdio/remove.h"
|
||||
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/unlinkat.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include "hdr/errno_macros.h" // For EISDIR.
|
||||
#include "hdr/fcntl_macros.h" // For AT_* macros.
|
||||
#include "src/__support/libc_errno.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
#include <sys/syscall.h> // For syscall numbers.
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
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 = LIBC_NAMESPACE::syscall_impl<int>(SYS_unlinkat, AT_FDCWD, path, 0);
|
||||
if (ret == -EISDIR)
|
||||
ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_unlinkat, AT_FDCWD, path,
|
||||
AT_REMOVEDIR);
|
||||
if (ret >= 0)
|
||||
auto ret = linux_syscalls::unlinkat(AT_FDCWD, path, 0);
|
||||
if (!ret && ret.error() == EISDIR)
|
||||
ret = linux_syscalls::unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
|
||||
if (ret)
|
||||
return 0;
|
||||
libc_errno = -ret;
|
||||
libc_errno = ret.error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,3 @@
|
|||
add_header_library(
|
||||
kernel_statx
|
||||
HDRS
|
||||
kernel_statx.h
|
||||
DEPENDS
|
||||
libc.hdr.fcntl_macros
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.error_or
|
||||
libc.src.__support.OSUtil.osutil
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
ftok
|
||||
SRCS
|
||||
|
|
@ -16,8 +5,10 @@ add_entrypoint_object(
|
|||
HDRS
|
||||
../ftok.h
|
||||
DEPENDS
|
||||
.kernel_statx
|
||||
libc.hdr.fcntl_macros
|
||||
libc.hdr.types.key_t
|
||||
libc.src.__support.OSUtil.linux.stat.kernel_statx_types
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.statx
|
||||
libc.src.__support.common
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
|
|
|||
|
|
@ -7,18 +7,19 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
#include "src/sys/ipc/ftok.h"
|
||||
|
||||
#include "hdr/fcntl_macros.h" // For AT_FDCWD.
|
||||
#include "src/__support/OSUtil/linux/stat/kernel_statx_types.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/statx.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/error_or.h"
|
||||
#include "src/__support/libc_errno.h"
|
||||
|
||||
#include "kernel_statx.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(key_t, ftok, (const char *path, int id)) {
|
||||
struct statx xbuf;
|
||||
internal::kernel_statx_buf xbuf;
|
||||
|
||||
ErrorOr<int> err = statx_for_ftok(path, xbuf);
|
||||
auto err = linux_syscalls::statx(
|
||||
AT_FDCWD, path, 0, internal::KERNEL_STATX_BASIC_STATS_MASK, &xbuf);
|
||||
|
||||
if (!err.has_value()) {
|
||||
libc_errno = err.error();
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
//===-- Wrapper over SYS_statx syscall for ftok ---------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC_SYS_IPC_LINUX_KERNEL_STATX_H
|
||||
#define LLVM_LIBC_SRC_SYS_IPC_LINUX_KERNEL_STATX_H
|
||||
|
||||
#include "hdr/fcntl_macros.h"
|
||||
#include "src/__support/OSUtil/syscall.h"
|
||||
#include "src/__support/error_or.h"
|
||||
#include "sys/syscall.h"
|
||||
|
||||
#include <linux/stat.h>
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LIBC_INLINE ErrorOr<int> statx_for_ftok(const char *path, struct statx &xbuf) {
|
||||
|
||||
// store the file stats metadata into xbuf
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_statx, AT_FDCWD, path, 0,
|
||||
STATX_BASIC_STATS, &xbuf);
|
||||
|
||||
if (ret < 0)
|
||||
return Error(-ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC_SYS_IPC_LINUX_KERNEL_STATX_H
|
||||
|
|
@ -306,6 +306,7 @@ add_entrypoint_object(
|
|||
HDRS
|
||||
../shm_unlink.h
|
||||
DEPENDS
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.unlink
|
||||
libc.src.errno.errno
|
||||
.shm_common
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,37 +8,26 @@
|
|||
|
||||
#include "src/sys/mman/shm_unlink.h"
|
||||
|
||||
#include "hdr/fcntl_macros.h"
|
||||
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
|
||||
#include "src/__support/libc_errno.h" // For internal errno.
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/unlink.h"
|
||||
#include "src/__support/libc_errno.h" // For internal errno.
|
||||
#include "src/__support/macros/config.h"
|
||||
#include "src/sys/mman/linux/shm_common.h"
|
||||
#include <sys/syscall.h> // For SYS_unlink, SYS_unlinkat
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
// TODO: move the unlink syscall to a shared utility.
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, shm_unlink, (const char *name)) {
|
||||
auto path_result = shm_common::translate_name(name);
|
||||
if (!path_result.has_value()) {
|
||||
libc_errno = path_result.error();
|
||||
return -1;
|
||||
}
|
||||
#ifdef SYS_unlink
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_unlink, path_result->data());
|
||||
#elif defined(SYS_unlinkat)
|
||||
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_unlinkat, AT_FDCWD,
|
||||
path_result->data(), 0);
|
||||
#else
|
||||
#error "unlink and unlinkat syscalls not available."
|
||||
#endif
|
||||
|
||||
if (ret < 0) {
|
||||
libc_errno = -ret;
|
||||
auto result = linux_syscalls::unlink(path_result->data());
|
||||
if (!result) {
|
||||
libc_errno = result.error();
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ add_entrypoint_object(
|
|||
libc.hdr.types.struct_timespec
|
||||
libc.hdr.types.struct_timeval
|
||||
libc.hdr.fcntl_macros
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.utimensat
|
||||
libc.include.sys_stat
|
||||
libc.include.sys_syscall
|
||||
libc.include.fcntl
|
||||
libc.src.__support.libc_errno
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,17 +13,12 @@
|
|||
#include "hdr/types/struct_timeval.h"
|
||||
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/utimensat.h"
|
||||
#include "src/__support/OSUtil/syscall.h"
|
||||
#include "src/__support/libc_errno.h"
|
||||
|
||||
#include <sys/syscall.h>
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(int, utimes,
|
||||
(const char *path, const struct timeval times[2])) {
|
||||
#if defined(SYS_utimensat) || defined(SYS_utimensat_time64)
|
||||
|
||||
// the utimensat syscall requires a timespec struct, not timeval.
|
||||
struct timespec ts[2];
|
||||
struct timespec *ts_ptr = nullptr; // default value if times is nullptr
|
||||
|
|
@ -64,8 +59,5 @@ LLVM_LIBC_FUNCTION(int, utimes,
|
|||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
#error "utimensat or utimensat_time64 syscalls not available."
|
||||
#endif // SYS_utimensat || SYS_utimensat_time64
|
||||
}
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ add_startup_object(
|
|||
libc.hdr.sys_mman_macros
|
||||
libc.include.sys_syscall
|
||||
libc.src.__support.OSUtil.osutil
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.getrandom
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.mmap
|
||||
libc.src.__support.OSUtil.linux.syscall_wrappers.munmap
|
||||
libc.src.string.memory_utils.inline_memcpy
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "hdr/sys_mman_macros.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/getrandom.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/mmap.h"
|
||||
#include "src/__support/OSUtil/linux/syscall_wrappers/munmap.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
|
@ -57,11 +58,11 @@ void init_tls(TLSDescriptor &tls_descriptor) {
|
|||
// Setting the stack guard to a random value.
|
||||
// We cannot call the get_random function here as the function sets errno on
|
||||
// failure. Since errno is implemented via a thread local variable, we cannot
|
||||
// use errno before TLS is setup.
|
||||
long stack_guard_retval =
|
||||
syscall_impl(SYS_getrandom, reinterpret_cast<long>(stack_guard_addr),
|
||||
sizeof(uint64_t), 0);
|
||||
if (stack_guard_retval < 0)
|
||||
// use errno before TLS is setup. The linux_syscalls wrapper is safe as it
|
||||
// reports errors via ErrorOr instead of errno.
|
||||
ErrorOr<ssize_t> stack_guard_retval =
|
||||
linux_syscalls::getrandom(stack_guard_addr, sizeof(uint64_t), 0);
|
||||
if (!stack_guard_retval.has_value())
|
||||
syscall_impl(SYS_exit, 1);
|
||||
|
||||
tls_descriptor = {tls_size_with_addr, reinterpret_cast<uintptr_t>(tls_addr),
|
||||
|
|
|
|||
|
|
@ -1603,10 +1603,12 @@ libc_support_library(
|
|||
":__support_file_file",
|
||||
":__support_libc_errno",
|
||||
":__support_macros_config",
|
||||
":__support_osutil_linux_syscall_wrappers_close",
|
||||
":__support_osutil_linux_syscall_wrappers_fcntl",
|
||||
":__support_osutil_linux_syscall_wrappers_lseek",
|
||||
":__support_osutil_linux_syscall_wrappers_open",
|
||||
":__support_osutil_syscall",
|
||||
":__support_osutil_linux_syscall_wrappers_read",
|
||||
":__support_osutil_linux_syscall_wrappers_write",
|
||||
":hdr_fcntl_macros",
|
||||
":hdr_stdint_proxy",
|
||||
":hdr_stdio_macros",
|
||||
|
|
@ -2932,11 +2934,14 @@ libc_support_library(
|
|||
}),
|
||||
deps = [
|
||||
":__support_common",
|
||||
":__support_osutil_linux_syscall_wrappers_close",
|
||||
":__support_osutil_linux_syscall_wrappers_mmap",
|
||||
":__support_osutil_linux_syscall_wrappers_munmap",
|
||||
":__support_osutil_linux_syscall_wrappers_open",
|
||||
":__support_osutil_linux_syscall_wrappers_read",
|
||||
":__support_osutil_syscall",
|
||||
":__support_threads_callonce",
|
||||
":hdr_errno_macros",
|
||||
":hdr_fcntl_macros",
|
||||
":hdr_sys_auxv_macros",
|
||||
":hdr_sys_mman_macros",
|
||||
|
|
@ -15702,8 +15707,9 @@ libc_function(
|
|||
":__support_common",
|
||||
":__support_libc_errno",
|
||||
":__support_macros_config",
|
||||
":__support_osutil_syscall",
|
||||
":__support_osutil_linux_syscall_wrappers_unlinkat",
|
||||
":errno",
|
||||
":hdr_errno_macros",
|
||||
":hdr_fcntl_macros",
|
||||
":hdr_stdio_overlay",
|
||||
":types_FILE",
|
||||
|
|
@ -16090,9 +16096,8 @@ libc_function(
|
|||
":__support_common",
|
||||
":__support_libc_errno",
|
||||
":__support_macros_config",
|
||||
":__support_osutil_syscall",
|
||||
":__support_osutil_linux_syscall_wrappers_unlink",
|
||||
":errno",
|
||||
":hdr_fcntl_macros",
|
||||
":shm_common",
|
||||
":types_mode_t",
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue