AK: Use getrlimit() to find the correct main thread stack size on macOS

This is what JavaScriptCore does as well.
This commit is contained in:
Andreas Kling 2024-11-10 13:24:21 +01:00 committed by Andreas Kling
parent 1510c1876c
commit 11458f0d91
Notes: github-actions[bot] 2024-11-10 18:14:09 +00:00

View file

@ -65,11 +65,16 @@ StackInfo::StackInfo()
// MacOS seems inconsistent on what stack size is given for the main thread.
// According to the Apple docs, default for main thread is 8MB, and default for
// other threads is 512KB
constexpr size_t eight_megabytes = 0x800000;
if (pthread_main_np() == 1 && m_size < eight_megabytes) {
// Assume no one messed with stack size linker options for the main thread,
// and just set it to 8MB.
m_size = eight_megabytes;
if (pthread_main_np() == 1) {
// Apparently the main thread's stack size is not reported correctly on macOS
// but we can use getrlimit to get the correct value.
rlimit limit {};
getrlimit(RLIMIT_STACK, &limit);
if (limit.rlim_cur == RLIM_INFINITY) {
m_size = 8 * MiB;
} else {
m_size = limit.rlim_cur;
}
}
m_base = top_of_stack - m_size;
#elif defined(AK_OS_OPENBSD)