Bug 1508416: Check TLS initialization before reading sAlreadyHandlingTrap. r=luke

--HG--
extra : rebase_source : e8d9c35323a54540b57ef4efed2fe05548e07260
This commit is contained in:
David Major 2018-11-19 20:30:51 -05:00
Родитель d6372b1489
Коммит ca5f5855d3
1 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -27,6 +27,7 @@
#include "wasm/WasmInstance.h"
#if defined(XP_WIN)
# include <winternl.h> // must include before util/Windows.h's `#undef`s
# include "util/Windows.h"
#elif defined(XP_DARWIN)
# include <mach/exc.h>
@ -490,10 +491,18 @@ HandleTrap(CONTEXT* context, JSContext* assertCx = nullptr)
// =============================================================================
#if defined(XP_WIN)
// Obtained empirically from thread_local codegen on x86/x64/arm64.
// Compiled in all user binaries, so should be stable over time.
static const unsigned sThreadLocalArrayPointerIndex = 11;
static LONG WINAPI
WasmTrapHandler(LPEXCEPTION_POINTERS exception)
{
// Make sure TLS is initialized before reading sAlreadyHandlingTrap.
if (!NtCurrentTeb()->Reserved1[sThreadLocalArrayPointerIndex]) {
return EXCEPTION_CONTINUE_SEARCH;
}
if (sAlreadyHandlingTrap.get()) {
return EXCEPTION_CONTINUE_SEARCH;
}