Fri, 26 Jul 2013 00:59:18 +0200
8020775: PPC64 (part 12): posix signal printing
Summary: Implement methods printing posix signal information and call them in unix os files.
Reviewed-by: kvn, dholmes, twisti
Contributed-by: thomas.stuefe@sap.com
ctornqvi@2520 | 1 | /* |
goetz@6460 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
goetz@6460 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
goetz@6460 | 4 | * |
goetz@6460 | 5 | * This code is free software; you can redistribute it and/or modify it |
goetz@6460 | 6 | * under the terms of the GNU General Public License version 2 only, as |
goetz@6460 | 7 | * published by the Free Software Foundation. |
goetz@6460 | 8 | * |
goetz@6460 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
goetz@6460 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
goetz@6460 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
goetz@6460 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
goetz@6460 | 13 | * accompanied this code). |
goetz@6460 | 14 | * |
goetz@6460 | 15 | * You should have received a copy of the GNU General Public License version |
goetz@6460 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
goetz@6460 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
goetz@6460 | 18 | * |
goetz@6460 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
goetz@6460 | 20 | * or visit www.oracle.com if you need additional information or have any |
goetz@6460 | 21 | * questions. |
goetz@6460 | 22 | * |
goetz@6460 | 23 | */ |
ctornqvi@2520 | 24 | |
goetz@6460 | 25 | #include "utilities/globalDefinitions.hpp" |
ctornqvi@2520 | 26 | #include "prims/jvm.h" |
zgu@3900 | 27 | #include "runtime/frame.inline.hpp" |
ctornqvi@2520 | 28 | #include "runtime/os.hpp" |
ctornqvi@2520 | 29 | #include "utilities/vmError.hpp" |
ctornqvi@2520 | 30 | |
goetz@6460 | 31 | #include <signal.h> |
ctornqvi@2520 | 32 | #include <unistd.h> |
ctornqvi@2520 | 33 | #include <sys/resource.h> |
nloodin@3783 | 34 | #include <sys/utsname.h> |
nloodin@3783 | 35 | |
goetz@6460 | 36 | // Todo: provide a os::get_max_process_id() or similar. Number of processes |
goetz@6460 | 37 | // may have been configured, can be read more accurately from proc fs etc. |
goetz@6460 | 38 | #ifndef MAX_PID |
goetz@6460 | 39 | #define MAX_PID INT_MAX |
goetz@6460 | 40 | #endif |
goetz@6460 | 41 | #define IS_VALID_PID(p) (p > 0 && p < MAX_PID) |
ctornqvi@2520 | 42 | |
ctornqvi@2520 | 43 | // Check core dump limit and report possible place where core can be found |
ctornqvi@2520 | 44 | void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) { |
mikael@3903 | 45 | int n; |
ctornqvi@2520 | 46 | struct rlimit rlim; |
ctornqvi@2520 | 47 | bool success; |
ctornqvi@2520 | 48 | |
mikael@3903 | 49 | n = get_core_path(buffer, bufferSize); |
ctornqvi@2520 | 50 | |
ctornqvi@2520 | 51 | if (getrlimit(RLIMIT_CORE, &rlim) != 0) { |
mikael@3903 | 52 | jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (may not exist)", current_process_id()); |
ctornqvi@2520 | 53 | success = true; |
ctornqvi@2520 | 54 | } else { |
ctornqvi@2520 | 55 | switch(rlim.rlim_cur) { |
ctornqvi@2520 | 56 | case RLIM_INFINITY: |
mikael@3903 | 57 | jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d", current_process_id()); |
ctornqvi@2520 | 58 | success = true; |
ctornqvi@2520 | 59 | break; |
ctornqvi@2520 | 60 | case 0: |
ctornqvi@2520 | 61 | jio_snprintf(buffer, bufferSize, "Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again"); |
ctornqvi@2520 | 62 | success = false; |
ctornqvi@2520 | 63 | break; |
ctornqvi@2520 | 64 | default: |
mikael@3903 | 65 | jio_snprintf(buffer + n, bufferSize - n, "/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", current_process_id(), (unsigned long)(rlim.rlim_cur >> 10)); |
ctornqvi@2520 | 66 | success = true; |
ctornqvi@2520 | 67 | break; |
ctornqvi@2520 | 68 | } |
ctornqvi@2520 | 69 | } |
ctornqvi@2520 | 70 | VMError::report_coredump_status(buffer, success); |
ctornqvi@2520 | 71 | } |
ctornqvi@2520 | 72 | |
zgu@3900 | 73 | address os::get_caller_pc(int n) { |
zgu@3900 | 74 | #ifdef _NMT_NOINLINE_ |
zgu@3900 | 75 | n ++; |
zgu@3900 | 76 | #endif |
zgu@3900 | 77 | frame fr = os::current_frame(); |
zgu@3900 | 78 | while (n > 0 && fr.pc() && |
zgu@3900 | 79 | !os::is_first_C_frame(&fr) && fr.sender_pc()) { |
zgu@3900 | 80 | fr = os::get_sender_for_C_frame(&fr); |
zgu@3900 | 81 | n --; |
zgu@3900 | 82 | } |
zgu@3900 | 83 | if (n == 0) { |
zgu@3900 | 84 | return fr.pc(); |
zgu@3900 | 85 | } else { |
zgu@3900 | 86 | return NULL; |
zgu@3900 | 87 | } |
zgu@3900 | 88 | } |
zgu@3900 | 89 | |
phh@3379 | 90 | int os::get_last_error() { |
phh@3379 | 91 | return errno; |
phh@3379 | 92 | } |
phh@3379 | 93 | |
sla@2584 | 94 | bool os::is_debugger_attached() { |
sla@2584 | 95 | // not implemented |
sla@2584 | 96 | return false; |
sla@2584 | 97 | } |
sla@2584 | 98 | |
sla@2584 | 99 | void os::wait_for_keypress_at_exit(void) { |
sla@2584 | 100 | // don't do anything on posix platforms |
sla@2584 | 101 | return; |
sla@2584 | 102 | } |
nloodin@3783 | 103 | |
brutisso@4369 | 104 | // Multiple threads can race in this code, and can remap over each other with MAP_FIXED, |
brutisso@4369 | 105 | // so on posix, unmap the section at the start and at the end of the chunk that we mapped |
brutisso@4369 | 106 | // rather than unmapping and remapping the whole chunk to get requested alignment. |
brutisso@4369 | 107 | char* os::reserve_memory_aligned(size_t size, size_t alignment) { |
brutisso@4369 | 108 | assert((alignment & (os::vm_allocation_granularity() - 1)) == 0, |
brutisso@4369 | 109 | "Alignment must be a multiple of allocation granularity (page size)"); |
brutisso@4369 | 110 | assert((size & (alignment -1)) == 0, "size must be 'alignment' aligned"); |
brutisso@4369 | 111 | |
brutisso@4369 | 112 | size_t extra_size = size + alignment; |
brutisso@4369 | 113 | assert(extra_size >= size, "overflow, size is too large to allow alignment"); |
brutisso@4369 | 114 | |
brutisso@4369 | 115 | char* extra_base = os::reserve_memory(extra_size, NULL, alignment); |
brutisso@4369 | 116 | |
brutisso@4369 | 117 | if (extra_base == NULL) { |
brutisso@4369 | 118 | return NULL; |
brutisso@4369 | 119 | } |
brutisso@4369 | 120 | |
brutisso@4369 | 121 | // Do manual alignment |
brutisso@4369 | 122 | char* aligned_base = (char*) align_size_up((uintptr_t) extra_base, alignment); |
brutisso@4369 | 123 | |
brutisso@4369 | 124 | // [ | | ] |
brutisso@4369 | 125 | // ^ extra_base |
brutisso@4369 | 126 | // ^ extra_base + begin_offset == aligned_base |
brutisso@4369 | 127 | // extra_base + begin_offset + size ^ |
brutisso@4369 | 128 | // extra_base + extra_size ^ |
brutisso@4369 | 129 | // |<>| == begin_offset |
brutisso@4369 | 130 | // end_offset == |<>| |
brutisso@4369 | 131 | size_t begin_offset = aligned_base - extra_base; |
brutisso@4369 | 132 | size_t end_offset = (extra_base + extra_size) - (aligned_base + size); |
brutisso@4369 | 133 | |
brutisso@4369 | 134 | if (begin_offset > 0) { |
brutisso@4369 | 135 | os::release_memory(extra_base, begin_offset); |
brutisso@4369 | 136 | } |
brutisso@4369 | 137 | |
brutisso@4369 | 138 | if (end_offset > 0) { |
brutisso@4369 | 139 | os::release_memory(extra_base + begin_offset + size, end_offset); |
brutisso@4369 | 140 | } |
brutisso@4369 | 141 | |
brutisso@4369 | 142 | return aligned_base; |
brutisso@4369 | 143 | } |
brutisso@4369 | 144 | |
nloodin@3783 | 145 | void os::Posix::print_load_average(outputStream* st) { |
nloodin@3783 | 146 | st->print("load average:"); |
nloodin@3783 | 147 | double loadavg[3]; |
nloodin@3783 | 148 | os::loadavg(loadavg, 3); |
nloodin@3783 | 149 | st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]); |
nloodin@3783 | 150 | st->cr(); |
nloodin@3783 | 151 | } |
nloodin@3783 | 152 | |
nloodin@3783 | 153 | void os::Posix::print_rlimit_info(outputStream* st) { |
nloodin@3783 | 154 | st->print("rlimit:"); |
nloodin@3783 | 155 | struct rlimit rlim; |
nloodin@3783 | 156 | |
nloodin@3783 | 157 | st->print(" STACK "); |
nloodin@3783 | 158 | getrlimit(RLIMIT_STACK, &rlim); |
nloodin@3783 | 159 | if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); |
nloodin@3783 | 160 | else st->print("%uk", rlim.rlim_cur >> 10); |
nloodin@3783 | 161 | |
nloodin@3783 | 162 | st->print(", CORE "); |
nloodin@3783 | 163 | getrlimit(RLIMIT_CORE, &rlim); |
nloodin@3783 | 164 | if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); |
nloodin@3783 | 165 | else st->print("%uk", rlim.rlim_cur >> 10); |
nloodin@3783 | 166 | |
goetz@6460 | 167 | // Isn't there on solaris |
nloodin@3783 | 168 | #ifndef TARGET_OS_FAMILY_solaris |
nloodin@3783 | 169 | st->print(", NPROC "); |
nloodin@3783 | 170 | getrlimit(RLIMIT_NPROC, &rlim); |
nloodin@3783 | 171 | if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); |
nloodin@3783 | 172 | else st->print("%d", rlim.rlim_cur); |
nloodin@3783 | 173 | #endif |
nloodin@3783 | 174 | |
nloodin@3783 | 175 | st->print(", NOFILE "); |
nloodin@3783 | 176 | getrlimit(RLIMIT_NOFILE, &rlim); |
nloodin@3783 | 177 | if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); |
nloodin@3783 | 178 | else st->print("%d", rlim.rlim_cur); |
nloodin@3783 | 179 | |
nloodin@3783 | 180 | st->print(", AS "); |
nloodin@3783 | 181 | getrlimit(RLIMIT_AS, &rlim); |
nloodin@3783 | 182 | if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); |
nloodin@3783 | 183 | else st->print("%uk", rlim.rlim_cur >> 10); |
nloodin@3783 | 184 | st->cr(); |
nloodin@3783 | 185 | } |
nloodin@3783 | 186 | |
nloodin@3783 | 187 | void os::Posix::print_uname_info(outputStream* st) { |
nloodin@3783 | 188 | // kernel |
nloodin@3783 | 189 | st->print("uname:"); |
nloodin@3783 | 190 | struct utsname name; |
nloodin@3783 | 191 | uname(&name); |
nloodin@3783 | 192 | st->print(name.sysname); st->print(" "); |
nloodin@3783 | 193 | st->print(name.release); st->print(" "); |
nloodin@3783 | 194 | st->print(name.version); st->print(" "); |
nloodin@3783 | 195 | st->print(name.machine); |
nloodin@3783 | 196 | st->cr(); |
nloodin@3783 | 197 | } |
nloodin@3783 | 198 | |
tschatzl@4854 | 199 | bool os::has_allocatable_memory_limit(julong* limit) { |
tschatzl@4854 | 200 | struct rlimit rlim; |
tschatzl@4854 | 201 | int getrlimit_res = getrlimit(RLIMIT_AS, &rlim); |
tschatzl@4854 | 202 | // if there was an error when calling getrlimit, assume that there is no limitation |
tschatzl@4854 | 203 | // on virtual memory. |
tschatzl@4854 | 204 | bool result; |
tschatzl@4854 | 205 | if ((getrlimit_res != 0) || (rlim.rlim_cur == RLIM_INFINITY)) { |
tschatzl@4854 | 206 | result = false; |
tschatzl@4854 | 207 | } else { |
tschatzl@4854 | 208 | *limit = (julong)rlim.rlim_cur; |
tschatzl@4854 | 209 | result = true; |
tschatzl@4854 | 210 | } |
tschatzl@4854 | 211 | #ifdef _LP64 |
tschatzl@4854 | 212 | return result; |
tschatzl@4854 | 213 | #else |
tschatzl@4854 | 214 | // arbitrary virtual space limit for 32 bit Unices found by testing. If |
tschatzl@4854 | 215 | // getrlimit above returned a limit, bound it with this limit. Otherwise |
tschatzl@4854 | 216 | // directly use it. |
tschatzl@4854 | 217 | const julong max_virtual_limit = (julong)3800*M; |
tschatzl@4854 | 218 | if (result) { |
tschatzl@4854 | 219 | *limit = MIN2(*limit, max_virtual_limit); |
tschatzl@4854 | 220 | } else { |
tschatzl@4854 | 221 | *limit = max_virtual_limit; |
tschatzl@4854 | 222 | } |
nloodin@3783 | 223 | |
tschatzl@4854 | 224 | // bound by actually allocatable memory. The algorithm uses two bounds, an |
tschatzl@4854 | 225 | // upper and a lower limit. The upper limit is the current highest amount of |
tschatzl@4854 | 226 | // memory that could not be allocated, the lower limit is the current highest |
tschatzl@4854 | 227 | // amount of memory that could be allocated. |
tschatzl@4854 | 228 | // The algorithm iteratively refines the result by halving the difference |
tschatzl@4854 | 229 | // between these limits, updating either the upper limit (if that value could |
tschatzl@4854 | 230 | // not be allocated) or the lower limit (if the that value could be allocated) |
tschatzl@4854 | 231 | // until the difference between these limits is "small". |
tschatzl@4854 | 232 | |
tschatzl@4854 | 233 | // the minimum amount of memory we care about allocating. |
tschatzl@4854 | 234 | const julong min_allocation_size = M; |
tschatzl@4854 | 235 | |
tschatzl@4854 | 236 | julong upper_limit = *limit; |
tschatzl@4854 | 237 | |
tschatzl@4854 | 238 | // first check a few trivial cases |
tschatzl@4854 | 239 | if (is_allocatable(upper_limit) || (upper_limit <= min_allocation_size)) { |
tschatzl@4854 | 240 | *limit = upper_limit; |
tschatzl@4854 | 241 | } else if (!is_allocatable(min_allocation_size)) { |
tschatzl@4854 | 242 | // we found that not even min_allocation_size is allocatable. Return it |
tschatzl@4854 | 243 | // anyway. There is no point to search for a better value any more. |
tschatzl@4854 | 244 | *limit = min_allocation_size; |
tschatzl@4854 | 245 | } else { |
tschatzl@4854 | 246 | // perform the binary search. |
tschatzl@4854 | 247 | julong lower_limit = min_allocation_size; |
tschatzl@4854 | 248 | while ((upper_limit - lower_limit) > min_allocation_size) { |
tschatzl@4854 | 249 | julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit; |
tschatzl@4854 | 250 | temp_limit = align_size_down_(temp_limit, min_allocation_size); |
tschatzl@4854 | 251 | if (is_allocatable(temp_limit)) { |
tschatzl@4854 | 252 | lower_limit = temp_limit; |
tschatzl@4854 | 253 | } else { |
tschatzl@4854 | 254 | upper_limit = temp_limit; |
tschatzl@4854 | 255 | } |
tschatzl@4854 | 256 | } |
tschatzl@4854 | 257 | *limit = lower_limit; |
tschatzl@4854 | 258 | } |
tschatzl@4854 | 259 | return true; |
tschatzl@4854 | 260 | #endif |
tschatzl@4854 | 261 | } |
vlivanov@5027 | 262 | |
vlivanov@5027 | 263 | const char* os::get_current_directory(char *buf, size_t buflen) { |
vlivanov@5027 | 264 | return getcwd(buf, buflen); |
vlivanov@5027 | 265 | } |
vlivanov@5027 | 266 | |
vlivanov@5027 | 267 | FILE* os::open(int fd, const char* mode) { |
vlivanov@5027 | 268 | return ::fdopen(fd, mode); |
vlivanov@5027 | 269 | } |
rbackman@5424 | 270 | |
goetz@6460 | 271 | |
goetz@6460 | 272 | // Returned string is a constant. For unknown signals "UNKNOWN" is returned. |
goetz@6460 | 273 | const char* os::Posix::get_signal_name(int sig, char* out, size_t outlen) { |
goetz@6460 | 274 | |
goetz@6460 | 275 | static const struct { |
goetz@6460 | 276 | int sig; const char* name; |
goetz@6460 | 277 | } |
goetz@6460 | 278 | info[] = |
goetz@6460 | 279 | { |
goetz@6460 | 280 | { SIGABRT, "SIGABRT" }, |
goetz@6460 | 281 | #ifdef SIGAIO |
goetz@6460 | 282 | { SIGAIO, "SIGAIO" }, |
goetz@6460 | 283 | #endif |
goetz@6460 | 284 | { SIGALRM, "SIGALRM" }, |
goetz@6460 | 285 | #ifdef SIGALRM1 |
goetz@6460 | 286 | { SIGALRM1, "SIGALRM1" }, |
goetz@6460 | 287 | #endif |
goetz@6460 | 288 | { SIGBUS, "SIGBUS" }, |
goetz@6460 | 289 | #ifdef SIGCANCEL |
goetz@6460 | 290 | { SIGCANCEL, "SIGCANCEL" }, |
goetz@6460 | 291 | #endif |
goetz@6460 | 292 | { SIGCHLD, "SIGCHLD" }, |
goetz@6460 | 293 | #ifdef SIGCLD |
goetz@6460 | 294 | { SIGCLD, "SIGCLD" }, |
goetz@6460 | 295 | #endif |
goetz@6460 | 296 | { SIGCONT, "SIGCONT" }, |
goetz@6460 | 297 | #ifdef SIGCPUFAIL |
goetz@6460 | 298 | { SIGCPUFAIL, "SIGCPUFAIL" }, |
goetz@6460 | 299 | #endif |
goetz@6460 | 300 | #ifdef SIGDANGER |
goetz@6460 | 301 | { SIGDANGER, "SIGDANGER" }, |
goetz@6460 | 302 | #endif |
goetz@6460 | 303 | #ifdef SIGDIL |
goetz@6460 | 304 | { SIGDIL, "SIGDIL" }, |
goetz@6460 | 305 | #endif |
goetz@6460 | 306 | #ifdef SIGEMT |
goetz@6460 | 307 | { SIGEMT, "SIGEMT" }, |
goetz@6460 | 308 | #endif |
goetz@6460 | 309 | { SIGFPE, "SIGFPE" }, |
goetz@6460 | 310 | #ifdef SIGFREEZE |
goetz@6460 | 311 | { SIGFREEZE, "SIGFREEZE" }, |
goetz@6460 | 312 | #endif |
goetz@6460 | 313 | #ifdef SIGGFAULT |
goetz@6460 | 314 | { SIGGFAULT, "SIGGFAULT" }, |
goetz@6460 | 315 | #endif |
goetz@6460 | 316 | #ifdef SIGGRANT |
goetz@6460 | 317 | { SIGGRANT, "SIGGRANT" }, |
goetz@6460 | 318 | #endif |
goetz@6460 | 319 | { SIGHUP, "SIGHUP" }, |
goetz@6460 | 320 | { SIGILL, "SIGILL" }, |
goetz@6460 | 321 | { SIGINT, "SIGINT" }, |
goetz@6460 | 322 | #ifdef SIGIO |
goetz@6460 | 323 | { SIGIO, "SIGIO" }, |
goetz@6460 | 324 | #endif |
goetz@6460 | 325 | #ifdef SIGIOINT |
goetz@6460 | 326 | { SIGIOINT, "SIGIOINT" }, |
goetz@6460 | 327 | #endif |
goetz@6460 | 328 | #ifdef SIGIOT |
goetz@6460 | 329 | // SIGIOT is there for BSD compatibility, but on most Unices just a |
goetz@6460 | 330 | // synonym for SIGABRT. The result should be "SIGABRT", not |
goetz@6460 | 331 | // "SIGIOT". |
goetz@6460 | 332 | #if (SIGIOT != SIGABRT ) |
goetz@6460 | 333 | { SIGIOT, "SIGIOT" }, |
goetz@6460 | 334 | #endif |
goetz@6460 | 335 | #endif |
goetz@6460 | 336 | #ifdef SIGKAP |
goetz@6460 | 337 | { SIGKAP, "SIGKAP" }, |
goetz@6460 | 338 | #endif |
goetz@6460 | 339 | { SIGKILL, "SIGKILL" }, |
goetz@6460 | 340 | #ifdef SIGLOST |
goetz@6460 | 341 | { SIGLOST, "SIGLOST" }, |
goetz@6460 | 342 | #endif |
goetz@6460 | 343 | #ifdef SIGLWP |
goetz@6460 | 344 | { SIGLWP, "SIGLWP" }, |
goetz@6460 | 345 | #endif |
goetz@6460 | 346 | #ifdef SIGLWPTIMER |
goetz@6460 | 347 | { SIGLWPTIMER, "SIGLWPTIMER" }, |
goetz@6460 | 348 | #endif |
goetz@6460 | 349 | #ifdef SIGMIGRATE |
goetz@6460 | 350 | { SIGMIGRATE, "SIGMIGRATE" }, |
goetz@6460 | 351 | #endif |
goetz@6460 | 352 | #ifdef SIGMSG |
goetz@6460 | 353 | { SIGMSG, "SIGMSG" }, |
goetz@6460 | 354 | #endif |
goetz@6460 | 355 | { SIGPIPE, "SIGPIPE" }, |
goetz@6460 | 356 | #ifdef SIGPOLL |
goetz@6460 | 357 | { SIGPOLL, "SIGPOLL" }, |
goetz@6460 | 358 | #endif |
goetz@6460 | 359 | #ifdef SIGPRE |
goetz@6460 | 360 | { SIGPRE, "SIGPRE" }, |
goetz@6460 | 361 | #endif |
goetz@6460 | 362 | { SIGPROF, "SIGPROF" }, |
goetz@6460 | 363 | #ifdef SIGPTY |
goetz@6460 | 364 | { SIGPTY, "SIGPTY" }, |
goetz@6460 | 365 | #endif |
goetz@6460 | 366 | #ifdef SIGPWR |
goetz@6460 | 367 | { SIGPWR, "SIGPWR" }, |
goetz@6460 | 368 | #endif |
goetz@6460 | 369 | { SIGQUIT, "SIGQUIT" }, |
goetz@6460 | 370 | #ifdef SIGRECONFIG |
goetz@6460 | 371 | { SIGRECONFIG, "SIGRECONFIG" }, |
goetz@6460 | 372 | #endif |
goetz@6460 | 373 | #ifdef SIGRECOVERY |
goetz@6460 | 374 | { SIGRECOVERY, "SIGRECOVERY" }, |
goetz@6460 | 375 | #endif |
goetz@6460 | 376 | #ifdef SIGRESERVE |
goetz@6460 | 377 | { SIGRESERVE, "SIGRESERVE" }, |
goetz@6460 | 378 | #endif |
goetz@6460 | 379 | #ifdef SIGRETRACT |
goetz@6460 | 380 | { SIGRETRACT, "SIGRETRACT" }, |
goetz@6460 | 381 | #endif |
goetz@6460 | 382 | #ifdef SIGSAK |
goetz@6460 | 383 | { SIGSAK, "SIGSAK" }, |
goetz@6460 | 384 | #endif |
goetz@6460 | 385 | { SIGSEGV, "SIGSEGV" }, |
goetz@6460 | 386 | #ifdef SIGSOUND |
goetz@6460 | 387 | { SIGSOUND, "SIGSOUND" }, |
goetz@6460 | 388 | #endif |
goetz@6460 | 389 | { SIGSTOP, "SIGSTOP" }, |
goetz@6460 | 390 | { SIGSYS, "SIGSYS" }, |
goetz@6460 | 391 | #ifdef SIGSYSERROR |
goetz@6460 | 392 | { SIGSYSERROR, "SIGSYSERROR" }, |
goetz@6460 | 393 | #endif |
goetz@6460 | 394 | #ifdef SIGTALRM |
goetz@6460 | 395 | { SIGTALRM, "SIGTALRM" }, |
goetz@6460 | 396 | #endif |
goetz@6460 | 397 | { SIGTERM, "SIGTERM" }, |
goetz@6460 | 398 | #ifdef SIGTHAW |
goetz@6460 | 399 | { SIGTHAW, "SIGTHAW" }, |
goetz@6460 | 400 | #endif |
goetz@6460 | 401 | { SIGTRAP, "SIGTRAP" }, |
goetz@6460 | 402 | #ifdef SIGTSTP |
goetz@6460 | 403 | { SIGTSTP, "SIGTSTP" }, |
goetz@6460 | 404 | #endif |
goetz@6460 | 405 | { SIGTTIN, "SIGTTIN" }, |
goetz@6460 | 406 | { SIGTTOU, "SIGTTOU" }, |
goetz@6460 | 407 | #ifdef SIGURG |
goetz@6460 | 408 | { SIGURG, "SIGURG" }, |
goetz@6460 | 409 | #endif |
goetz@6460 | 410 | { SIGUSR1, "SIGUSR1" }, |
goetz@6460 | 411 | { SIGUSR2, "SIGUSR2" }, |
goetz@6460 | 412 | #ifdef SIGVIRT |
goetz@6460 | 413 | { SIGVIRT, "SIGVIRT" }, |
goetz@6460 | 414 | #endif |
goetz@6460 | 415 | { SIGVTALRM, "SIGVTALRM" }, |
goetz@6460 | 416 | #ifdef SIGWAITING |
goetz@6460 | 417 | { SIGWAITING, "SIGWAITING" }, |
goetz@6460 | 418 | #endif |
goetz@6460 | 419 | #ifdef SIGWINCH |
goetz@6460 | 420 | { SIGWINCH, "SIGWINCH" }, |
goetz@6460 | 421 | #endif |
goetz@6460 | 422 | #ifdef SIGWINDOW |
goetz@6460 | 423 | { SIGWINDOW, "SIGWINDOW" }, |
goetz@6460 | 424 | #endif |
goetz@6460 | 425 | { SIGXCPU, "SIGXCPU" }, |
goetz@6460 | 426 | { SIGXFSZ, "SIGXFSZ" }, |
goetz@6460 | 427 | #ifdef SIGXRES |
goetz@6460 | 428 | { SIGXRES, "SIGXRES" }, |
goetz@6460 | 429 | #endif |
goetz@6460 | 430 | { -1, NULL } |
goetz@6460 | 431 | }; |
goetz@6460 | 432 | |
goetz@6460 | 433 | const char* ret = NULL; |
goetz@6460 | 434 | |
goetz@6460 | 435 | #ifdef SIGRTMIN |
goetz@6460 | 436 | if (sig >= SIGRTMIN && sig <= SIGRTMAX) { |
goetz@6460 | 437 | if (sig == SIGRTMIN) { |
goetz@6460 | 438 | ret = "SIGRTMIN"; |
goetz@6460 | 439 | } else if (sig == SIGRTMAX) { |
goetz@6460 | 440 | ret = "SIGRTMAX"; |
goetz@6460 | 441 | } else { |
goetz@6460 | 442 | jio_snprintf(out, outlen, "SIGRTMIN+%d", sig - SIGRTMIN); |
goetz@6460 | 443 | return out; |
goetz@6460 | 444 | } |
goetz@6460 | 445 | } |
goetz@6460 | 446 | #endif |
goetz@6460 | 447 | |
goetz@6460 | 448 | if (sig > 0) { |
goetz@6460 | 449 | for (int idx = 0; info[idx].sig != -1; idx ++) { |
goetz@6460 | 450 | if (info[idx].sig == sig) { |
goetz@6460 | 451 | ret = info[idx].name; |
goetz@6460 | 452 | break; |
goetz@6460 | 453 | } |
goetz@6460 | 454 | } |
goetz@6460 | 455 | } |
goetz@6460 | 456 | |
goetz@6460 | 457 | if (!ret) { |
goetz@6460 | 458 | if (!is_valid_signal(sig)) { |
goetz@6460 | 459 | ret = "INVALID"; |
goetz@6460 | 460 | } else { |
goetz@6460 | 461 | ret = "UNKNOWN"; |
goetz@6460 | 462 | } |
goetz@6460 | 463 | } |
goetz@6460 | 464 | |
goetz@6460 | 465 | jio_snprintf(out, outlen, ret); |
goetz@6460 | 466 | return out; |
goetz@6460 | 467 | } |
goetz@6460 | 468 | |
goetz@6460 | 469 | // Returns true if signal number is valid. |
goetz@6460 | 470 | bool os::Posix::is_valid_signal(int sig) { |
goetz@6460 | 471 | // MacOS not really POSIX compliant: sigaddset does not return |
goetz@6460 | 472 | // an error for invalid signal numbers. However, MacOS does not |
goetz@6460 | 473 | // support real time signals and simply seems to have just 33 |
goetz@6460 | 474 | // signals with no holes in the signal range. |
goetz@6460 | 475 | #ifdef __APPLE__ |
goetz@6460 | 476 | return sig >= 1 && sig < NSIG; |
goetz@6460 | 477 | #else |
goetz@6460 | 478 | // Use sigaddset to check for signal validity. |
goetz@6460 | 479 | sigset_t set; |
goetz@6460 | 480 | if (sigaddset(&set, sig) == -1 && errno == EINVAL) { |
goetz@6460 | 481 | return false; |
goetz@6460 | 482 | } |
goetz@6460 | 483 | return true; |
goetz@6460 | 484 | #endif |
goetz@6460 | 485 | } |
goetz@6460 | 486 | |
goetz@6460 | 487 | #define NUM_IMPORTANT_SIGS 32 |
goetz@6460 | 488 | // Returns one-line short description of a signal set in a user provided buffer. |
goetz@6460 | 489 | const char* os::Posix::describe_signal_set_short(const sigset_t* set, char* buffer, size_t buf_size) { |
goetz@6460 | 490 | assert(buf_size = (NUM_IMPORTANT_SIGS + 1), "wrong buffer size"); |
goetz@6460 | 491 | // Note: for shortness, just print out the first 32. That should |
goetz@6460 | 492 | // cover most of the useful ones, apart from realtime signals. |
goetz@6460 | 493 | for (int sig = 1; sig <= NUM_IMPORTANT_SIGS; sig++) { |
goetz@6460 | 494 | const int rc = sigismember(set, sig); |
goetz@6460 | 495 | if (rc == -1 && errno == EINVAL) { |
goetz@6460 | 496 | buffer[sig-1] = '?'; |
goetz@6460 | 497 | } else { |
goetz@6460 | 498 | buffer[sig-1] = rc == 0 ? '0' : '1'; |
goetz@6460 | 499 | } |
goetz@6460 | 500 | } |
goetz@6460 | 501 | buffer[NUM_IMPORTANT_SIGS] = 0; |
goetz@6460 | 502 | return buffer; |
goetz@6460 | 503 | } |
goetz@6460 | 504 | |
goetz@6460 | 505 | // Prints one-line description of a signal set. |
goetz@6460 | 506 | void os::Posix::print_signal_set_short(outputStream* st, const sigset_t* set) { |
goetz@6460 | 507 | char buf[NUM_IMPORTANT_SIGS + 1]; |
goetz@6460 | 508 | os::Posix::describe_signal_set_short(set, buf, sizeof(buf)); |
goetz@6460 | 509 | st->print(buf); |
goetz@6460 | 510 | } |
goetz@6460 | 511 | |
goetz@6460 | 512 | // Writes one-line description of a combination of sigaction.sa_flags into a user |
goetz@6460 | 513 | // provided buffer. Returns that buffer. |
goetz@6460 | 514 | const char* os::Posix::describe_sa_flags(int flags, char* buffer, size_t size) { |
goetz@6460 | 515 | char* p = buffer; |
goetz@6460 | 516 | size_t remaining = size; |
goetz@6460 | 517 | bool first = true; |
goetz@6460 | 518 | int idx = 0; |
goetz@6460 | 519 | |
goetz@6460 | 520 | assert(buffer, "invalid argument"); |
goetz@6460 | 521 | |
goetz@6460 | 522 | if (size == 0) { |
goetz@6460 | 523 | return buffer; |
goetz@6460 | 524 | } |
goetz@6460 | 525 | |
goetz@6460 | 526 | strncpy(buffer, "none", size); |
goetz@6460 | 527 | |
goetz@6460 | 528 | const struct { |
goetz@6460 | 529 | int i; |
goetz@6460 | 530 | const char* s; |
goetz@6460 | 531 | } flaginfo [] = { |
goetz@6460 | 532 | { SA_NOCLDSTOP, "SA_NOCLDSTOP" }, |
goetz@6460 | 533 | { SA_ONSTACK, "SA_ONSTACK" }, |
goetz@6460 | 534 | { SA_RESETHAND, "SA_RESETHAND" }, |
goetz@6460 | 535 | { SA_RESTART, "SA_RESTART" }, |
goetz@6460 | 536 | { SA_SIGINFO, "SA_SIGINFO" }, |
goetz@6460 | 537 | { SA_NOCLDWAIT, "SA_NOCLDWAIT" }, |
goetz@6460 | 538 | { SA_NODEFER, "SA_NODEFER" }, |
goetz@6460 | 539 | #ifdef AIX |
goetz@6460 | 540 | { SA_ONSTACK, "SA_ONSTACK" }, |
goetz@6460 | 541 | { SA_OLDSTYLE, "SA_OLDSTYLE" }, |
goetz@6460 | 542 | #endif |
goetz@6460 | 543 | { 0, NULL } |
goetz@6460 | 544 | }; |
goetz@6460 | 545 | |
goetz@6460 | 546 | for (idx = 0; flaginfo[idx].s && remaining > 1; idx++) { |
goetz@6460 | 547 | if (flags & flaginfo[idx].i) { |
goetz@6460 | 548 | if (first) { |
goetz@6460 | 549 | jio_snprintf(p, remaining, "%s", flaginfo[idx].s); |
goetz@6460 | 550 | first = false; |
goetz@6460 | 551 | } else { |
goetz@6460 | 552 | jio_snprintf(p, remaining, "|%s", flaginfo[idx].s); |
goetz@6460 | 553 | } |
goetz@6460 | 554 | const size_t len = strlen(p); |
goetz@6460 | 555 | p += len; |
goetz@6460 | 556 | remaining -= len; |
goetz@6460 | 557 | } |
goetz@6460 | 558 | } |
goetz@6460 | 559 | |
goetz@6460 | 560 | buffer[size - 1] = '\0'; |
goetz@6460 | 561 | |
goetz@6460 | 562 | return buffer; |
goetz@6460 | 563 | } |
goetz@6460 | 564 | |
goetz@6460 | 565 | // Prints one-line description of a combination of sigaction.sa_flags. |
goetz@6460 | 566 | void os::Posix::print_sa_flags(outputStream* st, int flags) { |
goetz@6460 | 567 | char buffer[0x100]; |
goetz@6460 | 568 | os::Posix::describe_sa_flags(flags, buffer, sizeof(buffer)); |
goetz@6460 | 569 | st->print(buffer); |
goetz@6460 | 570 | } |
goetz@6460 | 571 | |
goetz@6460 | 572 | // Helper function for os::Posix::print_siginfo_...(): |
goetz@6460 | 573 | // return a textual description for signal code. |
goetz@6460 | 574 | struct enum_sigcode_desc_t { |
goetz@6460 | 575 | const char* s_name; |
goetz@6460 | 576 | const char* s_desc; |
goetz@6460 | 577 | }; |
goetz@6460 | 578 | |
goetz@6460 | 579 | static bool get_signal_code_description(const siginfo_t* si, enum_sigcode_desc_t* out) { |
goetz@6460 | 580 | |
goetz@6460 | 581 | const struct { |
goetz@6460 | 582 | int sig; int code; const char* s_code; const char* s_desc; |
goetz@6460 | 583 | } t1 [] = { |
goetz@6460 | 584 | { SIGILL, ILL_ILLOPC, "ILL_ILLOPC", "Illegal opcode." }, |
goetz@6460 | 585 | { SIGILL, ILL_ILLOPN, "ILL_ILLOPN", "Illegal operand." }, |
goetz@6460 | 586 | { SIGILL, ILL_ILLADR, "ILL_ILLADR", "Illegal addressing mode." }, |
goetz@6460 | 587 | { SIGILL, ILL_ILLTRP, "ILL_ILLTRP", "Illegal trap." }, |
goetz@6460 | 588 | { SIGILL, ILL_PRVOPC, "ILL_PRVOPC", "Privileged opcode." }, |
goetz@6460 | 589 | { SIGILL, ILL_PRVREG, "ILL_PRVREG", "Privileged register." }, |
goetz@6460 | 590 | { SIGILL, ILL_COPROC, "ILL_COPROC", "Coprocessor error." }, |
goetz@6460 | 591 | { SIGILL, ILL_BADSTK, "ILL_BADSTK", "Internal stack error." }, |
goetz@6460 | 592 | #if defined(IA64) && defined(LINUX) |
goetz@6460 | 593 | { SIGILL, ILL_BADIADDR, "ILL_BADIADDR", "Unimplemented instruction address" }, |
goetz@6460 | 594 | { SIGILL, ILL_BREAK, "ILL_BREAK", "Application Break instruction" }, |
goetz@6460 | 595 | #endif |
goetz@6460 | 596 | { SIGFPE, FPE_INTDIV, "FPE_INTDIV", "Integer divide by zero." }, |
goetz@6460 | 597 | { SIGFPE, FPE_INTOVF, "FPE_INTOVF", "Integer overflow." }, |
goetz@6460 | 598 | { SIGFPE, FPE_FLTDIV, "FPE_FLTDIV", "Floating-point divide by zero." }, |
goetz@6460 | 599 | { SIGFPE, FPE_FLTOVF, "FPE_FLTOVF", "Floating-point overflow." }, |
goetz@6460 | 600 | { SIGFPE, FPE_FLTUND, "FPE_FLTUND", "Floating-point underflow." }, |
goetz@6460 | 601 | { SIGFPE, FPE_FLTRES, "FPE_FLTRES", "Floating-point inexact result." }, |
goetz@6460 | 602 | { SIGFPE, FPE_FLTINV, "FPE_FLTINV", "Invalid floating-point operation." }, |
goetz@6460 | 603 | { SIGFPE, FPE_FLTSUB, "FPE_FLTSUB", "Subscript out of range." }, |
goetz@6460 | 604 | { SIGSEGV, SEGV_MAPERR, "SEGV_MAPERR", "Address not mapped to object." }, |
goetz@6460 | 605 | { SIGSEGV, SEGV_ACCERR, "SEGV_ACCERR", "Invalid permissions for mapped object." }, |
goetz@6460 | 606 | #ifdef AIX |
goetz@6460 | 607 | // no explanation found what keyerr would be |
goetz@6460 | 608 | { SIGSEGV, SEGV_KEYERR, "SEGV_KEYERR", "key error" }, |
goetz@6460 | 609 | #endif |
goetz@6460 | 610 | #if defined(IA64) && !defined(AIX) |
goetz@6460 | 611 | { SIGSEGV, SEGV_PSTKOVF, "SEGV_PSTKOVF", "Paragraph stack overflow" }, |
goetz@6460 | 612 | #endif |
goetz@6460 | 613 | { SIGBUS, BUS_ADRALN, "BUS_ADRALN", "Invalid address alignment." }, |
goetz@6460 | 614 | { SIGBUS, BUS_ADRERR, "BUS_ADRERR", "Nonexistent physical address." }, |
goetz@6460 | 615 | { SIGBUS, BUS_OBJERR, "BUS_OBJERR", "Object-specific hardware error." }, |
goetz@6460 | 616 | { SIGTRAP, TRAP_BRKPT, "TRAP_BRKPT", "Process breakpoint." }, |
goetz@6460 | 617 | { SIGTRAP, TRAP_TRACE, "TRAP_TRACE", "Process trace trap." }, |
goetz@6460 | 618 | { SIGCHLD, CLD_EXITED, "CLD_EXITED", "Child has exited." }, |
goetz@6460 | 619 | { SIGCHLD, CLD_KILLED, "CLD_KILLED", "Child has terminated abnormally and did not create a core file." }, |
goetz@6460 | 620 | { SIGCHLD, CLD_DUMPED, "CLD_DUMPED", "Child has terminated abnormally and created a core file." }, |
goetz@6460 | 621 | { SIGCHLD, CLD_TRAPPED, "CLD_TRAPPED", "Traced child has trapped." }, |
goetz@6460 | 622 | { SIGCHLD, CLD_STOPPED, "CLD_STOPPED", "Child has stopped." }, |
goetz@6460 | 623 | { SIGCHLD, CLD_CONTINUED,"CLD_CONTINUED","Stopped child has continued." }, |
goetz@6460 | 624 | #ifdef SIGPOLL |
goetz@6460 | 625 | { SIGPOLL, POLL_OUT, "POLL_OUT", "Output buffers available." }, |
goetz@6460 | 626 | { SIGPOLL, POLL_MSG, "POLL_MSG", "Input message available." }, |
goetz@6460 | 627 | { SIGPOLL, POLL_ERR, "POLL_ERR", "I/O error." }, |
goetz@6460 | 628 | { SIGPOLL, POLL_PRI, "POLL_PRI", "High priority input available." }, |
goetz@6460 | 629 | { SIGPOLL, POLL_HUP, "POLL_HUP", "Device disconnected. [Option End]" }, |
goetz@6460 | 630 | #endif |
goetz@6460 | 631 | { -1, -1, NULL, NULL } |
goetz@6460 | 632 | }; |
goetz@6460 | 633 | |
goetz@6460 | 634 | // Codes valid in any signal context. |
goetz@6460 | 635 | const struct { |
goetz@6460 | 636 | int code; const char* s_code; const char* s_desc; |
goetz@6460 | 637 | } t2 [] = { |
goetz@6460 | 638 | { SI_USER, "SI_USER", "Signal sent by kill()." }, |
goetz@6460 | 639 | { SI_QUEUE, "SI_QUEUE", "Signal sent by the sigqueue()." }, |
goetz@6460 | 640 | { SI_TIMER, "SI_TIMER", "Signal generated by expiration of a timer set by timer_settime()." }, |
goetz@6460 | 641 | { SI_ASYNCIO, "SI_ASYNCIO", "Signal generated by completion of an asynchronous I/O request." }, |
goetz@6460 | 642 | { SI_MESGQ, "SI_MESGQ", "Signal generated by arrival of a message on an empty message queue." }, |
goetz@6460 | 643 | // Linux specific |
goetz@6460 | 644 | #ifdef SI_TKILL |
goetz@6460 | 645 | { SI_TKILL, "SI_TKILL", "Signal sent by tkill (pthread_kill)" }, |
goetz@6460 | 646 | #endif |
goetz@6460 | 647 | #ifdef SI_DETHREAD |
goetz@6460 | 648 | { SI_DETHREAD, "SI_DETHREAD", "Signal sent by execve() killing subsidiary threads" }, |
goetz@6460 | 649 | #endif |
goetz@6460 | 650 | #ifdef SI_KERNEL |
goetz@6460 | 651 | { SI_KERNEL, "SI_KERNEL", "Signal sent by kernel." }, |
goetz@6460 | 652 | #endif |
goetz@6460 | 653 | #ifdef SI_SIGIO |
goetz@6460 | 654 | { SI_SIGIO, "SI_SIGIO", "Signal sent by queued SIGIO" }, |
goetz@6460 | 655 | #endif |
goetz@6460 | 656 | |
goetz@6460 | 657 | #ifdef AIX |
goetz@6460 | 658 | { SI_UNDEFINED, "SI_UNDEFINED","siginfo contains partial information" }, |
goetz@6460 | 659 | { SI_EMPTY, "SI_EMPTY", "siginfo contains no useful information" }, |
goetz@6460 | 660 | #endif |
goetz@6460 | 661 | |
goetz@6460 | 662 | #ifdef __sun |
goetz@6460 | 663 | { SI_NOINFO, "SI_NOINFO", "No signal information" }, |
goetz@6460 | 664 | { SI_RCTL, "SI_RCTL", "kernel generated signal via rctl action" }, |
goetz@6460 | 665 | { SI_LWP, "SI_LWP", "Signal sent via lwp_kill" }, |
goetz@6460 | 666 | #endif |
goetz@6460 | 667 | |
goetz@6460 | 668 | { -1, NULL, NULL } |
goetz@6460 | 669 | }; |
goetz@6460 | 670 | |
goetz@6460 | 671 | const char* s_code = NULL; |
goetz@6460 | 672 | const char* s_desc = NULL; |
goetz@6460 | 673 | |
goetz@6460 | 674 | for (int i = 0; t1[i].sig != -1; i ++) { |
goetz@6460 | 675 | if (t1[i].sig == si->si_signo && t1[i].code == si->si_code) { |
goetz@6460 | 676 | s_code = t1[i].s_code; |
goetz@6460 | 677 | s_desc = t1[i].s_desc; |
goetz@6460 | 678 | break; |
goetz@6460 | 679 | } |
goetz@6460 | 680 | } |
goetz@6460 | 681 | |
goetz@6460 | 682 | if (s_code == NULL) { |
goetz@6460 | 683 | for (int i = 0; t2[i].s_code != NULL; i ++) { |
goetz@6460 | 684 | if (t2[i].code == si->si_code) { |
goetz@6460 | 685 | s_code = t2[i].s_code; |
goetz@6460 | 686 | s_desc = t2[i].s_desc; |
goetz@6460 | 687 | } |
goetz@6460 | 688 | } |
goetz@6460 | 689 | } |
goetz@6460 | 690 | |
goetz@6460 | 691 | if (s_code == NULL) { |
goetz@6460 | 692 | out->s_name = "unknown"; |
goetz@6460 | 693 | out->s_desc = "unknown"; |
goetz@6460 | 694 | return false; |
goetz@6460 | 695 | } |
goetz@6460 | 696 | |
goetz@6460 | 697 | out->s_name = s_code; |
goetz@6460 | 698 | out->s_desc = s_desc; |
goetz@6460 | 699 | |
goetz@6460 | 700 | return true; |
goetz@6460 | 701 | } |
goetz@6460 | 702 | |
goetz@6460 | 703 | // A POSIX conform, platform-independend siginfo print routine. |
goetz@6460 | 704 | // Short print out on one line. |
goetz@6460 | 705 | void os::Posix::print_siginfo_brief(outputStream* os, const siginfo_t* si) { |
goetz@6460 | 706 | char buf[20]; |
goetz@6460 | 707 | os->print("siginfo: "); |
goetz@6460 | 708 | |
goetz@6460 | 709 | if (!si) { |
goetz@6460 | 710 | os->print("<null>"); |
goetz@6460 | 711 | return; |
goetz@6460 | 712 | } |
goetz@6460 | 713 | |
goetz@6460 | 714 | // See print_siginfo_full() for details. |
goetz@6460 | 715 | const int sig = si->si_signo; |
goetz@6460 | 716 | |
goetz@6460 | 717 | os->print("si_signo: %d (%s)", sig, os::Posix::get_signal_name(sig, buf, sizeof(buf))); |
goetz@6460 | 718 | |
goetz@6460 | 719 | enum_sigcode_desc_t ed; |
goetz@6460 | 720 | if (get_signal_code_description(si, &ed)) { |
goetz@6460 | 721 | os->print(", si_code: %d (%s)", si->si_code, ed.s_name); |
goetz@6460 | 722 | } else { |
goetz@6460 | 723 | os->print(", si_code: %d (unknown)", si->si_code); |
goetz@6460 | 724 | } |
goetz@6460 | 725 | |
goetz@6460 | 726 | if (si->si_errno) { |
goetz@6460 | 727 | os->print(", si_errno: %d", si->si_errno); |
goetz@6460 | 728 | } |
goetz@6460 | 729 | |
goetz@6460 | 730 | const int me = (int) ::getpid(); |
goetz@6460 | 731 | const int pid = (int) si->si_pid; |
goetz@6460 | 732 | |
goetz@6460 | 733 | if (si->si_code == SI_USER || si->si_code == SI_QUEUE) { |
goetz@6460 | 734 | if (IS_VALID_PID(pid) && pid != me) { |
goetz@6460 | 735 | os->print(", sent from pid: %d (uid: %d)", pid, (int) si->si_uid); |
goetz@6460 | 736 | } |
goetz@6460 | 737 | } else if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || |
goetz@6460 | 738 | sig == SIGTRAP || sig == SIGFPE) { |
goetz@6460 | 739 | os->print(", si_addr: " PTR_FORMAT, si->si_addr); |
goetz@6460 | 740 | #ifdef SIGPOLL |
goetz@6460 | 741 | } else if (sig == SIGPOLL) { |
goetz@6460 | 742 | os->print(", si_band: " PTR64_FORMAT, (uint64_t)si->si_band); |
goetz@6460 | 743 | #endif |
goetz@6460 | 744 | } else if (sig == SIGCHLD) { |
goetz@6460 | 745 | os->print_cr(", si_pid: %d, si_uid: %d, si_status: %d", (int) si->si_pid, si->si_uid, si->si_status); |
goetz@6460 | 746 | } |
goetz@6460 | 747 | } |
goetz@6460 | 748 | |
rbackman@5424 | 749 | os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() { |
rbackman@5424 | 750 | assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread"); |
rbackman@5424 | 751 | } |
rbackman@5424 | 752 | |
rbackman@5424 | 753 | /* |
rbackman@5424 | 754 | * See the caveats for this class in os_posix.hpp |
rbackman@5424 | 755 | * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this |
rbackman@5424 | 756 | * method and returns false. If none of the signals are raised, returns true. |
rbackman@5424 | 757 | * The callback is supposed to provide the method that should be protected. |
rbackman@5424 | 758 | */ |
rbackman@5424 | 759 | bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) { |
rbackman@5424 | 760 | assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread"); |
rbackman@5424 | 761 | assert(!WatcherThread::watcher_thread()->has_crash_protection(), |
rbackman@5424 | 762 | "crash_protection already set?"); |
rbackman@5424 | 763 | |
rbackman@5424 | 764 | if (sigsetjmp(_jmpbuf, 1) == 0) { |
rbackman@5424 | 765 | // make sure we can see in the signal handler that we have crash protection |
rbackman@5424 | 766 | // installed |
rbackman@5424 | 767 | WatcherThread::watcher_thread()->set_crash_protection(this); |
rbackman@5424 | 768 | cb.call(); |
rbackman@5424 | 769 | // and clear the crash protection |
rbackman@5424 | 770 | WatcherThread::watcher_thread()->set_crash_protection(NULL); |
rbackman@5424 | 771 | return true; |
rbackman@5424 | 772 | } |
rbackman@5424 | 773 | // this happens when we siglongjmp() back |
rbackman@5424 | 774 | WatcherThread::watcher_thread()->set_crash_protection(NULL); |
rbackman@5424 | 775 | return false; |
rbackman@5424 | 776 | } |
rbackman@5424 | 777 | |
rbackman@5424 | 778 | void os::WatcherThreadCrashProtection::restore() { |
rbackman@5424 | 779 | assert(WatcherThread::watcher_thread()->has_crash_protection(), |
rbackman@5424 | 780 | "must have crash protection"); |
rbackman@5424 | 781 | |
rbackman@5424 | 782 | siglongjmp(_jmpbuf, 1); |
rbackman@5424 | 783 | } |
rbackman@5424 | 784 | |
rbackman@5424 | 785 | void os::WatcherThreadCrashProtection::check_crash_protection(int sig, |
rbackman@5424 | 786 | Thread* thread) { |
rbackman@5424 | 787 | |
rbackman@5424 | 788 | if (thread != NULL && |
rbackman@5424 | 789 | thread->is_Watcher_thread() && |
rbackman@5424 | 790 | WatcherThread::watcher_thread()->has_crash_protection()) { |
rbackman@5424 | 791 | |
rbackman@5424 | 792 | if (sig == SIGSEGV || sig == SIGBUS) { |
rbackman@5424 | 793 | WatcherThread::watcher_thread()->crash_protection()->restore(); |
rbackman@5424 | 794 | } |
rbackman@5424 | 795 | } |
rbackman@5424 | 796 | } |