1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-26 17:17:39 +01:00

(set_as_arg): New function.

(get_initial_stack_pointers): Likewise.
(unw_init_local): Use new functions to make code more readable and add
	Linux kernel support.

(Logical change 1.296)
This commit is contained in:
hp.com!davidm 2005-05-20 12:47:59 +00:00
parent 84bd124a24
commit 50bbc1fe3d

View file

@ -36,47 +36,75 @@ unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
#else /* !UNW_REMOTE_ONLY */ #else /* !UNW_REMOTE_ONLY */
static inline void
set_as_arg (struct cursor *c, unw_context_t *uc)
{
#if defined(__linux) && defined(__KERNEL__)
c->task = current;
c->as_arg = &uc->sw;
#else
c->as_arg = uc;
#endif
}
static inline int
get_initial_stack_pointers (struct cursor *c, unw_context_t *uc,
unw_word_t *sp, unw_word_t *bsp)
{
#if defined(__linux)
unw_word_t sol, bspstore;
#ifdef __KERNEL__
sol = (uc->sw.ar_pfs >> 7) & 0x7f;
bspstore = uc->sw.ar_bspstore;
*sp = uc->ksp;
# else
sol = (uc->uc_mcontext.sc_ar_pfs >> 7) & 0x7f;
bspstore = uc->uc_mcontext.sc_ar_bsp;
*sp = uc->uc_mcontext.sc_gr[12];
# endif
*bsp = rse_skip_regs (bspstore, -sol);
#elif defined(__hpux)
int ret;
if ((ret = ia64_get (c, IA64_REG_LOC (c, UNW_IA64_GR + 12), sp)) < 0
|| (ret = ia64_get (c, IA64_REG_LOC (c, UNW_IA64_AR_BSP), bsp)) < 0)
return ret;
#else
# error Fix me.
#endif
return 0;
}
PROTECTED int PROTECTED int
unw_init_local (unw_cursor_t *cursor, unw_context_t *uc) unw_init_local (unw_cursor_t *cursor, unw_context_t *uc)
{ {
struct cursor *c = (struct cursor *) cursor; struct cursor *c = (struct cursor *) cursor;
unw_word_t sol; unw_word_t sp, bsp;
int ret;
if (tdep_needs_initialization) if (tdep_needs_initialization)
tdep_init (); tdep_init ();
Debug (1, "(cursor=%p)\n", c); Debug (1, "(cursor=%p)\n", c);
#ifdef __hpux
{
int ret;
c->as = unw_local_addr_space;
c->as_arg = uc;
if ((ret = common_init (c)) < 0)
return ret;
/* On HP-UX, the context created by getcontext() points to the
getcontext() system call stub. Step over it: */
return unw_step (cursor);
}
#else
/* The bsp value stored by getcontext() points to the *end* of the
register frame of the initial function. We correct for this by
storing the adjusted value in sc_rbs_base, which isn't used by
getcontext()/setcontext(). We can be certain that the entire
frame is stored in a contiguous rbs-area because the frame didn't
become part of the dirty partition until getcontext() was called
and we know that getcontext() doesn't switch the register-backing
store. */
sol = (uc->uc_mcontext.sc_ar_pfs >> 7) & 0x7f;
uc->uc_mcontext.sc_rbs_base = rse_skip_regs (uc->uc_mcontext.sc_ar_bsp,
-sol);
#endif
c->as = unw_local_addr_space; c->as = unw_local_addr_space;
c->as_arg = uc; set_as_arg (c, uc);
return common_init (c);
if ((ret = get_initial_stack_pointers (c, uc, &sp, &bsp)) < 0)
return ret;
Debug (4, "initial bsp=%lx, sp=%lx\n", bsp, sp);
if ((ret = common_init (c, sp, bsp)) < 0)
return ret;
#ifdef __hpux
/* On HP-UX, the context created by getcontext() points to the
getcontext() system call stub. Step over it: */
ret = unw_step (cursor);
#endif
return ret;
} }
#endif /* !UNW_REMOTE_ONLY */ #endif /* !UNW_REMOTE_ONLY */