Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef jit_AsmJSSignalHandlers_h |
michael@0 | 8 | #define jit_AsmJSSignalHandlers_h |
michael@0 | 9 | |
michael@0 | 10 | struct JSRuntime; |
michael@0 | 11 | |
michael@0 | 12 | #ifdef XP_MACOSX |
michael@0 | 13 | # include <mach/mach.h> |
michael@0 | 14 | # include "jslock.h" |
michael@0 | 15 | #endif |
michael@0 | 16 | |
michael@0 | 17 | namespace js { |
michael@0 | 18 | |
michael@0 | 19 | // Returns whether signal handlers for asm.js and for JitRuntime access |
michael@0 | 20 | // violations have been installed. |
michael@0 | 21 | bool |
michael@0 | 22 | EnsureAsmJSSignalHandlersInstalled(JSRuntime *rt); |
michael@0 | 23 | |
michael@0 | 24 | // Force any currently-executing asm.js code to call |
michael@0 | 25 | // js::HandleExecutionInterrupt. |
michael@0 | 26 | extern void |
michael@0 | 27 | RequestInterruptForAsmJSCode(JSRuntime *rt); |
michael@0 | 28 | |
michael@0 | 29 | // On OSX we are forced to use the lower-level Mach exception mechanism instead |
michael@0 | 30 | // of Unix signals. Mach exceptions are not handled on the victim's stack but |
michael@0 | 31 | // rather require an extra thread. For simplicity, we create one such thread |
michael@0 | 32 | // per JSRuntime (upon the first use of asm.js in the JSRuntime). This thread |
michael@0 | 33 | // and related resources are owned by AsmJSMachExceptionHandler which is owned |
michael@0 | 34 | // by JSRuntime. |
michael@0 | 35 | #ifdef XP_MACOSX |
michael@0 | 36 | class AsmJSMachExceptionHandler |
michael@0 | 37 | { |
michael@0 | 38 | bool installed_; |
michael@0 | 39 | PRThread *thread_; |
michael@0 | 40 | mach_port_t port_; |
michael@0 | 41 | |
michael@0 | 42 | void uninstall(); |
michael@0 | 43 | |
michael@0 | 44 | public: |
michael@0 | 45 | AsmJSMachExceptionHandler(); |
michael@0 | 46 | ~AsmJSMachExceptionHandler() { uninstall(); } |
michael@0 | 47 | mach_port_t port() const { return port_; } |
michael@0 | 48 | bool installed() const { return installed_; } |
michael@0 | 49 | bool install(JSRuntime *rt); |
michael@0 | 50 | }; |
michael@0 | 51 | #endif |
michael@0 | 52 | |
michael@0 | 53 | } // namespace js |
michael@0 | 54 | |
michael@0 | 55 | #endif // jit_AsmJSSignalHandlers_h |