Skip to content

Commit

Permalink
merge revision(s) 58769,59710,59712: [Backport #13566]
Browse files Browse the repository at this point in the history
	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_4@62639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nagachika committed Mar 3, 2018
1 parent e5a430e commit 794ec1d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
21 changes: 21 additions & 0 deletions test/ruby/test_vm_dump.rb
@@ -0,0 +1,21 @@
# frozen_string_literal: true
require 'test/unit'

class TestVMDump < Test::Unit::TestCase
def assert_darwin_vm_dump_works(args)
skip if RUBY_PLATFORM !~ /darwin/
assert_in_out_err(args, "", [], [:*, /^.* main \+ \d+$/, :*, /^\[IMPORTANT\]/, :*])
end

def test_darwin_invalid_call
assert_darwin_vm_dump_works(['-rfiddle', '-eFiddle::Function.new(Fiddle::Pointer.new(1), [], Fiddle::TYPE_VOID).call'])
end

def test_darwin_segv_in_syscall
assert_darwin_vm_dump_works('-e1.times{Process.kill :SEGV,$$}')
end

def test_darwin_invalid_access
assert_darwin_vm_dump_works(['-rfiddle', '-eFiddle.dlunwrap(100).class'])
end
end
2 changes: 1 addition & 1 deletion version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.4.4"
#define RUBY_RELEASE_DATE "2018-03-03"
#define RUBY_PATCHLEVEL 243
#define RUBY_PATCHLEVEL 244

#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 3
Expand Down
9 changes: 7 additions & 2 deletions vm_dump.c
Expand Up @@ -426,6 +426,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)
Expand All @@ -452,6 +453,8 @@ backtrace(void **trace, int size)
/* 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
Expand All @@ -475,8 +478,10 @@ backtrace(void **trace, int size)
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;
}
Expand Down

0 comments on commit 794ec1d

Please sign in to comment.