Skip to content

Commit c03b95d

Browse files
Xin LiuPaul Hohensee
authored andcommitted
8279124: VM does not handle SIGQUIT during initialization
Backport-of: 9bf6ffa19f1ea9efcadb3396d921305c9ec0b1d1
1 parent 45002c0 commit c03b95d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/hotspot/os/posix/signals_posix.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -562,6 +562,11 @@ int JVM_HANDLE_XXX_SIGNAL(int sig, siginfo_t* info,
562562
{
563563
assert(info != NULL && ucVoid != NULL, "sanity");
564564

565+
if (sig == BREAK_SIGNAL) {
566+
assert(!ReduceSignalUsage, "Should not happen with -Xrs/-XX:+ReduceSignalUsage");
567+
return true; // ignore it
568+
}
569+
565570
// Note: it's not uncommon that JNI code uses signal/sigset to install,
566571
// then restore certain signal handler (e.g. to temporarily block SIGPIPE,
567572
// or have a SIGILL handler when detecting CPU type). When that happens,
@@ -1197,7 +1202,7 @@ int os::get_signal_number(const char* signal_name) {
11971202
return -1;
11981203
}
11991204

1200-
void set_signal_handler(int sig) {
1205+
void set_signal_handler(int sig, bool do_check = true) {
12011206
// Check for overwrite.
12021207
struct sigaction oldAct;
12031208
sigaction(sig, (struct sigaction*)NULL, &oldAct);
@@ -1241,7 +1246,7 @@ void set_signal_handler(int sig) {
12411246

12421247
// Save handler setup for later checking
12431248
vm_handlers.set(sig, &sigAct);
1244-
do_check_signal_periodically[sig] = true;
1249+
do_check_signal_periodically[sig] = do_check;
12451250

12461251
int ret = sigaction(sig, &sigAct, &oldAct);
12471252
assert(ret == 0, "check");
@@ -1279,7 +1284,12 @@ void install_signal_handlers() {
12791284
set_signal_handler(SIGFPE);
12801285
PPC64_ONLY(set_signal_handler(SIGTRAP);)
12811286
set_signal_handler(SIGXFSZ);
1282-
1287+
if (!ReduceSignalUsage) {
1288+
// This is just for early initialization phase. Intercepting the signal here reduces the risk
1289+
// that an attach client accidentally forces HotSpot to quit prematurely. We skip the periodic
1290+
// check because late initialization will overwrite it to UserHandler.
1291+
set_signal_handler(BREAK_SIGNAL, false);
1292+
}
12831293
#if defined(__APPLE__)
12841294
// lldb (gdb) installs both standard BSD signal handlers, and mach exception
12851295
// handlers. By replacing the existing task exception handler, we disable lldb's mach

0 commit comments

Comments
 (0)