@@ -803,8 +803,8 @@ static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context);
803
803
804
804
// Semantically compare two sigaction structures. Return true if they are referring to
805
805
// the same handler, using the same flags.
806
- static bool are_handlers_equal (const struct sigaction * sa,
807
- const struct sigaction * expected_sa) {
806
+ static bool are_actions_equal (const struct sigaction * sa,
807
+ const struct sigaction * expected_sa) {
808
808
address this_handler = get_signal_handler (sa);
809
809
address expected_handler = get_signal_handler (expected_sa);
810
810
const int this_flags = get_sanitized_sa_flags (sa);
@@ -814,13 +814,14 @@ static bool are_handlers_equal(const struct sigaction* sa,
814
814
}
815
815
816
816
// If we installed one of our signal handlers for sig, check that the current
817
- // setup matches what we originally installed.
818
- static void check_signal_handler (int sig) {
817
+ // setup matches what we originally installed. Return true if signal handler
818
+ // is different. Otherwise, return false;
819
+ static bool check_signal_handler (int sig) {
819
820
char buf[O_BUFLEN];
820
821
bool mismatch = false ;
821
822
822
823
if (!do_check_signal_periodically[sig]) {
823
- return ;
824
+ return false ;
824
825
}
825
826
826
827
const struct sigaction * expected_act = vm_handlers.get (sig);
@@ -832,28 +833,28 @@ static void check_signal_handler(int sig) {
832
833
if (os_sigaction == NULL ) {
833
834
// only trust the default sigaction, in case it has been interposed
834
835
os_sigaction = (os_sigaction_t )dlsym (RTLD_DEFAULT, " sigaction" );
835
- if (os_sigaction == NULL ) return ;
836
+ if (os_sigaction == NULL ) return false ;
836
837
}
837
838
838
839
os_sigaction (sig, (struct sigaction *)NULL , &act);
839
840
840
841
// Compare both sigaction structures (intelligently; only the members we care about).
841
- if (!are_handlers_equal (&act, expected_act)) {
842
+ // Ignore if the handler is our own crash handler.
843
+ if (!are_actions_equal (&act, expected_act) &&
844
+ !(HANDLER_IS (get_signal_handler (&act), VMError::crash_handler_address))) {
842
845
tty->print_cr (" Warning: %s handler modified!" , os::exception_name (sig, buf, sizeof (buf)));
843
846
// If we had a mismatch:
844
- // - print all signal handlers. As part of that printout, details will be printed
845
- // about any modified handlers.
846
847
// - Disable any further checks for this signal - we do not want to flood stdout. Though
847
848
// depending on which signal had been overwritten, we may die very soon anyway.
848
- os::print_signal_handlers (tty, buf, O_BUFLEN);
849
849
do_check_signal_periodically[sig] = false ;
850
- tty->print_cr (" Consider using jsig library." );
851
850
// Running under non-interactive shell, SHUTDOWN2_SIGNAL will be reassigned SIG_IGN
852
851
if (sig == SHUTDOWN2_SIGNAL && !isatty (fileno (stdin))) {
853
852
tty->print_cr (" Note: Running in non-interactive shell, %s handler is replaced by shell" ,
854
853
os::exception_name (sig, buf, O_BUFLEN));
855
854
}
855
+ return true ;
856
856
}
857
+ return false ;
857
858
}
858
859
859
860
void * os::user_handler () {
@@ -896,24 +897,35 @@ void os::run_periodic_checks() {
896
897
// generation of hs*.log in the event of a crash, debugging
897
898
// such a case can be very challenging, so we absolutely
898
899
// check the following for a good measure:
899
- check_signal_handler (SIGSEGV);
900
- check_signal_handler (SIGILL);
901
- check_signal_handler (SIGFPE);
902
- check_signal_handler (SIGBUS);
903
- check_signal_handler (SIGPIPE);
904
- check_signal_handler (SIGXFSZ);
905
- PPC64_ONLY (check_signal_handler (SIGTRAP);)
900
+ bool print_handlers = false ;
901
+
902
+ print_handlers |= check_signal_handler (SIGSEGV);
903
+ print_handlers |= check_signal_handler (SIGILL);
904
+ print_handlers |= check_signal_handler (SIGFPE);
905
+ print_handlers |= check_signal_handler (SIGBUS);
906
+ print_handlers |= check_signal_handler (SIGPIPE);
907
+ print_handlers |= check_signal_handler (SIGXFSZ);
908
+ PPC64_ONLY (print_handlers |= check_signal_handler (SIGTRAP);)
906
909
907
910
// ReduceSignalUsage allows the user to override these handlers
908
911
// see comments at the very top and jvm_md.h
909
912
if (!ReduceSignalUsage) {
910
- check_signal_handler (SHUTDOWN1_SIGNAL);
911
- check_signal_handler (SHUTDOWN2_SIGNAL);
912
- check_signal_handler (SHUTDOWN3_SIGNAL);
913
- check_signal_handler (BREAK_SIGNAL);
913
+ print_handlers |= check_signal_handler (SHUTDOWN1_SIGNAL);
914
+ print_handlers |= check_signal_handler (SHUTDOWN2_SIGNAL);
915
+ print_handlers |= check_signal_handler (SHUTDOWN3_SIGNAL);
916
+ print_handlers |= check_signal_handler (BREAK_SIGNAL);
914
917
}
915
918
916
- check_signal_handler (PosixSignals::SR_signum);
919
+ print_handlers |= check_signal_handler (PosixSignals::SR_signum);
920
+
921
+ if (print_handlers) {
922
+ // If we had a mismatch:
923
+ // - print all signal handlers. As part of that printout, details will be printed
924
+ // about any modified handlers.
925
+ char buf[O_BUFLEN];
926
+ os::print_signal_handlers (tty, buf, O_BUFLEN);
927
+ tty->print_cr (" Consider using jsig library." );
928
+ }
917
929
}
918
930
919
931
// Helper function for PosixSignals::print_siginfo_...():
@@ -1410,7 +1422,7 @@ void PosixSignals::print_signal_handler(outputStream* st, int sig,
1410
1422
if (expected_act != NULL ) {
1411
1423
const address current_handler = get_signal_handler (¤t_act);
1412
1424
if (!(HANDLER_IS (current_handler, VMError::crash_handler_address))) {
1413
- if (!are_handlers_equal (¤t_act, expected_act)) {
1425
+ if (!are_actions_equal (¤t_act, expected_act)) {
1414
1426
st->print_cr (" *** Handler was modified!" );
1415
1427
st->print (" *** Expected: " );
1416
1428
print_single_signal_handler (st, expected_act, buf, buflen);
1 commit comments
openjdk-notifier[bot] commentedon Jul 27, 2022
Review
Issues