summaryrefslogtreecommitdiff
path: root/vm_dump.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 09:21:48 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 09:21:48 +0000
commitfff6809b30d84c06c83fcc3fa2cd9e857bd146c9 (patch)
treed559d9e7b4e3d92dbcaf21992142a26452c06e7e /vm_dump.c
parentea49381e51dab839aac2e3b49161b51ad5193f89 (diff)
fix the case High Sierra's mincore(2) may return -128 [Bug #13895]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_dump.c')
-rw-r--r--vm_dump.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/vm_dump.c b/vm_dump.c
index aa4ee247c6..c5fa48e76e 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -442,7 +442,7 @@ darwin_sigtramp:
ucontext_t *uctx;
char vec[1];
int r;
- /* get _sigtramp's ucontext_t and set values to cursor
+ /* get previous frame information from %rbx at _sigtramp 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
*/
@@ -465,8 +465,35 @@ 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;
+
+ /* There's 4 cases for SEGV:
+ * (1) called invalid address
+ * (2) read or write invalid address
+ * (3) received signal
+ *
+ * Detail:
+ * (1) called invalid address
+ * In this case, saved ip is invalid address.
+ * It needs to just save the address for the information,
+ * skip the frame, and restore the frame calling the
+ * invalid address from %rsp.
+ * The problem is how to check whether the ip is valid or not.
+ * This code uses mincore(2) and assume the address's page is
+ * incore/referenced or not reflects the problem.
+ * Note that High Sierra's mincore(2) may return -128.
+ * (2) read or write invalid address
+ * saved ip is valid. just restart backtracing.
+ * (3) received signal in user space
+ * Same as (2).
+ * (4) received signal in kernel
+ * In this case saved ip points just after syscall, but registers are
+ * already overwriten by kernel. To fix register consistency,
+ * skip libc's kernel wrapper.
+ * To detect this case, just previous two bytes of ip is "\x0f\x05",
+ * syscall instruction of x86_64.
+ */
r = mincore((const void *)ip, 1, vec);
- if (r || !vec[0] || memcmp((const char *)ip-2, "\x0f\x05", 2) == 0) {
+ if (r || vec[0] <= 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;