Skip to content

Commit 540402c

Browse files
authored
[sanitizer_common] Remove workarounds for older Android (#124881)
Anything supported has CPU_COUNT and sched_getaffinity().
1 parent bfabd5b commit 540402c

File tree

1 file changed

+0
-50
lines changed

1 file changed

+0
-50
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ extern "C" int __sys_sigaction(int signum, const struct sigaction *act,
7474
# include <thread.h>
7575
# endif
7676

77-
# if SANITIZER_ANDROID
78-
# include <android/api-level.h>
79-
# if !defined(CPU_COUNT) && !defined(__aarch64__)
80-
# include <dirent.h>
81-
# include <fcntl.h>
82-
struct __sanitizer::linux_dirent {
83-
long d_ino;
84-
off_t d_off;
85-
unsigned short d_reclen;
86-
char d_name[];
87-
};
88-
# endif
89-
# endif
90-
9177
# if !SANITIZER_ANDROID
9278
# include <elf.h>
9379
# include <unistd.h>
@@ -857,42 +843,6 @@ u32 GetNumberOfCPUs() {
857843
req[1] = HW_NCPU;
858844
CHECK_EQ(internal_sysctl(req, 2, &ncpu, &len, NULL, 0), 0);
859845
return ncpu;
860-
# elif SANITIZER_ANDROID && !defined(CPU_COUNT) && !defined(__aarch64__)
861-
// Fall back to /sys/devices/system/cpu on Android when cpu_set_t doesn't
862-
// exist in sched.h. That is the case for toolchains generated with older
863-
// NDKs.
864-
// This code doesn't work on AArch64 because internal_getdents makes use of
865-
// the 64bit getdents syscall, but cpu_set_t seems to always exist on AArch64.
866-
uptr fd = internal_open("/sys/devices/system/cpu", O_RDONLY | O_DIRECTORY);
867-
if (internal_iserror(fd))
868-
return 0;
869-
InternalMmapVector<u8> buffer(4096);
870-
uptr bytes_read = buffer.size();
871-
uptr n_cpus = 0;
872-
u8 *d_type;
873-
struct linux_dirent *entry = (struct linux_dirent *)&buffer[bytes_read];
874-
while (true) {
875-
if ((u8 *)entry >= &buffer[bytes_read]) {
876-
bytes_read = internal_getdents(fd, (struct linux_dirent *)buffer.data(),
877-
buffer.size());
878-
if (internal_iserror(bytes_read) || !bytes_read)
879-
break;
880-
entry = (struct linux_dirent *)buffer.data();
881-
}
882-
d_type = (u8 *)entry + entry->d_reclen - 1;
883-
if (d_type >= &buffer[bytes_read] ||
884-
(u8 *)&entry->d_name[3] >= &buffer[bytes_read])
885-
break;
886-
if (entry->d_ino != 0 && *d_type == DT_DIR) {
887-
if (entry->d_name[0] == 'c' && entry->d_name[1] == 'p' &&
888-
entry->d_name[2] == 'u' && entry->d_name[3] >= '0' &&
889-
entry->d_name[3] <= '9')
890-
n_cpus++;
891-
}
892-
entry = (struct linux_dirent *)(((u8 *)entry) + entry->d_reclen);
893-
}
894-
internal_close(fd);
895-
return n_cpus;
896846
# elif SANITIZER_SOLARIS
897847
return sysconf(_SC_NPROCESSORS_ONLN);
898848
# else

0 commit comments

Comments
 (0)