Commit 329d2c15 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

infect: Move seized_native() into infect.c

Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 795049e6
#include "infect.h"
static struct syscall_exec_desc sc_exec_table_64[] = { static struct syscall_exec_desc sc_exec_table_64[] = {
#include "sys-exec-tbl-64.c" #include "sys-exec-tbl-64.c"
...@@ -29,7 +30,7 @@ find_syscall_table(char *name, struct syscall_exec_desc *tbl) ...@@ -29,7 +30,7 @@ find_syscall_table(char *name, struct syscall_exec_desc *tbl)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
struct syscall_exec_desc * find_syscall(char *name, struct parasite_ctl *ctl) struct syscall_exec_desc * find_syscall(char *name, struct parasite_ctl *ctl)
{ {
if (seized_native(ctl)) if (compel_mode_native(ctl))
return find_syscall_table(name, sc_exec_table_64); return find_syscall_table(name, sc_exec_table_64);
else else
return find_syscall_table(name, sc_exec_table_32); return find_syscall_table(name, sc_exec_table_32);
......
...@@ -76,4 +76,7 @@ extern int compel_stop_on_syscall(int tasks, int sys_nr, ...@@ -76,4 +76,7 @@ extern int compel_stop_on_syscall(int tasks, int sys_nr,
extern int compel_stop_pie(pid_t pid, void *addr, enum trace_flags *tf, bool no_bp); extern int compel_stop_pie(pid_t pid, void *addr, enum trace_flags *tf, bool no_bp);
extern int compel_unmap(struct parasite_ctl *ctl, unsigned long addr); extern int compel_unmap(struct parasite_ctl *ctl, unsigned long addr);
extern int compel_mode_native(struct parasite_ctl *ctl);
#endif #endif
...@@ -90,6 +90,5 @@ extern int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret, ...@@ -90,6 +90,5 @@ extern int syscall_seized(struct parasite_ctl *ctl, int nr, unsigned long *ret,
unsigned long arg5, unsigned long arg6); unsigned long arg5, unsigned long arg6);
extern bool arch_can_dump_task(struct parasite_ctl *ctl); extern bool arch_can_dump_task(struct parasite_ctl *ctl);
extern bool seized_native(struct parasite_ctl *ctl);
#endif /* __CR_PARASITE_SYSCALL_H__ */ #endif /* __CR_PARASITE_SYSCALL_H__ */
...@@ -638,7 +638,7 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size) ...@@ -638,7 +638,7 @@ static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size)
pid_t pid = ctl->rpid; pid_t pid = ctl->rpid;
unsigned long sret = -ENOSYS; unsigned long sret = -ENOSYS;
int ret, fd, lfd; int ret, fd, lfd;
bool __maybe_unused compat_task = !seized_native(ctl); bool __maybe_unused compat_task = !compel_mode_native(ctl);
if (ctl->ictx.flags & INFECT_NO_MEMFD) if (ctl->ictx.flags & INFECT_NO_MEMFD)
return 1; return 1;
...@@ -752,7 +752,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l ...@@ -752,7 +752,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l
* without using ptrace at all. * without using ptrace at all.
*/ */
if (seized_native(ctl)) if (compel_mode_native(ctl))
parasite_size = pie_size(parasite_native); parasite_size = pie_size(parasite_native);
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
else else
...@@ -773,7 +773,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l ...@@ -773,7 +773,7 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l
pr_info("Putting parasite blob into %p->%p\n", ctl->local_map, ctl->remote_map); pr_info("Putting parasite blob into %p->%p\n", ctl->local_map, ctl->remote_map);
if (seized_native(ctl)) if (compel_mode_native(ctl))
init_parasite_ctl(ctl, native); init_parasite_ctl(ctl, native);
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
else else
...@@ -964,7 +964,7 @@ int compel_cure_remote(struct parasite_ctl *ctl) ...@@ -964,7 +964,7 @@ int compel_cure_remote(struct parasite_ctl *ctl)
} else { } else {
unsigned long ret; unsigned long ret;
syscall_seized(ctl, __NR(munmap, !seized_native(ctl)), &ret, syscall_seized(ctl, __NR(munmap, !compel_mode_native(ctl)), &ret,
(unsigned long)ctl->remote_map, ctl->map_length, (unsigned long)ctl->remote_map, ctl->map_length,
0, 0, 0, 0); 0, 0, 0, 0);
if (ret) { if (ret) {
...@@ -1206,3 +1206,8 @@ goon: ...@@ -1206,3 +1206,8 @@ goon:
return 0; return 0;
} }
int compel_mode_native(struct parasite_ctl *ctl)
{
return user_regs_native(&ctl->orig.regs);
}
...@@ -306,7 +306,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, ...@@ -306,7 +306,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
* use, i.e. on non-lazy non-predump. * use, i.e. on non-lazy non-predump.
*/ */
cpp_flags |= PP_CHUNK_MODE; cpp_flags |= PP_CHUNK_MODE;
if (!seized_native(ctl)) if (!compel_mode_native(ctl))
cpp_flags |= PP_COMPAT; cpp_flags |= PP_COMPAT;
pp = create_page_pipe(vma_area_list->priv_size, pp = create_page_pipe(vma_area_list->priv_size,
pargs_iovs(args), cpp_flags); pargs_iovs(args), cpp_flags);
......
...@@ -89,11 +89,6 @@ static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs) ...@@ -89,11 +89,6 @@ static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs)
} }
#endif #endif
bool seized_native(struct parasite_ctl *ctl)
{
return user_regs_native(&ctl->orig.regs);
}
int parasite_send_fd(struct parasite_ctl *ctl, int fd) int parasite_send_fd(struct parasite_ctl *ctl, int fd)
{ {
int sk; int sk;
...@@ -180,7 +175,7 @@ int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, CoreEn ...@@ -180,7 +175,7 @@ int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, CoreEn
struct parasite_dump_creds *pc; struct parasite_dump_creds *pc;
int ret; int ret;
if (seized_native(ctl)) { if (compel_mode_native(ctl)) {
args = compel_parasite_args(ctl, struct parasite_dump_thread); args = compel_parasite_args(ctl, struct parasite_dump_thread);
pc = args->creds; pc = args->creds;
} else { } else {
...@@ -200,7 +195,7 @@ int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, CoreEn ...@@ -200,7 +195,7 @@ int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, CoreEn
return -1; return -1;
} }
if (seized_native(ctl)) if (compel_mode_native(ctl))
return dump_thread_core(pid, core, true, args); return dump_thread_core(pid, core, true, args);
else else
return dump_thread_core(pid, core, false, args_c); return dump_thread_core(pid, core, false, args_c);
...@@ -220,7 +215,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id, ...@@ -220,7 +215,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
BUG_ON(id == 0); /* Leader is dumped in dump_task_core_all */ BUG_ON(id == 0); /* Leader is dumped in dump_task_core_all */
if (seized_native(ctl)) { if (compel_mode_native(ctl)) {
args = compel_parasite_args(ctl, struct parasite_dump_thread); args = compel_parasite_args(ctl, struct parasite_dump_thread);
pc = args->creds; pc = args->creds;
} else { } else {
...@@ -255,7 +250,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id, ...@@ -255,7 +250,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
return -1; return -1;
} }
if (seized_native(ctl)) { if (compel_mode_native(ctl)) {
tid->ns[0].virt = args->tid; tid->ns[0].virt = args->tid;
return dump_thread_core(pid, core, true, args); return dump_thread_core(pid, core, true, args);
} else { } else {
...@@ -281,7 +276,7 @@ int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_imgset *cr_ ...@@ -281,7 +276,7 @@ int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_imgset *cr_
int ret, sig; int ret, sig;
struct cr_img *img; struct cr_img *img;
SaEntry se = SA_ENTRY__INIT; SaEntry se = SA_ENTRY__INIT;
bool native_task = seized_native(ctl); bool native_task = compel_mode_native(ctl);
if (native_task) if (native_task)
args = compel_parasite_args(ctl, struct parasite_dump_sa_args); args = compel_parasite_args(ctl, struct parasite_dump_sa_args);
...@@ -335,7 +330,7 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct pstree_item *i ...@@ -335,7 +330,7 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct pstree_item *i
struct parasite_dump_itimers_args_compat *args_c = NULL; struct parasite_dump_itimers_args_compat *args_c = NULL;
int ret; int ret;
if (seized_native(ctl)) if (compel_mode_native(ctl))
args = compel_parasite_args(ctl, struct parasite_dump_itimers_args); args = compel_parasite_args(ctl, struct parasite_dump_itimers_args);
else else
args_c = compel_parasite_args(ctl, struct parasite_dump_itimers_args_compat); args_c = compel_parasite_args(ctl, struct parasite_dump_itimers_args_compat);
...@@ -344,7 +339,7 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct pstree_item *i ...@@ -344,7 +339,7 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct pstree_item *i
if (ret < 0) if (ret < 0)
return ret; return ret;
if (seized_native(ctl)) if (compel_mode_native(ctl))
ASSIGN_ITIMER(args); ASSIGN_ITIMER(args);
else else
ASSIGN_ITIMER(args_c); ASSIGN_ITIMER(args_c);
...@@ -373,7 +368,7 @@ static int core_alloc_posix_timers(TaskTimersEntry *tte, int n, ...@@ -373,7 +368,7 @@ static int core_alloc_posix_timers(TaskTimersEntry *tte, int n,
#define set_posix_timer_arg(args, ctl, m, val) \ #define set_posix_timer_arg(args, ctl, m, val) \
do { \ do { \
if (seized_native(ctl)) \ if (compel_mode_native(ctl)) \
ASSIGN_TYPED( \ ASSIGN_TYPED( \
((struct parasite_dump_posix_timers_args*)args)->m, val); \ ((struct parasite_dump_posix_timers_args*)args)->m, val); \
else \ else \
...@@ -383,7 +378,7 @@ do { \ ...@@ -383,7 +378,7 @@ do { \
#define get_posix_timer_arg(out, m) \ #define get_posix_timer_arg(out, m) \
do { \ do { \
if (seized_native(ctl)) \ if (compel_mode_native(ctl)) \
ASSIGN_TYPED( \ ASSIGN_TYPED( \
out, ((struct parasite_dump_posix_timers_args*)args)->m); \ out, ((struct parasite_dump_posix_timers_args*)args)->m); \
else \ else \
...@@ -423,7 +418,7 @@ int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args, ...@@ -423,7 +418,7 @@ int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args,
if (core_alloc_posix_timers(tte, proc_args->timer_n, &pte)) if (core_alloc_posix_timers(tte, proc_args->timer_n, &pte))
return -1; return -1;
if (seized_native(ctl)) if (compel_mode_native(ctl))
args_size = posix_timers_dump_size(proc_args->timer_n); args_size = posix_timers_dump_size(proc_args->timer_n);
else else
args_size = posix_timers_compat_dump_size(proc_args->timer_n); args_size = posix_timers_compat_dump_size(proc_args->timer_n);
......
...@@ -106,7 +106,7 @@ int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid, ...@@ -106,7 +106,7 @@ int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid,
* XXX: For compatible tasks, vDSO pfn is different from * XXX: For compatible tasks, vDSO pfn is different from
* our native vdso_pfn. Check vma explicitly. * our native vdso_pfn. Check vma explicitly.
*/ */
if (!seized_native(ctl)) if (!compel_mode_native(ctl))
args->try_fill_symtable = true; args->try_fill_symtable = true;
else else
args->try_fill_symtable = (fd < 0) ? true : false; args->try_fill_symtable = (fd < 0) ? true : false;
......
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