476 // NOTE that since there is no "lock" around the interrupt and
477 // is_interrupted operations, there is the possibility that the
478 // interrupted flag (in osThread) will be "false" but that the
479 // low-level events will be in the signaled state. This is
480 // intentional. The effect of this is that Object.wait() and
481 // LockSupport.park() will appear to have a spurious wakeup, which
482 // is allowed and not harmful, and the possibility is so rare that
483 // it is not worth the added complexity to add yet another lock.
484 // For the sleep event an explicit reset is performed on entry
485 // to os::sleep, so there is no early return. It has also been
486 // recommended not to put the interrupted flag into the "event"
487 // structure because it hides the issue.
488 if (interrupted && clear_interrupted) {
489 osthread->set_interrupted(false);
490 // consider thread->_SleepEvent->reset() ... optional optimization
491 }
492
493 return interrupted;
494 }
495
496 // Returned string is a constant. For unknown signals "UNKNOWN" is returned.
497 const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) {
498
499 static const struct {
500 int sig; const char* name;
501 }
502 info[] =
503 {
504 { SIGABRT, "SIGABRT" },
505 #ifdef SIGAIO
506 { SIGAIO, "SIGAIO" },
507 #endif
508 { SIGALRM, "SIGALRM" },
509 #ifdef SIGALRM1
510 { SIGALRM1, "SIGALRM1" },
511 #endif
512 { SIGBUS, "SIGBUS" },
513 #ifdef SIGCANCEL
514 { SIGCANCEL, "SIGCANCEL" },
515 #endif
516 { SIGCHLD, "SIGCHLD" },
517 #ifdef SIGCLD
518 { SIGCLD, "SIGCLD" },
519 #endif
520 { SIGCONT, "SIGCONT" },
521 #ifdef SIGCPUFAIL
522 { SIGCPUFAIL, "SIGCPUFAIL" },
533 { SIGFPE, "SIGFPE" },
534 #ifdef SIGFREEZE
535 { SIGFREEZE, "SIGFREEZE" },
536 #endif
537 #ifdef SIGGFAULT
538 { SIGGFAULT, "SIGGFAULT" },
539 #endif
540 #ifdef SIGGRANT
541 { SIGGRANT, "SIGGRANT" },
542 #endif
543 { SIGHUP, "SIGHUP" },
544 { SIGILL, "SIGILL" },
545 { SIGINT, "SIGINT" },
546 #ifdef SIGIO
547 { SIGIO, "SIGIO" },
548 #endif
549 #ifdef SIGIOINT
550 { SIGIOINT, "SIGIOINT" },
551 #endif
552 #ifdef SIGIOT
553 // SIGIOT is there for BSD compatibility, but on most Unices just a
554 // synonym for SIGABRT. The result should be "SIGABRT", not
555 // "SIGIOT".
556 #if (SIGIOT != SIGABRT )
557 { SIGIOT, "SIGIOT" },
558 #endif
559 #endif
560 #ifdef SIGKAP
561 { SIGKAP, "SIGKAP" },
562 #endif
563 { SIGKILL, "SIGKILL" },
564 #ifdef SIGLOST
565 { SIGLOST, "SIGLOST" },
566 #endif
567 #ifdef SIGLWP
568 { SIGLWP, "SIGLWP" },
569 #endif
570 #ifdef SIGLWPTIMER
571 { SIGLWPTIMER, "SIGLWPTIMER" },
572 #endif
573 #ifdef SIGMIGRATE
574 { SIGMIGRATE, "SIGMIGRATE" },
575 #endif
576 #ifdef SIGMSG
577 { SIGMSG, "SIGMSG" },
578 #endif
593 { SIGQUIT, "SIGQUIT" },
594 #ifdef SIGRECONFIG
595 { SIGRECONFIG, "SIGRECONFIG" },
596 #endif
597 #ifdef SIGRECOVERY
598 { SIGRECOVERY, "SIGRECOVERY" },
599 #endif
600 #ifdef SIGRESERVE
601 { SIGRESERVE, "SIGRESERVE" },
602 #endif
603 #ifdef SIGRETRACT
604 { SIGRETRACT, "SIGRETRACT" },
605 #endif
606 #ifdef SIGSAK
607 { SIGSAK, "SIGSAK" },
608 #endif
609 { SIGSEGV, "SIGSEGV" },
610 #ifdef SIGSOUND
611 { SIGSOUND, "SIGSOUND" },
612 #endif
613 { SIGSTOP, "SIGSTOP" },
614 { SIGSYS, "SIGSYS" },
615 #ifdef SIGSYSERROR
616 { SIGSYSERROR, "SIGSYSERROR" },
617 #endif
618 #ifdef SIGTALRM
619 { SIGTALRM, "SIGTALRM" },
620 #endif
621 { SIGTERM, "SIGTERM" },
622 #ifdef SIGTHAW
623 { SIGTHAW, "SIGTHAW" },
624 #endif
625 { SIGTRAP, "SIGTRAP" },
626 #ifdef SIGTSTP
627 { SIGTSTP, "SIGTSTP" },
628 #endif
629 { SIGTTIN, "SIGTTIN" },
630 { SIGTTOU, "SIGTTOU" },
631 #ifdef SIGURG
632 { SIGURG, "SIGURG" },
635 { SIGUSR2, "SIGUSR2" },
636 #ifdef SIGVIRT
637 { SIGVIRT, "SIGVIRT" },
638 #endif
639 { SIGVTALRM, "SIGVTALRM" },
640 #ifdef SIGWAITING
641 { SIGWAITING, "SIGWAITING" },
642 #endif
643 #ifdef SIGWINCH
644 { SIGWINCH, "SIGWINCH" },
645 #endif
646 #ifdef SIGWINDOW
647 { SIGWINDOW, "SIGWINDOW" },
648 #endif
649 { SIGXCPU, "SIGXCPU" },
650 { SIGXFSZ, "SIGXFSZ" },
651 #ifdef SIGXRES
652 { SIGXRES, "SIGXRES" },
653 #endif
654 { -1, NULL }
655 };
656
657 const char* ret = NULL;
658
659 #ifdef SIGRTMIN
660 if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
661 if (sig == SIGRTMIN) {
662 ret = "SIGRTMIN";
663 } else if (sig == SIGRTMAX) {
664 ret = "SIGRTMAX";
665 } else {
666 jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN);
667 return out;
668 }
669 }
670 #endif
671
672 if (sig > 0) {
673 for (int idx = 0; info[idx].sig != -1; idx ++) {
674 if (info[idx].sig == sig) {
675 ret = info[idx].name;
676 break;
677 }
678 }
679 }
680
681 if (!ret) {
682 if (!is_valid_signal(sig)) {
683 ret = "INVALID";
684 } else {
685 ret = "UNKNOWN";
686 }
687 }
688
689 if (out && outlen > 0) {
690 strncpy(out, ret, outlen);
691 out[outlen - 1] = '\0';
692 }
693 return out;
694 }
695
696 // Returns true if signal number is valid.
697 bool os::Posix::is_valid_signal(int sig) {
698 // MacOS not really POSIX compliant: sigaddset does not return
699 // an error for invalid signal numbers. However, MacOS does not
700 // support real time signals and simply seems to have just 33
701 // signals with no holes in the signal range.
702 #ifdef __APPLE__
703 return sig >= 1 && sig < NSIG;
704 #else
705 // Use sigaddset to check for signal validity.
706 sigset_t set;
707 if (sigaddset(&set, sig) == -1 && errno == EINVAL) {
708 return false;
709 }
710 return true;
711 #endif
712 }
713
714 #define NUM_IMPORTANT_SIGS 32
715 // Returns one-line short description of a signal set in a user provided buffer.
716 const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) {
717 assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size");
718 // Note: for shortness, just print out the first 32. That should
719 // cover most of the useful ones, apart from realtime signals.
720 for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) {
721 const int rc = sigismember(set, sig);
722 if (rc == -1 && errno == EINVAL) {
723 buffer[sig-1] = '?';
724 } else {
725 buffer[sig-1] = rc == 0 ? '0' : '1';
726 }
727 }
728 buffer[NUM_IMPORTANT_SIGS] = 0;
729 return buffer;
730 }
731
|
476 // NOTE that since there is no "lock" around the interrupt and
477 // is_interrupted operations, there is the possibility that the
478 // interrupted flag (in osThread) will be "false" but that the
479 // low-level events will be in the signaled state. This is
480 // intentional. The effect of this is that Object.wait() and
481 // LockSupport.park() will appear to have a spurious wakeup, which
482 // is allowed and not harmful, and the possibility is so rare that
483 // it is not worth the added complexity to add yet another lock.
484 // For the sleep event an explicit reset is performed on entry
485 // to os::sleep, so there is no early return. It has also been
486 // recommended not to put the interrupted flag into the "event"
487 // structure because it hides the issue.
488 if (interrupted && clear_interrupted) {
489 osthread->set_interrupted(false);
490 // consider thread->_SleepEvent->reset() ... optional optimization
491 }
492
493 return interrupted;
494 }
495
496
497
498 static const struct {
499 int sig; const char* name;
500 }
501 g_signal_info[] =
502 {
503 { SIGABRT, "SIGABRT" },
504 #ifdef SIGAIO
505 { SIGAIO, "SIGAIO" },
506 #endif
507 { SIGALRM, "SIGALRM" },
508 #ifdef SIGALRM1
509 { SIGALRM1, "SIGALRM1" },
510 #endif
511 { SIGBUS, "SIGBUS" },
512 #ifdef SIGCANCEL
513 { SIGCANCEL, "SIGCANCEL" },
514 #endif
515 { SIGCHLD, "SIGCHLD" },
516 #ifdef SIGCLD
517 { SIGCLD, "SIGCLD" },
518 #endif
519 { SIGCONT, "SIGCONT" },
520 #ifdef SIGCPUFAIL
521 { SIGCPUFAIL, "SIGCPUFAIL" },
532 { SIGFPE, "SIGFPE" },
533 #ifdef SIGFREEZE
534 { SIGFREEZE, "SIGFREEZE" },
535 #endif
536 #ifdef SIGGFAULT
537 { SIGGFAULT, "SIGGFAULT" },
538 #endif
539 #ifdef SIGGRANT
540 { SIGGRANT, "SIGGRANT" },
541 #endif
542 { SIGHUP, "SIGHUP" },
543 { SIGILL, "SIGILL" },
544 { SIGINT, "SIGINT" },
545 #ifdef SIGIO
546 { SIGIO, "SIGIO" },
547 #endif
548 #ifdef SIGIOINT
549 { SIGIOINT, "SIGIOINT" },
550 #endif
551 #ifdef SIGIOT
552 // SIGIOT is there for BSD compatibility, but on most Unices just a
553 // synonym for SIGABRT. The result should be "SIGABRT", not
554 // "SIGIOT".
555 #if (SIGIOT != SIGABRT )
556 { SIGIOT, "SIGIOT" },
557 #endif
558 #endif
559 #ifdef SIGKAP
560 { SIGKAP, "SIGKAP" },
561 #endif
562 { SIGKILL, "SIGKILL" },
563 #ifdef SIGLOST
564 { SIGLOST, "SIGLOST" },
565 #endif
566 #ifdef SIGLWP
567 { SIGLWP, "SIGLWP" },
568 #endif
569 #ifdef SIGLWPTIMER
570 { SIGLWPTIMER, "SIGLWPTIMER" },
571 #endif
572 #ifdef SIGMIGRATE
573 { SIGMIGRATE, "SIGMIGRATE" },
574 #endif
575 #ifdef SIGMSG
576 { SIGMSG, "SIGMSG" },
577 #endif
592 { SIGQUIT, "SIGQUIT" },
593 #ifdef SIGRECONFIG
594 { SIGRECONFIG, "SIGRECONFIG" },
595 #endif
596 #ifdef SIGRECOVERY
597 { SIGRECOVERY, "SIGRECOVERY" },
598 #endif
599 #ifdef SIGRESERVE
600 { SIGRESERVE, "SIGRESERVE" },
601 #endif
602 #ifdef SIGRETRACT
603 { SIGRETRACT, "SIGRETRACT" },
604 #endif
605 #ifdef SIGSAK
606 { SIGSAK, "SIGSAK" },
607 #endif
608 { SIGSEGV, "SIGSEGV" },
609 #ifdef SIGSOUND
610 { SIGSOUND, "SIGSOUND" },
611 #endif
612 #ifdef SIGSTKFLT
613 { SIGSTKFLT, "SIGSTKFLT" },
614 #endif
615 { SIGSTOP, "SIGSTOP" },
616 { SIGSYS, "SIGSYS" },
617 #ifdef SIGSYSERROR
618 { SIGSYSERROR, "SIGSYSERROR" },
619 #endif
620 #ifdef SIGTALRM
621 { SIGTALRM, "SIGTALRM" },
622 #endif
623 { SIGTERM, "SIGTERM" },
624 #ifdef SIGTHAW
625 { SIGTHAW, "SIGTHAW" },
626 #endif
627 { SIGTRAP, "SIGTRAP" },
628 #ifdef SIGTSTP
629 { SIGTSTP, "SIGTSTP" },
630 #endif
631 { SIGTTIN, "SIGTTIN" },
632 { SIGTTOU, "SIGTTOU" },
633 #ifdef SIGURG
634 { SIGURG, "SIGURG" },
637 { SIGUSR2, "SIGUSR2" },
638 #ifdef SIGVIRT
639 { SIGVIRT, "SIGVIRT" },
640 #endif
641 { SIGVTALRM, "SIGVTALRM" },
642 #ifdef SIGWAITING
643 { SIGWAITING, "SIGWAITING" },
644 #endif
645 #ifdef SIGWINCH
646 { SIGWINCH, "SIGWINCH" },
647 #endif
648 #ifdef SIGWINDOW
649 { SIGWINDOW, "SIGWINDOW" },
650 #endif
651 { SIGXCPU, "SIGXCPU" },
652 { SIGXFSZ, "SIGXFSZ" },
653 #ifdef SIGXRES
654 { SIGXRES, "SIGXRES" },
655 #endif
656 { -1, NULL }
657 };
658
659 // Returned string is a constant. For unknown signals "UNKNOWN" is returned.
660 const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) {
661
662 const char* ret = NULL;
663
664 #ifdef SIGRTMIN
665 if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
666 if (sig == SIGRTMIN) {
667 ret = "SIGRTMIN";
668 } else if (sig == SIGRTMAX) {
669 ret = "SIGRTMAX";
670 } else {
671 jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN);
672 return out;
673 }
674 }
675 #endif
676
677 if (sig > 0) {
678 for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) {
679 if (g_signal_info[idx].sig == sig) {
680 ret = g_signal_info[idx].name;
681 break;
682 }
683 }
684 }
685
686 if (!ret) {
687 if (!is_valid_signal(sig)) {
688 ret = "INVALID";
689 } else {
690 ret = "UNKNOWN";
691 }
692 }
693
694 if (out && outlen > 0) {
695 strncpy(out, ret, outlen);
696 out[outlen - 1] = '\0';
697 }
698 return out;
699 }
700
701 int os::Posix::get_signal_number(const char* signal_name) {
702 char tmp[30];
703 const char* s = signal_name;
704 if (s[0] != 'S' || s[1] != 'I' || s[2] != 'G') {
705 jio_snprintf(tmp, sizeof(tmp), "SIG%s", signal_name);
706 s = tmp;
707 }
708 for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) {
709 if (strcmp(g_signal_info[idx].name, s) == 0) {
710 return g_signal_info[idx].sig;
711 }
712 }
713 return -1;
714 }
715
716 int os::get_signal_number(const char* signal_name) {
717 return os::Posix::get_signal_number(signal_name);
718 }
719
720 // Returns true if signal number is valid.
721 bool os::Posix::is_valid_signal(int sig) {
722 // MacOS not really POSIX compliant: sigaddset does not return
723 // an error for invalid signal numbers. However, MacOS does not
724 // support real time signals and simply seems to have just 33
725 // signals with no holes in the signal range.
726 #ifdef __APPLE__
727 return sig >= 1 && sig < NSIG;
728 #else
729 // Use sigaddset to check for signal validity.
730 sigset_t set;
731 if (sigaddset(&set, sig) == -1 && errno == EINVAL) {
732 return false;
733 }
734 return true;
735 #endif
736 }
737
738 // Returns:
739 // "invalid (<num>)" for an invalid signal number
740 // "SIG<num>" for a valid but unknown signal number
741 // signal name otherwise.
742 const char* os::exception_name(int sig, char* buf, size_t size) {
743 if (!os::Posix::is_valid_signal(sig)) {
744 jio_snprintf(buf, size, "invalid (%d)", sig);
745 }
746 const char* const name = os::Posix::get_signal_name(sig, buf, size);
747 if (strcmp(name, "UNKNOWN") == 0) {
748 jio_snprintf(buf, size, "SIG%d", sig);
749 }
750 return buf;
751 }
752
753 #define NUM_IMPORTANT_SIGS 32
754 // Returns one-line short description of a signal set in a user provided buffer.
755 const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) {
756 assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size");
757 // Note: for shortness, just print out the first 32. That should
758 // cover most of the useful ones, apart from realtime signals.
759 for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) {
760 const int rc = sigismember(set, sig);
761 if (rc == -1 && errno == EINVAL) {
762 buffer[sig-1] = '?';
763 } else {
764 buffer[sig-1] = rc == 0 ? '0' : '1';
765 }
766 }
767 buffer[NUM_IMPORTANT_SIGS] = 0;
768 return buffer;
769 }
770
|