2004-08-17 17:34:28 +02:00
|
|
|
/* libunwind - a platform-independent unwind library
|
2010-04-05 15:14:50 +02:00
|
|
|
Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org>
|
2004-08-17 17:34:28 +02:00
|
|
|
|
|
|
|
This file is part of libunwind.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
|
2010-04-05 15:14:50 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <ucontext.h>
|
|
|
|
#include <machine/sigframe.h>
|
|
|
|
|
2004-08-17 17:34:28 +02:00
|
|
|
#include "unwind_i.h"
|
2010-04-05 15:14:50 +02:00
|
|
|
#include "offsets.h"
|
2004-08-17 17:34:28 +02:00
|
|
|
|
|
|
|
PROTECTED int
|
|
|
|
unw_is_signal_frame (unw_cursor_t *cursor)
|
|
|
|
{
|
2010-03-10 23:50:40 +01:00
|
|
|
struct cursor *c = (struct cursor *) cursor;
|
|
|
|
unw_word_t w0, w1, w2, w3, w4, w5, ip;
|
|
|
|
unw_addr_space_t as;
|
|
|
|
unw_accessors_t *a;
|
|
|
|
void *arg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
as = c->dwarf.as;
|
|
|
|
a = unw_get_accessors (as);
|
|
|
|
arg = c->dwarf.as_arg;
|
|
|
|
|
|
|
|
/* Check if EIP points at sigreturn() sequence. It can be:
|
2010-03-13 20:26:50 +01:00
|
|
|
sigcode+4: from amd64 freebsd32 environment
|
|
|
|
8d 44 24 20 lea 0x20(%esp),%eax
|
|
|
|
50 push %eax
|
|
|
|
b8 a1 01 00 00 mov $0x1a1,%ea
|
|
|
|
50 push %eax
|
|
|
|
cd 80 int $0x80
|
|
|
|
|
|
|
|
sigcode+4: from real i386
|
2010-03-10 23:50:40 +01:00
|
|
|
8d 44 24 20 lea 0x20(%esp),%eax
|
|
|
|
50 push %eax
|
|
|
|
f7 40 54 00 02 00 testl $0x20000,0x54(%eax)
|
|
|
|
75 03 jne sigcode+21
|
|
|
|
8e 68 14 mov 0x14(%eax),%gs
|
|
|
|
b8 a1 01 00 00 mov $0x1a1,%eax
|
|
|
|
50 push %eax
|
|
|
|
cd 80 int $0x80
|
|
|
|
|
|
|
|
freebsd4_sigcode+4:
|
|
|
|
XXX
|
|
|
|
osigcode:
|
|
|
|
XXX
|
|
|
|
*/
|
|
|
|
ip = c->dwarf.ip;
|
2010-03-13 19:28:12 +01:00
|
|
|
ret = X86_SCF_NONE;
|
2010-04-05 15:14:50 +02:00
|
|
|
c->sigcontext_format = ret;
|
2010-03-13 20:26:50 +01:00
|
|
|
if ((*a->access_mem) (as, ip, &w0, 0, arg) < 0 ||
|
|
|
|
(*a->access_mem) (as, ip + 4, &w1, 0, arg) < 0 ||
|
|
|
|
(*a->access_mem) (as, ip + 8, &w2, 0, arg) < 0 ||
|
|
|
|
(*a->access_mem) (as, ip + 12, &w3, 0, arg) < 0)
|
|
|
|
return ret;
|
|
|
|
if (w0 == 0x2024448d && w1 == 0x01a1b850 && w2 == 0xcd500000 &&
|
|
|
|
(w3 & 0xff) == 0x80)
|
2010-03-13 19:28:12 +01:00
|
|
|
ret = X86_SCF_FREEBSD_SIGFRAME;
|
2010-03-13 20:26:50 +01:00
|
|
|
else {
|
|
|
|
if ((*a->access_mem) (as, ip + 16, &w4, 0, arg) < 0 ||
|
|
|
|
(*a->access_mem) (as, ip + 20, &w5, 0, arg) < 0)
|
|
|
|
return ret;
|
|
|
|
if (w0 == 0x2024448d && w1 == 0x5440f750 && w2 == 0x75000200 &&
|
|
|
|
w3 == 0x14688e03 && w4 == 0x0001a1b8 && w5 == 0x80cd5000)
|
|
|
|
ret = X86_SCF_FREEBSD_SIGFRAME;
|
|
|
|
}
|
2010-03-10 23:50:40 +01:00
|
|
|
Debug (16, "returning %d\n", ret);
|
2010-04-05 15:14:50 +02:00
|
|
|
c->sigcontext_format = ret;
|
2010-03-13 19:28:12 +01:00
|
|
|
return (ret);
|
2010-04-05 15:14:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PROTECTED int
|
|
|
|
unw_handle_signal_frame (unw_cursor_t *cursor)
|
|
|
|
{
|
|
|
|
struct cursor *c = (struct cursor *) cursor;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (c->sigcontext_format == X86_SCF_FREEBSD_SIGFRAME) {
|
|
|
|
struct sigframe *sf;
|
|
|
|
uintptr_t uc_addr;
|
|
|
|
struct dwarf_loc esp_loc;
|
|
|
|
|
|
|
|
sf = (struct sigframe *)c->dwarf.cfa;
|
|
|
|
uc_addr = (uintptr_t)&(sf->sf_uc);
|
|
|
|
|
|
|
|
esp_loc = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_ESP_OFF, 0);
|
|
|
|
ret = dwarf_get (&c->dwarf, esp_loc, &c->dwarf.cfa);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
Debug (2, "returning 0\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->dwarf.loc[EIP] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EIP_OFF, 0);
|
|
|
|
c->dwarf.loc[ESP] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_ESP_OFF, 0);
|
|
|
|
c->dwarf.loc[EAX] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EAX_OFF, 0);
|
|
|
|
c->dwarf.loc[ECX] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_ECX_OFF, 0);
|
|
|
|
c->dwarf.loc[EDX] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EDX_OFF, 0);
|
|
|
|
c->dwarf.loc[EBX] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EBX_OFF, 0);
|
|
|
|
c->dwarf.loc[EBP] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EBP_OFF, 0);
|
|
|
|
c->dwarf.loc[ESI] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_ESI_OFF, 0);
|
|
|
|
c->dwarf.loc[EDI] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EDI_OFF, 0);
|
|
|
|
c->dwarf.loc[EFLAGS] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_EFLAGS_OFF, 0);
|
|
|
|
c->dwarf.loc[TRAPNO] = DWARF_LOC (uc_addr + FREEBSD_UC_MCONTEXT_TRAPNO_OFF, 0);
|
|
|
|
c->dwarf.loc[ST0] = DWARF_NULL_LOC;
|
|
|
|
} else {
|
|
|
|
Debug (8, "Gstep: not handling frame format %d\n", c->sigcontext_format);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return 0;
|
2004-08-17 17:34:28 +02:00
|
|
|
}
|
2010-04-05 21:22:55 +02:00
|
|
|
|
|
|
|
HIDDEN dwarf_loc_t
|
|
|
|
x86_get_scratch_loc (struct cursor *c, unw_regnum_t reg)
|
|
|
|
{
|
|
|
|
unw_word_t addr = c->sigcontext_addr, fpstate_addr, off;
|
|
|
|
int ret, is_fpstate = 0;
|
|
|
|
|
|
|
|
switch (c->sigcontext_format)
|
|
|
|
{
|
|
|
|
case X86_SCF_NONE:
|
|
|
|
return DWARF_REG_LOC (&c->dwarf, reg);
|
|
|
|
|
|
|
|
case X86_SCF_FREEBSD_SIGFRAME:
|
|
|
|
addr += FREEBSD_UC_MCONTEXT_OFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X86_SCF_FREEBSD_SIGFRAME4:
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X86_SCF_FREEBSD_OSIGFRAME:
|
|
|
|
/* XXXKIB */
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case X86_SCF_FREEBSD_SYSCALL:
|
|
|
|
/* XXXKIB */
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* XXXKIB */
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (reg)
|
|
|
|
{
|
|
|
|
case UNW_X86_GS: off = FREEBSD_UC_MCONTEXT_GS_OFF; break;
|
|
|
|
case UNW_X86_FS: off = FREEBSD_UC_MCONTEXT_FS_OFF; break;
|
|
|
|
case UNW_X86_ES: off = FREEBSD_UC_MCONTEXT_ES_OFF; break;
|
|
|
|
case UNW_X86_DS: off = FREEBSD_UC_MCONTEXT_SS_OFF; break;
|
|
|
|
case UNW_X86_EDI: off = FREEBSD_UC_MCONTEXT_EDI_OFF; break;
|
|
|
|
case UNW_X86_ESI: off = FREEBSD_UC_MCONTEXT_ESI_OFF; break;
|
|
|
|
case UNW_X86_EBP: off = FREEBSD_UC_MCONTEXT_EBP_OFF; break;
|
|
|
|
case UNW_X86_ESP: off = FREEBSD_UC_MCONTEXT_ESP_OFF; break;
|
|
|
|
case UNW_X86_EBX: off = FREEBSD_UC_MCONTEXT_EBX_OFF; break;
|
|
|
|
case UNW_X86_EDX: off = FREEBSD_UC_MCONTEXT_EDX_OFF; break;
|
|
|
|
case UNW_X86_ECX: off = FREEBSD_UC_MCONTEXT_ECX_OFF; break;
|
|
|
|
case UNW_X86_EAX: off = FREEBSD_UC_MCONTEXT_EAX_OFF; break;
|
|
|
|
case UNW_X86_TRAPNO: off = FREEBSD_UC_MCONTEXT_TRAPNO_OFF; break;
|
|
|
|
case UNW_X86_EIP: off = FREEBSD_UC_MCONTEXT_EIP_OFF; break;
|
|
|
|
case UNW_X86_CS: off = FREEBSD_UC_MCONTEXT_CS_OFF; break;
|
|
|
|
case UNW_X86_EFLAGS: off = FREEBSD_UC_MCONTEXT_EFLAGS_OFF; break;
|
|
|
|
case UNW_X86_SS: off = FREEBSD_UC_MCONTEXT_SS_OFF; break;
|
|
|
|
|
|
|
|
/* XXXKIB fix */
|
|
|
|
case UNW_X86_FCW: is_fpstate = 1; off = LINUX_FPSTATE_CW_OFF; break;
|
|
|
|
case UNW_X86_FSW: is_fpstate = 1; off = LINUX_FPSTATE_SW_OFF; break;
|
|
|
|
case UNW_X86_FTW: is_fpstate = 1; off = LINUX_FPSTATE_TAG_OFF; break;
|
|
|
|
case UNW_X86_FCS: is_fpstate = 1; off = LINUX_FPSTATE_CSSEL_OFF; break;
|
|
|
|
case UNW_X86_FIP: is_fpstate = 1; off = LINUX_FPSTATE_IPOFF_OFF; break;
|
|
|
|
case UNW_X86_FEA: is_fpstate = 1; off = LINUX_FPSTATE_DATAOFF_OFF; break;
|
|
|
|
case UNW_X86_FDS: is_fpstate = 1; off = LINUX_FPSTATE_DATASEL_OFF; break;
|
|
|
|
case UNW_X86_MXCSR: is_fpstate = 1; off = LINUX_FPSTATE_MXCSR_OFF; break;
|
|
|
|
|
|
|
|
/* stacked fp registers */
|
|
|
|
case UNW_X86_ST0: case UNW_X86_ST1: case UNW_X86_ST2: case UNW_X86_ST3:
|
|
|
|
case UNW_X86_ST4: case UNW_X86_ST5: case UNW_X86_ST6: case UNW_X86_ST7:
|
|
|
|
is_fpstate = 1;
|
|
|
|
off = LINUX_FPSTATE_ST0_OFF + 10*(reg - UNW_X86_ST0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* SSE fp registers */
|
|
|
|
case UNW_X86_XMM0_lo: case UNW_X86_XMM0_hi:
|
|
|
|
case UNW_X86_XMM1_lo: case UNW_X86_XMM1_hi:
|
|
|
|
case UNW_X86_XMM2_lo: case UNW_X86_XMM2_hi:
|
|
|
|
case UNW_X86_XMM3_lo: case UNW_X86_XMM3_hi:
|
|
|
|
case UNW_X86_XMM4_lo: case UNW_X86_XMM4_hi:
|
|
|
|
case UNW_X86_XMM5_lo: case UNW_X86_XMM5_hi:
|
|
|
|
case UNW_X86_XMM6_lo: case UNW_X86_XMM6_hi:
|
|
|
|
case UNW_X86_XMM7_lo: case UNW_X86_XMM7_hi:
|
|
|
|
is_fpstate = 1;
|
|
|
|
off = LINUX_FPSTATE_XMM0_OFF + 8*(reg - UNW_X86_XMM0_lo);
|
|
|
|
break;
|
|
|
|
case UNW_X86_XMM0:
|
|
|
|
case UNW_X86_XMM1:
|
|
|
|
case UNW_X86_XMM2:
|
|
|
|
case UNW_X86_XMM3:
|
|
|
|
case UNW_X86_XMM4:
|
|
|
|
case UNW_X86_XMM5:
|
|
|
|
case UNW_X86_XMM6:
|
|
|
|
case UNW_X86_XMM7:
|
|
|
|
is_fpstate = 1;
|
|
|
|
off = LINUX_FPSTATE_XMM0_OFF + 16*(reg - UNW_X86_XMM0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNW_X86_FOP:
|
|
|
|
case UNW_X86_TSS:
|
|
|
|
case UNW_X86_LDT:
|
|
|
|
default:
|
|
|
|
return DWARF_REG_LOC (&c->dwarf, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_fpstate)
|
|
|
|
{
|
|
|
|
if ((ret = dwarf_get (&c->dwarf,
|
|
|
|
DWARF_MEM_LOC (&c->dwarf,
|
|
|
|
addr + LINUX_SC_FPSTATE_OFF),
|
|
|
|
&fpstate_addr)) < 0)
|
|
|
|
return DWARF_NULL_LOC;
|
|
|
|
|
|
|
|
if (!fpstate_addr)
|
|
|
|
return DWARF_NULL_LOC;
|
|
|
|
|
|
|
|
return DWARF_MEM_LOC (c, fpstate_addr + off);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return DWARF_MEM_LOC (c, addr + off);
|
|
|
|
}
|
2010-04-05 21:42:23 +02:00
|
|
|
|
|
|
|
#ifndef UNW_REMOTE_ONLY
|
|
|
|
HIDDEN void *
|
|
|
|
x86_r_uc_addr (ucontext_t *uc, int reg)
|
|
|
|
{
|
|
|
|
void *addr;
|
|
|
|
|
|
|
|
switch (reg)
|
|
|
|
{
|
|
|
|
case UNW_X86_GS: addr = &uc->uc_mcontext.mc_gs; break;
|
|
|
|
case UNW_X86_FS: addr = &uc->uc_mcontext.mc_fs; break;
|
|
|
|
case UNW_X86_ES: addr = &uc->uc_mcontext.mc_es; break;
|
|
|
|
case UNW_X86_DS: addr = &uc->uc_mcontext.mc_ds; break;
|
|
|
|
case UNW_X86_EAX: addr = &uc->uc_mcontext.mc_eax; break;
|
|
|
|
case UNW_X86_EBX: addr = &uc->uc_mcontext.mc_ebx; break;
|
|
|
|
case UNW_X86_ECX: addr = &uc->uc_mcontext.mc_ecx; break;
|
|
|
|
case UNW_X86_EDX: addr = &uc->uc_mcontext.mc_edx; break;
|
|
|
|
case UNW_X86_ESI: addr = &uc->uc_mcontext.mc_esi; break;
|
|
|
|
case UNW_X86_EDI: addr = &uc->uc_mcontext.mc_edi; break;
|
|
|
|
case UNW_X86_EBP: addr = &uc->uc_mcontext.mc_ebp; break;
|
|
|
|
case UNW_X86_EIP: addr = &uc->uc_mcontext.mc_eip; break;
|
|
|
|
case UNW_X86_ESP: addr = &uc->uc_mcontext.mc_esp; break;
|
|
|
|
case UNW_X86_TRAPNO: addr = &uc->uc_mcontext.mc_trapno; break;
|
|
|
|
case UNW_X86_CS: addr = &uc->uc_mcontext.mc_cs; break;
|
|
|
|
case UNW_X86_EFLAGS: addr = &uc->uc_mcontext.mc_eflags; break;
|
|
|
|
case UNW_X86_SS: addr = &uc->uc_mcontext.mc_ss; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
addr = NULL;
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
#endif
|