Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
3
*
4
* Copyright 2014 Mozilla Foundation
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
19
#ifndef wasm_signal_handlers_h
20
#define wasm_signal_handlers_h
21
22
#include "mozilla/Attributes.h"
23
24
#include "js/ProfilingFrameIterator.h"
25
#include "wasm/WasmProcess.h"
26
27
namespace js {
28
namespace wasm {
29
30
typedef JS::ProfilingFrameIterator::RegisterState RegisterState;
31
32
// This function performs the low-overhead signal handler initialization that we
33
// want to do eagerly to ensure a more-deterministic global process state. This
34
// is especially relevant for signal handlers since handler ordering depends on
35
// installation order: the wasm signal handler must run *before* the other crash
36
// handlers (ds/MemoryProtectionExceptionHandler.h and breakpad) and since POSIX
37
// signal handlers work LIFO, this function needs to be called at the end of the
38
// startup process, after the other two handlers have been installed. Currently,
39
// this is achieved by having JSRuntime() call this function. There can be
40
// multiple JSRuntimes per process so this function can thus be called multiple
41
// times, having no effect after the first call.
42
void EnsureEagerProcessSignalHandlers();
43
44
// Assuming EnsureEagerProcessSignalHandlers() has already been called,
45
// this function performs the full installation of signal handlers which must
46
// be performed per-thread/JSContext. This operation may incur some overhead and
47
// so should be done only when needed to use wasm. Currently, this is done in
48
// wasm::HasCompilerSupport() which is called when deciding whether to expose
49
// the 'WebAssembly' object on the global object.
50
bool EnsureFullSignalHandlers(JSContext* cx);
51
52
// Return whether, with the given simulator register state, a memory access to
53
// 'addr' of size 'numBytes' needs to trap and, if so, where the simulator
54
// should redirect pc to.
55
bool MemoryAccessTraps(const RegisterState& regs, uint8_t* addr,
56
uint32_t numBytes, uint8_t** newPC);
57
58
// Return whether, with the given simulator register state, an illegal
59
// instruction fault is expected and, if so, the value of the next PC.
60
bool HandleIllegalInstruction(const RegisterState& regs, uint8_t** newPC);
61
62
} // namespace wasm
63
} // namespace js
64
65
#endif // wasm_signal_handlers_h