handler-outside-win.cc 1.77 KB
Newer Older
1 2 3 4 5 6
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// PLEASE READ BEFORE CHANGING THIS FILE!
//
7 8 9
// This file implements the support code for the out of bounds trap handler.
// Nothing in here actually runs in the trap handler, but the code here
// manipulates data structures used by the trap handler so we still need to be
10 11 12 13 14 15 16 17 18 19
// careful. In order to minimize this risk, here are some rules to follow.
//
// 1. Avoid introducing new external dependencies. The files in src/trap-handler
//    should be as self-contained as possible to make it easy to audit the code.
//
// 2. Any changes must be reviewed by someone from the crash reporting
//    or security team. Se OWNERS for suggested reviewers.
//
// For more information, see https://goo.gl/yMeyUY.
//
20 21 22 23 24 25
// For the code that runs in the trap handler itself, see handler-inside.cc.

#include <windows.h>

#include "src/trap-handler/handler-inside-win.h"
#include "src/trap-handler/trap-handler.h"
26 27 28 29 30 31

namespace v8 {
namespace internal {
namespace trap_handler {

#if V8_TRAP_HANDLER_SUPPORTED
32 33 34 35 36 37 38 39 40

namespace {

// A handle to our registered exception handler, so that we can remove it
// again later.
void* g_registered_handler = nullptr;

}  // namespace

41
bool RegisterDefaultTrapHandler() {
42 43 44 45 46
  constexpr ULONG first = TRUE;
  CHECK_NULL(g_registered_handler);
  g_registered_handler = AddVectoredExceptionHandler(first, HandleWasmTrap);

  return nullptr != g_registered_handler;
47
}
48 49 50 51 52 53 54 55 56

void RemoveTrapHandler() {
  if (!g_registered_handler) return;

  RemoveVectoredExceptionHandler(g_registered_handler);
  g_registered_handler = nullptr;
}

#endif  // V8_TRAP_HANDLER_SUPPORTED
57 58 59 60

}  // namespace trap_handler
}  // namespace internal
}  // namespace v8