From 13e44ab035426991abe8e055c6ed35bc09bfde9f Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Sun, 12 May 2024 03:13:40 +0200 Subject: [PATCH] AK: Add stack size fixup for musl libc Fixes #16681 --- AK/StackInfo.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AK/StackInfo.cpp b/AK/StackInfo.cpp index 944e7b7a7e6..4777c48375d 100644 --- a/AK/StackInfo.cpp +++ b/AK/StackInfo.cpp @@ -14,6 +14,7 @@ # include #elif defined(AK_OS_LINUX) || defined(AK_LIBC_GLIBC) || defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_NETBSD) || defined(AK_OS_SOLARIS) || defined(AK_OS_HAIKU) # include +# include #elif defined(AK_OS_FREEBSD) || defined(AK_OS_OPENBSD) # include # include @@ -95,6 +96,21 @@ StackInfo::StackInfo() #endif m_top = m_base + m_size; + +#if defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID) && !defined(AK_LIBC_GLIBC) + // Note: musl libc always gives the initial size of the main thread's stack + if (getpid() == static_cast(gettid())) { + rlimit limit; + getrlimit(RLIMIT_STACK, &limit); + rlim_t size = limit.rlim_cur; + if (size == RLIM_INFINITY) + size = 8 * 0x10000; + // account for a guard page + size -= static_cast(sysconf(_SC_PAGESIZE)); + m_size = static_cast(size); + m_base = m_top - m_size; + } +#endif } }