summaryrefslogtreecommitdiff
path: root/vm_dump.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-18 14:25:01 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-18 14:25:01 +0000
commit148f1b91176fb2f68dfbdf85720f18901d6e4b60 (patch)
treef1258336fcef5b9fdd81d231db97f3d414a1f51b /vm_dump.c
parent89ceb340ac674debd2858cf8eef698116cfd70ed (diff)
merge revision(s) 58769,59710,59712: [Backport #13566]
Treat NULL reference case [Bug #13566] Fix C level backtrace on Darwin SEGV caused by invalid instruction call. skip unless PLATFORM is darwin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_dump.c')
-rw-r--r--vm_dump.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/vm_dump.c b/vm_dump.c
index 01d15062fc..e3250470ac 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -434,6 +434,7 @@ rb_vmdebug_thread_dump_state(VALUE self)
# elif defined(__APPLE__) && defined(__x86_64__) && defined(HAVE_LIBUNWIND_H)
# define UNW_LOCAL_ONLY
# include <libunwind.h>
+# include <sys/mman.h>
# undef backtrace
int
backtrace(void **trace, int size)
@@ -460,6 +461,8 @@ darwin_sigtramp:
/* darwin's bundled libunwind doesn't support signal trampoline */
{
ucontext_t *uctx;
+ char vec[1];
+ int r;
/* get _sigtramp's ucontext_t and set values to cursor
* http://www.opensource.apple.com/source/Libc/Libc-825.25/i386/sys/_sigtramp.s
* http://www.opensource.apple.com/source/libunwind/libunwind-35.1/src/unw_getcontext.s
@@ -483,8 +486,10 @@ darwin_sigtramp:
unw_set_reg(&cursor, UNW_X86_64_R14, uctx->uc_mcontext->__ss.__r14);
unw_set_reg(&cursor, UNW_X86_64_R15, uctx->uc_mcontext->__ss.__r15);
ip = uctx->uc_mcontext->__ss.__rip;
- if (((char*)ip)[-2] == 0x0f && ((char*)ip)[-1] == 5) {
- /* signal received in syscall */
+ r = mincore((const void *)ip, 1, vec);
+ if (r || !vec[0] || memcmp((const char *)ip-2, "\x0f\x05", 2) == 0) {
+ /* if segv is caused by invalid call or signal received in syscall */
+ /* the frame is invalid; skip */
trace[n++] = (void *)ip;
ip = *(unw_word_t*)uctx->uc_mcontext->__ss.__rsp;
}