blob: f71f8452fdb1f46051d48ccebe4e2bcdc0e0128b [file] [log] [blame]
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001From 04e4999c6fa2e9810634745a07f1e380f27b8e61 Mon Sep 17 00:00:00 2001
2From: 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
28index bb6d2f1d..a6209742 100644
Andrew Geissler95ac1b82021-03-31 14:34:31 -050029--- a/Source/JavaScriptCore/runtime/OptionsList.h
30+++ b/Source/JavaScriptCore/runtime/OptionsList.h
William A. Kennington IIIac69b482021-06-02 12:28:27 -070031@@ -71,6 +71,18 @@ JS_EXPORT_PRIVATE bool canUseJITCage();
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") \
William A. Kennington IIIac69b482021-06-02 12:28:27 -070050@@ -86,9 +98,9 @@ JS_EXPORT_PRIVATE bool canUseJITCage();
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
64index 9495d6c1..190b3811 100644
Andrew Geissler95ac1b82021-03-31 14:34:31 -050065--- a/Source/WTF/wtf/Threading.h
66+++ b/Source/WTF/wtf/Threading.h
William A. Kennington IIIac69b482021-06-02 12:28:27 -070067@@ -60,6 +60,10 @@
68 #include <dispatch/dispatch.h>
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;