Commit c2a366d4 authored by Pavel Emelyanov's avatar Pavel Emelyanov

ptrace: Introduce get/set regs helpers

Required for simpler next patching.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c1c9b8f6
...@@ -65,6 +65,16 @@ static struct vma_area *get_vma_by_ip(struct list_head *vma_area_list, unsigned ...@@ -65,6 +65,16 @@ static struct vma_area *get_vma_by_ip(struct list_head *vma_area_list, unsigned
return NULL; return NULL;
} }
static inline int ptrace_get_regs(int pid, user_regs_struct_t *regs)
{
return ptrace(PTRACE_GETREGS, pid, NULL, regs);
}
static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs)
{
return ptrace(PTRACE_SETREGS, pid, NULL, regs);
}
static int get_thread_ctx(int pid, struct thread_ctx *ctx) static int get_thread_ctx(int pid, struct thread_ctx *ctx)
{ {
if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(k_rtsigset_t), &ctx->sigmask)) { if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(k_rtsigset_t), &ctx->sigmask)) {
...@@ -72,7 +82,7 @@ static int get_thread_ctx(int pid, struct thread_ctx *ctx) ...@@ -72,7 +82,7 @@ static int get_thread_ctx(int pid, struct thread_ctx *ctx)
return -1; return -1;
} }
if (ptrace(PTRACE_GETREGS, pid, NULL, &ctx->regs)) { if (ptrace_get_regs(pid, &ctx->regs)) {
pr_perror("Can't obtain registers (pid: %d)", pid); pr_perror("Can't obtain registers (pid: %d)", pid);
return -1; return -1;
} }
...@@ -84,7 +94,7 @@ static int restore_thread_ctx(int pid, struct thread_ctx *ctx) ...@@ -84,7 +94,7 @@ static int restore_thread_ctx(int pid, struct thread_ctx *ctx)
{ {
int ret = 0; int ret = 0;
if (ptrace(PTRACE_SETREGS, pid, NULL, &ctx->regs)) { if (ptrace_set_regs(pid, &ctx->regs)) {
pr_perror("Can't restore registers (pid: %d)", pid); pr_perror("Can't restore registers (pid: %d)", pid);
ret = -1; ret = -1;
} }
...@@ -108,7 +118,7 @@ static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, ...@@ -108,7 +118,7 @@ static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack,
} }
parasite_setup_regs(ip, stack, regs); parasite_setup_regs(ip, stack, regs);
if (ptrace(PTRACE_SETREGS, pid, NULL, regs)) { if (ptrace_set_regs(pid, regs)) {
pr_perror("Can't set registers for %d", pid); pr_perror("Can't set registers for %d", pid);
goto err_regs; goto err_regs;
} }
...@@ -121,7 +131,7 @@ static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack, ...@@ -121,7 +131,7 @@ static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack,
return 0; return 0;
err_cont: err_cont:
if (ptrace(PTRACE_SETREGS, pid, NULL, &octx->regs)) if (ptrace_set_regs(pid, &octx->regs))
pr_perror("Can't restore regs for %d", pid); pr_perror("Can't restore regs for %d", pid);
err_regs: err_regs:
if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &octx->sigmask)) if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &octx->sigmask))
...@@ -159,7 +169,7 @@ static int parasite_trap(struct parasite_ctl *ctl, pid_t pid, ...@@ -159,7 +169,7 @@ static int parasite_trap(struct parasite_ctl *ctl, pid_t pid,
goto err; goto err;
} }
if (ptrace(PTRACE_GETREGS, pid, NULL, regs)) { if (ptrace_get_regs(pid, regs)) {
pr_perror("Can't obtain registers (pid: %d)", pid); pr_perror("Can't obtain registers (pid: %d)", pid);
goto err; goto err;
} }
...@@ -812,7 +822,7 @@ static int parasite_fini_seized(struct parasite_ctl *ctl) ...@@ -812,7 +822,7 @@ static int parasite_fini_seized(struct parasite_ctl *ctl)
return -1; return -1;
} }
ret = ptrace(PTRACE_GETREGS, pid, NULL, &regs); ret = ptrace_get_regs(pid, &regs);
if (ret) { if (ret) {
pr_perror("Unable to get registers"); pr_perror("Unable to get registers");
return -1; return -1;
...@@ -876,7 +886,7 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr) ...@@ -876,7 +886,7 @@ int parasite_stop_on_syscall(int tasks, const int sys_nr)
pr_err("%d\n", status); pr_err("%d\n", status);
return -1; return -1;
} }
ret = ptrace(PTRACE_GETREGS, pid, NULL, &regs); ret = ptrace_get_regs(pid, &regs);
if (ret) { if (ret) {
pr_perror("ptrace"); pr_perror("ptrace");
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment