Skip to content

Commit a062055

Browse files
committed
[GR-45860] Ignore SIGXFSZ signal.
PullRequest: graal/14485
2 parents 9fd7ce8 + b8f4d0c commit a062055

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/SunMiscSubstitutions.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ protected long decrementCount() {
401401
}
402402

403403
@AutomaticallyRegisteredFeature
404-
class IgnoreSIGPIPEFeature implements InternalFeature {
404+
class IgnoreSignalsFeature implements InternalFeature {
405405

406406
@Override
407407
public void beforeAnalysis(BeforeAnalysisAccess access) {
408-
RuntimeSupport.getRuntimeSupport().addStartupHook(new IgnoreSIGPIPEStartupHook());
408+
RuntimeSupport.getRuntimeSupport().addStartupHook(new IgnoreSignalsStartupHook());
409409
}
410410
}
411411

412-
final class IgnoreSIGPIPEStartupHook implements RuntimeSupport.Hook {
412+
final class IgnoreSignalsStartupHook implements RuntimeSupport.Hook {
413413

414414
@CEntryPoint(publishAs = Publish.NotPublished)
415415
@CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class)
@@ -418,20 +418,24 @@ static void noopSignalHandler(@SuppressWarnings("unused") int sig) {
418418
}
419419

420420
private static final CEntryPointLiteral<Signal.SignalDispatcher> NOOP_SIGNAL_HANDLER = //
421-
CEntryPointLiteral.create(IgnoreSIGPIPEStartupHook.class, "noopSignalHandler", int.class);
421+
CEntryPointLiteral.create(IgnoreSignalsStartupHook.class, "noopSignalHandler", int.class);
422422

423423
/**
424+
* HotSpot ignores the SIGPIPE and SIGXFSZ signals (see <a
425+
* href=https://github.com/openjdk/jdk/blob/fc76687c2fac39fcbf706c419bfa170b8efa5747/src/hotspot/os/posix/signals_posix.cpp#L608>signals_posix.cpp</a>).
426+
* When signal handling is enabled we do the same thing.
427+
* <p>
424428
* Ignore SIGPIPE. Reading from a closed pipe, instead of delivering a process-wide signal whose
425429
* default action is to terminate the process, will instead return an error code from the
426430
* specific write operation.
427-
*
431+
* <p>
428432
* From pipe(7): If all file descriptors referring to the read end of a pipe have been closed,
429433
* then a write(2) will cause a SIGPIPE signal to be generated for the calling process. If the
430434
* calling process is ignoring this signal, then write(2) fails with the error EPIPE.
431-
*
435+
* <p>
432436
* Note that the handler must be an empty function and not SIG_IGN. The problem is SIG_IGN is
433437
* inherited to subprocess but we only want to affect the current process.
434-
*
438+
* <p>
435439
* From signal(7): A child created via fork(2) inherits a copy of its parent's signal
436440
* dispositions. During an execve(2), the dispositions of handled signals are reset to the
437441
* default; the dispositions of ignored signals are left unchanged.
@@ -440,15 +444,21 @@ static void noopSignalHandler(@SuppressWarnings("unused") int sig) {
440444
public void execute(boolean isFirstIsolate) {
441445
if (isFirstIsolate && SubstrateOptions.EnableSignalHandling.getValue()) {
442446
synchronized (Target_jdk_internal_misc_Signal.class) {
443-
int signum = Signal.SignalEnum.SIGPIPE.getCValue();
444-
if (Util_jdk_internal_misc_Signal.isCurrentDispatcher(signum, Signal.SIG_DFL())) {
445-
/*
446-
* Replace with NOOP signal handler if a custom one has not already been
447-
* installed.
448-
*/
449-
final SignalDispatcher signalResult = PosixUtils.installSignalHandler(signum, NOOP_SIGNAL_HANDLER.getFunctionPointer());
450-
VMError.guarantee(signalResult != Signal.SIG_ERR(), "IgnoreSIGPIPEFeature.run: Could not ignore SIGPIPE");
451-
}
447+
installNoopHandler(Signal.SignalEnum.SIGPIPE);
448+
installNoopHandler(Signal.SignalEnum.SIGXFSZ);
449+
}
450+
}
451+
}
452+
453+
private static void installNoopHandler(Signal.SignalEnum signal) {
454+
int signum = signal.getCValue();
455+
if (Util_jdk_internal_misc_Signal.isCurrentDispatcher(signum, Signal.SIG_DFL())) {
456+
/*
457+
* Replace with no-op signal handler if a custom one has not already been installed.
458+
*/
459+
final SignalDispatcher signalResult = PosixUtils.installSignalHandler(signum, NOOP_SIGNAL_HANDLER.getFunctionPointer());
460+
if (signalResult == Signal.SIG_ERR()) {
461+
throw VMError.shouldNotReachHere(String.format("IgnoreSignalsStartupHook: Could not install signal: %s", signal));
452462
}
453463
}
454464
}

0 commit comments

Comments
 (0)