diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp --- a/compiler-rt/lib/scudo/standalone/linux.cpp +++ b/compiler-rt/lib/scudo/standalone/linux.cpp @@ -130,9 +130,12 @@ static_cast(TS.tv_nsec); } +// sched_getaffinity can fail (no CAP_SYS_NICE, syscall filtering, etc), in +// which case the function shall return 0. u32 getNumberOfCPUs() { cpu_set_t CPUs; - CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); + if (sched_getaffinity(0, sizeof(cpu_set_t), &CPUs) != 0) + return 0; return static_cast(CPU_COUNT(&CPUs)); } diff --git a/compiler-rt/lib/scudo/standalone/tsd_shared.h b/compiler-rt/lib/scudo/standalone/tsd_shared.h --- a/compiler-rt/lib/scudo/standalone/tsd_shared.h +++ b/compiler-rt/lib/scudo/standalone/tsd_shared.h @@ -18,7 +18,9 @@ void initLinkerInitialized(Allocator *Instance) { Instance->initLinkerInitialized(); CHECK_EQ(pthread_key_create(&PThreadKey, nullptr), 0); // For non-TLS - NumberOfTSDs = Min(Max(1U, getNumberOfCPUs()), MaxTSDCount); + const u32 NumberOfCPUs = getNumberOfCPUs(); + NumberOfTSDs = + (NumberOfCPUs == 0) ? MaxTSDCount : Min(NumberOfCPUs, MaxTSDCount); TSDs = reinterpret_cast *>( map(nullptr, sizeof(TSD) * NumberOfTSDs, "scudo:tsd")); for (u32 I = 0; I < NumberOfTSDs; I++)