src/os/posix/vm/os_posix.cpp

Thu, 02 Aug 2018 03:54:51 -0700

author
kevinw
date
Thu, 02 Aug 2018 03:54:51 -0700
changeset 9478
f3108e56b502
parent 8423
2988e5adeb8c
child 9572
624a0741915c
child 9610
f43f77de876a
permissions
-rw-r--r--

8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
Summary: Add os::vsnprintf and os::snprintf.
Reviewed-by: kbarrett, lfoltan, stuefe, mlarsson

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

mercurial