909 910 // Returns true if signal number is valid. 911 bool os::Posix::is_valid_signal(int sig) { 912 // MacOS not really POSIX compliant: sigaddset does not return 913 // an error for invalid signal numbers. However, MacOS does not 914 // support real time signals and simply seems to have just 33 915 // signals with no holes in the signal range. 916 #ifdef __APPLE__ 917 return sig >= 1 && sig < NSIG; 918 #else 919 // Use sigaddset to check for signal validity. 920 sigset_t set; 921 sigemptyset(&set); 922 if (sigaddset(&set, sig) == -1 && errno == EINVAL) { 923 return false; 924 } 925 return true; 926 #endif 927 } 928 929 // Returns: 930 // NULL for an invalid signal number 931 // "SIG<num>" for a valid but unknown signal number 932 // signal name otherwise. 933 const char* os::exception_name(int sig, char* buf, size_t size) { 934 if (!os::Posix::is_valid_signal(sig)) { 935 return NULL; 936 } 937 const char* const name = os::Posix::get_signal_name(sig, buf, size); 938 if (strcmp(name, "UNKNOWN") == 0) { 939 jio_snprintf(buf, size, "SIG%d", sig); 940 } 941 return buf; 942 } 943 944 #define NUM_IMPORTANT_SIGS 32 945 // Returns one-line short description of a signal set in a user provided buffer. 946 const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) { 947 assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size"); 948 // Note: for shortness, just print out the first 32. That should | 909 910 // Returns true if signal number is valid. 911 bool os::Posix::is_valid_signal(int sig) { 912 // MacOS not really POSIX compliant: sigaddset does not return 913 // an error for invalid signal numbers. However, MacOS does not 914 // support real time signals and simply seems to have just 33 915 // signals with no holes in the signal range. 916 #ifdef __APPLE__ 917 return sig >= 1 && sig < NSIG; 918 #else 919 // Use sigaddset to check for signal validity. 920 sigset_t set; 921 sigemptyset(&set); 922 if (sigaddset(&set, sig) == -1 && errno == EINVAL) { 923 return false; 924 } 925 return true; 926 #endif 927 } 928 929 bool os::Posix::is_sig_ignored(int sig) { 930 struct sigaction oact; 931 sigaction(sig, (struct sigaction*)NULL, &oact); 932 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) 933 : CAST_FROM_FN_PTR(void*, oact.sa_handler); 934 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { 935 return true; 936 } else { 937 return false; 938 } 939 } 940 941 // Returns: 942 // NULL for an invalid signal number 943 // "SIG<num>" for a valid but unknown signal number 944 // signal name otherwise. 945 const char* os::exception_name(int sig, char* buf, size_t size) { 946 if (!os::Posix::is_valid_signal(sig)) { 947 return NULL; 948 } 949 const char* const name = os::Posix::get_signal_name(sig, buf, size); 950 if (strcmp(name, "UNKNOWN") == 0) { 951 jio_snprintf(buf, size, "SIG%d", sig); 952 } 953 return buf; 954 } 955 956 #define NUM_IMPORTANT_SIGS 32 957 // Returns one-line short description of a signal set in a user provided buffer. 958 const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) { 959 assert(buf_size == (NUM_IMPORTANT_SIGS + 1), "wrong buffer size"); 960 // Note: for shortness, just print out the first 32. That should |