Revert "[scudo] Make getNumberOfCPUs Fuchsia compliant"

This reverts commit r317604.

Android doesn't have cpu_set_t.

llvm-svn: 317655
This commit is contained in:
Reid Kleckner 2017-11-08 01:33:15 +00:00
parent 48db01b980
commit f7fdac4508
6 changed files with 8 additions and 40 deletions

View File

@ -933,9 +933,6 @@ void CheckNoDeepBind(const char *filename, int flag);
// be used to seed a PRNG. Defaults to blocking like the underlying syscall. // be used to seed a PRNG. Defaults to blocking like the underlying syscall.
bool GetRandom(void *buffer, uptr length, bool blocking = true); bool GetRandom(void *buffer, uptr length, bool blocking = true);
// Returns the number of logical processors on the system.
u32 GetNumberOfCPUs();
} // namespace __sanitizer } // namespace __sanitizer
inline void *operator new(__sanitizer::operator_new_size_type size, inline void *operator new(__sanitizer::operator_new_size_type size,

View File

@ -520,10 +520,6 @@ bool GetRandom(void *buffer, uptr length, bool blocking) {
return true; return true;
} }
u32 GetNumberOfCPUs() {
return zx_system_get_num_cpus();
}
} // namespace __sanitizer } // namespace __sanitizer
using namespace __sanitizer; // NOLINT using namespace __sanitizer; // NOLINT

View File

@ -37,14 +37,9 @@
#if SANITIZER_FREEBSD #if SANITIZER_FREEBSD
#include <pthread_np.h> #include <pthread_np.h>
#include <osreldate.h> #include <osreldate.h>
#include <sys/sysctl.h>
#define pthread_getattr_np pthread_attr_get_np #define pthread_getattr_np pthread_attr_get_np
#endif #endif
#if SANITIZER_NETBSD
#include <sys/sysctl.h>
#endif
#if SANITIZER_LINUX #if SANITIZER_LINUX
#include <sys/prctl.h> #include <sys/prctl.h>
#endif #endif
@ -543,23 +538,6 @@ uptr GetRSS() {
return rss * GetPageSizeCached(); return rss * GetPageSizeCached();
} }
// sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used as they allocate memory.
u32 GetNumberOfCPUs() {
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
u32 ncpu;
int req[2];
size_t len = sizeof(ncpu);
req[0] = CTL_HW;
req[1] = HW_NCPU;
CHECK_EQ(sysctl(req, 2, &ncpu, &len, NULL, 0), 0);
return ncpu;
#else
cpu_set_t CPUs;
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
return CPU_COUNT(&CPUs);
#endif
}
// 64-bit Android targets don't provide the deprecated __android_log_write. // 64-bit Android targets don't provide the deprecated __android_log_write.
// Starting with the L release, syslog() works and is preferable to // Starting with the L release, syslog() works and is preferable to
// __android_log_write. // __android_log_write.

View File

@ -1000,11 +1000,6 @@ bool GetRandom(void *buffer, uptr length, bool blocking) {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
// FIXME: implement on this platform.
u32 GetNumberOfCPUs() {
UNIMPLEMENTED();
}
} // namespace __sanitizer } // namespace __sanitizer
#endif // SANITIZER_MAC #endif // SANITIZER_MAC

View File

@ -1093,11 +1093,6 @@ bool GetRandom(void *buffer, uptr length, bool blocking) {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
// FIXME: implement on this platform.
u32 GetNumberOfCPUs() {
UNIMPLEMENTED();
}
} // namespace __sanitizer } // namespace __sanitizer
#endif // _WIN32 #endif // _WIN32

View File

@ -24,10 +24,17 @@ static atomic_uint32_t CurrentIndex;
static ScudoTSD *TSDs; static ScudoTSD *TSDs;
static u32 NumberOfTSDs; static u32 NumberOfTSDs;
// sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used as they allocate memory.
static u32 getNumberOfCPUs() {
cpu_set_t CPUs;
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
return CPU_COUNT(&CPUs);
}
static void initOnce() { static void initOnce() {
CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0); CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0);
initScudo(); initScudo();
NumberOfTSDs = Min(Max(1U, GetNumberOfCPUs()), NumberOfTSDs = Min(Max(1U, getNumberOfCPUs()),
static_cast<u32>(SCUDO_SHARED_TSD_POOL_SIZE)); static_cast<u32>(SCUDO_SHARED_TSD_POOL_SIZE));
TSDs = reinterpret_cast<ScudoTSD *>( TSDs = reinterpret_cast<ScudoTSD *>(
MmapOrDie(sizeof(ScudoTSD) * NumberOfTSDs, "ScudoTSDs")); MmapOrDie(sizeof(ScudoTSD) * NumberOfTSDs, "ScudoTSDs"));