[PATCH] D73055: [scudo][standalone] Allow sched_getaffinity to fail
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 09:58:25 PST 2020
cryptoad created this revision.
cryptoad added reviewers: cferris, eugenis, hctim, morehouse, pcc.
Herald added projects: Sanitizers, LLVM.
Herald added a subscriber: Sanitizers.
In some configuration, `sched_getaffinity` can fail. Some reasons for
that being the lack of `CAP_SYS_NICE` capability or some syscall
filtering and so on.
This should not be fatal to the allocator, so in this situation, we
will fallback to the `MaxTSDCount` value specified in the allocator
configuration.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73055
Files:
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
@@ -130,9 +130,12 @@
static_cast<u64>(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<u32>(CPU_COUNT(&CPUs));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73055.239157.patch
Type: text/x-patch
Size: 1420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200120/7f3422bb/attachment.bin>
More information about the llvm-commits
mailing list