From cfee927fb9fc96fa06c55219abce6349a15d47e6 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 20 Apr 2009 13:54:51 -0500 Subject: [PATCH] Uses upstream ia64 syscall functions. 2009-04-20 David Smith * runtime/syscall.h (syscall_get_nr): Uses upstream version of syscall_get_nr() for ia64. (syscall_get_arguments): Ditto. (in_syscall): New ia64-only function from upstream. (syscall_get_set_args_cb): Ditto. (ia64_syscall_get_set_arguments): Ditto. * runtime/task_finder.c (stap_register_task_finder_target): Removed ia64 register cache. --- runtime/syscall.h | 143 ++++++++++++++++++++++++++++++++++-------- runtime/task_finder.c | 3 - 2 files changed, 116 insertions(+), 30 deletions(-) diff --git a/runtime/syscall.h b/runtime/syscall.h index 5e5383895..ffc21efce 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -124,6 +124,14 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs) static inline long syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { + if ((long)regs->cr_ifs < 0) /* Not a syscall */ + return -1; + +#ifdef CONFIG_IA32_SUPPORT + if (IS_IA32_PROCESS(regs)) + return regs->r1; +#endif + return regs->r15; } #endif @@ -320,38 +328,119 @@ syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, #endif #if defined(__ia64__) -#define syscall_get_arguments(task, regs, i, n, args) \ - __ia64_syscall_get_arguments(task, regs, i, n, args, &c->unwaddr) -static inline void -__ia64_syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, - unsigned int i, unsigned int n, - unsigned long *args, unsigned long **cache) +/* Return TRUE if PT was created due to kernel-entry via a system-call. */ + +static inline int +in_syscall (struct pt_regs *pt) { - if (i + n > 6) { - _stp_error("invalid syscall arg request"); + return (long) pt->cr_ifs >= 0; +} + +struct syscall_get_set_args { + unsigned int i; + unsigned int n; + unsigned long *args; + struct pt_regs *regs; + int rw; +}; + +static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) +{ + struct syscall_get_set_args *args = data; + struct pt_regs *pt = args->regs; + unsigned long *krbs, cfm, ndirty; + int i, count; + + if (unw_unwind_to_user(info) < 0) return; + + cfm = pt->cr_ifs; + krbs = (unsigned long *)info->task + IA64_RBS_OFFSET/8; + ndirty = ia64_rse_num_regs(krbs, krbs + (pt->loadrs >> 19)); + + count = 0; + if (in_syscall(pt)) + count = min_t(int, args->n, cfm & 0x7f); + + for (i = 0; i < count; i++) { + if (args->rw) + *ia64_rse_skip_regs(krbs, ndirty + i + args->i) = + args->args[i]; + else + args->args[i] = *ia64_rse_skip_regs(krbs, + ndirty + i + args->i); } - switch (i) { - case 0: - if (!n--) break; - *args++ = ia64_fetch_register(32, regs, cache); - case 1: - if (!n--) break; - *args++ = ia64_fetch_register(33, regs, cache); - case 2: - if (!n--) break; - *args++ = ia64_fetch_register(34, regs, cache); - case 3: - if (!n--) break; - *args++ = ia64_fetch_register(35, regs, cache); - case 4: - if (!n--) break; - *args++ = ia64_fetch_register(36, regs, cache); - case 5: - if (!n--) break; - *args++ = ia64_fetch_register(37, regs, cache); + + if (!args->rw) { + while (i < args->n) { + args->args[i] = 0; + i++; + } + } +} + +void ia64_syscall_get_set_arguments(struct task_struct *task, + struct pt_regs *regs, unsigned int i, unsigned int n, + unsigned long *args, int rw) +{ + struct syscall_get_set_args data = { + .i = i, + .n = n, + .args = args, + .regs = regs, + .rw = rw, + }; + + if (task == current) + unw_init_running(syscall_get_set_args_cb, &data); + else { + struct unw_frame_info ufi; + memset(&ufi, 0, sizeof(ufi)); + unw_init_from_blocked_task(&ufi, task); + syscall_get_set_args_cb(&ufi, &data); + } +} + +static inline void syscall_get_arguments(struct task_struct *task, + struct pt_regs *regs, + unsigned int i, unsigned int n, + unsigned long *args) +{ + BUG_ON(i + n > 6); + +#ifdef CONFIG_IA32_SUPPORT + if (IS_IA32_PROCESS(regs)) { + switch (i + n) { + case 6: + if (!n--) break; + *args++ = regs->r13; + case 5: + if (!n--) break; + *args++ = regs->r15; + case 4: + if (!n--) break; + *args++ = regs->r14; + case 3: + if (!n--) break; + *args++ = regs->r10; + case 2: + if (!n--) break; + *args++ = regs->r9; + case 1: + if (!n--) break; + *args++ = regs->r11; + case 0: + if (!n--) break; + default: + BUG(); + break; + } + + return; } +#endif + ia64_syscall_get_set_arguments(task, regs, i, n, args, 0); } #endif diff --git a/runtime/task_finder.c b/runtime/task_finder.c index fa6c296e2..93b89cb9d 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -1071,9 +1071,6 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, int rc; struct mm_struct *mm; struct vm_area_struct *vma; -#if defined(__ia64__) - struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; -#endif if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) { debug_task_finder_detach(); -- 2.43.5