1 /*
2 * Copyright (c) 1999, 2019, 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 *
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
|
1 /*
2 * Copyright (c) 1999, 20209, 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 *
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->is_in_full_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
|