Commit dbb32a0e authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

parasite: return ability to execute code in a thread with specified pid

Currently we use id to get pid and other properties, which used when a
thread is daemonized. We are going to not demonize threads, so pid will
be only one useful field on parasite_thread_ctl.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ce4cd8d4
......@@ -202,19 +202,19 @@ void *parasite_args_s(struct parasite_ctl *ctl, int args_size)
ctl->addr_args; \
})
static int parasite_execute_trap_by_id(unsigned int cmd, struct parasite_ctl *ctl, int id)
static int parasite_execute_trap_by_pid(unsigned int cmd,
struct parasite_ctl *ctl, pid_t pid,
user_regs_struct_t *regs_orig,
void *stack, bool use_sig_blocked)
{
struct parasite_thread_ctl *thread = &ctl->threads[id];
user_regs_struct_t regs = thread->regs_orig;
pid_t pid = thread->tid;
user_regs_struct_t regs = *regs_orig;
int ret;
*ctl->addr_cmd = cmd;
parasite_setup_regs(ctl->parasite_ip, thread->rstack, &regs);
parasite_setup_regs(ctl->parasite_ip, stack, &regs);
ret = __parasite_execute_trap(ctl, pid, &regs, &thread->regs_orig,
thread->use_sig_blocked);
ret = __parasite_execute_trap(ctl, pid, &regs, regs_orig, use_sig_blocked);
if (ret == 0)
ret = (int)REG_RES(regs);
......@@ -222,7 +222,7 @@ static int parasite_execute_trap_by_id(unsigned int cmd, struct parasite_ctl *ct
pr_err("Parasite exited with %d\n", ret);
if (ctl->pid.real != pid)
if (ptrace(PTRACE_SETREGS, pid, NULL, &thread->regs_orig)) {
if (ptrace(PTRACE_SETREGS, pid, NULL, regs_orig)) {
pr_perror("Can't restore registers (pid: %d)", pid);
return -1;
}
......@@ -230,6 +230,18 @@ static int parasite_execute_trap_by_id(unsigned int cmd, struct parasite_ctl *ct
return ret;
}
static int parasite_execute_trap_by_id(unsigned int cmd, struct parasite_ctl *ctl, int id)
{
struct parasite_thread_ctl *thread = &ctl->threads[id];
pid_t pid = thread->tid;
int ret;
ret = parasite_execute_trap_by_pid(cmd, ctl, pid, &thread->regs_orig,
thread->rstack, thread->use_sig_blocked);
return ret;
}
static int parasite_execute_trap(unsigned int cmd, struct parasite_ctl *ctl)
{
return parasite_execute_trap_by_id(cmd, ctl, 0);
......
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