blob: dc3a71d932d654b878868bbb7a251045baf5b73f [file] [log] [blame]
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001reduce thread stack and heap usage for javascriptcore on musl
2
3default sizes for musl are smaller compared to glibc, this matches
4to musl defaults, avoid stack overflow crashes in jscore
5
6This is based on Alpine Linux's patch based on suggestion from
7https://bugs.webkit.org/show_bug.cgi?id=187485
8
9Real solution would entail more as the suggestions to increase
10stack size via -Wl,-z,stack-size=N does not work fully and also
11setting DEFAULT_THREAD_STACK_SIZE_IN_KB alone is not enough either
12
13This patch only changes behavior when using musl, the defaults for
14glibc in OE remains same
15
16Upstream-Status: Pending
17Signed-off-by: Khem Raj <raj.khem@gmail.com>
18
19--- a/Source/JavaScriptCore/runtime/OptionsList.h
20+++ b/Source/JavaScriptCore/runtime/OptionsList.h
21@@ -75,6 +75,18 @@ constexpr bool enableWebAssemblyStreamin
22 // On instantiation of the first VM instance, the Options will be write protected
23 // and cannot be modified thereafter.
24
25+#if OS(LINUX) && !defined(__GLIBC__)
26+// non-glibc options on linux ( musl )
27+constexpr unsigned jscMaxPerThreadStack = 128 * KB;
28+constexpr unsigned jscSoftReservedZoneSize = 32 * KB;
29+constexpr unsigned jscReservedZoneSize = 16 * KB;
30+#else
31+//default
32+constexpr unsigned jscMaxPerThreadStack = 4 * MB;
33+constexpr unsigned jscSoftReservedZoneSize = 128 * KB;
34+constexpr unsigned jscReservedZoneSize = 64 * KB;
35+#endif
36+
37 #define FOR_EACH_JSC_OPTION(v) \
38 v(Bool, useKernTCSM, defaultTCSMValue(), Normal, "Note: this needs to go before other options since they depend on this value.") \
39 v(Bool, validateOptions, false, Normal, "crashes if mis-typed JSC options were passed to the VM") \
40@@ -90,9 +102,9 @@ constexpr bool enableWebAssemblyStreamin
41 \
42 v(Bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \
43 \
44- v(Unsigned, maxPerThreadStackUsage, 5 * MB, Normal, "Max allowed stack usage by the VM") \
45- v(Unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
46- v(Unsigned, reservedZoneSize, 64 * KB, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \
47+ v(Unsigned, maxPerThreadStackUsage, jscMaxPerThreadStack, Normal, "Max allowed stack usage by the VM") \
48+ v(Unsigned, softReservedZoneSize, jscSoftReservedZoneSize, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
49+ v(Unsigned, reservedZoneSize, jscReservedZoneSize, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \
50 \
51 v(Bool, crashOnDisallowedVMEntry, ASSERT_ENABLED, Normal, "Forces a crash if we attempt to enter the VM when disallowed") \
52 v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
53@@ -601,7 +613,7 @@ public:
54 bool init(const char*);
55 bool isInRange(unsigned);
56 const char* rangeString() const { return (m_state > InitError) ? m_rangeString : s_nullRangeStr; }
57-
58+
59 void dump(PrintStream& out) const;
60
61 private:
62--- a/Source/WTF/wtf/Threading.h
63+++ b/Source/WTF/wtf/Threading.h
64@@ -56,6 +56,10 @@
65 #include <array>
66 #endif
67
68+#if OS(LINUX) && !defined(__GLIBC__)
69+#define DEFAULT_THREAD_STACK_SIZE_IN_KB 128
70+#endif
71+
72 namespace WTF {
73
74 class AbstractLocker;