The signal-chaining facility was introduced to remedy a problem with signal handling in previous versions of the Java HotSpot VM. Prior to version 1.4, the Java HotSpot VM would not allow application-installed signal handlers for certain signals including, for example, SIGBUS, SIGSEGV, SIGILL, etc, since those signal handlers could conflict with the signal handlers used internally by the Java HotSpot VM.
The signal-chaining facility offers:
A. Support for pre-installed signal handlers when the HotSpot VM is created.
B. Support for signal handler installation after the HotSpot VM is created, inside JNI code or from another native thread.
Pre-installed signal handlers (A) are supported by means of saving existing signal handlers, for signals that are used by the VM, when the VM is first created. Later, when any of these signals are raised and found not to be targeted at the Java HotSpot VM, the pre-installed handlers are invoked. In other words, pre-installed handlers are "chained" behind the VM handlers for these signals.
The signal-chaining facility also allows an application to link and load a shared library libjsig.so before libc/libthread/libpthread. This library ensures that calls such as signal(), sigset(), and sigaction() are intercepted so that they do not actually replace the Java HotSpot VM's signal handlers if the handlers conflict with those already installed by the Java HotSpot VM (B). Instead, these calls save the new signal handlers, or "chain" them behind the VM-installed handlers. Later, when any of these signals are raised and found not to be targeted at the Java HotSpot VM, the pre-installed handlers are invoked. libjsig.so is not needed if (B) is not required.
To use libjsig.so, either link it with the application that creates/embeds a HotSpot VM, for example:
or use LD_PRELOAD environment variable, for example:cc -L <libjvm.so dir> -ljsig -ljvm java_application.c
The interposed signal()/sigset()/sigaction() return the saved signal handlers, not the signal handlers installed by the Java HotSpot VM which are seen by the OS.export LD_PRELOAD=<libjvm.so dir>/libjsig.so; java_application (ksh) setenv LD_PRELOAD <libjvm.so dir>/libjsig.so; java_application (csh)
The signal-chaining facility was introduced to address Request for Enhancement number 4381843.
Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved.