Change ptrace_request() to find utrace_engine and pass it to callees. ---
kernel/ptrace.c | 63 +++++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) --- PU/kernel/ptrace.c~50_PTRACE_REQUEST_LOOKUP_ENGINE 2009-09-17 20:46:55.000000000 +0200 +++ PU/kernel/ptrace.c 2009-09-17 21:03:11.000000000 +0200 @@ -806,27 +806,20 @@ int ptrace_writedata(struct task_struct return copied; } -static int ptrace_set_options(struct task_struct *child, long data) +static int ptrace_set_options(struct utrace_engine *engine, + struct task_struct *child, long data) { - struct utrace_engine *engine = ptrace_lookup_engine(child); - - if (likely(!IS_ERR(engine))) { - __ptrace_set_options(child, engine, data & PTRACE_O_MASK); - utrace_engine_put(engine); - } + __ptrace_set_options(child, engine, data & PTRACE_O_MASK); return (data & ~PTRACE_O_MASK) ? -EINVAL : 0; } -static int ptrace_getsiginfo(struct task_struct *child, siginfo_t *info) +static int ptrace_getsiginfo(struct utrace_engine *engine, + struct task_struct *child, siginfo_t *info) { - struct utrace_engine *engine = ptrace_lookup_engine(child); unsigned long flags; int error = -ESRCH; - if (IS_ERR(engine)) - return error; - if (lock_task_sighand(child, &flags)) { error = -EINVAL; if (likely(ptrace_context(engine)->siginfo != NULL)) { @@ -836,19 +829,15 @@ static int ptrace_getsiginfo(struct task unlock_task_sighand(child, &flags); } - utrace_engine_put(engine); return error; } -static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info) +static int ptrace_setsiginfo(struct utrace_engine *engine, + struct task_struct *child, const siginfo_t *info) { - struct utrace_engine *engine = ptrace_lookup_engine(child); unsigned long flags; int error = -ESRCH; - if (IS_ERR(engine)) - return error; - if (lock_task_sighand(child, &flags)) { error = -EINVAL; if (likely(ptrace_context(engine)->siginfo != NULL)) { @@ -858,7 +847,6 @@ static int ptrace_setsiginfo(struct task unlock_task_sighand(child, &flags); } - utrace_engine_put(engine); return error; } @@ -965,10 +953,9 @@ static void do_ptrace_resume(struct utra ptrace_wake_up(engine, tracee, UTRACE_RESUME); } -static int ptrace_resume(struct task_struct *child, long request, long data) +static int ptrace_resume(struct utrace_engine *engine, + struct task_struct *child, long request, long data) { - struct utrace_engine *engine; - struct ptrace_context *context; enum utrace_resume_action action; enum utrace_syscall_action syscall; int ret = 0; @@ -976,12 +963,6 @@ static int ptrace_resume(struct task_str if (!valid_signal(data)) return -EIO; - engine = ptrace_lookup_engine(child); - if (IS_ERR(engine)) - return -ESRCH; - - context = ptrace_context(engine); - syscall = UTRACE_SYSCALL_RUN; #ifdef PTRACE_SYSEMU if (request == PTRACE_SYSEMU || request == PTRACE_SYSEMU_SINGLESTEP) @@ -1013,17 +994,19 @@ static int ptrace_resume(struct task_str if (!ret) do_ptrace_resume(engine, child, request, data); - utrace_engine_put(engine); - return ret; } int ptrace_request(struct task_struct *child, long request, long addr, long data) { + struct utrace_engine *engine = ptrace_lookup_engine(child); siginfo_t siginfo; int ret; + if (unlikely(IS_ERR(engine))) + return -ESRCH; + switch (request) { case PTRACE_PEEKTEXT: case PTRACE_PEEKDATA: @@ -1038,14 +1021,14 @@ int ptrace_request(struct task_struct *c case PTRACE_OLDSETOPTIONS: #endif case PTRACE_SETOPTIONS: - ret = ptrace_set_options(child, data); + ret = ptrace_set_options(engine, child, data); break; case PTRACE_GETEVENTMSG: ret = put_user(child->ptrace_message, (unsigned long __user *) data); break; case PTRACE_GETSIGINFO: - ret = ptrace_getsiginfo(child, &siginfo); + ret = ptrace_getsiginfo(engine, child, &siginfo); if (!ret) ret = copy_siginfo_to_user((siginfo_t __user *) data, &siginfo); @@ -1056,7 +1039,7 @@ int ptrace_request(struct task_struct *c sizeof siginfo)) ret = -EFAULT; else - ret = ptrace_setsiginfo(child, &siginfo); + ret = ptrace_setsiginfo(engine, child, &siginfo); break; case PTRACE_DETACH: /* detach a process that was attached. */ @@ -1075,13 +1058,13 @@ int ptrace_request(struct task_struct *c #endif case PTRACE_SYSCALL: case PTRACE_CONT: - ret = ptrace_resume(child, request, data); + ret = ptrace_resume(engine, child, request, data); break; case PTRACE_KILL: ret = 0; if (!child->exit_state) /* already dead */ - ret = ptrace_resume(child, request, SIGKILL); + ret = ptrace_resume(engine, child, request, SIGKILL); break; default: @@ -1089,6 +1072,7 @@ int ptrace_request(struct task_struct *c break; } + utrace_engine_put(engine); return ret; } @@ -1182,11 +1166,15 @@ int generic_ptrace_pokedata(struct task_ int compat_ptrace_request(struct task_struct *child, compat_long_t request, compat_ulong_t addr, compat_ulong_t data) { + struct utrace_engine *engine = ptrace_lookup_engine(child); compat_ulong_t __user *datap = compat_ptr(data); compat_ulong_t word; siginfo_t siginfo; int ret; + if (unlikely(IS_ERR(engine))) + return -ESRCH; + switch (request) { case PTRACE_PEEKTEXT: case PTRACE_PEEKDATA: @@ -1208,7 +1196,7 @@ int compat_ptrace_request(struct task_st break; case PTRACE_GETSIGINFO: - ret = ptrace_getsiginfo(child, &siginfo); + ret = ptrace_getsiginfo(engine, child, &siginfo); if (!ret) ret = copy_siginfo_to_user32( (struct compat_siginfo __user *) datap, @@ -1221,13 +1209,14 @@ int compat_ptrace_request(struct task_st &siginfo, (struct compat_siginfo __user *) datap)) ret = -EFAULT; else - ret = ptrace_setsiginfo(child, &siginfo); + ret = ptrace_setsiginfo(engine, child, &siginfo); break; default: ret = ptrace_request(child, request, addr, data); } + utrace_engine_put(engine); return ret; }