mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
AK: Use getrlimit() to find the correct main thread stack size on macOS
This is what JavaScriptCore does as well. (cherry picked from commit 11458f0d91654feed9b4e225c4e6ac8528057355)
This commit is contained in:
1 parent
c00dda5a3a
commit
f670b2ca32
1 file changed
+10
-5
+10
-5
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user