summaryrefslogtreecommitdiffstats
path: root/meta/recipes-sato/webkit/webkitgtk/musl-lower-stack-usage.patch
blob: e4b58183582d005c2bdf30879ecbbbf14f682d75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
From 5c82d20a00749e9106db78cdd23a09609dd3511c Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Wed, 17 Mar 2021 13:24:57 -0700
Subject: [PATCH] reduce thread stack and heap usage for javascriptcore on musl

default sizes for musl are smaller compared to glibc, this matches
to musl defaults, avoid stack overflow crashes in jscore

This is based on Alpine Linux's patch based on suggestion from
https://bugs.webkit.org/show_bug.cgi?id=187485

Real solution would entail more as the suggestions to increase
stack size via -Wl,-z,stack-size=N does not work fully and also
setting DEFAULT_THREAD_STACK_SIZE_IN_KB alone is not enough either

This patch only changes behavior when using musl, the defaults for
glibc in OE remains same

Upstream-Status: Accepted
Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 Source/JavaScriptCore/runtime/OptionsList.h | 20 ++++++++++++++++----
 Source/WTF/wtf/Threading.h                  |  4 ++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Source/JavaScriptCore/runtime/OptionsList.h b/Source/JavaScriptCore/runtime/OptionsList.h
index bc1cedb9..a6209742 100644
--- a/Source/JavaScriptCore/runtime/OptionsList.h
+++ b/Source/JavaScriptCore/runtime/OptionsList.h
@@ -71,6 +71,18 @@ JS_EXPORT_PRIVATE bool canUseJITCage();
 // On instantiation of the first VM instance, the Options will be write protected
 // and cannot be modified thereafter.
 
+#if OS(LINUX) && !defined(__GLIBC__)
+// non-glibc options on linux ( musl )
+constexpr unsigned jscMaxPerThreadStack = 128 * KB;
+constexpr unsigned jscSoftReservedZoneSize = 32 * KB;
+constexpr unsigned jscReservedZoneSize = 16 * KB;
+#else
+//default
+constexpr unsigned jscMaxPerThreadStack = 4 * MB;
+constexpr unsigned jscSoftReservedZoneSize = 128 * KB;
+constexpr unsigned jscReservedZoneSize = 64 * KB;
+#endif
+
 #define FOR_EACH_JSC_OPTION(v)                                          \
     v(Bool, useKernTCSM, defaultTCSMValue(), Normal, "Note: this needs to go before other options since they depend on this value.") \
     v(Bool, validateOptions, false, Normal, "crashes if mis-typed JSC options were passed to the VM") \
@@ -86,9 +98,9 @@ JS_EXPORT_PRIVATE bool canUseJITCage();
     \
     v(Bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \
     \
-    v(Unsigned, maxPerThreadStackUsage, 5 * MB, Normal, "Max allowed stack usage by the VM") \
-    v(Unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
-    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).") \
+    v(Unsigned, maxPerThreadStackUsage, jscMaxPerThreadStack, Normal, "Max allowed stack usage by the VM") \
+    v(Unsigned, softReservedZoneSize, jscSoftReservedZoneSize, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \
+    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).") \
     \
     v(Bool, crashOnDisallowedVMEntry, ASSERT_ENABLED, Normal, "Forces a crash if we attempt to enter the VM when disallowed") \
     v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
@@ -608,7 +620,7 @@ public:
     bool init(const char*);
     bool isInRange(unsigned);
     const char* rangeString() const { return (m_state > InitError) ? m_rangeString : s_nullRangeStr; }
-    
+
     void dump(PrintStream& out) const;
 
 private:
diff --git a/Source/WTF/wtf/Threading.h b/Source/WTF/wtf/Threading.h
index 9495d6c1..190b3811 100644
--- a/Source/WTF/wtf/Threading.h
+++ b/Source/WTF/wtf/Threading.h
@@ -60,6 +60,10 @@
 #include <dispatch/dispatch.h>
 #endif
 
+#if OS(LINUX) && !defined(__GLIBC__)
+#define DEFAULT_THREAD_STACK_SIZE_IN_KB 128
+#endif
+
 namespace WTF {
 
 class AbstractLocker;