예제 #1
0
bool
EnsureAsmJSSignalHandlersInstalled(JSRuntime *rt)
{
#if defined(XP_MACOSX)
    // On OSX, each JSRuntime gets its own handler.
    return rt->asmJSMachExceptionHandler.installed() || rt->asmJSMachExceptionHandler.install(rt);
#elif defined(XP_OS2)
    return rt->asmJSOS2ExceptionHandler.installed() || rt->asmJSOS2ExceptionHandler.setCurrentThread();
#else
    // Assume Windows or Unix. For these platforms, there is a single,
    // process-wide signal handler installed. Take care to only install it once.
    InstallSignalHandlersMutex::Lock lock;
    if (lock.handlersInstalled())
        return true;

# if defined(XP_WIN)
    if (!AddVectoredExceptionHandler(/* FirstHandler = */true, AsmJSExceptionHandler))
        return false;
# else  // assume Unix
    struct sigaction sigAction;
    sigAction.sa_sigaction = &AsmJSFaultHandler;
    sigemptyset(&sigAction.sa_mask);
    sigAction.sa_flags = SA_SIGINFO;
    if (sigaction(SIGSEGV, &sigAction, &sPrevSegvHandler))
        return false;
    if (sigaction(SIGBUS, &sigAction, &sPrevBusHandler))
        return false;
# endif

    lock.setHandlersInstalled();
#endif
    return true;
}
예제 #2
0
bool
js::EnsureAsmJSSignalHandlersInstalled(JSRuntime *rt)
{
#if defined(XP_MACOSX)
    // On OSX, each JSRuntime gets its own handler.
    return rt->asmJSMachExceptionHandler.installed() || rt->asmJSMachExceptionHandler.install(rt);
#else
    // Assume Windows or Unix. For these platforms, there is a single,
    // process-wide signal handler installed. Take care to only install it once.
    InstallSignalHandlersMutex::Lock lock;
    if (lock.handlersInstalled())
        return true;

# if defined(XP_WIN)
    if (!AddVectoredExceptionHandler(/* FirstHandler = */true, AsmJSExceptionHandler))
        return false;
# else  // assume Unix
    struct sigaction sigAction;
    sigAction.sa_sigaction = &AsmJSFaultHandler;
    sigemptyset(&sigAction.sa_mask);

    // Note: SA_NODEFER allows us to reenter the signal handler if we crash
    // while handling the signal, and fall through to the Breakpad handler
    // by testing handlingSignal.
    sigAction.sa_flags = SA_SIGINFO | SA_NODEFER;

    if (sigaction(SIGSEGV, &sigAction, &sPrevSegvHandler))
        return false;
    if (sigaction(SIGBUS, &sigAction, &sPrevBusHandler))
        return false;
# endif

    lock.setHandlersInstalled();
#endif
    return true;
}