Commit 7df2d7e5 authored by Michel Salim's avatar Michel Salim Committed by Facebook GitHub Bot

handle non-constant SIGSTKSZ

Summary:
On glibc > 2.33 (e.g. on Fedora rawhide/35), `SIGSTKSZ` is no longer constant:
http://sourceware-org.1504.n7.nabble.com/PATCH-sysconf-Add-SC-MINSIGSTKSZ-SC-SIGSTKSZ-BZ-20305-td650948.html

Assume it's non-constant, and so:
- use `std::max` rather than `folly::constexpr_max` to compute the stack size
- cast both arguments to `size_t` since in the non-constant case we get a `long int` back
- use `std::unique_ptr<char[]>` and compute the size at the time of use rather than make it class-wide

Reviewed By: yfeldblum

Differential Revision: D27143320

fbshipit-source-id: 7dcdd7cf3d5e96db605266504f443cf2b48ba18c
parent 5b373171
...@@ -341,10 +341,6 @@ static AsanUnpoisonMemoryRegionFuncPtr getUnpoisonMemoryRegionFunc() { ...@@ -341,10 +341,6 @@ static AsanUnpoisonMemoryRegionFuncPtr getUnpoisonMemoryRegionFunc() {
namespace { namespace {
// SIGSTKSZ (8 kB on our architectures) isn't always enough for
// folly::symbolizer, so allocate 32 kB.
constexpr size_t kAltStackSize = folly::constexpr_max(SIGSTKSZ, 32 * 1024);
bool hasAlternateStack() { bool hasAlternateStack() {
stack_t ss; stack_t ss;
sigaltstack(nullptr, &ss); sigaltstack(nullptr, &ss);
...@@ -372,9 +368,13 @@ class ScopedAlternateSignalStack { ...@@ -372,9 +368,13 @@ class ScopedAlternateSignalStack {
return; return;
} }
stack_ = std::make_unique<AltStackBuffer>(); // SIGSTKSZ (8 kB on our architectures) isn't always enough for
// folly::symbolizer, so allocate 32 kB.
size_t kAltStackSize = std::max(size_t(SIGSTKSZ), size_t(32 * 1024));
stack_ = std::unique_ptr<char[]>(new char[kAltStackSize]);
setAlternateStack(stack_->data(), stack_->size()); setAlternateStack(stack_.get(), kAltStackSize);
} }
ScopedAlternateSignalStack(ScopedAlternateSignalStack&&) = default; ScopedAlternateSignalStack(ScopedAlternateSignalStack&&) = default;
...@@ -387,8 +387,7 @@ class ScopedAlternateSignalStack { ...@@ -387,8 +387,7 @@ class ScopedAlternateSignalStack {
} }
private: private:
using AltStackBuffer = std::array<char, kAltStackSize>; std::unique_ptr<char[]> stack_;
std::unique_ptr<AltStackBuffer> stack_;
}; };
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment