Source: @q66, @pullmoll
Original upstream: Alpine Linux
Reason: fixing machine context access for musl libc; reduce stack/heap usage for jsc; fix some overly restrictive __GLIBC__ checks

Updated for latest webkit2gtk.

--- a/Source/JavaScriptCore/runtime/MachineContext.h
+++ b/Source/JavaScriptCore/runtime/MachineContext.h
@@ -188,7 +188,7 @@ static inline void*& stackPointerImpl(mcontext_t& machineContext)
 #error Unknown Architecture
 #endif

-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || defined(__linux__)

 #if CPU(X86)
     return reinterpret_cast<void*&>((uintptr_t&) machineContext.gregs[REG_ESP]);
@@ -335,7 +335,7 @@ static inline void*& framePointerImpl(mcontext_t& machineContext)
 #error Unknown Architecture
 #endif

-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || defined(__linux__)

 // The following sequence depends on glibc's sys/ucontext.h.
 #if CPU(X86)
@@ -482,7 +482,7 @@ static inline void*& instructionPointerImpl(mcontext_t& machineContext)
 #error Unknown Architecture
 #endif

-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || defined(__linux__)

 // The following sequence depends on glibc's sys/ucontext.h.
 #if CPU(X86)
@@ -639,7 +639,7 @@ inline void*& argumentPointer<1>(mcontext_t& machineContext)
 #error Unknown Architecture
 #endif

-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || defined(__linux__)

 // The following sequence depends on glibc's sys/ucontext.h.
 #if CPU(X86)
@@ -756,7 +756,7 @@ inline void*& llintInstructionPointer(mcontext_t& machineContext)
 #error Unknown Architecture
 #endif

-#elif OS(FUCHSIA) || defined(__GLIBC__) || defined(__BIONIC__)
+#elif OS(FUCHSIA) || defined(__linux__)

 // The following sequence depends on glibc's sys/ucontext.h.
 #if CPU(X86)
--- a/Source/JavaScriptCore/runtime/Options.h
+++ b/Source/JavaScriptCore/runtime/Options.h
@@ -112,6 +112,16 @@ constexpr bool enableWebAssemblyStreamingApi = true;
 constexpr bool enableWebAssemblyStreamingApi = false;
 #endif

+#if defined(__GLIBC__)
+constexpr unsigned jscMaxPerThreadStack = 4 * MB;
+constexpr unsigned jscSoftReservedZoneSize = 128 * KB;
+constexpr unsigned jscReservedZoneSize = 64 * KB;
+#else
+constexpr unsigned jscMaxPerThreadStack = 80 * KB;
+constexpr unsigned jscSoftReservedZoneSize = 32 * KB;
+constexpr unsigned jscReservedZoneSize = 16 * KB;
+#endif
+
 #define JSC_OPTIONS(v) \
     v(bool, useKernTCSM, true, 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") \
@@ -126,9 +136,9 @@ constexpr bool enableWebAssemblyStreamingApi = false;
     \
     v(bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \
     \
-    v(unsigned, maxPerThreadStackUsage, 4 * 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, crashIfCantAllocateJITMemory, false, Normal, nullptr) \
     v(unsigned, jitMemoryReservationSize, 0, Normal, "Set this number to change the executable allocation size in ExecutableAllocatorFixedVMPool. (In bytes.)") \
--- a/Source/ThirdParty/ANGLE/src/compiler/preprocessor/ExpressionParser.cpp
+++ b/Source/ThirdParty/ANGLE/src/compiler/preprocessor/ExpressionParser.cpp
@@ -728,7 +728,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.  */
@@ -743,7 +743,7 @@ static YYSIZE_T yystrlen(const char *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
--- a/Source/WTF/wtf/Platform.h
+++ b/Source/WTF/wtf/Platform.h
@@ -707,7 +707,7 @@

 #endif /* OS(DARWIN) */

-#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) || defined(__linux__)) && (CPU(X86) || CPU(X86_64) || CPU(ARM) || CPU(ARM64) || CPU(MIPS)))
 #define HAVE_MACHINE_CONTEXT 1
 #endif

--- a/Source/WebCore/xml/XPathGrammar.cpp
+++ b/Source/WebCore/xml/XPathGrammar.cpp
@@ -966,7 +966,7 @@
 #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 @@
 # 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