[PATCH] D73055: [scudo][standalone] Allow sched_getaffinity to fail
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 08:33:11 PST 2020
cryptoad updated this revision to Diff 239334.
cryptoad added a comment.
Commenting `getNumberOfCPUs` to indicate failure value in `common.h`,
moving `sched_getaffinity` comment in `linux.cpp` in body of function.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73055/new/
https://reviews.llvm.org/D73055
Files:
compiler-rt/lib/scudo/standalone/common.h
compiler-rt/lib/scudo/standalone/linux.cpp
compiler-rt/lib/scudo/standalone/tsd_shared.h
Index: compiler-rt/lib/scudo/standalone/tsd_shared.h
===================================================================
--- compiler-rt/lib/scudo/standalone/tsd_shared.h
+++ 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<TSD<Allocator> *>(
map(nullptr, sizeof(TSD<Allocator>) * NumberOfTSDs, "scudo:tsd"));
for (u32 I = 0; I < NumberOfTSDs; I++)
Index: compiler-rt/lib/scudo/standalone/linux.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/linux.cpp
+++ compiler-rt/lib/scudo/standalone/linux.cpp
@@ -132,7 +132,10 @@
u32 getNumberOfCPUs() {
cpu_set_t CPUs;
- CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
+ // sched_getaffinity can fail for a variety of legitimate reasons (lack of
+ // CAP_SYS_NICE, syscall filtering, etc), in which case we shall return 0.
+ if (sched_getaffinity(0, sizeof(cpu_set_t), &CPUs) != 0)
+ return 0;
return static_cast<u32>(CPU_COUNT(&CPUs));
}
Index: compiler-rt/lib/scudo/standalone/common.h
===================================================================
--- compiler-rt/lib/scudo/standalone/common.h
+++ compiler-rt/lib/scudo/standalone/common.h
@@ -126,6 +126,7 @@
return getPageSizeSlow();
}
+// Returns 0 if the number of CPUs could not be determined.
u32 getNumberOfCPUs();
const char *getEnv(const char *Name);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73055.239334.patch
Type: text/x-patch
Size: 1801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200121/683851f7/attachment.bin>
More information about the llvm-commits
mailing list