1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2016, 2017 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 // This file is organized as os_linux_x86.cpp.
  27 
  28 // no precompiled headers
  29 #include "jvm.h"
  30 #include "asm/assembler.inline.hpp"
  31 #include "classfile/classLoader.hpp"
  32 #include "classfile/systemDictionary.hpp"
  33 #include "classfile/vmSymbols.hpp"
  34 #include "code/icBuffer.hpp"
  35 #include "code/nativeInst.hpp"
  36 #include "code/vtableStubs.hpp"
  37 #include "compiler/disassembler.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "memory/allocation.inline.hpp"
  40 #include "nativeInst_s390.hpp"
  41 #include "os_share_linux.hpp"
  42 #include "prims/jniFastGetField.hpp"
  43 #include "prims/jvm_misc.hpp"
  44 #include "runtime/arguments.hpp"
  45 #include "runtime/extendedPC.hpp"
  46 #include "runtime/frame.inline.hpp"
  47 #include "runtime/interfaceSupport.hpp"
  48 #include "runtime/java.hpp"
  49 #include "runtime/javaCalls.hpp"
  50 #include "runtime/mutexLocker.hpp"
  51 #include "runtime/osThread.hpp"
  52 #include "runtime/sharedRuntime.hpp"
  53 #include "runtime/stubRoutines.hpp"
  54 #include "runtime/thread.inline.hpp"
  55 #include "runtime/timer.hpp"
  56 #include "utilities/events.hpp"
  57 #include "utilities/vmError.hpp"
  58 
  59 // put OS-includes here
  60 # include <sys/types.h>
  61 # include <sys/mman.h>
  62 # include <pthread.h>
  63 # include <signal.h>
  64 # include <errno.h>
  65 # include <dlfcn.h>
  66 # include <stdlib.h>
  67 # include <stdio.h>
  68 # include <unistd.h>
  69 # include <sys/resource.h>
  70 # include <pthread.h>
  71 # include <sys/stat.h>
  72 # include <sys/time.h>
  73 # include <sys/utsname.h>
  74 # include <sys/socket.h>
  75 # include <sys/wait.h>
  76 # include <pwd.h>
  77 # include <poll.h>
  78 # include <ucontext.h>
  79 
  80 address os::current_stack_pointer() {
  81   intptr_t* csp;
  82 
  83   // Inline assembly for `z_lgr regno(csp), Z_SP' (Z_SP = Z_R15):
  84   __asm__ __volatile__ ("lgr %0, 15":"=r"(csp):);
  85 
  86   assert(((uint64_t)csp & (frame::alignment_in_bytes-1)) == 0, "SP must be aligned");
  87   return (address) csp;
  88 }
  89 
  90 char* os::non_memory_address_word() {
  91   // Must never look like an address returned by reserve_memory,
  92   // even in its subfields (as defined by the CPU immediate fields,
  93   // if the CPU splits constants across multiple instructions).
  94   return (char*) -1;
  95 }
  96 
  97 // OS specific thread initialization.
  98 void os::initialize_thread(Thread* thread) { }
  99 
 100 // Frame information (pc, sp, fp) retrieved via ucontext
 101 // always looks like a C-frame according to the frame
 102 // conventions in frame_s390.hpp.
 103 address os::Linux::ucontext_get_pc(const ucontext_t * uc) {
 104   return (address)uc->uc_mcontext.psw.addr;
 105 }
 106 
 107 void os::Linux::ucontext_set_pc(ucontext_t * uc, address pc) {
 108   uc->uc_mcontext.psw.addr = (unsigned long)pc;
 109 }
 110 
 111 intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
 112   return (intptr_t*)uc->uc_mcontext.gregs[15/*REG_SP*/];
 113 }
 114 
 115 intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
 116   return NULL;
 117 }
 118 
 119 ExtendedPC os::fetch_frame_from_context(const void* ucVoid,
 120                     intptr_t** ret_sp, intptr_t** ret_fp) {
 121 
 122   ExtendedPC  epc;
 123   const ucontext_t* uc = (const ucontext_t*)ucVoid;
 124 
 125   if (uc != NULL) {
 126     epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
 127     if (ret_sp) { *ret_sp = os::Linux::ucontext_get_sp(uc); }
 128     if (ret_fp) { *ret_fp = os::Linux::ucontext_get_fp(uc); }
 129   } else {
 130     // Construct empty ExtendedPC for return value checking.
 131     epc = ExtendedPC(NULL);
 132     if (ret_sp) { *ret_sp = (intptr_t *)NULL; }
 133     if (ret_fp) { *ret_fp = (intptr_t *)NULL; }
 134   }
 135 
 136   return epc;
 137 }
 138 
 139 frame os::fetch_frame_from_context(const void* ucVoid) {
 140   intptr_t* sp;
 141   intptr_t* fp;
 142   ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
 143   return frame(sp, epc.pc());
 144 }
 145 
 146 bool os::Linux::get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr) {
 147   address pc = (address) os::Linux::ucontext_get_pc(uc);
 148   if (Interpreter::contains(pc)) {
 149     // Interpreter performs stack banging after the fixed frame header has
 150     // been generated while the compilers perform it before. To maintain
 151     // semantic consistency between interpreted and compiled frames, the
 152     // method returns the Java sender of the current frame.
 153     *fr = os::fetch_frame_from_context(uc);
 154     if (!fr->is_first_java_frame()) {
 155       assert(fr->safe_for_sender(thread), "Safety check");
 156       *fr = fr->java_sender();
 157     }
 158   } else {
 159     // More complex code with compiled code.
 160     assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
 161     CodeBlob* cb = CodeCache::find_blob(pc);
 162     if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) {
 163       // Not sure where the pc points to, fallback to default
 164       // stack overflow handling. In compiled code, we bang before
 165       // the frame is complete.
 166       return false;
 167     } else {
 168       intptr_t* fp = os::Linux::ucontext_get_fp(uc);
 169       intptr_t* sp = os::Linux::ucontext_get_sp(uc);
 170       *fr = frame(sp, (address)*sp);
 171       if (!fr->is_java_frame()) {
 172         assert(fr->safe_for_sender(thread), "Safety check");
 173         assert(!fr->is_first_frame(), "Safety check");
 174         *fr = fr->java_sender();
 175       }
 176     }
 177   }
 178   assert(fr->is_java_frame(), "Safety check");
 179   return true;
 180 }
 181 
 182 frame os::get_sender_for_C_frame(frame* fr) {
 183   if (*fr->sp() == 0) {
 184     // fr is the last C frame.
 185     return frame();
 186   }
 187 
 188   // If its not one of our frames, the return pc is saved at gpr14
 189   // stack slot. The call_stub stores the return_pc to the stack slot
 190   // of gpr10.
 191   if ((Interpreter::code() != NULL && Interpreter::contains(fr->pc())) ||
 192       (CodeCache::contains(fr->pc()) && !StubRoutines::contains(fr->pc()))) {
 193     return frame(fr->sender_sp(), fr->sender_pc());
 194   } else {
 195     if (StubRoutines::contains(fr->pc())) {
 196       StubCodeDesc* desc = StubCodeDesc::desc_for(fr->pc());
 197       if (desc && !strcmp(desc->name(),"call_stub")) {
 198         return frame(fr->sender_sp(), fr->callstub_sender_pc());
 199       } else {
 200         return frame(fr->sender_sp(), fr->sender_pc());
 201       }
 202     } else {
 203       return frame(fr->sender_sp(), fr->native_sender_pc());
 204     }
 205   }
 206 }
 207 
 208 frame os::current_frame() {
 209   // Expected to return the stack pointer of this method.
 210   // But if inlined, returns the stack pointer of our caller!
 211   intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
 212   assert (csp != NULL, "sp should not be NULL");
 213   // Pass a dummy pc. This way we don't have to load it from the
 214   // stack, since we don't know in which slot we can find it.
 215   frame topframe(csp, (address)0x8);
 216   if (os::is_first_C_frame(&topframe)) {
 217     // Stack is not walkable.
 218     return frame();
 219   } else {
 220     frame senderFrame = os::get_sender_for_C_frame(&topframe);
 221     assert(senderFrame.pc() != NULL, "Sender pc should not be NULL");
 222     // Return sender of sender of current topframe which hopefully
 223     // both have pc != NULL.
 224 #ifdef _NMT_NOINLINE_   // Is set in slowdebug builds.
 225     // Current_stack_pointer is not inlined, we must pop one more frame.
 226     frame tmp = os::get_sender_for_C_frame(&topframe);
 227     return os::get_sender_for_C_frame(&tmp);
 228 #else
 229     return os::get_sender_for_C_frame(&topframe);
 230 #endif
 231   }
 232 }
 233 
 234 // Utility functions
 235 
 236 extern "C" JNIEXPORT int
 237 JVM_handle_linux_signal(int sig,
 238                         siginfo_t* info,
 239                         void* ucVoid,
 240                         int abort_if_unrecognized) {
 241   ucontext_t* uc = (ucontext_t*) ucVoid;
 242 
 243   Thread* t = Thread::current_or_null_safe();
 244 
 245   // Must do this before SignalHandlerMark, if crash protection installed we will longjmp away
 246   // (no destructors can be run).
 247   os::ThreadCrashProtection::check_crash_protection(sig, t);
 248 
 249   SignalHandlerMark shm(t);
 250 
 251   // Note: it's not uncommon that JNI code uses signal/sigset to install
 252   // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
 253   // or have a SIGILL handler when detecting CPU type). When that happens,
 254   // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
 255   // avoid unnecessary crash when libjsig is not preloaded, try handle signals
 256   // that do not require siginfo/ucontext first.
 257 
 258   if (sig == SIGPIPE) {
 259     if (os::Linux::chained_handler(sig, info, ucVoid)) {
 260       return true;
 261     } else {
 262       if (PrintMiscellaneous && (WizardMode || Verbose)) {
 263         warning("Ignoring SIGPIPE - see bug 4229104");
 264       }
 265       return true;
 266     }
 267   }
 268 
 269   JavaThread* thread = NULL;
 270   VMThread* vmthread = NULL;
 271   if (os::Linux::signal_handlers_are_installed) {
 272     if (t != NULL) {
 273       if(t->is_Java_thread()) {
 274         thread = (JavaThread*)t;
 275       } else if(t->is_VM_thread()) {
 276         vmthread = (VMThread *)t;
 277       }
 278     }
 279   }
 280 
 281   // Moved SafeFetch32 handling outside thread!=NULL conditional block to make
 282   // it work if no associated JavaThread object exists.
 283   if (uc) {
 284     address const pc = os::Linux::ucontext_get_pc(uc);
 285     if (pc && StubRoutines::is_safefetch_fault(pc)) {
 286       os::Linux::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
 287       return true;
 288     }
 289   }
 290 
 291   // Decide if this trap can be handled by a stub.
 292   address stub    = NULL;
 293   address pc      = NULL;  // Pc as retrieved from PSW. Usually points past failing instruction.
 294   address trap_pc = NULL;  // Pc of the instruction causing the trap.
 295 
 296   //%note os_trap_1
 297   if (info != NULL && uc != NULL && thread != NULL) {
 298     pc = os::Linux::ucontext_get_pc(uc);
 299     if (TraceTraps) {
 300       tty->print_cr("     pc at " INTPTR_FORMAT, p2i(pc));
 301     }
 302     if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {
 303       trap_pc = (address)info->si_addr;
 304       if (TraceTraps) {
 305         tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));
 306       }
 307     }
 308 
 309     // Handle ALL stack overflow variations here
 310     if (sig == SIGSEGV) {
 311       address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.
 312 
 313       // Check if fault address is within thread stack.
 314       if (thread->on_local_stack(addr)) {
 315         // stack overflow
 316         if (thread->in_stack_yellow_reserved_zone(addr)) {
 317           if (thread->thread_state() == _thread_in_Java) {
 318             if (thread->in_stack_reserved_zone(addr)) {
 319               frame fr;
 320               if (os::Linux::get_frame_at_stack_banging_point(thread, uc, &fr)) {
 321                 assert(fr.is_java_frame(), "Must be a Javac frame");
 322                 frame activation =
 323                   SharedRuntime::look_for_reserved_stack_annotated_method(thread, fr);
 324                 if (activation.sp() != NULL) {
 325                   thread->disable_stack_reserved_zone();
 326                   if (activation.is_interpreted_frame()) {
 327                     thread->set_reserved_stack_activation((address)activation.fp());
 328                   } else {
 329                     thread->set_reserved_stack_activation((address)activation.unextended_sp());
 330                   }
 331                   return 1;
 332                 }
 333               }
 334             }
 335             // Throw a stack overflow exception.
 336             // Guard pages will be reenabled while unwinding the stack.
 337             thread->disable_stack_yellow_reserved_zone();
 338             stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
 339           } else {
 340             // Thread was in the vm or native code. Return and try to finish.
 341             thread->disable_stack_yellow_reserved_zone();
 342             return 1;
 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 1;
 364              }
 365              thread->osthread()->clear_expanding_stack();
 366           } else {
 367              fatal("recursive segv. expanding stack.");
 368           }
 369         }
 370       }
 371     }
 372 
 373     if (thread->thread_state() == _thread_in_Java) {
 374       // Java thread running in Java code => find exception handler if any
 375       // a fault inside compiled code, the interpreter, or a stub
 376 
 377       // Handle signal from NativeJump::patch_verified_entry().
 378       if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
 379         if (TraceTraps) {
 380           tty->print_cr("trap: zombie_not_entrant (SIGILL)");
 381         }
 382         stub = SharedRuntime::get_handle_wrong_method_stub();
 383       }
 384 
 385       else if (sig == SIGSEGV &&
 386                os::is_poll_address((address)info->si_addr)) {
 387         if (TraceTraps) {
 388           tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
 389         }
 390         stub = SharedRuntime::get_poll_stub(pc);
 391 
 392         // Info->si_addr only points to the page base address, so we
 393         // must extract the real si_addr from the instruction and the
 394         // ucontext.
 395         assert(((NativeInstruction*)pc)->is_safepoint_poll(), "must be safepoint poll");
 396         const address real_si_addr = ((NativeInstruction*)pc)->get_poll_address(uc);
 397       }
 398 
 399       // SIGTRAP-based implicit null check in compiled code.
 400       else if ((sig == SIGFPE) &&
 401                TrapBasedNullChecks &&
 402                (trap_pc != NULL) &&
 403                Assembler::is_sigtrap_zero_check(trap_pc)) {
 404         if (TraceTraps) {
 405           tty->print_cr("trap: NULL_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
 406         }
 407         stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
 408       }
 409 
 410       else if (sig == SIGSEGV && ImplicitNullChecks &&
 411                CodeCache::contains((void*) pc) &&
 412                !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
 413         if (TraceTraps) {
 414           tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
 415         }
 416         stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
 417       }
 418 
 419       // SIGTRAP-based implicit range check in compiled code.
 420       else if (sig == SIGFPE && TrapBasedRangeChecks &&
 421                (trap_pc != NULL) &&
 422                Assembler::is_sigtrap_range_check(trap_pc)) {
 423         if (TraceTraps) {
 424           tty->print_cr("trap: RANGE_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
 425         }
 426         stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
 427       }
 428 
 429       else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
 430         stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
 431       }
 432 
 433       else if (sig == SIGBUS) {
 434         // BugId 4454115: A read from a MappedByteBuffer can fault here if the
 435         // underlying file has been truncated. Do not crash the VM in such a case.
 436         CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
 437         CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
 438         if (nm != NULL && nm->has_unsafe_access()) {
 439           // We don't really need a stub here! Just set the pending exeption and
 440           // continue at the next instruction after the faulting read. Returning
 441           // garbage from this read is ok.
 442           thread->set_pending_unsafe_access_error();
 443           uc->uc_mcontext.psw.addr = ((unsigned long)pc) + Assembler::instr_len(pc);
 444           return true;
 445         }
 446       }
 447     }
 448 
 449     else { // thread->thread_state() != _thread_in_Java
 450       if ((sig == SIGILL) && VM_Version::is_determine_features_test_running()) {
 451         // SIGILL must be caused by VM_Version::determine_features()
 452         // when attempting to execute a non-existing instruction.
 453         //*(int *) (pc-6)=0; // Patch instruction to 0 to indicate that it causes a SIGILL.
 454                              // Flushing of icache is not necessary.
 455         stub = pc; // Continue with next instruction.
 456       } else if ((sig == SIGFPE) && VM_Version::is_determine_features_test_running()) {
 457         // SIGFPE is known to be caused by trying to execute a vector instruction
 458         // when the vector facility is installed, but operating system support is missing.
 459         VM_Version::reset_has_VectorFacility();
 460         stub = pc; // Continue with next instruction.
 461       } else if (thread->thread_state() == _thread_in_vm &&
 462                  sig == SIGBUS && thread->doing_unsafe_access()) {
 463         // We don't really need a stub here! Just set the pending exeption and
 464         // continue at the next instruction after the faulting read. Returning
 465         // garbage from this read is ok.
 466         thread->set_pending_unsafe_access_error();
 467         os::Linux::ucontext_set_pc(uc, pc + Assembler::instr_len(pc));
 468         return true;
 469       }
 470     }
 471 
 472     // Check to see if we caught the safepoint code in the
 473     // process of write protecting the memory serialization page.
 474     // It write enables the page immediately after protecting it
 475     // so we can just return to retry the write.
 476     // Info->si_addr need not be the exact address, it is only
 477     // guaranteed to be on the same page as the address that caused
 478     // the SIGSEGV.
 479     if ((sig == SIGSEGV) && !UseMembar &&
 480         (os::get_memory_serialize_page() ==
 481          (address)((uintptr_t)info->si_addr & ~(os::vm_page_size()-1)))) {
 482       return true;
 483     }
 484   }
 485 
 486   if (stub != NULL) {
 487     // Save all thread context in case we need to restore it.
 488     if (thread != NULL) thread->set_saved_exception_pc(pc);
 489     os::Linux::ucontext_set_pc(uc, stub);
 490     return true;
 491   }
 492 
 493   // signal-chaining
 494   if (os::Linux::chained_handler(sig, info, ucVoid)) {
 495     return true;
 496   }
 497 
 498   if (!abort_if_unrecognized) {
 499     // caller wants another chance, so give it to him
 500     return false;
 501   }
 502 
 503   if (pc == NULL && uc != NULL) {
 504     pc = os::Linux::ucontext_get_pc(uc);
 505   }
 506 
 507   // unmask current signal
 508   sigset_t newset;
 509   sigemptyset(&newset);
 510   sigaddset(&newset, sig);
 511   sigprocmask(SIG_UNBLOCK, &newset, NULL);
 512 
 513   // Hand down correct pc for SIGILL, SIGFPE. pc from context
 514   // usually points to the instruction after the failing instruction.
 515   // Note: this should be combined with the trap_pc handling above,
 516   // because it handles the same issue.
 517   if (sig == SIGILL || sig == SIGFPE) {
 518     pc = (address)info->si_addr;
 519   }
 520 
 521   VMError::report_and_die(t, sig, pc, info, ucVoid);
 522 
 523   ShouldNotReachHere();
 524   return false;
 525 }
 526 
 527 void os::Linux::init_thread_fpu_state(void) {
 528   // Nothing to do on z/Architecture.
 529 }
 530 
 531 int os::Linux::get_fpu_control_word(void) {
 532   // Nothing to do on z/Architecture.
 533   return 0;
 534 }
 535 
 536 void os::Linux::set_fpu_control_word(int fpu_control) {
 537   // Nothing to do on z/Architecture.
 538 }
 539 
 540 ////////////////////////////////////////////////////////////////////////////////
 541 // thread stack
 542 
 543 // Minimum usable stack sizes required to get to user code. Space for
 544 // HotSpot guard pages is added later.
 545 size_t os::Posix::_compiler_thread_min_stack_allowed = (52 DEBUG_ONLY(+ 32)) * K;
 546 size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 8)) * K;
 547 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 32 * K;
 548 
 549 // Return default stack size for thr_type.
 550 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
 551   // Default stack size (compiler thread needs larger stack).
 552   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
 553   return s;
 554 }
 555 
 556 /////////////////////////////////////////////////////////////////////////////
 557 // helper functions for fatal error handler
 558 
 559 void os::print_context(outputStream *st, const void *context) {
 560   if (context == NULL) return;
 561 
 562   const ucontext_t* uc = (const ucontext_t*)context;
 563 
 564   st->print_cr("Processor state:");
 565   st->print_cr("----------------");
 566   st->print_cr("        ip = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.addr);
 567   st->print_cr(" proc mask = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.mask);
 568   st->print_cr("   fpc reg = 0x%8.8x "          , uc->uc_mcontext.fpregs.fpc);
 569   st->cr();
 570 
 571   st->print_cr("General Purpose Registers:");
 572   st->print_cr("--------------------------");
 573   for( int i = 0; i < 16; i+=2 ) {
 574     st->print("  r%-2d = " INTPTR_FORMAT "  " ,  i,   uc->uc_mcontext.gregs[i]);
 575     st->print("  r%-2d = " INTPTR_FORMAT "  |",  i+1, uc->uc_mcontext.gregs[i+1]);
 576     st->print("  r%-2d = %23.1ld  "           ,  i,   uc->uc_mcontext.gregs[i]);
 577     st->print("  r%-2d = %23.1ld  "           ,  i+1, uc->uc_mcontext.gregs[i+1]);
 578     st->cr();
 579   }
 580   st->cr();
 581 
 582   st->print_cr("Access Registers:");
 583   st->print_cr("-----------------");
 584   for( int i = 0; i < 16; i+=2 ) {
 585     st->print("  ar%-2d = 0x%8.8x  ", i,   uc->uc_mcontext.aregs[i]);
 586     st->print("  ar%-2d = 0x%8.8x  ", i+1, uc->uc_mcontext.aregs[i+1]);
 587     st->cr();
 588   }
 589   st->cr();
 590 
 591   st->print_cr("Float Registers:");
 592   st->print_cr("----------------");
 593   for (int i = 0; i < 16; i += 2) {
 594     st->print("  fr%-2d = " INTPTR_FORMAT "  " , i,   (int64_t)(uc->uc_mcontext.fpregs.fprs[i].d));
 595     st->print("  fr%-2d = " INTPTR_FORMAT "  |", i+1, (int64_t)(uc->uc_mcontext.fpregs.fprs[i+1].d));
 596     st->print("  fr%-2d = %23.15e  "           , i,   (uc->uc_mcontext.fpregs.fprs[i].d));
 597     st->print("  fr%-2d = %23.15e  "           , i+1, (uc->uc_mcontext.fpregs.fprs[i+1].d));
 598     st->cr();
 599   }
 600   st->cr();
 601   st->cr();
 602 
 603   intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
 604   st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
 605   print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
 606   st->cr();
 607 
 608   // Note: it may be unsafe to inspect memory near pc. For example, pc may
 609   // point to garbage if entry point in an nmethod is corrupted. Leave
 610   // this at the end, and hope for the best.
 611   address pc = os::Linux::ucontext_get_pc(uc);
 612   if (Verbose) { st->print_cr("pc at " PTR_FORMAT, p2i(pc)); }
 613   st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
 614   print_hex_dump(st, pc-64, pc+64, /*intrsize=*/4);
 615   st->cr();
 616 }
 617 
 618 void os::print_register_info(outputStream *st, const void *context) {
 619   st->print("Not ported\n");
 620 }
 621 
 622 #ifndef PRODUCT
 623 void os::verify_stack_alignment() {
 624 }
 625 #endif
 626 
 627 int os::extra_bang_size_in_bytes() {
 628   // z/Architecture does not require the additional stack bang.
 629   return 0;
 630 }