[PATCH] D39338: [scudo] Allow to specify the maximum number of TSDs at compile time

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 11:05:32 PDT 2017


cryptoad updated this revision to Diff 120655.
cryptoad marked 5 inline comments as done.
cryptoad added a comment.

Renaming the define to `SCUDO_SHARED_TSD_POOL_SIZE`.
Adding a `static_cast<u32>` to make sure it's unsigned.


https://reviews.llvm.org/D39338

Files:
  lib/scudo/scudo_platform.h
  lib/scudo/scudo_tsd_shared.cpp


Index: lib/scudo/scudo_tsd_shared.cpp
===================================================================
--- lib/scudo/scudo_tsd_shared.cpp
+++ lib/scudo/scudo_tsd_shared.cpp
@@ -25,20 +25,17 @@
 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);
 }
 
 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++)
Index: lib/scudo/scudo_platform.h
===================================================================
--- lib/scudo/scudo_platform.h
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39338.120655.patch
Type: text/x-patch
Size: 1493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171027/6a332080/attachment.bin>


More information about the llvm-commits mailing list