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