#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/wtf/stack_util.h"
#include "build/build_config.h"
#include "base/notreached.h"
#include "third_party/blink/renderer/platform/wtf/threading.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <intrin.h>
#include <stddef.h>
#include <winnt.h>
#elif defined(__GLIBC__)
extern "C" void* __libc_stack_end;
#endif
namespace WTF {
size_t GetUnderestimatedStackSize() { … }
void* GetStackStart() { … }
uintptr_t GetCurrentStackPosition() { … }
namespace internal {
uintptr_t g_main_thread_stack_start = …;
uintptr_t g_main_thread_underestimated_stack_size = …;
void InitializeMainThreadStackEstimate() { … }
#if BUILDFLAG(IS_WIN) && defined(COMPILER_MSVC)
size_t ThreadStackSize() {
MEMORY_BASIC_INFORMATION stack_info;
memset(&stack_info, 0, sizeof(MEMORY_BASIC_INFORMATION));
size_t result_size =
VirtualQuery(&stack_info, &stack_info, sizeof(MEMORY_BASIC_INFORMATION));
DCHECK_GE(result_size, sizeof(MEMORY_BASIC_INFORMATION));
uint8_t* stack_end = reinterpret_cast<uint8_t*>(stack_info.AllocationBase);
uint8_t* stack_start = reinterpret_cast<uint8_t*>(WTF::GetStackStart());
CHECK(stack_start);
CHECK_GT(stack_start, stack_end);
size_t thread_stack_size = static_cast<size_t>(stack_start - stack_end);
CHECK_GT(thread_stack_size, 4u * 0x1000);
thread_stack_size -= 4 * 0x1000;
return thread_stack_size;
}
#endif
}
}