Skip to content

Commit fa240f2

Browse files
author
David Holmes
committedNov 20, 2020
8256594: Unexpected warning: SIGSEGV handler flags expected:SA_RESTART|SA_SIGINFO found:SA_RESTART|SA_SIGINFO
Reviewed-by: stuefe, coleenp, dcubed
1 parent 4c09525 commit fa240f2

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed
 

‎src/hotspot/os/posix/signals_posix.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
// signal handling (except suspend/resume)
4848
// suspend/resume
4949

50+
// Glibc on Linux uses the SA_RESTORER flag to indicate
51+
// the use of a "signal trampoline". We have no interest
52+
// in this flag and need to ignore it when checking our
53+
// own flag settings.
54+
// Note: SA_RESTORER is not exposed through signal.h so we
55+
// have to hardwire its 0x04000000 value in the mask.
56+
LINUX_ONLY(const int SA_RESTORER_FLAG_MASK = ~0x04000000;)
57+
5058
// Todo: provide a os::get_max_process_id() or similar. Number of processes
5159
// may have been configured, can be read more accurately from proc fs etc.
5260
#ifndef MAX_PID
@@ -657,9 +665,19 @@ static const char* describe_sa_flags(int flags, char* buffer, size_t size) {
657665

658666
strncpy(buffer, "none", size);
659667

668+
const unsigned int unknown_flag = ~(SA_NOCLDSTOP |
669+
SA_ONSTACK |
670+
SA_NOCLDSTOP |
671+
SA_RESTART |
672+
SA_SIGINFO |
673+
SA_NOCLDWAIT |
674+
SA_NODEFER
675+
AIX_ONLY(| SA_OLDSTYLE)
676+
);
677+
660678
const struct {
661679
// NB: i is an unsigned int here because SA_RESETHAND is on some
662-
// systems 0x80000000, which is implicitly unsigned. Assignining
680+
// systems 0x80000000, which is implicitly unsigned. Assigning
663681
// it to an int field would be an overflow in unsigned-to-signed
664682
// conversion.
665683
unsigned int i;
@@ -675,10 +693,10 @@ static const char* describe_sa_flags(int flags, char* buffer, size_t size) {
675693
#if defined(AIX)
676694
{ SA_OLDSTYLE, "SA_OLDSTYLE" },
677695
#endif
678-
{ 0, NULL }
696+
{ unknown_flag, "NOT USED" }
679697
};
680698

681-
for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) {
699+
for (idx = 0; flaginfo[idx].i != unknown_flag && remaining > 1; idx++) {
682700
if (flags & flaginfo[idx].i) {
683701
if (first) {
684702
jio_snprintf(p, remaining, "%s", flaginfo[idx].s);
@@ -691,6 +709,10 @@ static const char* describe_sa_flags(int flags, char* buffer, size_t size) {
691709
remaining -= len;
692710
}
693711
}
712+
unsigned int unknowns = flags & unknown_flag;
713+
if (unknowns != 0) {
714+
jio_snprintf(p, remaining, "|Unknown_flags:%x", unknowns);
715+
}
694716

695717
buffer[size - 1] = '\0';
696718

@@ -734,6 +756,9 @@ static void check_signal_handler(int sig) {
734756

735757
os_sigaction(sig, (struct sigaction*)NULL, &act);
736758

759+
// See comment for SA_RESTORER_FLAG_MASK
760+
LINUX_ONLY(act.sa_flags &= SA_RESTORER_FLAG_MASK;)
761+
737762
address thisHandler = (act.sa_flags & SA_SIGINFO)
738763
? CAST_FROM_FN_PTR(address, act.sa_sigaction)
739764
: CAST_FROM_FN_PTR(address, act.sa_handler);
@@ -1310,6 +1335,9 @@ void PosixSignals::print_signal_handler(outputStream* st, int sig,
13101335
struct sigaction sa;
13111336
sigaction(sig, NULL, &sa);
13121337

1338+
// See comment for SA_RESTORER_FLAG_MASK
1339+
LINUX_ONLY(sa.sa_flags &= SA_RESTORER_FLAG_MASK;)
1340+
13131341
st->print("%s: ", os::exception_name(sig, buf, buflen));
13141342

13151343
address handler = (sa.sa_flags & SA_SIGINFO)
@@ -1331,7 +1359,8 @@ void PosixSignals::print_signal_handler(outputStream* st, int sig,
13311359
// May be, handler was resetted by VMError?
13321360
if (rh != NULL) {
13331361
handler = rh;
1334-
sa.sa_flags = VMError::get_resetted_sigflags(sig);
1362+
// See comment for SA_RESTORER_FLAG_MASK
1363+
sa.sa_flags = VMError::get_resetted_sigflags(sig) LINUX_ONLY(& SA_RESTORER_FLAG_MASK);
13351364
}
13361365

13371366
// Print textual representation of sa_flags.

0 commit comments

Comments
 (0)
Please sign in to comment.