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
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
634 { SIGUSR2, "SIGUSR2" },
635 #ifdef SIGVIRT
636 { SIGVIRT, "SIGVIRT" },
637 #endif
638 { SIGVTALRM, "SIGVTALRM" },
639 #ifdef SIGWAITING
640 { SIGWAITING, "SIGWAITING" },
641 #endif
642 #ifdef SIGWINCH
643 { SIGWINCH, "SIGWINCH" },
644 #endif
645 #ifdef SIGWINDOW
646 { SIGWINDOW, "SIGWINDOW" },
647 #endif
648 { SIGXCPU, "SIGXCPU" },
649 { SIGXFSZ, "SIGXFSZ" },
650 #ifdef SIGXRES
651 { SIGXRES, "SIGXRES" },
652 #endif
653 { -1, NULL }
654 };
655
656 // Returned string is a constant. For unknown signals "UNKNOWN" is returned.
657 const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) {
658
659 const char* ret = NULL;
660
661 #ifdef SIGRTMIN
662 if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
663 if (sig == SIGRTMIN) {
664 ret = "SIGRTMIN";
665 } else if (sig == SIGRTMAX) {
666 ret = "SIGRTMAX";
667 } else {
668 jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN);
669 return out;
670 }
671 }
672 #endif
673
674 if (sig > 0) {
675 for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) {
676 if (g_signal_info[idx].sig == sig) {
677 ret = g_signal_info[idx].name;
678 break;
679 }
680 }
681 }
682
683 if (!ret) {
684 if (!is_valid_signal(sig)) {
685 ret = "INVALID";
686 } else {
687 ret = "UNKNOWN";
688 }
689 }
690
691 if (out && outlen > 0) {
692 strncpy(out, ret, outlen);
693 out[outlen - 1] = '\0';
694 }
695 return out;
696 }
697
698 int os::Posix::get_signal_number(const char* signal_name) {
699 char tmp[30];
700 const char* s = signal_name;
701 if (s[0] != 'S' || s[1] != 'I' || s[2] != 'G') {
702 jio_snprintf(tmp, sizeof(tmp), "SIG%s", signal_name);
703 s = tmp;
704 }
705 for (int idx = 0; g_signal_info[idx].sig != -1; idx ++) {
706 if (strcmp(g_signal_info[idx].name, s) == 0) {
707 return g_signal_info[idx].sig;
708 }
709 }
710 return -1;
711 }
712
713 // Returns true if signal number is valid.
714 bool os::Posix::is_valid_signal(int sig) {
715 // MacOS not really POSIX compliant: sigaddset does not return
716 // an error for invalid signal numbers. However, MacOS does not
717 // support real time signals and simply seems to have just 33
718 // signals with no holes in the signal range.
719 #ifdef __APPLE__
720 return sig >= 1 && sig < NSIG;
721 #else
722 // Use sigaddset to check for signal validity.
723 sigset_t set;
724 if (sigaddset(&set, sig) == -1 && errno == EINVAL) {
725 return false;
726 }
727 return true;
728 #endif
729 }
730
731 // Returns:
732 // "invalid (<num>)" for an invalid signal number
733 // "SIG<num>" for a valid but unknown signal number
734 // signal name otherwise.
735 const char* os::exception_name(int sig, char* buf, size_t size) {
736 if (!os::Posix::is_valid_signal(sig)) {
737 jio_snprintf(buf, size, "invalid (%d)", sig);
738 }
739 const char* const name = os::Posix::get_signal_name(sig, buf, size);
740 if (strcmp(name, "UNKNOWN") == 0) {
741 jio_snprintf(buf, size, "SIG%d", sig);
742 }
743 return buf;
744 }
745
746 #define NUM_IMPORTANT_SIGS 32
747 // Returns one-line short description of a signal set in a user provided buffer.
748 const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) {
749 assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size");
750 // Note: for shortness, just print out the first 32. That should
751 // cover most of the useful ones, apart from realtime signals.
752 for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) {
753 const int rc = sigismember(set, sig);
754 if (rc == -1 && errno == EINVAL) {
755 buffer[sig-1] = '?';
756 } else {
757 buffer[sig-1] = rc == 0 ? '0' : '1';
758 }
759 }
760 buffer[NUM_IMPORTANT_SIGS] = 0;
761 return buffer;
762 }
763
|