webkit2gtk: work out the remaining musl stack size problems

This commit is contained in:
q66 2021-04-27 22:58:48 +02:00
parent 2269ad8f4e
commit b0b0bbe0ad
5 changed files with 214 additions and 120 deletions

View file

@ -0,0 +1,80 @@
Upstream: yes
--- Source/JavaScriptCore/runtime/MachineContext.h
+++ Source/JavaScriptCore/runtime/MachineContext.h
@@ -196,7 +196,7 @@ static inline void*& stackPointerImpl(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
#if CPU(X86)
return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_ESP]);
@@ -347,7 +347,7 @@ static inline void*& framePointerImpl(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
@@ -498,7 +498,7 @@ static inline void*& instructionPointerImpl(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
@@ -656,7 +656,7 @@ inline void*& argumentPointer<1>(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
@@ -773,7 +773,7 @@ inline void*& llintInstructionPointer(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
--- Source/WebCore/xml/XPathGrammar.cpp
+++ Source/WebCore/xml/XPathGrammar.cpp
@@ -966,7 +966,7 @@ int yydebug;
#if YYERROR_VERBOSE
# ifndef yystrlen
-# if defined __GLIBC__ && defined _STRING_H
+# if defined __linux__ && defined _STRING_H
# define yystrlen strlen
# else
/* Return the length of YYSTR. */
@@ -989,7 +989,7 @@ yystrlen (yystr)
# endif
# ifndef yystpcpy
-# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
+# if defined __linux__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
--- Source/WTF/wtf/PlatformHave.h
+++ Source/WTF/wtf/PlatformHave.h
@@ -206,7 +206,7 @@
#define HAVE_HOSTED_CORE_ANIMATION 1
#endif
-#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || defined(__GLIBC__) || defined(__BIONIC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || OS(LINUX)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
#define HAVE_MACHINE_CONTEXT 1
#endif

View file

@ -0,0 +1,74 @@
https://bugs.webkit.org/show_bug.cgi?id=225099
From ab7e2bfae280b151ac173d6fc9d8eaa3da2e92a8 Mon Sep 17 00:00:00 2001
From: q66 <daniel@octaforge.org>
Date: Tue, 27 Apr 2021 22:51:22 +0200
Subject: [PATCH] fix stack size issues on musl
---
Source/WTF/wtf/StackBounds.cpp | 26 +++++++++++++++++++++++++-
Source/WTF/wtf/Threading.cpp | 4 ++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git Source/WTF/wtf/StackBounds.cpp Source/WTF/wtf/StackBounds.cpp
index e6f7095..58bdb18 100644
--- Source/WTF/wtf/StackBounds.cpp
+++ Source/WTF/wtf/StackBounds.cpp
@@ -36,6 +36,12 @@
#include <pthread_np.h>
#endif
+#if OS(LINUX)
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#endif
+
#endif
namespace WTF {
@@ -107,7 +113,25 @@ StackBounds StackBounds::newThreadStackBounds(PlatformThreadHandle thread)
StackBounds StackBounds::currentThreadStackBoundsInternal()
{
- return newThreadStackBounds(pthread_self());
+ auto ret = newThreadStackBounds(pthread_self());
+#if OS(LINUX)
+ // on glibc, pthread_attr_getstack will generally return the limit size (minus a guard page)
+ // for the main thread; this is however not necessarily always true on every libc - for example
+ // on musl, it will return the currently reserved size - since the stack bounds are expected to
+ // be constant (and they are for every thread except main, which is allowed to grow), check
+ // resource limits and use that as the boundary instead (and prevent stack overflows in JSC)
+ if (getpid() == static_cast<pid_t>(syscall(SYS_gettid))) {
+ void* origin = ret.origin();
+ rlimit limit;
+ getrlimit(RLIMIT_STACK, &limit);
+ rlim_t size = limit.rlim_cur;
+ // account for a guard page
+ size -= static_cast<rlim_t>(sysconf(_SC_PAGESIZE));
+ void* bound = static_cast<char*>(origin) - size;
+ return StackBounds { origin, bound };
+ }
+#endif
+ return ret;
}
#elif OS(WINDOWS)
diff --git Source/WTF/wtf/Threading.cpp Source/WTF/wtf/Threading.cpp
index 99d09c0..362bf35 100644
--- Source/WTF/wtf/Threading.cpp
+++ Source/WTF/wtf/Threading.cpp
@@ -58,6 +58,10 @@ static Optional<size_t> stackSize(ThreadType threadType)
#if defined(DEFAULT_THREAD_STACK_SIZE_IN_KB) && DEFAULT_THREAD_STACK_SIZE_IN_KB > 0
return DEFAULT_THREAD_STACK_SIZE_IN_KB * 1024;
+#elif OS(LINUX) && !defined(__BIONIC__) && !defined(__GLIBC__)
+ // on libc's other than glibc and bionic (e.g. musl) we are either unsure how big
+ // the default thread stack is, or we know it's too small - pick a robust default
+ return 1 * MB;
#else
// Use the platform's default stack size
return WTF::nullopt;
--
2.30.1

View file

@ -1,113 +0,0 @@
Source: https://github.com/WebKit/WebKit/commit/6884d13 (tweaked values)
diff --git Source/JavaScriptCore/runtime/MachineContext.h Source/JavaScriptCore/runtime/MachineContext.h
index ead9cdf..86b36ca 100644
--- Source/JavaScriptCore/runtime/MachineContext.h
+++ Source/JavaScriptCore/runtime/MachineContext.h
@@ -196,7 +196,7 @@ static inline void*& stackPointerImpl(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
#if CPU(X86)
return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_ESP]);
@@ -347,7 +347,7 @@ static inline void*& framePointerImpl(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
@@ -498,7 +498,7 @@ static inline void*& instructionPointerImpl(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
@@ -656,7 +656,7 @@ inline void*& argumentPointer<1>(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
@@ -773,7 +773,7 @@ inline void*& llintInstructionPointer(mcontext_t& machineContext)
#error Unknown Architecture
#endif
-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || OS(LINUX)
// The following sequence depends on glibc's sys/ucontext.h.
#if CPU(X86)
diff --git Source/JavaScriptCore/runtime/OptionsList.h Source/JavaScriptCore/runtime/OptionsList.h
index bc1cedb..f4a86a5 100644
--- Source/JavaScriptCore/runtime/OptionsList.h
+++ 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(__BIONIC__) && !defined(__GLIBC__)
+// non-glibc/non-android options on linux ( musl )
+constexpr unsigned jscMaxPerThreadStack = 2 * MB;
+constexpr unsigned jscSoftReservedZoneSize = 64 * KB;
+constexpr unsigned jscReservedZoneSize = 32 * KB;
+#else
+// default
+constexpr unsigned jscMaxPerThreadStack = 5 * 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) \
diff --git Source/WTF/wtf/PlatformHave.h Source/WTF/wtf/PlatformHave.h
index 41afbb4..ab5263c 100644
--- Source/WTF/wtf/PlatformHave.h
+++ Source/WTF/wtf/PlatformHave.h
@@ -206,7 +206,7 @@
#define HAVE_HOSTED_CORE_ANIMATION 1
#endif
-#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || defined(__GLIBC__) || defined(__BIONIC__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
+#if OS(DARWIN) || OS(FUCHSIA) || ((OS(FREEBSD) || OS(LINUX)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
#define HAVE_MACHINE_CONTEXT 1
#endif
diff --git Source/WTF/wtf/Threading.cpp Source/WTF/wtf/Threading.cpp
index 99d09c0..723a8f4 100644
--- Source/WTF/wtf/Threading.cpp
+++ Source/WTF/wtf/Threading.cpp
@@ -52,6 +52,8 @@ static Optional<size_t> stackSize(ThreadType threadType)
#elif OS(DARWIN) && ASAN_ENABLED
if (threadType == ThreadType::Compiler)
return 1 * MB; // ASan needs more stack space (especially on Debug builds).
+#elif OS(LINUX) && !defined(__BIONIC__) && !defined(__GLIBC__) // MUSL default thread stack size.
+ return 2 * MB;
#else
UNUSED_PARAM(threadType);
#endif

View file

@ -0,0 +1,59 @@
Upstream: yes
From 1b7144916774dbb4cc4705ba9a4377844e35f47d Mon Sep 17 00:00:00 2001
From: q66 <daniel@octaforge.org>
Date: Tue, 27 Apr 2021 22:56:33 +0200
Subject: [PATCH] remove __WORDSIZE usage
---
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp | 6 +++---
Source/WebCore/rendering/RenderLayerBacking.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp
index cfe3698..e5bc870 100644
--- Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp
+++ Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_GCM.cpp
@@ -39,7 +39,7 @@ namespace CryptoAlgorithmAES_GCMInternal {
static const char* const ALG128 = "A128GCM";
static const char* const ALG192 = "A192GCM";
static const char* const ALG256 = "A256GCM";
-#if __WORDSIZE >= 64
+#if CPU(ADDRESS64)
static const uint64_t PlainTextMaxLength = 549755813632ULL; // 2^39 - 256
#endif
static const uint8_t DefaultTagLength = 128;
@@ -77,7 +77,7 @@ void CryptoAlgorithmAES_GCM::encrypt(const CryptoAlgorithmParameters& parameters
auto& aesParameters = downcast<CryptoAlgorithmAesGcmParams>(parameters);
-#if __WORDSIZE >= 64
+#if CPU(ADDRESS64)
if (plainText.size() > PlainTextMaxLength) {
exceptionCallback(OperationError);
return;
@@ -120,7 +120,7 @@ void CryptoAlgorithmAES_GCM::decrypt(const CryptoAlgorithmParameters& parameters
return;
}
-#if __WORDSIZE >= 64
+#if CPU(ADDRESS64)
if (aesParameters.ivVector().size() > UINT64_MAX) {
exceptionCallback(OperationError);
return;
diff --git Source/WebCore/rendering/RenderLayerBacking.h Source/WebCore/rendering/RenderLayerBacking.h
index 9960724..193c5d1 100644
--- Source/WebCore/rendering/RenderLayerBacking.h
+++ Source/WebCore/rendering/RenderLayerBacking.h
@@ -43,7 +43,7 @@ class TiledBacking;
class TransformationMatrix;
-#if __WORDSIZE == 64 && PLATFORM(COCOA)
+#if CPU(ADDRESS64) && PLATFORM(COCOA)
#define USE_OWNING_LAYER_BEAR_TRAP 1
#define BEAR_TRAP_VALUE 0xEEEEEEEEEEEEEEEE
#else
--
2.30.1

View file

@ -2,7 +2,7 @@
# ping q66 before touching this # ping q66 before touching this
pkgname=webkit2gtk pkgname=webkit2gtk
version=2.32.0 version=2.32.0
revision=2 revision=3
wrksrc="webkitgtk-${version}" wrksrc="webkitgtk-${version}"
build_style=cmake build_style=cmake
build_helper="gir" build_helper="gir"
@ -48,12 +48,6 @@ desc_option_sampling_profiler="Sampling profiler support (JIT + glibc only)"
desc_option_minibrowser="Build the minibrowser" desc_option_minibrowser="Build the minibrowser"
export CFLAGS="-DNDEBUG" export CFLAGS="-DNDEBUG"
if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
# this is not defined on musl and is occasionally used
export CFLAGS+=" -D__WORDSIZE=${XBPS_TARGET_WORDSIZE}"
fi
export CXXFLAGS="$CFLAGS" export CXXFLAGS="$CFLAGS"
# WebKitCCache.cmake set this variable # WebKitCCache.cmake set this variable