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 "macroAssembler_sparc.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "classfile/vmSymbols.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "code/icBuffer.hpp"
  34 #include "code/vtableStubs.hpp"
  35 #include "interpreter/interpreter.hpp"
  36 #include "memory/allocation.inline.hpp"
  37 #include "nativeInst_sparc.hpp"
  38 #include "os_share_solaris.hpp"
  39 #include "prims/jniFastGetField.hpp"
  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.inline.hpp"
  45 #include "runtime/java.hpp"
  46 #include "runtime/javaCalls.hpp"
  47 #include "runtime/mutexLocker.hpp"
  48 #include "runtime/osThread.hpp"
  49 #include "runtime/safepointMechanism.hpp"
  50 #include "runtime/sharedRuntime.hpp"
  51 #include "runtime/stubRoutines.hpp"
  52 #include "runtime/thread.inline.hpp"
  53 #include "runtime/timer.hpp"
  54 #include "utilities/events.hpp"
  55 #include "utilities/vmError.hpp"
  56 
  57 # include <signal.h>        // needed first to avoid name collision for "std" with SC 5.0
  58 
  59 // put OS-includes here
  60 # include <sys/types.h>
  61 # include <sys/mman.h>
  62 # include <pthread.h>
  63 # include <errno.h>
  64 # include <dlfcn.h>
  65 # include <stdio.h>
  66 # include <unistd.h>
  67 # include <sys/resource.h>
  68 # include <thread.h>
  69 # include <sys/stat.h>
  70 # include <sys/time.h>
  71 # include <sys/filio.h>
  72 # include <sys/utsname.h>
  73 # include <sys/systeminfo.h>
  74 # include <sys/socket.h>
  75 # include <sys/lwp.h>
  76 # include <poll.h>
  77 # include <sys/lwp.h>
  78 
  79 # define _STRUCTURED_PROC 1  //  this gets us the new structured proc interfaces of 5.6 & later
  80 # include <sys/procfs.h>     //  see comment in <sys/procfs.h>
  81 
  82 #define MAX_PATH (2 * K)
  83 
  84 // Minimum usable stack sizes required to get to user code. Space for
  85 // HotSpot guard pages is added later.
  86 size_t os::Posix::_compiler_thread_min_stack_allowed = 104 * K;
  87 size_t os::Posix::_java_thread_min_stack_allowed = 86 * K;
  88 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
  89 
  90 static void handle_unflushed_register_windows(gwindows_t *win) {
  91   int restore_count = win->wbcnt;
  92   int i;
  93 
  94   for(i=0; i<restore_count; i++) {
  95     address sp = ((address)win->spbuf[i]) + STACK_BIAS;
  96     address reg_win = (address)&win->wbuf[i];
  97     memcpy(sp,reg_win,sizeof(struct rwindow));
  98   }
  99 }
 100 
 101 char* os::non_memory_address_word() {
 102   // Must never look like an address returned by reserve_memory,
 103   // even in its subfields (as defined by the CPU immediate fields,
 104   // if the CPU splits constants across multiple instructions).
 105   // On SPARC, 0 != %hi(any real address), because there is no
 106   // allocation in the first 1Kb of the virtual address space.
 107   return (char*) 0;
 108 }
 109 
 110 // Validate a ucontext retrieved from walking a uc_link of a ucontext.
 111 // There are issues with libthread giving out uc_links for different threads
 112 // on the same uc_link chain and bad or circular links.
 113 //
 114 bool os::Solaris::valid_ucontext(Thread* thread, const ucontext_t* valid, const ucontext_t* suspect) {
 115   if (valid >= suspect ||
 116       valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags ||
 117       valid->uc_stack.ss_sp    != suspect->uc_stack.ss_sp    ||
 118       valid->uc_stack.ss_size  != suspect->uc_stack.ss_size) {
 119     DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");)
 120     return false;
 121   }
 122 
 123   if (thread->is_Java_thread()) {
 124     if (!thread->is_in_full_stack_checked((address)suspect)) {
 125       DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");)
 126       return false;
 127     }
 128     address _sp   = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS);
 129     if (!thread->is_in_full_stack_checked(_sp) ||
 130         !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) {
 131       DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");)
 132       return false;
 133     }
 134   }
 135   return true;
 136 }
 137 
 138 // We will only follow one level of uc_link since there are libthread
 139 // issues with ucontext linking and it is better to be safe and just
 140 // let caller retry later.
 141 const ucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread,
 142   const ucontext_t *uc) {
 143 
 144   const ucontext_t *retuc = NULL;
 145 
 146   // Sometimes the topmost register windows are not properly flushed.
 147   // i.e., if the kernel would have needed to take a page fault
 148   if (uc != NULL && uc->uc_mcontext.gwins != NULL) {
 149     ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
 150   }
 151 
 152   if (uc != NULL) {
 153     if (uc->uc_link == NULL) {
 154       // cannot validate without uc_link so accept current ucontext
 155       retuc = uc;
 156     } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
 157       // first ucontext is valid so try the next one
 158       uc = uc->uc_link;
 159       if (uc->uc_link == NULL) {
 160         // cannot validate without uc_link so accept current ucontext
 161         retuc = uc;
 162       } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) {
 163         // the ucontext one level down is also valid so return it
 164         retuc = uc;
 165       }
 166     }
 167   }
 168   return retuc;
 169 }
 170 
 171 // Assumes ucontext is valid
 172 ExtendedPC os::Solaris::ucontext_get_ExtendedPC(const ucontext_t *uc) {
 173   address pc = (address)uc->uc_mcontext.gregs[REG_PC];
 174   // set npc to zero to avoid using it for safepoint, good for profiling only
 175   return ExtendedPC(pc);
 176 }
 177 
 178 void os::Solaris::ucontext_set_pc(ucontext_t* uc, address pc) {
 179   uc->uc_mcontext.gregs [REG_PC]  = (greg_t) pc;
 180   uc->uc_mcontext.gregs [REG_nPC] = (greg_t) (pc + 4);
 181 }
 182 
 183 // Assumes ucontext is valid
 184 intptr_t* os::Solaris::ucontext_get_sp(const ucontext_t *uc) {
 185   return (intptr_t*)((intptr_t)uc->uc_mcontext.gregs[REG_SP] + STACK_BIAS);
 186 }
 187 
 188 // Solaris X86 only
 189 intptr_t* os::Solaris::ucontext_get_fp(const ucontext_t *uc) {
 190   ShouldNotReachHere();
 191   return NULL;
 192 }
 193 
 194 address os::Solaris::ucontext_get_pc(const ucontext_t *uc) {
 195   return (address) uc->uc_mcontext.gregs[REG_PC];
 196 }
 197 
 198 
 199 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
 200 // is currently interrupted by SIGPROF.
 201 //
 202 // ret_fp parameter is only used by Solaris X86.
 203 //
 204 // The difference between this and os::fetch_frame_from_context() is that
 205 // here we try to skip nested signal frames.
 206 // This method is also used for stack overflow signal handling.
 207 ExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread,
 208   const ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
 209 
 210   assert(thread != NULL, "just checking");
 211   assert(ret_sp != NULL, "just checking");
 212   assert(ret_fp == NULL, "just checking");
 213 
 214   const ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc);
 215 
 216   return os::fetch_frame_from_context(luc, ret_sp, ret_fp);
 217 }
 218 
 219 
 220 // ret_fp parameter is only used by Solaris X86.
 221 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 222                     intptr_t** ret_sp, intptr_t** ret_fp) {
 223 
 224   ExtendedPC  epc;
 225   const ucontext_t *uc = (const ucontext_t*)ucVoid;
 226 
 227   if (uc != NULL) {
 228     epc = os::Solaris::ucontext_get_ExtendedPC(uc);
 229     if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc);
 230   } else {
 231     // construct empty ExtendedPC for return value checking
 232     epc = ExtendedPC(NULL);
 233     if (ret_sp) *ret_sp = (intptr_t *)NULL;
 234   }
 235 
 236   return epc;
 237 }
 238 
 239 frame os::fetch_frame_from_context(const void* ucVoid) {
 240   intptr_t* sp;
 241   intptr_t* fp;
 242   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 243   return frame(sp, frame::unpatchable, epc.pc());
 244 }
 245 
 246 frame os::fetch_frame_from_ucontext(Thread* thread, void* ucVoid) {
 247   intptr_t* sp;
 248   ExtendedPC epc = os::Solaris::fetch_frame_from_ucontext(thread, (ucontext_t*)ucVoid, &sp, NULL);
 249   return frame(sp, frame::unpatchable, epc.pc());
 250 }
 251 
 252 bool os::Solaris::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
 253   address pc = (address) os::Solaris::ucontext_get_pc(uc);
 254   if (Interpreter::contains(pc)) {
 255     *fr = os::fetch_frame_from_ucontext(thread, uc);
 256     if (!fr->is_first_java_frame()) {
 257       assert(fr->safe_for_sender(thread), "Safety check");
 258       *fr = fr->java_sender();
 259     }
 260   } else {
 261     // more complex code with compiled code
 262     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 263     CodeBlob* cb = CodeCache::find_blob(pc);
 264     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 265       // Not sure where the pc points to, fallback to default
 266       // stack overflow handling
 267       return false;
 268     } else {
 269       // Returned frame will be the caller of the method that faults on the stack bang.
 270       // Register window not yet rotated (happens at SAVE after stack bang), so there is no new
 271       // frame to go with the faulting PC. Using caller SP that is still in SP, and caller PC
 272       // that was written to O7 at call.
 273       intptr_t* sp = os::Solaris::ucontext_get_sp(uc);
 274       address pc = (address)uc->uc_mcontext.gregs[REG_O7];
 275       *fr = frame(sp, frame::unpatchable, pc);
 276 
 277       if (!fr->is_java_frame()) {
 278         assert(fr->safe_for_sender(thread), "Safety check");
 279         *fr = fr->java_sender();
 280       }
 281     }
 282   }
 283   assert(fr->is_java_frame(), "Safety check");
 284   return true;
 285 }
 286 
 287 frame os::get_sender_for_C_frame(frame* fr) {
 288   return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc());
 289 }
 290 
 291 // Returns an estimate of the current stack pointer. Result must be guaranteed to
 292 // point into the calling threads stack, and be no lower than the current stack
 293 // pointer.
 294 address os::current_stack_pointer() {
 295   volatile int dummy;
 296   address sp = (address)&dummy + 8;     // %%%% need to confirm if this is right
 297   return sp;
 298 }
 299 
 300 frame os::current_frame() {
 301   intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
 302   frame myframe(sp, frame::unpatchable,
 303                 CAST_FROM_FN_PTR(address, os::current_frame));
 304   if (os::is_first_C_frame(&myframe)) {
 305     // stack is not walkable
 306     return frame(NULL, NULL, false);
 307   } else {
 308     return os::get_sender_for_C_frame(&myframe);
 309   }
 310 }
 311 
 312 bool os::is_allocatable(size_t bytes) {
 313    return true;
 314 }
 315 
 316 extern "C" JNIEXPORT int
 317 JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid,
 318                           int abort_if_unrecognized) {
 319   ucontext_t* uc = (ucontext_t*) ucVoid;
 320 
 321   Thread* t = Thread::current_or_null_safe();
 322 
 323   // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
 324   // (no destructors can be run)
 325   os::ThreadCrashProtection::check_crash_protection(sig, t);
 326 
 327   SignalHandlerMark shm(t);
 328 
 329   if(sig == SIGPIPE || sig == SIGXFSZ) {
 330     if (os::Solaris::chained_handler(sig, info, ucVoid)) {
 331       return true;
 332     } else {
 333       // Ignoring SIGPIPE/SIGXFSZ - see bugs 4229104 or 6499219
 334       return true;
 335     }
 336   }
 337 
 338   JavaThread* thread = NULL;
 339   VMThread* vmthread = NULL;
 340   if (os::Solaris::signal_handlers_are_installed) {
 341     if (t != NULL ){
 342       if(t->is_Java_thread()) {
 343         thread = (JavaThread*)t;
 344       }
 345       else if(t->is_VM_thread()){
 346         vmthread = (VMThread *)t;
 347       }
 348     }
 349   }
 350 
 351   if (sig == ASYNC_SIGNAL) {
 352     if (thread || vmthread) {
 353       OSThread::SR_handler(t, uc);
 354       return true;
 355     } else if (os::Solaris::chained_handler(sig, info, ucVoid)) {
 356       return true;
 357     } else {
 358       // If ASYNC_SIGNAL not chained, and this is a non-vm and
 359       // non-java thread
 360       return true;
 361     }
 362   }
 363 
 364   if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
 365     // can't decode this kind of signal
 366     info = NULL;
 367   } else {
 368     assert(sig == info->si_signo, "bad siginfo");
 369   }
 370 
 371   // decide if this trap can be handled by a stub
 372   address stub = NULL;
 373 
 374   address pc          = NULL;
 375   address npc         = NULL;
 376 
 377   //%note os_trap_1
 378   if (info != NULL && uc != NULL && thread != NULL) {
 379     // factor me: getPCfromContext
 380     pc  = (address) uc->uc_mcontext.gregs[REG_PC];
 381     npc = (address) uc->uc_mcontext.gregs[REG_nPC];
 382 
 383     // SafeFetch() support
 384     if (StubRoutines::is_safefetch_fault(pc)) {
 385       os::Solaris::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 386       return 1;
 387     }
 388 
 389     // Handle ALL stack overflow variations here
 390     if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) {
 391       address addr = (address) info->si_addr;
 392       if (thread->in_stack_yellow_reserved_zone(addr)) {
 393         // Sometimes the register windows are not properly flushed.
 394         if(uc->uc_mcontext.gwins != NULL) {
 395           ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
 396         }
 397         if (thread->thread_state() == _thread_in_Java) {
 398           if (thread->in_stack_reserved_zone(addr)) {
 399             frame fr;
 400             if (os::Solaris::get_frame_at_stack_banging_point(thread, uc, &fr)) {
 401               assert(fr.is_java_frame(), "Must be a Java frame");
 402               frame activation = SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
 403               if (activation.sp() != NULL) {
 404                 thread->disable_stack_reserved_zone();
 405                 RegisterMap map(thread);
 406                 int frame_size = activation.frame_size(&map);
 407                 thread->set_reserved_stack_activation((address)(((address)activation.sp()) - STACK_BIAS));
 408                 return true;
 409               }
 410             }
 411           }
 412           // Throw a stack overflow exception.  Guard pages will be reenabled
 413           // while unwinding the stack.
 414           thread->disable_stack_yellow_reserved_zone();
 415           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 416         } else {
 417           // Thread was in the vm or native code.  Return and try to finish.
 418           thread->disable_stack_yellow_reserved_zone();
 419           return true;
 420         }
 421       } else if (thread->in_stack_red_zone(addr)) {
 422         // Fatal red zone violation.  Disable the guard pages and fall through
 423         // to handle_unexpected_exception way down below.
 424         thread->disable_stack_red_zone();
 425         tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
 426         // Sometimes the register windows are not properly flushed.
 427         if(uc->uc_mcontext.gwins != NULL) {
 428           ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
 429         }
 430       }
 431     }
 432 
 433 
 434     if (thread->thread_state() == _thread_in_vm ||
 435         thread->thread_state() == _thread_in_native) {
 436       if (sig == SIGBUS && thread->doing_unsafe_access()) {
 437         if (UnsafeCopyMemory::contains_pc(pc)) {
 438           npc = UnsafeCopyMemory::page_error_continue_pc(pc);
 439         }
 440         stub = SharedRuntime::handle_unsafe_access(thread, npc);
 441       }
 442     }
 443 
 444     else if (thread->thread_state() == _thread_in_Java) {
 445       // Java thread running in Java code => find exception handler if any
 446       // a fault inside compiled code, the interpreter, or a stub
 447 
 448       // Support Safepoint Polling
 449       if (sig == SIGSEGV && SafepointMechanism::is_poll_address((address)info->si_addr)) {
 450         stub = SharedRuntime::get_poll_stub(pc);
 451       }
 452 
 453       // Not needed on x86 solaris because verify_oops doesn't generate
 454       // SEGV/BUS like sparc does.
 455       if ( (sig == SIGSEGV || sig == SIGBUS)
 456            && pc >= MacroAssembler::_verify_oop_implicit_branch[0]
 457            && pc <  MacroAssembler::_verify_oop_implicit_branch[1] ) {
 458         stub     =  MacroAssembler::_verify_oop_implicit_branch[2];
 459         warning("fixed up memory fault in +VerifyOops at address " INTPTR_FORMAT, info->si_addr);
 460       }
 461 
 462       // This is not factored because on x86 solaris the patching for
 463       // zombies does not generate a SEGV.
 464       else if (sig == SIGSEGV && nativeInstruction_at(pc)->is_zombie()) {
 465         // zombie method (ld [%g0],%o7 instruction)
 466         stub = SharedRuntime::get_handle_wrong_method_stub();
 467 
 468         // At the stub it needs to look like a call from the caller of this
 469         // method (not a call from the segv site).
 470         pc = (address)uc->uc_mcontext.gregs[REG_O7];
 471       }
 472       else if (sig == SIGBUS && info->si_code == BUS_OBJERR) {
 473         // BugId 4454115: A read from a MappedByteBuffer can fault
 474         // here if the underlying file has been truncated.
 475         // Do not crash the VM in such a case.
 476         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 477         CompiledMethod* nm = cb->as_compiled_method_or_null();
 478         bool is_unsafe_arraycopy = (thread->doing_unsafe_access() && UnsafeCopyMemory::contains_pc(pc));
 479         if ((nm != NULL && nm->has_unsafe_access()) || is_unsafe_arraycopy) {
 480           if (is_unsafe_arraycopy) {
 481             npc = UnsafeCopyMemory::page_error_continue_pc(pc);
 482           }
 483           stub = SharedRuntime::handle_unsafe_access(thread, npc);
 484         }
 485       }
 486 
 487       else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
 488         // integer divide by zero
 489         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 490       }
 491       else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) {
 492         // floating-point divide by zero
 493         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 494       }
 495 #ifdef COMPILER2
 496       else if (sig == SIGILL && nativeInstruction_at(pc)->is_ic_miss_trap()) {
 497 #ifdef ASSERT
 498   #ifdef TIERED
 499         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 500         assert(cb->is_compiled_by_c2(), "Wrong compiler");
 501   #endif // TIERED
 502 #endif // ASSERT
 503         // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken.
 504         stub = SharedRuntime::get_ic_miss_stub();
 505         // At the stub it needs to look like a call from the caller of this
 506         // method (not a call from the segv site).
 507         pc = (address)uc->uc_mcontext.gregs[REG_O7];
 508       }
 509 #endif  // COMPILER2
 510 
 511       else if (sig == SIGSEGV && info->si_code > 0 && MacroAssembler::uses_implicit_null_check(info->si_addr)) {
 512         // Determination of interpreter/vtable stub/compiled code null exception
 513         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 514       }
 515     }
 516 
 517     // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
 518     // and the heap gets shrunk before the field access.
 519     if ((sig == SIGSEGV) || (sig == SIGBUS)) {
 520       address addr = JNI_FastGetField::find_slowcase_pc(pc);
 521       if (addr != (address)-1) {
 522         stub = addr;
 523       }
 524     }
 525   }
 526 
 527   if (stub != NULL) {
 528     // save all thread context in case we need to restore it
 529 
 530     thread->set_saved_exception_pc(pc);
 531     thread->set_saved_exception_npc(npc);
 532 
 533     // simulate a branch to the stub (a "call" in the safepoint stub case)
 534     // factor me: setPC
 535     os::Solaris::ucontext_set_pc(uc, stub);
 536 
 537     return true;
 538   }
 539 
 540   // signal-chaining
 541   if (os::Solaris::chained_handler(sig, info, ucVoid)) {
 542     return true;
 543   }
 544 
 545   if (!abort_if_unrecognized) {
 546     // caller wants another chance, so give it to him
 547     return false;
 548   }
 549 
 550   if (!os::Solaris::libjsig_is_loaded) {
 551     struct sigaction oldAct;
 552     sigaction(sig, (struct sigaction *)0, &oldAct);
 553     if (oldAct.sa_sigaction != signalHandler) {
 554       void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
 555                                           : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
 556       warning("Unexpected Signal %d occurred under user-defined signal handler " INTPTR_FORMAT, sig, (intptr_t)sighand);
 557     }
 558   }
 559 
 560   if (pc == NULL && uc != NULL) {
 561     pc = (address) uc->uc_mcontext.gregs[REG_PC];
 562   }
 563 
 564   // Sometimes the register windows are not properly flushed.
 565   if(uc->uc_mcontext.gwins != NULL) {
 566     ::handle_unflushed_register_windows(uc->uc_mcontext.gwins);
 567   }
 568 
 569   // unmask current signal
 570   sigset_t newset;
 571   sigemptyset(&newset);
 572   sigaddset(&newset, sig);
 573   sigprocmask(SIG_UNBLOCK, &newset, NULL);
 574 
 575   // Determine which sort of error to throw.  Out of swap may signal
 576   // on the thread stack, which could get a mapping error when touched.
 577   address addr = (address) info->si_addr;
 578   if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) {
 579     vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "Out of swap space to map in thread stack.");
 580   }
 581 
 582   VMError::report_and_die(t, sig, pc, info, ucVoid);
 583 
 584   ShouldNotReachHere();
 585   return false;
 586 }
 587 
 588 void os::print_context(outputStream *st, const void *context) {
 589   if (context == NULL) return;
 590 
 591   const ucontext_t *uc = (const ucontext_t*)context;
 592   st->print_cr("Registers:");
 593 
 594   st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT
 595                " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT,
 596             uc->uc_mcontext.gregs[REG_G1],
 597             uc->uc_mcontext.gregs[REG_G2],
 598             uc->uc_mcontext.gregs[REG_G3],
 599             uc->uc_mcontext.gregs[REG_G4]);
 600   st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT
 601                " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT,
 602             uc->uc_mcontext.gregs[REG_G5],
 603             uc->uc_mcontext.gregs[REG_G6],
 604             uc->uc_mcontext.gregs[REG_G7],
 605             uc->uc_mcontext.gregs[REG_Y]);
 606   st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT
 607                " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT,
 608                  uc->uc_mcontext.gregs[REG_O0],
 609                  uc->uc_mcontext.gregs[REG_O1],
 610                  uc->uc_mcontext.gregs[REG_O2],
 611                  uc->uc_mcontext.gregs[REG_O3]);
 612   st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT
 613                " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT,
 614             uc->uc_mcontext.gregs[REG_O4],
 615             uc->uc_mcontext.gregs[REG_O5],
 616             uc->uc_mcontext.gregs[REG_O6],
 617             uc->uc_mcontext.gregs[REG_O7]);
 618 
 619 
 620   intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
 621   st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT
 622                " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT,
 623                sp[L0->sp_offset_in_saved_window()],
 624                sp[L1->sp_offset_in_saved_window()],
 625                sp[L2->sp_offset_in_saved_window()],
 626                sp[L3->sp_offset_in_saved_window()]);
 627   st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT
 628                " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT,
 629                sp[L4->sp_offset_in_saved_window()],
 630                sp[L5->sp_offset_in_saved_window()],
 631                sp[L6->sp_offset_in_saved_window()],
 632                sp[L7->sp_offset_in_saved_window()]);
 633   st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT
 634                " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT,
 635                sp[I0->sp_offset_in_saved_window()],
 636                sp[I1->sp_offset_in_saved_window()],
 637                sp[I2->sp_offset_in_saved_window()],
 638                sp[I3->sp_offset_in_saved_window()]);
 639   st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT
 640                " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT,
 641                sp[I4->sp_offset_in_saved_window()],
 642                sp[I5->sp_offset_in_saved_window()],
 643                sp[I6->sp_offset_in_saved_window()],
 644                sp[I7->sp_offset_in_saved_window()]);
 645 
 646   st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT,
 647             uc->uc_mcontext.gregs[REG_PC],
 648             uc->uc_mcontext.gregs[REG_nPC]);
 649   st->cr();
 650   st->cr();
 651 
 652   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
 653   print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t));
 654   st->cr();
 655 
 656   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 657   // point to garbage if entry point in an nmethod is corrupted. Leave
 658   // this at the end, and hope for the best.
 659   ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc);
 660   address pc = epc.pc();
 661   print_instructions(st, pc, sizeof(char));
 662   st->cr();
 663 }
 664 
 665 void os::print_register_info(outputStream *st, const void *context) {
 666   if (context == NULL) return;
 667 
 668   const ucontext_t *uc = (const ucontext_t*)context;
 669   intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc);
 670 
 671   st->print_cr("Register to memory mapping:");
 672   st->cr();
 673 
 674   // this is only for the "general purpose" registers
 675   st->print("G1="); print_location(st, uc->uc_mcontext.gregs[REG_G1]);
 676   st->print("G2="); print_location(st, uc->uc_mcontext.gregs[REG_G2]);
 677   st->print("G3="); print_location(st, uc->uc_mcontext.gregs[REG_G3]);
 678   st->print("G4="); print_location(st, uc->uc_mcontext.gregs[REG_G4]);
 679   st->print("G5="); print_location(st, uc->uc_mcontext.gregs[REG_G5]);
 680   st->print("G6="); print_location(st, uc->uc_mcontext.gregs[REG_G6]);
 681   st->print("G7="); print_location(st, uc->uc_mcontext.gregs[REG_G7]);
 682   st->cr();
 683 
 684   st->print("O0="); print_location(st, uc->uc_mcontext.gregs[REG_O0]);
 685   st->print("O1="); print_location(st, uc->uc_mcontext.gregs[REG_O1]);
 686   st->print("O2="); print_location(st, uc->uc_mcontext.gregs[REG_O2]);
 687   st->print("O3="); print_location(st, uc->uc_mcontext.gregs[REG_O3]);
 688   st->print("O4="); print_location(st, uc->uc_mcontext.gregs[REG_O4]);
 689   st->print("O5="); print_location(st, uc->uc_mcontext.gregs[REG_O5]);
 690   st->print("O6="); print_location(st, uc->uc_mcontext.gregs[REG_O6]);
 691   st->print("O7="); print_location(st, uc->uc_mcontext.gregs[REG_O7]);
 692   st->cr();
 693 
 694   st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]);
 695   st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]);
 696   st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]);
 697   st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]);
 698   st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]);
 699   st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]);
 700   st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]);
 701   st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]);
 702   st->cr();
 703 
 704   st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]);
 705   st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]);
 706   st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]);
 707   st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]);
 708   st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]);
 709   st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]);
 710   st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]);
 711   st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]);
 712   st->cr();
 713 }
 714 
 715 void os::Solaris::init_thread_fpu_state(void) {
 716     // Nothing needed on Sparc.
 717 }
 718 
 719 #ifndef PRODUCT
 720 void os::verify_stack_alignment() {
 721 }
 722 #endif
 723 
 724 int os::extra_bang_size_in_bytes() {
 725   // SPARC does not require an additional stack bang.
 726   return 0;
 727 }