1 /*
   2  * Copyright (c) 1999, 2018, 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 "jvm.h"
  27 #include "asm/macroAssembler.hpp"
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/vmSymbols.hpp"
  31 #include "code/codeCache.hpp"
  32 #include "code/icBuffer.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "interpreter/interpreter.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "nativeInst_sparc.hpp"
  37 #include "os_share_linux.hpp"
  38 #include "prims/jniFastGetField.hpp"
  39 #include "prims/jvm_misc.hpp"
  40 #include "runtime/arguments.hpp"
  41 #include "runtime/extendedPC.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/interfaceSupport.inline.hpp"
  44 #include "runtime/java.hpp"
  45 #include "runtime/javaCalls.hpp"
  46 #include "runtime/mutexLocker.hpp"
  47 #include "runtime/osThread.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 #include "runtime/stubRoutines.hpp"
  50 #include "runtime/thread.inline.hpp"
  51 #include "runtime/timer.hpp"
  52 #include "utilities/debug.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 #define SIG_PC(x) ((x)->sigc_regs.tpc)
  59 #define SIG_NPC(x) ((x)->sigc_regs.tnpc)
  60 #define SIG_REGS(x) ((x)->sigc_regs)
  61 
  62 // those are to reference registers in sigcontext
  63 enum {
  64   CON_G0 = 0,
  65   CON_G1,
  66   CON_G2,
  67   CON_G3,
  68   CON_G4,
  69   CON_G5,
  70   CON_G6,
  71   CON_G7,
  72   CON_O0,
  73   CON_O1,
  74   CON_O2,
  75   CON_O3,
  76   CON_O4,
  77   CON_O5,
  78   CON_O6,
  79   CON_O7,
  80 };
  81 
  82 // For Forte Analyzer AsyncGetCallTrace profiling support - thread is
  83 // currently interrupted by SIGPROF.
  84 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested
  85 // signal frames. Currently we don't do that on Linux, so it's the
  86 // same as os::fetch_frame_from_context().
  87 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread,
  88                                                 const ucontext_t* uc,
  89                                                 intptr_t** ret_sp,
  90                                                 intptr_t** ret_fp) {
  91   assert(thread != NULL, "just checking");
  92   assert(ret_sp != NULL, "just checking");
  93   assert(ret_fp != NULL, "just checking");
  94 
  95   return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
  96 }
  97 
  98 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
  99                                         intptr_t** ret_sp,
 100                                         intptr_t** ret_fp) {
 101   const ucontext_t* uc = (const ucontext_t*) ucVoid;
 102   ExtendedPC  epc;
 103 
 104   if (uc != NULL) {
 105     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 106     if (ret_sp) {
 107       *ret_sp = os::Linux::ucontext_get_sp(uc);
 108     }
 109     if (ret_fp) {
 110       *ret_fp = (intptr_t*)NULL;
 111     }
 112   } else {
 113     // construct empty ExtendedPC for return value checking
 114     epc = ExtendedPC(NULL);
 115     if (ret_sp) {
 116       *ret_sp = (intptr_t*) NULL;
 117     }
 118     if (ret_fp) {
 119       *ret_fp = (intptr_t*) NULL;
 120     }
 121   }
 122 
 123   return epc;
 124 }
 125 
 126 frame os::fetch_frame_from_context(const void* ucVoid) {
 127   intptr_t* sp;
 128   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, NULL);
 129   return frame(sp, frame::unpatchable, epc.pc());
 130 }
 131 
 132 frame os::get_sender_for_C_frame(frame* fr) {
 133   return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc());
 134 }
 135 
 136 frame os::current_frame() {
 137   intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
 138   frame myframe(sp, frame::unpatchable,
 139                 CAST_FROM_FN_PTR(address, os::current_frame));
 140   if (os::is_first_C_frame(&myframe)) {
 141     // stack is not walkable
 142     return frame(NULL, frame::unpatchable, NULL);
 143   } else {
 144     return os::get_sender_for_C_frame(&myframe);
 145   }
 146 }
 147 
 148 address os::current_stack_pointer() {
 149   register void *sp __asm__ ("sp");
 150   return (address)sp;
 151 }
 152 
 153 char* os::non_memory_address_word() {
 154   // Must never look like an address returned by reserve_memory,
 155   // even in its subfields (as defined by the CPU immediate fields,
 156   // if the CPU splits constants across multiple instructions).
 157   // On SPARC, 0 != %hi(any real address), because there is no
 158   // allocation in the first 1Kb of the virtual address space.
 159   return (char*) 0;
 160 }
 161 
 162 void os::print_context(outputStream *st, const void *context) {
 163   if (context == NULL) return;
 164 
 165   const ucontext_t* uc = (const ucontext_t*)context;
 166   sigcontext* sc = (sigcontext*)context;
 167   st->print_cr("Registers:");
 168 
 169   st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT
 170                " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT,
 171                SIG_REGS(sc).u_regs[CON_G1],
 172                SIG_REGS(sc).u_regs[CON_G2],
 173                SIG_REGS(sc).u_regs[CON_G3],
 174                SIG_REGS(sc).u_regs[CON_G4]);
 175   st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT
 176                " G7=" INTPTR_FORMAT " Y=0x%x",
 177                SIG_REGS(sc).u_regs[CON_G5],
 178                SIG_REGS(sc).u_regs[CON_G6],
 179                SIG_REGS(sc).u_regs[CON_G7],
 180                SIG_REGS(sc).y);
 181   st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT
 182                " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT,
 183                SIG_REGS(sc).u_regs[CON_O0],
 184                SIG_REGS(sc).u_regs[CON_O1],
 185                SIG_REGS(sc).u_regs[CON_O2],
 186                SIG_REGS(sc).u_regs[CON_O3]);
 187   st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT
 188                " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT,
 189                SIG_REGS(sc).u_regs[CON_O4],
 190                SIG_REGS(sc).u_regs[CON_O5],
 191                SIG_REGS(sc).u_regs[CON_O6],
 192                SIG_REGS(sc).u_regs[CON_O7]);
 193 
 194 
 195   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
 196   st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT
 197                " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT,
 198                sp[L0->sp_offset_in_saved_window()],
 199                sp[L1->sp_offset_in_saved_window()],
 200                sp[L2->sp_offset_in_saved_window()],
 201                sp[L3->sp_offset_in_saved_window()]);
 202   st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT
 203                " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT,
 204                sp[L4->sp_offset_in_saved_window()],
 205                sp[L5->sp_offset_in_saved_window()],
 206                sp[L6->sp_offset_in_saved_window()],
 207                sp[L7->sp_offset_in_saved_window()]);
 208   st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT
 209                " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT,
 210                sp[I0->sp_offset_in_saved_window()],
 211                sp[I1->sp_offset_in_saved_window()],
 212                sp[I2->sp_offset_in_saved_window()],
 213                sp[I3->sp_offset_in_saved_window()]);
 214   st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT
 215                " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT,
 216                sp[I4->sp_offset_in_saved_window()],
 217                sp[I5->sp_offset_in_saved_window()],
 218                sp[I6->sp_offset_in_saved_window()],
 219                sp[I7->sp_offset_in_saved_window()]);
 220 
 221   st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT,
 222                SIG_PC(sc),
 223                SIG_NPC(sc));
 224   st->cr();
 225   st->cr();
 226 
 227   st->print_cr("Top of Stack: (sp=" INTPTR_FORMAT ")", p2i(sp));
 228   print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
 229   st->cr();
 230 
 231   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 232   // point to garbage if entry point in an nmethod is corrupted. Leave
 233   // this at the end, and hope for the best.
 234   address pc = os::Linux::ucontext_get_pc(uc);
 235   print_instructions(st, pc, sizeof(char));
 236   st->cr();
 237 }
 238 
 239 
 240 void os::print_register_info(outputStream *st, const void *context) {
 241   if (context == NULL) return;
 242 
 243   const ucontext_t *uc = (const ucontext_t*)context;
 244   const sigcontext* sc = (const sigcontext*)context;
 245   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
 246 
 247   st->print_cr("Register to memory mapping:");
 248   st->cr();
 249 
 250   // this is only for the "general purpose" registers
 251   st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON_G1]);
 252   st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON_G2]);
 253   st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON_G3]);
 254   st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON_G4]);
 255   st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON_G5]);
 256   st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON_G6]);
 257   st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON_G7]);
 258   st->cr();
 259 
 260   st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON_O0]);
 261   st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON_O1]);
 262   st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON_O2]);
 263   st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON_O3]);
 264   st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON_O4]);
 265   st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON_O5]);
 266   st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON_O6]);
 267   st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON_O7]);
 268   st->cr();
 269 
 270   st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]);
 271   st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]);
 272   st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]);
 273   st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]);
 274   st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]);
 275   st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]);
 276   st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]);
 277   st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]);
 278   st->cr();
 279 
 280   st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]);
 281   st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]);
 282   st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]);
 283   st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]);
 284   st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]);
 285   st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]);
 286   st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]);
 287   st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]);
 288   st->cr();
 289 }
 290 
 291 
 292 address os::Linux::ucontext_get_pc(const ucontext_t* uc) {
 293   return (address) SIG_PC((sigcontext*)uc);
 294 }
 295 
 296 void os::Linux::ucontext_set_pc(ucontext_t* uc, address pc) {
 297   sigcontext* ctx = (sigcontext*) uc;
 298   SIG_PC(ctx)  = (intptr_t)pc;
 299   SIG_NPC(ctx) = (intptr_t)(pc+4);
 300 }
 301 
 302 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t *uc) {
 303   return (intptr_t*)
 304     ((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS);
 305 }
 306 
 307 // not used on Sparc
 308 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t *uc) {
 309   ShouldNotReachHere();
 310   return NULL;
 311 }
 312 
 313 // Utility functions
 314 
 315 inline static bool checkPrefetch(sigcontext* uc, address pc) {
 316   if (StubRoutines::is_safefetch_fault(pc)) {
 317     os::Linux::ucontext_set_pc((ucontext_t*)uc, StubRoutines::continuation_for_safefetch_fault(pc));
 318     return true;
 319   }
 320   return false;
 321 }
 322 
 323 inline static bool checkOverflow(sigcontext* uc,
 324                                  address pc,
 325                                  address addr,
 326                                  JavaThread* thread,
 327                                  address* stub) {
 328   // check if fault address is within thread stack
 329   if (thread->on_local_stack(addr)) {
 330     // stack overflow
 331     if (thread->in_stack_yellow_reserved_zone(addr)) {
 332       thread->disable_stack_yellow_reserved_zone();
 333       if (thread->thread_state() == _thread_in_Java) {
 334         // Throw a stack overflow exception.  Guard pages will be reenabled
 335         // while unwinding the stack.
 336         *stub =
 337           SharedRuntime::continuation_for_implicit_exception(thread,
 338                                                              pc,
 339                                                              SharedRuntime::STACK_OVERFLOW);
 340       } else {
 341         // Thread was in the vm or native code.  Return and try to finish.
 342         return true;
 343       }
 344     } else if (thread->in_stack_red_zone(addr)) {
 345       // Fatal red zone violation.  Disable the guard pages and fall through
 346       // to handle_unexpected_exception way down below.
 347       thread->disable_stack_red_zone();
 348       tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 349 
 350       // This is a likely cause, but hard to verify. Let's just print
 351       // it as a hint.
 352       tty->print_raw_cr("Please check if any of your loaded .so files has "
 353                         "enabled executable stack (see man page execstack(8))");
 354     } else {
 355       // Accessing stack address below sp may cause SEGV if current
 356       // thread has MAP_GROWSDOWN stack. This should only happen when
 357       // current thread was created by user code with MAP_GROWSDOWN flag
 358       // and then attached to VM. See notes in os_linux.cpp.
 359       if (thread->osthread()->expanding_stack() == 0) {
 360         thread->osthread()->set_expanding_stack();
 361         if (os::Linux::manually_expand_stack(thread, addr)) {
 362           thread->osthread()->clear_expanding_stack();
 363           return true;
 364         }
 365         thread->osthread()->clear_expanding_stack();
 366       } else {
 367         fatal("recursive segv. expanding stack.");
 368       }
 369     }
 370   }
 371   return false;
 372 }
 373 
 374 inline static bool checkPollingPage(address pc, address fault, address* stub) {
 375   if (os::is_poll_address(fault)) {
 376     *stub = SharedRuntime::get_poll_stub(pc);
 377     return true;
 378   }
 379   return false;
 380 }
 381 
 382 inline static bool checkByteBuffer(address pc, address npc, JavaThread * thread, address* stub) {
 383   // BugId 4454115: A read from a MappedByteBuffer can fault
 384   // here if the underlying file has been truncated.
 385   // Do not crash the VM in such a case.
 386   CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 387   CompiledMethod* nm = cb->as_compiled_method_or_null();
 388   if (nm != NULL && nm->has_unsafe_access()) {
 389     *stub = SharedRuntime::handle_unsafe_access(thread, npc);
 390     return true;
 391   }
 392   return false;
 393 }
 394 
 395 inline static bool checkVerifyOops(address pc, address fault, address* stub) {
 396   if (pc >= MacroAssembler::_verify_oop_implicit_branch[0]
 397       && pc <  MacroAssembler::_verify_oop_implicit_branch[1] ) {
 398     *stub     =  MacroAssembler::_verify_oop_implicit_branch[2];
 399     warning("fixed up memory fault in +VerifyOops at address "
 400             INTPTR_FORMAT, p2i(fault));
 401     return true;
 402   }
 403   return false;
 404 }
 405 
 406 inline static bool checkFPFault(address pc, int code,
 407                                 JavaThread* thread, address* stub) {
 408   if (code == FPE_INTDIV || code == FPE_FLTDIV) {
 409     *stub =
 410       SharedRuntime::
 411       continuation_for_implicit_exception(thread,
 412                                           pc,
 413                                           SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 414     return true;
 415   }
 416   return false;
 417 }
 418 
 419 inline static bool checkNullPointer(address pc, void* fault,
 420                                     JavaThread* thread, address* stub) {
 421   if (MacroAssembler::uses_implicit_null_check(fault)) {
 422     // Determination of interpreter/vtable stub/compiled code null
 423     // exception
 424     *stub =
 425       SharedRuntime::
 426       continuation_for_implicit_exception(thread, pc,
 427                                           SharedRuntime::IMPLICIT_NULL);
 428     return true;
 429   }
 430   return false;
 431 }
 432 
 433 inline static bool checkFastJNIAccess(address pc, address* stub) {
 434   address addr = JNI_FastGetField::find_slowcase_pc(pc);
 435   if (addr != (address)-1) {
 436     *stub = addr;
 437     return true;
 438   }
 439   return false;
 440 }
 441 
 442 inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) {
 443   if (nativeInstruction_at(*pc)->is_zombie()) {
 444     // zombie method (ld [%g0],%o7 instruction)
 445     *stub = SharedRuntime::get_handle_wrong_method_stub();
 446 
 447     // At the stub it needs to look like a call from the caller of this
 448     // method (not a call from the segv site).
 449     *pc = (address)SIG_REGS(uc).u_regs[CON_O7];
 450     return true;
 451   }
 452   return false;
 453 }
 454 
 455 inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) {
 456 #ifdef COMPILER2
 457   if (nativeInstruction_at(*pc)->is_ic_miss_trap()) {
 458 #ifdef ASSERT
 459 #ifdef TIERED
 460     CodeBlob* cb = CodeCache::find_blob_unsafe(*pc);
 461     assert(cb->is_compiled_by_c2(), "Wrong compiler");
 462 #endif // TIERED
 463 #endif // ASSERT
 464     // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken.
 465     *stub = SharedRuntime::get_ic_miss_stub();
 466     // At the stub it needs to look like a call from the caller of this
 467     // method (not a call from the segv site).
 468     *pc = (address)SIG_REGS(uc).u_regs[CON_O7];
 469     return true;
 470   }
 471 #endif  // COMPILER2
 472   return false;
 473 }
 474 
 475 extern "C" JNIEXPORT int
 476 JVM_handle_linux_signal(int sig,
 477                         siginfo_t* info,
 478                         void* ucVoid,
 479                         int abort_if_unrecognized) {
 480   // in fact this isn't ucontext_t* at all, but struct sigcontext*
 481   // but Linux porting layer uses ucontext_t, so to minimize code change
 482   // we cast as needed
 483   ucontext_t* ucFake = (ucontext_t*) ucVoid;
 484   sigcontext* uc = (sigcontext*)ucVoid;
 485 
 486   Thread* t = Thread::current_or_null_safe();
 487 
 488   // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
 489   // (no destructors can be run)
 490   os::ThreadCrashProtection::check_crash_protection(sig, t);
 491 
 492   SignalHandlerMark shm(t);
 493 
 494   // Note: it's not uncommon that JNI code uses signal/sigset to install
 495   // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
 496   // or have a SIGILL handler when detecting CPU type). When that happens,
 497   // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
 498   // avoid unnecessary crash when libjsig is not preloaded, try handle signals
 499   // that do not require siginfo/ucontext first.
 500 
 501   if (sig == SIGPIPE || sig == SIGXFSZ) {
 502     // allow chained handler to go first
 503     if (os::Linux::chained_handler(sig, info, ucVoid)) {
 504       return true;
 505     } else {
 506       // Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219
 507       return true;
 508     }
 509   }
 510 
 511 #ifdef CAN_SHOW_REGISTERS_ON_ASSERT
 512   if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) {
 513     if (handle_assert_poison_fault(ucVoid, info->si_addr)) {
 514       return 1;
 515     }
 516   }
 517 #endif
 518 
 519   JavaThread* thread = NULL;
 520   VMThread* vmthread = NULL;
 521   if (os::Linux::signal_handlers_are_installed) {
 522     if (t != NULL ){
 523       if(t->is_Java_thread()) {
 524         thread = (JavaThread*)t;
 525       }
 526       else if(t->is_VM_thread()){
 527         vmthread = (VMThread *)t;
 528       }
 529     }
 530   }
 531 
 532   // decide if this trap can be handled by a stub
 533   address stub = NULL;
 534   address pc = NULL;
 535   address npc = NULL;
 536 
 537   //%note os_trap_1
 538   if (info != NULL && uc != NULL && thread != NULL) {
 539     pc = address(SIG_PC(uc));
 540     npc = address(SIG_NPC(uc));
 541 
 542     if (checkPrefetch(uc, pc)) {
 543       return 1;
 544     }
 545 
 546     // Handle ALL stack overflow variations here
 547     if (sig == SIGSEGV) {
 548       if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) {
 549         return 1;
 550       }
 551     }
 552 
 553     if (sig == SIGBUS &&
 554         thread->thread_state() == _thread_in_vm &&
 555         thread->doing_unsafe_access()) {
 556       stub = SharedRuntime::handle_unsafe_access(thread, npc);
 557     }
 558 
 559     if (thread->thread_state() == _thread_in_Java) {
 560       do {
 561         // Java thread running in Java code => find exception handler if any
 562         // a fault inside compiled code, the interpreter, or a stub
 563 
 564         if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) {
 565           break;
 566         }
 567 
 568         if ((sig == SIGBUS) && checkByteBuffer(pc, npc, thread, &stub)) {
 569           break;
 570         }
 571 
 572         if ((sig == SIGSEGV || sig == SIGBUS) &&
 573             checkVerifyOops(pc, (address)info->si_addr, &stub)) {
 574           break;
 575         }
 576 
 577         if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) {
 578           break;
 579         }
 580 
 581         if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) {
 582           break;
 583         }
 584 
 585         if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) {
 586           break;
 587         }
 588 
 589         if ((sig == SIGSEGV) &&
 590             checkNullPointer(pc, info->si_addr, thread, &stub)) {
 591           break;
 592         }
 593       } while (0);
 594 
 595       // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
 596       // and the heap gets shrunk before the field access.
 597       if ((sig == SIGSEGV) || (sig == SIGBUS)) {
 598         checkFastJNIAccess(pc, &stub);
 599       }
 600     }
 601 
 602     if (stub != NULL) {
 603       // save all thread context in case we need to restore it
 604       thread->set_saved_exception_pc(pc);
 605       thread->set_saved_exception_npc(npc);
 606       os::Linux::ucontext_set_pc((ucontext_t*)uc, stub);
 607       return true;
 608     }
 609   }
 610 
 611   // signal-chaining
 612   if (os::Linux::chained_handler(sig, info, ucVoid)) {
 613     return true;
 614   }
 615 
 616   if (!abort_if_unrecognized) {
 617     // caller wants another chance, so give it to him
 618     return false;
 619   }
 620 
 621   if (pc == NULL && uc != NULL) {
 622     pc = os::Linux::ucontext_get_pc((const ucontext_t*)uc);
 623   }
 624 
 625   // unmask current signal
 626   sigset_t newset;
 627   sigemptyset(&newset);
 628   sigaddset(&newset, sig);
 629   sigprocmask(SIG_UNBLOCK, &newset, NULL);
 630 
 631   VMError::report_and_die(t, sig, pc, info, ucVoid);
 632 
 633   ShouldNotReachHere();
 634   return false;
 635 }
 636 
 637 void os::Linux::init_thread_fpu_state(void) {
 638   // Nothing to do
 639 }
 640 
 641 int os::Linux::get_fpu_control_word() {
 642   return 0;
 643 }
 644 
 645 void os::Linux::set_fpu_control_word(int fpu) {
 646   // nothing
 647 }
 648 
 649 bool os::is_allocatable(size_t bytes) {
 650   return true;
 651 }
 652 
 653 ///////////////////////////////////////////////////////////////////////////////
 654 // thread stack
 655 
 656 // Minimum usable stack sizes required to get to user code. Space for
 657 // HotSpot guard pages is added later.
 658 size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
 659 size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
 660 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 661 
 662 // return default stack size for thr_type
 663 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 664   // default stack size (compiler thread needs larger stack)
 665   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 666   return s;
 667 }
 668 
 669 #ifndef PRODUCT
 670 void os::verify_stack_alignment() {
 671 }
 672 #endif
 673 
 674 int os::extra_bang_size_in_bytes() {
 675   // SPARC does not require the additional stack bang.
 676   return 0;
 677 }