mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-24 00:20:21 +00:00
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:
parent
1510c1876c
commit
11458f0d91
Notes:
github-actions[bot]
2024-11-10 18:14:09 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/11458f0d916 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2268
1 changed files with 10 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue