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