Commit a1809b20 authored by Pavel Emelyanov's avatar Pavel Emelyanov

parasite: Generalize running parasite context

The only place left, that runs parasite by hands -- unmap().
Now we can use parasite_run() for that.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f0453c8e
...@@ -80,7 +80,7 @@ static int get_thread_ctx(int pid, struct thread_ctx *ctx) ...@@ -80,7 +80,7 @@ static int get_thread_ctx(int pid, struct thread_ctx *ctx)
return 0; return 0;
} }
static int parasite_run(pid_t pid, unsigned long ip, void *stack, static int parasite_run(pid_t pid, int cmd, unsigned long ip, void *stack,
user_regs_struct_t *regs, struct thread_ctx *octx) user_regs_struct_t *regs, struct thread_ctx *octx)
{ {
k_rtsigset_t block; k_rtsigset_t block;
...@@ -97,7 +97,7 @@ static int parasite_run(pid_t pid, unsigned long ip, void *stack, ...@@ -97,7 +97,7 @@ static int parasite_run(pid_t pid, unsigned long ip, void *stack,
goto err_regs; goto err_regs;
} }
if (ptrace(PTRACE_CONT, pid, NULL, NULL)) { if (ptrace(cmd, pid, NULL, NULL)) {
pr_perror("Can't run parasite at %d", pid); pr_perror("Can't run parasite at %d", pid);
goto err_cont; goto err_cont;
} }
...@@ -190,7 +190,7 @@ int __parasite_execute_syscall(struct parasite_ctl *ctl, user_regs_struct_t *reg ...@@ -190,7 +190,7 @@ int __parasite_execute_syscall(struct parasite_ctl *ctl, user_regs_struct_t *reg
return -1; return -1;
} }
err = parasite_run(pid, ctl->syscall_ip, 0, regs, &ctl->orig); err = parasite_run(pid, PTRACE_CONT, ctl->syscall_ip, 0, regs, &ctl->orig);
if (!err) if (!err)
err = parasite_trap(ctl, pid, regs, &ctl->orig); err = parasite_trap(ctl, pid, regs, &ctl->orig);
...@@ -219,7 +219,7 @@ static int parasite_execute_trap_by_pid(unsigned int cmd, ...@@ -219,7 +219,7 @@ static int parasite_execute_trap_by_pid(unsigned int cmd,
*ctl->addr_cmd = cmd; *ctl->addr_cmd = cmd;
ret = parasite_run(pid, ctl->parasite_ip, stack, &regs, octx); ret = parasite_run(pid, PTRACE_CONT, ctl->parasite_ip, stack, &regs, octx);
if (ret == 0) if (ret == 0)
ret = parasite_trap(ctl, pid, &regs, octx); ret = parasite_trap(ctl, pid, &regs, octx);
if (ret == 0) if (ret == 0)
...@@ -483,7 +483,7 @@ static int parasite_init_daemon(struct parasite_ctl *ctl) ...@@ -483,7 +483,7 @@ static int parasite_init_daemon(struct parasite_ctl *ctl)
goto err; goto err;
regs = ctl->orig.regs; regs = ctl->orig.regs;
if (parasite_run(pid, ctl->parasite_ip, ctl->rstack, &regs, &ctl->orig)) if (parasite_run(pid, PTRACE_CONT, ctl->parasite_ip, ctl->rstack, &regs, &ctl->orig))
goto err; goto err;
ctl->tsock = accept_tsock(); ctl->tsock = accept_tsock();
...@@ -968,38 +968,21 @@ int parasite_cure_seized(struct parasite_ctl *ctl) ...@@ -968,38 +968,21 @@ int parasite_cure_seized(struct parasite_ctl *ctl)
*/ */
int parasite_unmap(struct parasite_ctl *ctl, unsigned long addr) int parasite_unmap(struct parasite_ctl *ctl, unsigned long addr)
{ {
user_regs_struct_t regs; user_regs_struct_t regs = ctl->orig.regs;
pid_t pid = ctl->pid.real; pid_t pid = ctl->pid.real;
k_rtsigset_t block;
int ret = -1; int ret = -1;
ksigfillset(&block); ret = parasite_run(pid, PTRACE_SYSCALL, addr, NULL, &regs, &ctl->orig);
if (ret)
if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &block)) {
pr_perror("Can't block signals for %d", pid);
goto err; goto err;
}
regs = ctl->orig.regs;
parasite_setup_regs(addr, 0, &regs);
if (ptrace(PTRACE_SETREGS, pid, NULL, &regs)) {
pr_perror("Can't set registers for %d", pid);
goto err_sig;
}
if (ptrace(PTRACE_SYSCALL, pid, NULL, NULL)) {
pr_perror("ptrace");
goto err_regs;
}
ret = parasite_stop_on_syscall(1, __NR_munmap); ret = parasite_stop_on_syscall(1, __NR_munmap);
err_regs:
if (ptrace(PTRACE_SETREGS, pid, NULL, &ctl->orig.regs)) { if (ptrace(PTRACE_SETREGS, pid, NULL, &ctl->orig.regs)) {
pr_perror("Can't restore regs for %d", pid); pr_perror("Can't restore regs for %d", pid);
ret = -1; ret = -1;
} }
err_sig:
if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &ctl->orig.sigmask)) { if (ptrace(PTRACE_SETSIGMASK, pid, sizeof(k_rtsigset_t), &ctl->orig.sigmask)) {
pr_perror("Can't restore sigmask for %d", pid); pr_perror("Can't restore sigmask for %d", pid);
ret = -1; ret = -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