diff --git a/src/ia64/Ginit_local.c b/src/ia64/Ginit_local.c index 834881b2..42f8b1f0 100644 --- a/src/ia64/Ginit_local.c +++ b/src/ia64/Ginit_local.c @@ -36,47 +36,75 @@ unw_init_local (unw_cursor_t *cursor, unw_context_t *uc) #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 unw_init_local (unw_cursor_t *cursor, unw_context_t *uc) { struct cursor *c = (struct cursor *) cursor; - unw_word_t sol; + unw_word_t sp, bsp; + int ret; if (tdep_needs_initialization) tdep_init (); 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_arg = uc; - return common_init (c); + set_as_arg (c, uc); + + 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 */