Remove getdents from bionic.
Bug: 11156955
Change-Id: I6c306989801be552d85fba8a50dcdc79282fb9d2
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index 584c1ae..c165ef7 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -129,12 +129,7 @@
ssize_t flistxattr(int, char*, size_t) all
int fremovexattr(int, const char*) all
-# mips64 doesn't have getdents64 until 3.10 kernels.
-# We need this special-case hack as long as we need to support mips64 on older kernels.
-# The currently-available Debian qemu image is on a 3.2 kernel.
-int getdents:getdents64(unsigned int, struct dirent*, unsigned int) arm,arm64,mips,x86,x86_64
-int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int) mips64
-int __getdents:getdents(unsigned int, void*, unsigned int) mips64
+int __getdents64:getdents64(unsigned int, struct dirent*, unsigned int) arm,arm64,mips,mips64,x86,x86_64
int __openat:openat(int, const char*, int, mode_t) all
int faccessat(int, const char*, int, int) all
diff --git a/libc/arch-arm/syscalls/getdents.S b/libc/arch-arm/syscalls/__getdents64.S
similarity index 86%
rename from libc/arch-arm/syscalls/getdents.S
rename to libc/arch-arm/syscalls/__getdents64.S
index 8f0e81a..c3d5e5b 100644
--- a/libc/arch-arm/syscalls/getdents.S
+++ b/libc/arch-arm/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(getdents)
+ENTRY(__getdents64)
mov ip, r7
ldr r7, =__NR_getdents64
swi #0
@@ -11,4 +11,4 @@
bxls lr
neg r0, r0
b __set_errno
-END(getdents)
+END(__getdents64)
diff --git a/libc/arch-arm64/syscalls/getdents.S b/libc/arch-arm64/syscalls/__getdents64.S
similarity index 88%
rename from libc/arch-arm64/syscalls/getdents.S
rename to libc/arch-arm64/syscalls/__getdents64.S
index 8cd3ca7..9c65918 100644
--- a/libc/arch-arm64/syscalls/getdents.S
+++ b/libc/arch-arm64/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(getdents)
+ENTRY(__getdents64)
stp x29, x30, [sp, #-16]!
.cfi_def_cfa_offset 16
.cfi_rel_offset x29, 0
@@ -22,4 +22,5 @@
b.hi __set_errno
ret
-END(getdents)
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/arch-mips/syscalls/getdents.S b/libc/arch-mips/syscalls/__getdents64.S
similarity index 87%
rename from libc/arch-mips/syscalls/getdents.S
rename to libc/arch-mips/syscalls/__getdents64.S
index ce92886..136b408 100644
--- a/libc/arch-mips/syscalls/getdents.S
+++ b/libc/arch-mips/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(getdents)
+ENTRY(__getdents64)
.set noreorder
.cpload t9
li v0, __NR_getdents64
@@ -16,4 +16,4 @@
j t9
nop
.set reorder
-END(getdents)
+END(__getdents64)
diff --git a/libc/arch-mips64/bionic/getdents.cpp b/libc/arch-mips64/bionic/getdents.cpp
deleted file mode 100644
index 66a61ec..0000000
--- a/libc/arch-mips64/bionic/getdents.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * The MIPS64 getdents64() system call is only present in 3.10+ kernels.
- * If the getdents64() system call is not available fall back to using
- * getdents() and modify the result to be compatible with getdents64().
- */
-
-#include <dirent.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-
-/* The mips_getdents type is 64bit clean */
-struct mips_dirent {
- uint64_t d_ino; /* Inode number */
- uint64_t d_off; /* Offset to next mips_dirent */
- uint16_t d_reclen; /* Length of this mips_dirent */
- char d_name[]; /* Filename (null-terminated) */
- /* length is actually (d_reclen - 2 -
- offsetof(struct mips_dirent, d_name) */
- // char pad; /* Zero padding byte */
- // char d_type; /* File type (only since Linux 2.6.4; offset is (d_reclen - 1)) */
-};
-
-extern "C" int __getdents64(unsigned int fd, struct dirent *dirp, unsigned int count);
-extern "C" int __getdents(unsigned int fd, struct mips_dirent *dirp, unsigned int count);
-int getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
-{
- int r;
- int oerrno = errno;
-
- /* Use getdents64() if it is available */
- r = __getdents64(fd, dirp, count);
- if (r >= 0 || errno != ENOSYS)
- return r;
-
- /* Fallback to getdents() */
- errno = oerrno;
- r = __getdents(fd, (struct mips_dirent *)dirp, count);
- if (r > 0) {
- char *p;
- char type;
- union dirents {
- struct mips_dirent m;
- struct dirent d;
- } *u;
-
- p = (char *)dirp;
- do {
- u = (union dirents *)p;
-
- /* This should not happen, but just in case... */
- if (p + u->m.d_reclen > (char *)dirp + r)
- break;
-
- /* shuffle the dirent */
- type = *(p + u->m.d_reclen - 1);
- memmove(u->d.d_name, u->m.d_name,
- u->m.d_reclen - 2 - offsetof(struct mips_dirent, d_name) + 1);
- u->d.d_type = type;
-
- p += u->m.d_reclen;
- } while (p < (char *)dirp + r);
- }
- return r;
-}
diff --git a/libc/arch-mips64/mips64.mk b/libc/arch-mips64/mips64.mk
index 2b18042..cd14893 100644
--- a/libc/arch-mips64/mips64.mk
+++ b/libc/arch-mips64/mips64.mk
@@ -42,7 +42,6 @@
arch-mips64/bionic/__bionic_clone.S \
arch-mips64/bionic/_exit_with_stack_teardown.S \
arch-mips64/bionic/__get_sp.S \
- arch-mips64/bionic/getdents.cpp \
arch-mips64/bionic/memcmp16.S \
arch-mips64/bionic/_setjmp.S \
arch-mips64/bionic/setjmp.S \
diff --git a/libc/arch-mips64/syscalls/__getdents.S b/libc/arch-mips64/syscalls/__getdents.S
deleted file mode 100644
index 0a70a72..0000000
--- a/libc/arch-mips64/syscalls/__getdents.S
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Generated by gensyscalls.py. Do not edit. */
-
-#include <private/bionic_asm.h>
-
-ENTRY(__getdents)
- .set push
- .set noreorder
- li v0, __NR_getdents
- syscall
- bnez a3, 1f
- move a0, v0
- j ra
- nop
-1:
- move t0, ra
- bal 2f
- nop
-2:
- .cpsetup ra, t1, 2b
- LA t9,__set_errno
- .cpreturn
- j t9
- move ra, t0
- .set pop
-END(__getdents)
-.hidden __getdents
diff --git a/libc/arch-x86/syscalls/getdents.S b/libc/arch-x86/syscalls/__getdents64.S
similarity index 93%
rename from libc/arch-x86/syscalls/getdents.S
rename to libc/arch-x86/syscalls/__getdents64.S
index 0627532..3fc8719 100644
--- a/libc/arch-x86/syscalls/getdents.S
+++ b/libc/arch-x86/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(getdents)
+ENTRY(__getdents64)
pushl %ebx
.cfi_def_cfa_offset 8
.cfi_rel_offset ebx, 0
@@ -28,4 +28,4 @@
popl %ecx
popl %ebx
ret
-END(getdents)
+END(__getdents64)
diff --git a/libc/arch-x86_64/syscalls/getdents.S b/libc/arch-x86_64/syscalls/__getdents64.S
similarity index 80%
rename from libc/arch-x86_64/syscalls/getdents.S
rename to libc/arch-x86_64/syscalls/__getdents64.S
index 15e0f7e..64f82fd 100644
--- a/libc/arch-x86_64/syscalls/getdents.S
+++ b/libc/arch-x86_64/syscalls/__getdents64.S
@@ -2,7 +2,7 @@
#include <private/bionic_asm.h>
-ENTRY(getdents)
+ENTRY(__getdents64)
movl $__NR_getdents64, %eax
syscall
cmpq $-MAX_ERRNO, %rax
@@ -12,4 +12,5 @@
call __set_errno
1:
ret
-END(getdents)
+END(__getdents64)
+.hidden __getdents64
diff --git a/libc/bionic/dirent.cpp b/libc/bionic/dirent.cpp
index 0f9b26a..091423e 100644
--- a/libc/bionic/dirent.cpp
+++ b/libc/bionic/dirent.cpp
@@ -37,6 +37,8 @@
#include "private/ErrnoRestorer.h"
#include "private/ScopedPthreadMutexLocker.h"
+extern "C" int __getdents64(unsigned int, struct dirent*, unsigned int);
+
struct DIR {
int fd_;
size_t available_bytes_;
@@ -81,7 +83,7 @@
}
static bool __fill_DIR(DIR* d) {
- int rc = TEMP_FAILURE_RETRY(getdents(d->fd_, d->buff_, sizeof(d->buff_)));
+ int rc = TEMP_FAILURE_RETRY(__getdents64(d->fd_, d->buff_, sizeof(d->buff_)));
if (rc <= 0) {
return false;
}
diff --git a/libc/bionic/ndk_cruft.cpp b/libc/bionic/ndk_cruft.cpp
index cb9c9c9..b0adf26 100644
--- a/libc/bionic/ndk_cruft.cpp
+++ b/libc/bionic/ndk_cruft.cpp
@@ -238,4 +238,9 @@
return _signal(signum, handler, SA_RESETHAND);
}
+// This is a system call that was never in POSIX. Use readdir(3) instead.
+extern "C" int getdents(unsigned int fd, struct dirent* dirp, unsigned int count) {
+ return __getdents64(fd, dirp, count);
+}
+
#endif
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index 71eb2e7..a849a61 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -75,7 +75,6 @@
extern int alphasort64(const struct dirent64**, const struct dirent64**);
extern int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
extern int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
-extern int getdents(unsigned int, struct dirent*, unsigned int);
__END_DECLS