diff options
-rw-r--r-- | lib/scudo/scudo_platform.h | 5 | ||||
-rw-r--r-- | lib/scudo/scudo_tsd_shared.cpp | 9 |
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/scudo/scudo_platform.h b/lib/scudo/scudo_platform.h index 095d6ef19..7db1197fd 100644 --- a/lib/scudo/scudo_platform.h +++ b/lib/scudo/scudo_platform.h @@ -40,6 +40,11 @@ # error "The exclusive TSD model is not supported on this platform." #endif +// Maximum number of TSDs that can be created for the Shared model. +#ifndef SCUDO_SHARED_TSD_POOL_SIZE +# define SCUDO_SHARED_TSD_POOL_SIZE 32U +#endif // SCUDO_SHARED_TSD_POOL_SIZE + namespace __scudo { #if SANITIZER_CAN_USE_ALLOCATOR64 diff --git a/lib/scudo/scudo_tsd_shared.cpp b/lib/scudo/scudo_tsd_shared.cpp index 6ee2f84a0..191c9ff13 100644 --- a/lib/scudo/scudo_tsd_shared.cpp +++ b/lib/scudo/scudo_tsd_shared.cpp @@ -25,7 +25,7 @@ static ScudoTSD *TSDs; static u32 NumberOfTSDs; // sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used as they allocate memory. -static uptr getNumberOfCPUs() { +static u32 getNumberOfCPUs() { cpu_set_t CPUs; CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); return CPU_COUNT(&CPUs); @@ -34,11 +34,8 @@ static uptr getNumberOfCPUs() { static void initOnce() { CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0); initScudo(); - NumberOfTSDs = getNumberOfCPUs(); - if (NumberOfTSDs == 0) - NumberOfTSDs = 1; - if (NumberOfTSDs > 32) - NumberOfTSDs = 32; + NumberOfTSDs = Min(Max(1U, getNumberOfCPUs()), + static_cast<u32>(SCUDO_SHARED_TSD_POOL_SIZE)); TSDs = reinterpret_cast<ScudoTSD *>( MmapOrDie(sizeof(ScudoTSD) * NumberOfTSDs, "ScudoTSDs")); for (u32 i = 0; i < NumberOfTSDs; i++) |