blob: d8d36fad6b1908ac318658a7241877fd176fa602 [file] [log] [blame]
Andrew Geisslereff27472021-10-29 15:35:00 -05001From 358a8f053c367aab7fba8ab059244e0530c7ff82 Mon Sep 17 00:00:00 2001
William A. Kennington IIIac69b482021-06-02 12:28:27 -07002From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 17 Mar 2021 13:24:57 -0700
4Subject: [PATCH] reduce thread stack and heap usage for javascriptcore on musl
Andrew Geissler95ac1b82021-03-31 14:34:31 -05005
6default sizes for musl are smaller compared to glibc, this matches
7to musl defaults, avoid stack overflow crashes in jscore
8
9This is based on Alpine Linux's patch based on suggestion from
10https://bugs.webkit.org/show_bug.cgi?id=187485
11
12Real solution would entail more as the suggestions to increase
13stack size via -Wl,-z,stack-size=N does not work fully and also
14setting DEFAULT_THREAD_STACK_SIZE_IN_KB alone is not enough either
15
16This patch only changes behavior when using musl, the defaults for
17glibc in OE remains same
18
Andrew Geisslerc926e172021-05-07 16:11:35 -050019Upstream-Status: Accepted
Andrew Geissler95ac1b82021-03-31 14:34:31 -050020Signed-off-by: Khem Raj <raj.khem@gmail.com>
21
William A. Kennington IIIac69b482021-06-02 12:28:27 -070022---
23 Source/JavaScriptCore/runtime/OptionsList.h | 18 +++++++++++++++---
24 Source/WTF/wtf/Threading.h | 4 ++++
25 2 files changed, 19 insertions(+), 3 deletions(-)
26
27diff --git a/Source/JavaScriptCore/runtime/OptionsList.h b/Source/JavaScriptCore/runtime/OptionsList.h
Andrew Geisslereff27472021-10-29 15:35:00 -050028index a0c2170e..9e107af7 100644
Andrew Geissler95ac1b82021-03-31 14:34:31 -050029--- a/Source/JavaScriptCore/runtime/OptionsList.h
30+++ b/Source/JavaScriptCore/runtime/OptionsList.h
Andrew Geisslereff27472021-10-29 15:35:00 -050031@@ -77,6 +77,18 @@ bool canUseWebAssemblyFastMemory();
Andrew Geissler95ac1b82021-03-31 14:34:31 -050032 // On instantiation of the first VM instance, the Options will be write protected
33 // and cannot be modified thereafter.
34
35+#if OS(LINUX) && !defined(__GLIBC__)
36+// non-glibc options on linux ( musl )
37+constexpr unsigned jscMaxPerThreadStack = 128 * KB;
38+constexpr unsigned jscSoftReservedZoneSize = 32 * KB;
39+constexpr unsigned jscReservedZoneSize = 16 * KB;
40+#else
41+//default
42+constexpr unsigned jscMaxPerThreadStack = 4 * MB;
43+constexpr unsigned jscSoftReservedZoneSize = 128 * KB;
44+constexpr unsigned jscReservedZoneSize = 64 * KB;
45+#endif
46+
47 #define FOR_EACH_JSC_OPTION(v) \
48 v(Bool, useKernTCSM, defaultTCSMValue(), Normal, "Note: this needs to go before other options since they depend on this value.") \
49 v(Bool, validateOptions, false, Normal, "crashes if mis-typed JSC options were passed to the VM") \
Andrew Geisslereff27472021-10-29 15:35:00 -050050@@ -92,9 +104,9 @@ bool canUseWebAssemblyFastMemory();
Andrew Geissler95ac1b82021-03-31 14:34:31 -050051 \
52 v(Bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \
53 \
54- v(Unsigned, maxPerThreadStackUsage, 5 * MB, Normal, "Max allowed stack usage by the VM") \
55- v(Unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
56- 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).") \
57+ v(Unsigned, maxPerThreadStackUsage, jscMaxPerThreadStack, Normal, "Max allowed stack usage by the VM") \
58+ v(Unsigned, softReservedZoneSize, jscSoftReservedZoneSize, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
59+ 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).") \
60 \
61 v(Bool, crashOnDisallowedVMEntry, ASSERT_ENABLED, Normal, "Forces a crash if we attempt to enter the VM when disallowed") \
62 v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
William A. Kennington IIIac69b482021-06-02 12:28:27 -070063diff --git a/Source/WTF/wtf/Threading.h b/Source/WTF/wtf/Threading.h
Andrew Geisslereff27472021-10-29 15:35:00 -050064index 178f9808..95ec5a85 100644
Andrew Geissler95ac1b82021-03-31 14:34:31 -050065--- a/Source/WTF/wtf/Threading.h
66+++ b/Source/WTF/wtf/Threading.h
Andrew Geisslereff27472021-10-29 15:35:00 -050067@@ -67,6 +67,10 @@
68 #undef None
Andrew Geissler95ac1b82021-03-31 14:34:31 -050069 #endif
70
71+#if OS(LINUX) && !defined(__GLIBC__)
72+#define DEFAULT_THREAD_STACK_SIZE_IN_KB 128
73+#endif
74+
75 namespace WTF {
76
77 class AbstractLocker;