зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1257234 - Detect main thread's stack size at runtime, on Windows. r=ted
This commit is contained in:
Родитель
1f5ae2dc93
Коммит
bf89b25bca
|
@ -63,6 +63,10 @@
|
|||
#include "mozmemory.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace xpc;
|
||||
using namespace JS;
|
||||
|
@ -3362,6 +3366,40 @@ XPCJSRuntime::XPCJSRuntime()
|
|||
{
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
static size_t
|
||||
GetWindowsStackSize()
|
||||
{
|
||||
// First, get the stack base. Because the stack grows down, this is the top
|
||||
// of the stack.
|
||||
const uint8_t* stackTop;
|
||||
#ifdef _WIN64
|
||||
PNT_TIB64 pTib = reinterpret_cast<PNT_TIB64>(NtCurrentTeb());
|
||||
stackTop = reinterpret_cast<const uint8_t*>(pTib->StackBase);
|
||||
#else
|
||||
PNT_TIB pTib = reinterpret_cast<PNT_TIB>(NtCurrentTeb());
|
||||
stackTop = reinterpret_cast<const uint8_t*>(pTib->StackBase);
|
||||
#endif
|
||||
|
||||
// Now determine the stack bottom. Note that we can't use tib->StackLimit,
|
||||
// because that's the size of the committed area and we're also interested
|
||||
// in the reserved pages below that.
|
||||
MEMORY_BASIC_INFORMATION mbi;
|
||||
if (!VirtualQuery(&mbi, &mbi, sizeof(mbi)))
|
||||
MOZ_CRASH("VirtualQuery failed");
|
||||
|
||||
const uint8_t* stackBottom = reinterpret_cast<const uint8_t*>(mbi.AllocationBase);
|
||||
|
||||
// Do some sanity checks.
|
||||
size_t stackSize = size_t(stackTop - stackBottom);
|
||||
MOZ_RELEASE_ASSERT(stackSize >= 1 * 1024 * 1024);
|
||||
MOZ_RELEASE_ASSERT(stackSize <= 32 * 1024 * 1024);
|
||||
|
||||
// Subtract 20 KB to account for things like the guard page.
|
||||
return stackSize - 20 * 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
XPCJSRuntime::Initialize()
|
||||
{
|
||||
|
@ -3444,9 +3482,9 @@ XPCJSRuntime::Initialize()
|
|||
const size_t kStackQuota = 2 * kDefaultStackQuota;
|
||||
const size_t kTrustedScriptBuffer = 450 * 1024;
|
||||
#elif defined(XP_WIN)
|
||||
// 1MB is the default stack size on Windows, so use 980k.
|
||||
// Windows PGO stack frames have unfortunately gotten pretty large lately. :-(
|
||||
const size_t kStackQuota = 980 * 1024;
|
||||
// 1MB is the default stack size on Windows. We use the /STACK linker flag
|
||||
// to request a larger stack, so we determine the stack size at runtime.
|
||||
const size_t kStackQuota = GetWindowsStackSize();
|
||||
const size_t kTrustedScriptBuffer = (sizeof(size_t) == 8) ? 180 * 1024 //win64
|
||||
: 120 * 1024; //win32
|
||||
// The following two configurations are linux-only. Given the numbers above,
|
||||
|
|
Загрузка…
Ссылка в новой задаче