@@ -189,9 +189,27 @@ frame os::fetch_frame_from_context(const void* ucVoid) {
189189 intptr_t * sp;
190190 intptr_t * fp;
191191 address epc = fetch_frame_from_context (ucVoid, &sp, &fp);
192+ if (!is_readable_pointer (epc)) {
193+ // Try to recover from calling into bad memory
194+ // Assume new frame has not been set up, the same as
195+ // compiled frame stack bang
196+ return fetch_compiled_frame_from_context (ucVoid);
197+ }
192198 return frame (sp, fp, epc);
193199}
194200
201+ frame os::fetch_compiled_frame_from_context (const void * ucVoid) {
202+ const ucontext_t * uc = (const ucontext_t *)ucVoid;
203+ // In compiled code, the stack banging is performed before LR
204+ // has been saved in the frame. LR is live, and SP and FP
205+ // belong to the caller.
206+ intptr_t * fp = os::Linux::ucontext_get_fp (uc);
207+ intptr_t * sp = os::Linux::ucontext_get_sp (uc);
208+ address pc = (address)(uc->uc_mcontext .arm_lr
209+ - NativeInstruction::instruction_size);
210+ return frame (sp, fp, pc);
211+ }
212+
195213frame os::get_sender_for_C_frame (frame* fr) {
196214#ifdef __thumb__
197215 // We can't reliably get anything from a thumb C frame.
@@ -470,23 +488,6 @@ void os::print_context(outputStream *st, const void *context) {
470488 st->cr ();
471489}
472490
473- void os::print_tos_pc (outputStream *st, const void *context) {
474- if (context == nullptr ) return ;
475-
476- const ucontext_t * uc = (const ucontext_t *)context;
477-
478- address sp = (address)os::Linux::ucontext_get_sp (uc);
479- print_tos (st, sp);
480- st->cr ();
481-
482- // Note: it may be unsafe to inspect memory near pc. For example, pc may
483- // point to garbage if entry point in an nmethod is corrupted. Leave
484- // this at the end, and hope for the best.
485- address pc = os::Posix::ucontext_get_pc (uc);
486- print_instructions (st, pc);
487- st->cr ();
488- }
489-
490491void os::print_register_info (outputStream *st, const void *context, int & continuation) {
491492 const int register_count = ARM_REGS_IN_CONTEXT;
492493 int n = continuation;
0 commit comments