[libc-commits] [PATCH] D147738: [libc] Enable linux directory entries syscalls in riscv64

Mikhail Ramalho via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu May 4 12:37:52 PDT 2023


mikhail.ramalho updated this revision to Diff 519610.
mikhail.ramalho added a comment.

addressed comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147738/new/

https://reviews.llvm.org/D147738

Files:
  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


Index: libc/src/__support/File/linux_dir.cpp
===================================================================
--- libc/src/__support/File/linux_dir.cpp
+++ libc/src/__support/File/linux_dir.cpp
@@ -34,8 +34,13 @@
 }
 
 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));
   }
Index: libc/src/__support/File/dir.cpp
===================================================================
--- libc/src/__support/File/dir.cpp
+++ 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) {
Index: libc/src/__support/File/CMakeLists.txt
===================================================================
--- libc/src/__support/File/CMakeLists.txt
+++ libc/src/__support/File/CMakeLists.txt
@@ -11,7 +11,6 @@
   HDRS
     file.h
   DEPENDS
-    
     libc.src.__support.CPP.new
     libc.src.__support.CPP.span
     libc.src.__support.threads.mutex
@@ -37,7 +36,6 @@
       ${LIBC_TARGET_OS}_file.cpp
     DEPENDS
       .file
-      
       libc.include.fcntl
       libc.include.stdio
       libc.include.sys_syscall
Index: libc/include/llvm-libc-types/struct_dirent.h
===================================================================
--- libc/include/llvm-libc-types/struct_dirent.h
+++ libc/include/llvm-libc-types/struct_dirent.h
@@ -18,6 +18,7 @@
   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
Index: libc/config/linux/riscv64/headers.txt
===================================================================
--- libc/config/linux/riscv64/headers.txt
+++ 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
Index: libc/config/linux/riscv64/entrypoints.txt
===================================================================
--- libc/config/linux/riscv64/entrypoints.txt
+++ libc/config/linux/riscv64/entrypoints.txt
@@ -341,6 +341,12 @@
     # 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147738.519610.patch
Type: text/x-patch
Size: 3108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230504/fe28ec18/attachment-0001.bin>


More information about the libc-commits mailing list