1 /* 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 // no precompiled headers 26 #include "asm/macroAssembler.hpp" 27 #include "classfile/classLoader.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "code/icBuffer.hpp" 31 #include "code/vtableStubs.hpp" 32 #include "interpreter/interpreter.hpp" 33 #include "jvm_linux.h" 34 #include "memory/allocation.inline.hpp" 35 #include "mutex_linux.inline.hpp" 36 #include "nativeInst_sparc.hpp" 37 #include "os_share_linux.hpp" 38 #include "prims/jniFastGetField.hpp" 39 #include "prims/jvm.h" 40 #include "prims/jvm_misc.hpp" 41 #include "runtime/arguments.hpp" 42 #include "runtime/extendedPC.hpp" 43 #include "runtime/frame.inline.hpp" 44 #include "runtime/interfaceSupport.hpp" 45 #include "runtime/java.hpp" 46 #include "runtime/javaCalls.hpp" 47 #include "runtime/mutexLocker.hpp" 48 #include "runtime/osThread.hpp" 49 #include "runtime/sharedRuntime.hpp" 50 #include "runtime/stubRoutines.hpp" 51 #include "runtime/thread.inline.hpp" 52 #include "runtime/timer.hpp" 53 #include "utilities/events.hpp" 54 #include "utilities/vmError.hpp" 55 56 // Linux/Sparc has rather obscure naming of registers in sigcontext 57 // different between 32 and 64 bits 58 #ifdef _LP64 59 #define SIG_PC(x) ((x)->sigc_regs.tpc) 60 #define SIG_NPC(x) ((x)->sigc_regs.tnpc) 61 #define SIG_REGS(x) ((x)->sigc_regs) 62 #else 63 #define SIG_PC(x) ((x)->si_regs.pc) 64 #define SIG_NPC(x) ((x)->si_regs.npc) 65 #define SIG_REGS(x) ((x)->si_regs) 66 #endif 67 68 // those are to reference registers in sigcontext 69 enum { 70 CON_G0 = 0, 71 CON_G1, 72 CON_G2, 73 CON_G3, 74 CON_G4, 75 CON_G5, 76 CON_G6, 77 CON_G7, 78 CON_O0, 79 CON_O1, 80 CON_O2, 81 CON_O3, 82 CON_O4, 83 CON_O5, 84 CON_O6, 85 CON_O7, 86 }; 87 88 static inline void set_cont_address(sigcontext* ctx, address addr) { 89 SIG_PC(ctx) = (intptr_t)addr; 90 SIG_NPC(ctx) = (intptr_t)(addr+4); 91 } 92 93 // For Forte Analyzer AsyncGetCallTrace profiling support - thread is 94 // currently interrupted by SIGPROF. 95 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested 96 // signal frames. Currently we don't do that on Linux, so it's the 97 // same as os::fetch_frame_from_context(). 98 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, 99 ucontext_t* uc, 100 intptr_t** ret_sp, 101 intptr_t** ret_fp) { 102 assert(thread != NULL, "just checking"); 103 assert(ret_sp != NULL, "just checking"); 104 assert(ret_fp != NULL, "just checking"); 105 106 return os::fetch_frame_from_context(uc, ret_sp, ret_fp); 107 } 108 109 ExtendedPC os::fetch_frame_from_context(void* ucVoid, 110 intptr_t** ret_sp, 111 intptr_t** ret_fp) { 112 ucontext_t* uc = (ucontext_t*) ucVoid; 113 ExtendedPC epc; 114 115 if (uc != NULL) { 116 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); 117 if (ret_sp) { 118 *ret_sp = os::Linux::ucontext_get_sp(uc); 119 } 120 if (ret_fp) { 121 *ret_fp = (intptr_t*)NULL; 122 } 123 } else { 124 // construct empty ExtendedPC for return value checking 125 epc = ExtendedPC(NULL); 126 if (ret_sp) { 127 *ret_sp = (intptr_t*) NULL; 128 } 129 if (ret_fp) { 130 *ret_fp = (intptr_t*) NULL; 131 } 132 } 133 134 return epc; 135 } 136 137 frame os::fetch_frame_from_context(void* ucVoid) { 138 intptr_t* sp; 139 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, NULL); 140 return frame(sp, frame::unpatchable, epc.pc()); 141 } 142 143 frame os::get_sender_for_C_frame(frame* fr) { 144 return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); 145 } 146 147 frame os::current_frame() { 148 intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); 149 frame myframe(sp, frame::unpatchable, 150 CAST_FROM_FN_PTR(address, os::current_frame)); 151 if (os::is_first_C_frame(&myframe)) { 152 // stack is not walkable 153 return frame(NULL, frame::unpatchable, NULL); 154 } else { 155 return os::get_sender_for_C_frame(&myframe); 156 } 157 } 158 159 address os::current_stack_pointer() { 160 register void *sp __asm__ ("sp"); 161 return (address)sp; 162 } 163 164 static void current_stack_region(address* bottom, size_t* size) { 165 if (os::Linux::is_initial_thread()) { 166 // initial thread needs special handling because pthread_getattr_np() 167 // may return bogus value. 168 *bottom = os::Linux::initial_thread_stack_bottom(); 169 *size = os::Linux::initial_thread_stack_size(); 170 } else { 171 pthread_attr_t attr; 172 173 int rslt = pthread_getattr_np(pthread_self(), &attr); 174 175 // JVM needs to know exact stack location, abort if it fails 176 if (rslt != 0) { 177 if (rslt == ENOMEM) { 178 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); 179 } else { 180 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); 181 } 182 } 183 184 if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) { 185 fatal("Can not locate current stack attributes!"); 186 } 187 188 pthread_attr_destroy(&attr); 189 } 190 assert(os::current_stack_pointer() >= *bottom && 191 os::current_stack_pointer() < *bottom + *size, "just checking"); 192 } 193 194 address os::current_stack_base() { 195 address bottom; 196 size_t size; 197 current_stack_region(&bottom, &size); 198 return bottom + size; 199 } 200 201 size_t os::current_stack_size() { 202 // stack size includes normal stack and HotSpot guard pages 203 address bottom; 204 size_t size; 205 current_stack_region(&bottom, &size); 206 return size; 207 } 208 209 char* os::non_memory_address_word() { 210 // Must never look like an address returned by reserve_memory, 211 // even in its subfields (as defined by the CPU immediate fields, 212 // if the CPU splits constants across multiple instructions). 213 // On SPARC, 0 != %hi(any real address), because there is no 214 // allocation in the first 1Kb of the virtual address space. 215 return (char*) 0; 216 } 217 218 void os::initialize_thread(Thread* thr) {} 219 220 void os::print_context(outputStream *st, void *context) { 221 if (context == NULL) return; 222 223 ucontext_t* uc = (ucontext_t*)context; 224 sigcontext* sc = (sigcontext*)context; 225 st->print_cr("Registers:"); 226 227 st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT 228 " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, 229 SIG_REGS(sc).u_regs[CON_G1], 230 SIG_REGS(sc).u_regs[CON_G2], 231 SIG_REGS(sc).u_regs[CON_G3], 232 SIG_REGS(sc).u_regs[CON_G4]); 233 st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT 234 " G7=" INTPTR_FORMAT " Y=0x%x", 235 SIG_REGS(sc).u_regs[CON_G5], 236 SIG_REGS(sc).u_regs[CON_G6], 237 SIG_REGS(sc).u_regs[CON_G7], 238 SIG_REGS(sc).y); 239 st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT 240 " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, 241 SIG_REGS(sc).u_regs[CON_O0], 242 SIG_REGS(sc).u_regs[CON_O1], 243 SIG_REGS(sc).u_regs[CON_O2], 244 SIG_REGS(sc).u_regs[CON_O3]); 245 st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT 246 " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, 247 SIG_REGS(sc).u_regs[CON_O4], 248 SIG_REGS(sc).u_regs[CON_O5], 249 SIG_REGS(sc).u_regs[CON_O6], 250 SIG_REGS(sc).u_regs[CON_O7]); 251 252 253 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 254 st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT 255 " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, 256 sp[L0->sp_offset_in_saved_window()], 257 sp[L1->sp_offset_in_saved_window()], 258 sp[L2->sp_offset_in_saved_window()], 259 sp[L3->sp_offset_in_saved_window()]); 260 st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT 261 " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, 262 sp[L4->sp_offset_in_saved_window()], 263 sp[L5->sp_offset_in_saved_window()], 264 sp[L6->sp_offset_in_saved_window()], 265 sp[L7->sp_offset_in_saved_window()]); 266 st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT 267 " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, 268 sp[I0->sp_offset_in_saved_window()], 269 sp[I1->sp_offset_in_saved_window()], 270 sp[I2->sp_offset_in_saved_window()], 271 sp[I3->sp_offset_in_saved_window()]); 272 st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT 273 " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, 274 sp[I4->sp_offset_in_saved_window()], 275 sp[I5->sp_offset_in_saved_window()], 276 sp[I6->sp_offset_in_saved_window()], 277 sp[I7->sp_offset_in_saved_window()]); 278 279 st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, 280 SIG_PC(sc), 281 SIG_NPC(sc)); 282 st->cr(); 283 st->cr(); 284 285 st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", p2i(sp)); 286 print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); 287 st->cr(); 288 289 // Note: it may be unsafe to inspect memory near pc. For example, pc may 290 // point to garbage if entry point in an nmethod is corrupted. Leave 291 // this at the end, and hope for the best. 292 address pc = os::Linux::ucontext_get_pc(uc); 293 st->print_cr("Instructions: (pc=" INTPTR_FORMAT ")", p2i(pc)); 294 print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); 295 } 296 297 298 void os::print_register_info(outputStream *st, void *context) { 299 if (context == NULL) return; 300 301 ucontext_t *uc = (ucontext_t*)context; 302 sigcontext* sc = (sigcontext*)context; 303 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); 304 305 st->print_cr("Register to memory mapping:"); 306 st->cr(); 307 308 // this is only for the "general purpose" registers 309 st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]); 310 st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]); 311 st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]); 312 st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]); 313 st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]); 314 st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]); 315 st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]); 316 st->cr(); 317 318 st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]); 319 st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]); 320 st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]); 321 st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]); 322 st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]); 323 st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]); 324 st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]); 325 st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]); 326 st->cr(); 327 328 st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); 329 st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); 330 st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); 331 st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); 332 st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); 333 st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); 334 st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); 335 st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); 336 st->cr(); 337 338 st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); 339 st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); 340 st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); 341 st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); 342 st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); 343 st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); 344 st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); 345 st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); 346 st->cr(); 347 } 348 349 350 address os::Linux::ucontext_get_pc(ucontext_t* uc) { 351 return (address) SIG_PC((sigcontext*)uc); 352 } 353 354 void os::Linux::ucontext_set_pc(ucontext_t* uc, address pc) { 355 set_cont_address((sigcontext_t*) uc, pc); 356 } 357 358 intptr_t* os::Linux::ucontext_get_sp(ucontext_t *uc) { 359 return (intptr_t*) 360 ((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); 361 } 362 363 // not used on Sparc 364 intptr_t* os::Linux::ucontext_get_fp(ucontext_t *uc) { 365 ShouldNotReachHere(); 366 return NULL; 367 } 368 369 // Utility functions 370 371 inline static bool checkPrefetch(sigcontext* uc, address pc) { 372 if (StubRoutines::is_safefetch_fault(pc)) { 373 set_cont_address(uc, address(StubRoutines::continuation_for_safefetch_fault(pc))); 374 return true; 375 } 376 return false; 377 } 378 379 inline static bool checkOverflow(sigcontext* uc, 380 address pc, 381 address addr, 382 JavaThread* thread, 383 address* stub) { 384 // check if fault address is within thread stack 385 if (addr < thread->stack_base() && 386 addr >= thread->stack_base() - thread->stack_size()) { 387 // stack overflow 388 if (thread->in_stack_yellow_zone(addr)) { 389 thread->disable_stack_yellow_zone(); 390 if (thread->thread_state() == _thread_in_Java) { 391 // Throw a stack overflow exception. Guard pages will be reenabled 392 // while unwinding the stack. 393 *stub = 394 SharedRuntime::continuation_for_implicit_exception(thread, 395 pc, 396 SharedRuntime::STACK_OVERFLOW); 397 } else { 398 // Thread was in the vm or native code. Return and try to finish. 399 return true; 400 } 401 } else if (thread->in_stack_red_zone(addr)) { 402 // Fatal red zone violation. Disable the guard pages and fall through 403 // to handle_unexpected_exception way down below. 404 thread->disable_stack_red_zone(); 405 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); 406 407 // This is a likely cause, but hard to verify. Let's just print 408 // it as a hint. 409 tty->print_raw_cr("Please check if any of your loaded .so files has " 410 "enabled executable stack (see man page execstack(8))"); 411 } else { 412 // Accessing stack address below sp may cause SEGV if current 413 // thread has MAP_GROWSDOWN stack. This should only happen when 414 // current thread was created by user code with MAP_GROWSDOWN flag 415 // and then attached to VM. See notes in os_linux.cpp. 416 if (thread->osthread()->expanding_stack() == 0) { 417 thread->osthread()->set_expanding_stack(); 418 if (os::Linux::manually_expand_stack(thread, addr)) { 419 thread->osthread()->clear_expanding_stack(); 420 return true; 421 } 422 thread->osthread()->clear_expanding_stack(); 423 } else { 424 fatal("recursive segv. expanding stack."); 425 } 426 } 427 } 428 return false; 429 } 430 431 inline static bool checkPollingPage(address pc, address fault, address* stub) { 432 if (fault == os::get_polling_page()) { 433 *stub = SharedRuntime::get_poll_stub(pc); 434 return true; 435 } 436 return false; 437 } 438 439 inline static bool checkByteBuffer(address pc, address* stub) { 440 // BugId 4454115: A read from a MappedByteBuffer can fault 441 // here if the underlying file has been truncated. 442 // Do not crash the VM in such a case. 443 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); 444 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; 445 if (nm != NULL && nm->has_unsafe_access()) { 446 *stub = StubRoutines::handler_for_unsafe_access(); 447 return true; 448 } 449 return false; 450 } 451 452 inline static bool checkVerifyOops(address pc, address fault, address* stub) { 453 if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] 454 && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { 455 *stub = MacroAssembler::_verify_oop_implicit_branch[2]; 456 warning("fixed up memory fault in +VerifyOops at address " 457 INTPTR_FORMAT, p2i(fault)); 458 return true; 459 } 460 return false; 461 } 462 463 inline static bool checkFPFault(address pc, int code, 464 JavaThread* thread, address* stub) { 465 if (code == FPE_INTDIV || code == FPE_FLTDIV) { 466 *stub = 467 SharedRuntime:: 468 continuation_for_implicit_exception(thread, 469 pc, 470 SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); 471 return true; 472 } 473 return false; 474 } 475 476 inline static bool checkNullPointer(address pc, intptr_t fault, 477 JavaThread* thread, address* stub) { 478 if (!MacroAssembler::needs_explicit_null_check(fault)) { 479 // Determination of interpreter/vtable stub/compiled code null 480 // exception 481 *stub = 482 SharedRuntime:: 483 continuation_for_implicit_exception(thread, pc, 484 SharedRuntime::IMPLICIT_NULL); 485 return true; 486 } 487 return false; 488 } 489 490 inline static bool checkFastJNIAccess(address pc, address* stub) { 491 address addr = JNI_FastGetField::find_slowcase_pc(pc); 492 if (addr != (address)-1) { 493 *stub = addr; 494 return true; 495 } 496 return false; 497 } 498 499 inline static bool checkSerializePage(JavaThread* thread, address addr) { 500 return os::is_memory_serialize_page(thread, addr); 501 } 502 503 inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { 504 if (nativeInstruction_at(*pc)->is_zombie()) { 505 // zombie method (ld [%g0],%o7 instruction) 506 *stub = SharedRuntime::get_handle_wrong_method_stub(); 507 508 // At the stub it needs to look like a call from the caller of this 509 // method (not a call from the segv site). 510 *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; 511 return true; 512 } 513 return false; 514 } 515 516 inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { 517 #ifdef COMPILER2 518 if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { 519 #ifdef ASSERT 520 #ifdef TIERED 521 CodeBlob* cb = CodeCache::find_blob_unsafe(*pc); 522 assert(cb->is_compiled_by_c2(), "Wrong compiler"); 523 #endif // TIERED 524 #endif // ASSERT 525 // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. 526 *stub = SharedRuntime::get_ic_miss_stub(); 527 // At the stub it needs to look like a call from the caller of this 528 // method (not a call from the segv site). 529 *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; 530 return true; 531 } 532 #endif // COMPILER2 533 return false; 534 } 535 536 extern "C" JNIEXPORT int 537 JVM_handle_linux_signal(int sig, 538 siginfo_t* info, 539 void* ucVoid, 540 int abort_if_unrecognized) { 541 // in fact this isn't ucontext_t* at all, but struct sigcontext* 542 // but Linux porting layer uses ucontext_t, so to minimize code change 543 // we cast as needed 544 ucontext_t* ucFake = (ucontext_t*) ucVoid; 545 sigcontext* uc = (sigcontext*)ucVoid; 546 547 Thread* t = ThreadLocalStorage::get_thread_slow(); 548 549 // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away 550 // (no destructors can be run) 551 os::WatcherThreadCrashProtection::check_crash_protection(sig, t); 552 553 SignalHandlerMark shm(t); 554 555 // Note: it's not uncommon that JNI code uses signal/sigset to install 556 // then restore certain signal handler (e.g. to temporarily block SIGPIPE, 557 // or have a SIGILL handler when detecting CPU type). When that happens, 558 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To 559 // avoid unnecessary crash when libjsig is not preloaded, try handle signals 560 // that do not require siginfo/ucontext first. 561 562 if (sig == SIGPIPE || sig == SIGXFSZ) { 563 // allow chained handler to go first 564 if (os::Linux::chained_handler(sig, info, ucVoid)) { 565 return true; 566 } else { 567 if (PrintMiscellaneous && (WizardMode || Verbose)) { 568 char buf[64]; 569 warning("Ignoring %s - see bugs 4229104 or 646499219", 570 os::exception_name(sig, buf, sizeof(buf))); 571 } 572 return true; 573 } 574 } 575 576 JavaThread* thread = NULL; 577 VMThread* vmthread = NULL; 578 if (os::Linux::signal_handlers_are_installed) { 579 if (t != NULL ){ 580 if(t->is_Java_thread()) { 581 thread = (JavaThread*)t; 582 } 583 else if(t->is_VM_thread()){ 584 vmthread = (VMThread *)t; 585 } 586 } 587 } 588 589 // decide if this trap can be handled by a stub 590 address stub = NULL; 591 address pc = NULL; 592 address npc = NULL; 593 594 //%note os_trap_1 595 if (info != NULL && uc != NULL && thread != NULL) { 596 pc = address(SIG_PC(uc)); 597 npc = address(SIG_NPC(uc)); 598 599 // Check to see if we caught the safepoint code in the 600 // process of write protecting the memory serialization page. 601 // It write enables the page immediately after protecting it 602 // so we can just return to retry the write. 603 if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { 604 // Block current thread until the memory serialize page permission restored. 605 os::block_on_serialize_page_trap(); 606 return 1; 607 } 608 609 if (checkPrefetch(uc, pc)) { 610 return 1; 611 } 612 613 // Handle ALL stack overflow variations here 614 if (sig == SIGSEGV) { 615 if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { 616 return 1; 617 } 618 } 619 620 if (sig == SIGBUS && 621 thread->thread_state() == _thread_in_vm && 622 thread->doing_unsafe_access()) { 623 stub = StubRoutines::handler_for_unsafe_access(); 624 } 625 626 if (thread->thread_state() == _thread_in_Java) { 627 do { 628 // Java thread running in Java code => find exception handler if any 629 // a fault inside compiled code, the interpreter, or a stub 630 631 if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { 632 break; 633 } 634 635 if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { 636 break; 637 } 638 639 if ((sig == SIGSEGV || sig == SIGBUS) && 640 checkVerifyOops(pc, (address)info->si_addr, &stub)) { 641 break; 642 } 643 644 if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { 645 break; 646 } 647 648 if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { 649 break; 650 } 651 652 if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { 653 break; 654 } 655 656 if ((sig == SIGSEGV) && 657 checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { 658 break; 659 } 660 } while (0); 661 662 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in 663 // and the heap gets shrunk before the field access. 664 if ((sig == SIGSEGV) || (sig == SIGBUS)) { 665 checkFastJNIAccess(pc, &stub); 666 } 667 } 668 669 if (stub != NULL) { 670 // save all thread context in case we need to restore it 671 thread->set_saved_exception_pc(pc); 672 thread->set_saved_exception_npc(npc); 673 set_cont_address(uc, stub); 674 return true; 675 } 676 } 677 678 // signal-chaining 679 if (os::Linux::chained_handler(sig, info, ucVoid)) { 680 return true; 681 } 682 683 if (!abort_if_unrecognized) { 684 // caller wants another chance, so give it to him 685 return false; 686 } 687 688 if (pc == NULL && uc != NULL) { 689 pc = os::Linux::ucontext_get_pc((ucontext_t*)uc); 690 } 691 692 // unmask current signal 693 sigset_t newset; 694 sigemptyset(&newset); 695 sigaddset(&newset, sig); 696 sigprocmask(SIG_UNBLOCK, &newset, NULL); 697 698 VMError err(t, sig, pc, info, ucVoid); 699 err.report_and_die(); 700 701 ShouldNotReachHere(); 702 } 703 704 void os::Linux::init_thread_fpu_state(void) { 705 // Nothing to do 706 } 707 708 int os::Linux::get_fpu_control_word() { 709 return 0; 710 } 711 712 void os::Linux::set_fpu_control_word(int fpu) { 713 // nothing 714 } 715 716 bool os::is_allocatable(size_t bytes) { 717 #ifdef _LP64 718 return true; 719 #else 720 if (bytes < 2 * G) { 721 return true; 722 } 723 724 char* addr = reserve_memory(bytes, NULL); 725 726 if (addr != NULL) { 727 release_memory(addr, bytes); 728 } 729 730 return addr != NULL; 731 #endif // _LP64 732 } 733 734 /////////////////////////////////////////////////////////////////////////////// 735 // thread stack 736 737 size_t os::Linux::min_stack_allowed = 128 * K; 738 739 // pthread on Ubuntu is always in floating stack mode 740 bool os::Linux::supports_variable_stack_size() { return true; } 741 742 // return default stack size for thr_type 743 size_t os::Linux::default_stack_size(os::ThreadType thr_type) { 744 // default stack size (compiler thread needs larger stack) 745 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); 746 return s; 747 } 748 749 size_t os::Linux::default_guard_size(os::ThreadType thr_type) { 750 // Creating guard page is very expensive. Java thread has HotSpot 751 // guard page, only enable glibc guard page for non-Java threads. 752 return (thr_type == java_thread ? 0 : page_size()); 753 } 754 755 #ifndef PRODUCT 756 void os::verify_stack_alignment() { 757 } 758 #endif 759 760 int os::extra_bang_size_in_bytes() { 761 // SPARC does not require the additional stack bang. 762 return 0; 763 }