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 * 10 * http://www.apache.org/licenses/LICENSE-2.0 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 "js/ProfilingFrameIterator.h" 23 #include "wasm/WasmProcess.h" 24 25 namespace js { 26 namespace wasm { 27 28 using RegisterState = JS::ProfilingFrameIterator::RegisterState; 29 30 // This function performs the low-overhead signal handler initialization that we 31 // want to do eagerly to ensure a more-deterministic global process state. This 32 // is especially relevant for signal handlers since handler ordering depends on 33 // installation order: the wasm signal handler must run *before* the other crash 34 // handlers (ds/MemoryProtectionExceptionHandler.h and breakpad) and since POSIX 35 // signal handlers work LIFO, this function needs to be called at the end of the 36 // startup process, after the other two handlers have been installed. Currently, 37 // this is achieved by having JSRuntime() call this function. There can be 38 // multiple JSRuntimes per process so this function can thus be called multiple 39 // times, having no effect after the first call. 40 void EnsureEagerProcessSignalHandlers(); 41 42 // Assuming EnsureEagerProcessSignalHandlers() has already been called, 43 // this function performs the full installation of signal handlers which must 44 // be performed per-thread/JSContext. This operation may incur some overhead and 45 // so should be done only when needed to use wasm. Currently, this is done in 46 // wasm::HasPlatformSupport() which is called when deciding whether to expose 47 // the 'WebAssembly' object on the global object. 48 bool EnsureFullSignalHandlers(JSContext* cx); 49 50 // Return whether, with the given simulator register state, a memory access to 51 // 'addr' of size 'numBytes' needs to trap and, if so, where the simulator 52 // should redirect pc to. 53 bool MemoryAccessTraps(const RegisterState& regs, uint8_t* addr, 54 uint32_t numBytes, uint8_t** newPC); 55 56 // Return whether, with the given simulator register state, an illegal 57 // instruction fault is expected and, if so, the value of the next PC. 58 bool HandleIllegalInstruction(const RegisterState& regs, uint8_t** newPC); 59 60 } // namespace wasm 61 } // namespace js 62 63 #endif // wasm_signal_handlers_h 64