1From ef08d0dbc99db8c4620512e92bfb3154282eb5d3 Mon Sep 17 00:00:00 2001
2From: Andrew Morrow <acm@mongodb.com>
3Date: Wed, 15 Sep 2021 15:23:42 -0400
4Subject: [PATCH] SERVER-59459 With glibc-2.34, MINSIGSTKSZ is no longer a
5 constant
6
7[Retrieved (and backported) from:
8https://github.com/mongodb/mongo/commit/ef08d0dbc99db8c4620512e92bfb3154282eb5d3]
9Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
10---
11 src/mongo/stdx/thread.h | 14 ++++++++++----
12 1 file changed, 10 insertions(+), 4 deletions(-)
13
14diff --git a/src/mongo/stdx/thread.h b/src/mongo/stdx/thread.h
15index 7b15bb561bd9..6f1e16cdeb36 100644
16--- a/src/mongo/stdx/thread.h
17+++ b/src/mongo/stdx/thread.h
18@@ -76,11 +76,19 @@ class SigAltStackController {
19     }
20
21 private:
22+    static size_t _getStackSize() {
23+        // It would be nice for this to be a constexpr, but
24+        // MINSIGSTKSZ became a macro that invoked `sysconf` in glibc
25+        // 2.34.
26+        static const std::size_t kMinSigStkSz = MINSIGSTKSZ;
27+        return std::max(kMongoMinSignalStackSize, kMinSigStkSz);
28+    }
29+
30     void _install() const {
31         stack_t ss;
32         ss.ss_sp = _stackStorage.get();
33         ss.ss_flags = 0;
34-        ss.ss_size = kStackSize;
35+        ss.ss_size = _getStackSize();
36         if (sigaltstack(&ss, nullptr)) {
37             abort();
38         }
39@@ -107,9 +115,7 @@ class SigAltStackController {
40     //   ( https://jira.mongodb.org/secure/attachment/233569/233569_stacktrace-writeup.txt )
41     static constexpr std::size_t kMongoMinSignalStackSize = std::size_t{64} << 10;
42
43-    static constexpr std::size_t kStackSize =
44-        std::max(kMongoMinSignalStackSize, std::size_t{MINSIGSTKSZ});
45-    std::unique_ptr<std::byte[]> _stackStorage = std::make_unique<std::byte[]>(kStackSize);
46+    std::unique_ptr<std::byte[]> _stackStorage = std::make_unique<std::byte[]>(_getStackSize());
47
48 #else   // !MONGO_HAS_SIGALTSTACK
49     auto makeInstallGuard() const {
50