[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
Fri Apr 7 11:08:15 PDT 2023


mikhail.ramalho created this revision.
mikhail.ramalho added reviewers: michaelrj, sivachandra.
Herald added subscribers: libc-commits, asb, luke, VincentWu, vkmr, frasercrmck, ecnelises, evandro, luismarques, apazos, sameer.abuasal, tschuett, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added projects: libc-project, All.
mikhail.ramalho updated this revision to Diff 511739.
mikhail.ramalho added a comment.
mikhail.ramalho edited the summary of this revision.
mikhail.ramalho published this revision for review.
Herald added subscribers: pcwang-thead, eopXD.

Add support for SYS_getdents


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.

The change to SYS_getdents64 was necessary because SYS_getdents returns
a slightly different struct (without the d_type member), so when
returning a pointer to our internal buffer holding the directory entries,
the contents of the buffer would be off-by-one, resulting in garbage.

To support SYS_getdents, buffer is rewritten everytime the syscall is
called: as per the documentation, d_type is always the last byte in the
structure, so the rewrite:

1. gets d_type from the last byte in the structure
2. shifts d_name by one
3. stores d_type where d_name was previously
4. clears previous d_type location


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147738

Files:
  libc/config/linux/riscv64/entrypoints.txt
  libc/config/linux/riscv64/headers.txt
  libc/include/llvm-libc-types/CMakeLists.txt
  libc/include/llvm-libc-types/ino64_t.h
  libc/include/llvm-libc-types/struct_dirent.h
  libc/src/__support/File/dir.cpp
  libc/src/__support/File/linux_dir.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147738.511739.patch
Type: text/x-patch
Size: 6983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230407/74d520a3/attachment-0001.bin>


More information about the libc-commits mailing list