Index: vm/port/src/crash_handler/em64t/native_unwind_arch.cpp =================================================================== --- vm/port/src/crash_handler/em64t/native_unwind_arch.cpp (revision 638367) +++ vm/port/src/crash_handler/em64t/native_unwind_arch.cpp (working copy) @@ -24,49 +24,6 @@ #include "native_unwind.h" -bool native_is_frame_exists(UnwindContext* context, Registers* regs) -{ - // Check for frame layout and stack values - if ((regs->rbp < regs->rsp) || !native_is_in_stack(context, (void*)regs->rbp)) - return false; // Invalid frame - - void** frame_ptr = (void**)regs->rbp; - void* rip = frame_ptr[1]; // Return address - - // Check return address for meaning - return (native_is_in_code(context, rip)); -} - -bool native_unwind_stack_frame(UnwindContext* context, Registers* regs) -{ - void** frame = (void**)regs->rbp; - - void* rbp = frame[0]; - void* rip = frame[1]; -// void* rsp = (void*)(frame + 2); - void* rsp = &frame[2]; - - - if (native_is_in_stack(context, rsp) && - (native_is_in_code(context, rip))) - { - regs->rbp = (uint64)rbp; - regs->rsp = (uint64)rsp; - regs->rip = (uint64)rip; - return true; - } - - return false; -} - -static bool fill_regs_from_sp(UnwindContext* context, Registers* regs, void** sp) -{ - regs->rsp = (uint64)(sp + 1); - regs->rip = (uint64)*sp; - regs->rbp = native_is_in_stack(context, sp[-1]) ? (uint64)sp[-1] : regs->rsp; - return true; -} - static unsigned native_dec_instr(UnwindContext* context, void* addr, void** target) { Inst inst; @@ -114,7 +71,50 @@ return false; } +bool native_is_frame_exists(UnwindContext* context, Registers* regs) +{ + // Check for frame layout and stack values + if ((regs->rbp < regs->rsp) || !native_is_in_stack(context, (void*)regs->rbp)) + return false; // Invalid frame + void** frame_ptr = (void**)regs->rbp; + void* rip = frame_ptr[1]; // Return address + + // Check return address for meaning + return (native_is_in_code(context, rip) && native_check_caller(context, regs, frame_ptr + 1)); +} + +bool native_unwind_stack_frame(UnwindContext* context, Registers* regs) +{ + void** frame = (void**)regs->rbp; + + void* rbp = frame[0]; + void* rip = frame[1]; +// void* rsp = (void*)(frame + 2); + void* rsp = &frame[2]; + + + if (native_is_in_stack(context, rsp) && + (native_is_in_code(context, rip))) + { + regs->rbp = (uint64)rbp; + regs->rsp = (uint64)rsp; + regs->rip = (uint64)rip; + return true; + } + + return false; +} + +static bool fill_regs_from_sp(UnwindContext* context, Registers* regs, void** sp) +{ + regs->rsp = (uint64)(sp + 1); + regs->rip = (uint64)*sp; + regs->rbp = native_is_in_stack(context, sp[-1]) ? (uint64)sp[-1] : regs->rsp; + return true; +} + + // Max search depth for return address #define MAX_SPECIAL_DEPTH 0x900 #define NATIVE_STRICT_UNWINDING 1 Index: vm/port/src/crash_handler/native_unwind.cpp =================================================================== --- vm/port/src/crash_handler/native_unwind.cpp (revision 638367) +++ vm/port/src/crash_handler/native_unwind.cpp (working copy) @@ -87,11 +87,11 @@ bool port_unwind_frame(UnwindContext* context, Registers* regs) { -// if (native_is_frame_exists(context, regs)) -// { // Stack frame (x86) -// return native_unwind_stack_frame(context, regs); -// } -// else + if (native_is_frame_exists(context, regs)) + { // Stack frame (x86) + return native_unwind_stack_frame(context, regs); + } + else { // Stack frame does not exist, try using heuristics return native_unwind_special(context, regs); } Index: vm/port/src/crash_handler/ia32/native_unwind_arch.cpp =================================================================== --- vm/port/src/crash_handler/ia32/native_unwind_arch.cpp (revision 638367) +++ vm/port/src/crash_handler/ia32/native_unwind_arch.cpp (working copy) @@ -24,49 +24,6 @@ #include "native_unwind.h" -bool native_is_frame_exists(UnwindContext* context, Registers* regs) -{ - // Check for frame layout and stack values - if ((regs->ebp < regs->esp) || !native_is_in_stack(context, (void*)regs->ebp)) - return false; // Invalid frame - - void** frame_ptr = (void**)regs->ebp; - void* eip = frame_ptr[1]; // Return address - - // Check return address for meaning - return (native_is_in_code(context, eip)); -} - -bool native_unwind_stack_frame(UnwindContext* context, Registers* regs) -{ - void** frame = (void**)regs->ebp; - - void* ebp = frame[0]; - void* eip = frame[1]; -// void* esp = (void*)(frame + 2); - void* esp = &frame[2]; - - - if (native_is_in_stack(context, esp) && - (native_is_in_code(context, eip))) - { - regs->ebp = (uint32)ebp; - regs->esp = (uint32)esp; - regs->eip = (uint32)eip; - return true; - } - - return false; -} - -static bool fill_regs_from_sp(UnwindContext* context, Registers* regs, void** sp) -{ - regs->esp = (uint32)(sp + 1); - regs->eip = (uint32)*sp; - regs->ebp = native_is_in_stack(context, sp[-1]) ? (uint32)sp[-1] : regs->esp; - return true; -} - static unsigned native_dec_instr(UnwindContext* context, void* addr, void** target) { Inst inst; @@ -114,7 +71,50 @@ return false; } +bool native_is_frame_exists(UnwindContext* context, Registers* regs) +{ + // Check for frame layout and stack values + if ((regs->ebp < regs->esp) || !native_is_in_stack(context, (void*)regs->ebp)) + return false; // Invalid frame + void** frame_ptr = (void**)regs->ebp; + void* eip = frame_ptr[1]; // Return address + + // Check return address for meaning + return (native_is_in_code(context, eip) && native_check_caller(context, regs, frame_ptr + 1)); +} + +bool native_unwind_stack_frame(UnwindContext* context, Registers* regs) +{ + void** frame = (void**)regs->ebp; + + void* ebp = frame[0]; + void* eip = frame[1]; +// void* esp = (void*)(frame + 2); + void* esp = &frame[2]; + + + if (native_is_in_stack(context, esp) && + (native_is_in_code(context, eip))) + { + regs->ebp = (uint32)ebp; + regs->esp = (uint32)esp; + regs->eip = (uint32)eip; + return true; + } + + return false; +} + +static bool fill_regs_from_sp(UnwindContext* context, Registers* regs, void** sp) +{ + regs->esp = (uint32)(sp + 1); + regs->eip = (uint32)*sp; + regs->ebp = native_is_in_stack(context, sp[-1]) ? (uint32)sp[-1] : regs->esp; + return true; +} + + // Max search depth for return address #define MAX_SPECIAL_DEPTH 0x400 #define NATIVE_STRICT_UNWINDING 1