[libc-commits] [libc] 4c9c1a4 - [libc] Enable linux directory entries syscalls in riscv64
Mikhail R. Gadelha via libc-commits
libc-commits at lists.llvm.org
Thu May 4 15:07:34 PDT 2023
Author: Mikhail R. Gadelha
Date: 2023-05-04T19:07:16-03:00
New Revision: 4c9c1a4e4f854b2a4891813b2b1d7e1079a52a62
URL: https://github.com/llvm/llvm-project/commit/4c9c1a4e4f854b2a4891813b2b1d7e1079a52a62
DIFF: https://github.com/llvm/llvm-project/commit/4c9c1a4e4f854b2a4891813b2b1d7e1079a52a62.diff
LOG: [libc] Enable linux directory entries syscalls in riscv64
This patch updates the struct dirent to be on par with glibc (by adding
a missing d_type member) and update the readdir call to use SYS_getdents64
instead of SYS_getdents.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D147738
Added:
Modified:
libc/config/linux/riscv64/entrypoints.txt
libc/config/linux/riscv64/headers.txt
libc/include/llvm-libc-types/struct_dirent.h
libc/src/__support/File/CMakeLists.txt
libc/src/__support/File/dir.cpp
libc/src/__support/File/linux_dir.cpp
Removed:
################################################################################
diff --git a/libc/config/linux/riscv64/entrypoints.txt b/libc/config/linux/riscv64/entrypoints.txt
index dc700941c667c..c36a623701e5c 100644
--- a/libc/config/linux/riscv64/entrypoints.txt
+++ b/libc/config/linux/riscv64/entrypoints.txt
@@ -341,6 +341,12 @@ if(LLVM_LIBC_FULL_BUILD)
# assert.h entrypoints
libc.src.assert.__assert_fail
+ # dirent.h entrypoints
+ libc.src.dirent.closedir
+ libc.src.dirent.dirfd
+ libc.src.dirent.opendir
+ libc.src.dirent.readdir
+
# network.h entrypoints
libc.src.network.htonl
libc.src.network.htons
diff --git a/libc/config/linux/riscv64/headers.txt b/libc/config/linux/riscv64/headers.txt
index 2d8ed5001c143..aaa75a9dd08cb 100644
--- a/libc/config/linux/riscv64/headers.txt
+++ b/libc/config/linux/riscv64/headers.txt
@@ -1,6 +1,7 @@
set(TARGET_PUBLIC_HEADERS
libc.include.assert
libc.include.ctype
+ libc.include.dirent
libc.include.errno
libc.include.fcntl
libc.include.fenv
diff --git a/libc/include/llvm-libc-types/struct_dirent.h b/libc/include/llvm-libc-types/struct_dirent.h
index 44bda4caae452..fde3f8ce47980 100644
--- a/libc/include/llvm-libc-types/struct_dirent.h
+++ b/libc/include/llvm-libc-types/struct_dirent.h
@@ -18,6 +18,7 @@ struct dirent {
off_t d_off;
unsigned short d_reclen;
#endif
+ unsigned char d_type;
// The user code should use strlen to determine actual the size of d_name.
// Likewise, it is incorrect and prohibited by the POSIX standard to detemine
// the size of struct dirent type using sizeof. The size should be got using
diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt
index 2d94c2f30a49d..79de9250c642b 100644
--- a/libc/src/__support/File/CMakeLists.txt
+++ b/libc/src/__support/File/CMakeLists.txt
@@ -11,7 +11,6 @@ add_object_library(
HDRS
file.h
DEPENDS
-
libc.src.__support.CPP.new
libc.src.__support.CPP.span
libc.src.__support.threads.mutex
@@ -37,7 +36,6 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}_file.cpp)
${LIBC_TARGET_OS}_file.cpp
DEPENDS
.file
-
libc.include.fcntl
libc.include.stdio
libc.include.sys_syscall
diff --git a/libc/src/__support/File/dir.cpp b/libc/src/__support/File/dir.cpp
index 70f550ffab72d..e632c9293d617 100644
--- a/libc/src/__support/File/dir.cpp
+++ b/libc/src/__support/File/dir.cpp
@@ -12,8 +12,6 @@
#include "src/__support/error_or.h"
#include "src/errno/libc_errno.h" // For error macros
-#include <stdlib.h>
-
namespace __llvm_libc {
ErrorOr<Dir *> Dir::open(const char *path) {
diff --git a/libc/src/__support/File/linux_dir.cpp b/libc/src/__support/File/linux_dir.cpp
index 86aaaae907d22..aae565ffb337a 100644
--- a/libc/src/__support/File/linux_dir.cpp
+++ b/libc/src/__support/File/linux_dir.cpp
@@ -34,8 +34,13 @@ ErrorOr<int> platform_opendir(const char *name) {
}
ErrorOr<size_t> platform_fetch_dirents(int fd, cpp::span<uint8_t> buffer) {
- long size =
- __llvm_libc::syscall_impl(SYS_getdents, fd, buffer.data(), buffer.size());
+#ifdef SYS_getdents64
+ 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
+
if (size < 0) {
return __llvm_libc::Error(static_cast<int>(-size));
}
More information about the libc-commits
mailing list