2.1.2 • Published 7 months ago

segfault-raub v2.1.2

Weekly downloads
16
License
MIT, BSD-3-Clause...
Repository
github
Last release
7 months ago

Segfault handler for Node.js

This is a part of Node3D project.

NPM ESLint Test

npm i -s segfault-raub

This module installs platform-specific signal listeners (see sigaction for Unix and SetUnhandledExceptionFilter for Windows). Whenever a signal is raised, the module prints a native stack trace (if possible) to both STDERR and to the "segfault.log" file (if it exists). If there is no such file, it won't be created, so it is up to you if the log-file is needed.

Note: this addon uses N-API, and therefore is ABI-compatible across different Node.js versions. Addon binaries are precompiled and there is no compilation step during the npm i command.

A zero-setup is available: just require the module and it comes pre-equipped with several signal listeners enabled by default.

require('segfault-raub');

Note: if your project tree contains multiple versions of this module, the first one imported will seize global['segfault-raub']. The rest of them will only re-export global['segfault-raub'] and WILL NOT import their own binaries.

Enabling Signals

As listed below, some signals (platform specific) are enabled by default. But they can be enabled/disabled manually:

Example:

const {
    setSignal,
    EXCEPTION_ACCESS_VIOLATION, SIGSEGV,
    EXCEPTION_BREAKPOINT, SIGTRAP,
} = require('segfault-raub');

setSignal(EXCEPTION_ACCESS_VIOLATION, false);
setSignal(SIGSEGV, false);

setSignal(EXCEPTION_BREAKPOINT, true);
setSignal(SIGTRAP, true);

On Windows, all the Unix signals are null, and the opposite is true. Passing null as the first parameter to setSignal has no effect and is safe.

Demo Methods

These are be helpful to see how the signals are reported and if the log files are being written properly.

  • causeSegfault - Causes a memory access violation.
  • causeDivisionInt - Divides an integer by zero.
  • causeOverflow - Runs infinite recursion (stack overflow).
  • causeIllegal - Raises an "illegal instruction" exception.

Example:

const { causeSegfault } = require('segfault-raub');
causeSegfault();

Windows Signals

SignalEnabledDescription
EXCEPTION_ACCESS_VIOLATIONyesMemory access was denied.
EXCEPTION_ARRAY_BOUNDS_EXCEEDEDyesArray was accessed with an illegal index.
EXCEPTION_INT_DIVIDE_BY_ZEROyesAttempt to divide by an integer divisor of 0.
EXCEPTION_ILLEGAL_INSTRUCTIONyesAttempt to execute an illegal instruction.
EXCEPTION_NONCONTINUABLE_EXCEPTIONyesCan't continue after an exception.
EXCEPTION_STACK_OVERFLOWyesThe thread used up its stack.
EXCEPTION_INVALID_HANDLEyesAn invalid handle was specified.
EXCEPTION_FLT_DIVIDE_BY_ZEROnoAttempt to divide by a float divisor of 0.f.
EXCEPTION_DATATYPE_MISALIGNMENTnoA datatype misalignment was detected.
EXCEPTION_BREAKPOINTnoA Breakpoint has been reached.
EXCEPTION_SINGLE_STEPnoContinue single-stepping execution.
EXCEPTION_FLT_DENORMAL_OPERANDnoOne of the operands is denormal.
EXCEPTION_FLT_INEXACT_RESULTnoThe result cannot be represented exactly.
EXCEPTION_FLT_INVALID_OPERATIONnoFloating-point invalid operation.
EXCEPTION_FLT_OVERFLOWnoThe exponent of operation is too large.
EXCEPTION_FLT_STACK_CHECKnoThe Stack gone bad after a float operation.
EXCEPTION_FLT_UNDERFLOWnoThe exponent of operation is too low.
EXCEPTION_INT_OVERFLOWnoThe result of operation is too large.
EXCEPTION_PRIV_INSTRUCTIONnoOperation is not allowed in current mode.
EXCEPTION_IN_PAGE_ERRORnoCan't access a memory page.
EXCEPTION_INVALID_DISPOSITIONnoInvalid disposition returned.
EXCEPTION_GUARD_PAGEnoAccessing PAGE_GUARD-allocated modifier.

Unix Signals

SignalHandlingEnabledDescription
SIGABRTAyesProcess abort signal.
SIGFPEAyesErroneous arithmetic operation.
SIGSEGVAyesInvalid memory reference.
SIGILLAyesIllegal instruction.
SIGBUSAyesAccess to an undefined portion of a memory object.
SIGTERMTnoTermination signal.
SIGINTTnoTerminal interrupt signal.
SIGALRMTnoAlarm clock.
SIGCHLDInoChild process terminated, stopped, or continued.
SIGCONTCnoContinue executing, if stopped.
SIGHUPTnoHangup.
SIGKILLTnoKill (cannot be caught or ignored).
SIGPIPETnoWrite on a pipe with no one to read it.
SIGQUITAnoTerminal quit signal.
SIGSTOPSnoStop executing (cannot be caught or ignored).
SIGTSTPSnoTerminal stop signal.
SIGTTINSnoBackground process attempting read.
SIGTTOUSnoBackground process attempting write.
SIGUSR1TnoUser-defined signal 1.
SIGUSR2TnoUser-defined signal 2.
SIGPROFTnoProfiling timer expired.
SIGSYSAnoBad system call.
SIGTRAPAnoTrace/breakpoint trap.
SIGURGInoHigh bandwidth data is available at a socket.
SIGVTALRMTnoVirtual timer expired.
SIGXCPUAnoCPU time limit exceeded.
SIGXFSZAnoFile size limit exceeded.
  • T - Abnormal termination of the process.
  • A - Abnormal termination of the process with additional actions.
  • I - Ignore the signal.
  • S - Stop the process.
  • C - Continue the process, if it is stopped; otherwise, ignore the signal.

Legal notice

This package is derived from segfault-handler. The original licensing rules apply, see LICENSE_node-segfault-handler.

Also this project uses callstack walker which is licensed under BSD-2 Clause.

The rest of this package (the newly introduced files) is licensed under MIT.