Commit 6fee9c70 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Andrei Vagin

infect: Remove parasite-syscall.h from infect

This is

* Move parasite_setup_regs() and related into arch/infect
* Move arch_can_dump_task() into infect
* Move parasite_send_fd() into infect-util

and completes parasite-syscall.h removal.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 5156b096
#ifndef __COMPEL_PTRACE_H__
#define __COMPEL_PTRACE_H__
#define ARCH_SI_TRAP TRAP_BRKPT
#endif
#ifndef __COMPEL_SYSCALL_H__
#define __COMPEL_SYSCALL_H__
#define __NR(syscall, compat) __NR_##syscall
#endif
#ifndef __COMPEL_PTRACE_H__
#define __COMPEL_PTRACE_H__
#define ARCH_SI_TRAP TRAP_BRKPT
#endif
#ifndef __COMPEL_SYSCALL_H__
#define __COMPEL_SYSCALL_H__
#define __NR(syscall, compat) __NR_##syscall
#endif
#ifndef __COMPEL_PTRACE_H__
#define __COMPEL_PTRACE_H__
#define ARCH_SI_TRAP TRAP_BRKPT
#endif
#ifndef __COMPEL_SYSCALL_H__
#define __COMPEL_SYSCALL_H__
#define __NR(syscall, compat) __NR_##syscall
#endif
#ifndef __COMPEL_PTRACE_H__
#define __COMPEL_PTRACE_H__
#define ARCH_SI_TRAP SI_KERNEL
#endif
#ifndef __COMPEL_SYSCALL_H__
#define __COMPEL_SYSCALL_H__
#define __NR(syscall, compat) ((compat) ? __NR32_##syscall : __NR_##syscall)
#endif
......@@ -5,6 +5,7 @@ ccflags-y += -iquote compel/arch/$(ARCH)/plugins/std
obj-y += infect.o
obj-y += infect-rpc.o
obj-y += infect-util.o
obj-y += action-scripts.o
obj-y += external.o
obj-y += aio.o
......
......@@ -19,21 +19,6 @@
#include "restorer.h"
#include "infect.h"
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
regs->pc = new_ip;
if (stack)
regs->sp = (unsigned long)stack;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
/*
* TODO: Add proper check here
*/
return true;
}
#define assign_reg(dst, src, e) dst->e = (__typeof__(dst->e))(src)->e
int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpsimd)
......
......@@ -3,10 +3,4 @@
struct parasite_ctl;
#define ARCH_SI_TRAP TRAP_BRKPT
#define __NR(syscall, compat) __NR_##syscall
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);
#endif
......@@ -98,3 +98,17 @@ void *mmap_re(struct parasite_ctl *ctl,
return (void *)map;
}
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
regs->pc = new_ip;
if (stack)
regs->sp = (unsigned long)stack;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
/*
* TODO: Add proper check here
*/
return true;
}
......@@ -20,24 +20,6 @@
#include "kerndat.h"
#include "infect.h"
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
regs->ARM_pc = new_ip;
if (stack)
regs->ARM_sp = (unsigned long)stack;
/* Make sure flags are in known state */
regs->ARM_cpsr &= PSR_f | PSR_s | PSR_x | MODE32_BIT;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
/*
* TODO: Add proper check here
*/
return true;
}
#define assign_reg(dst, src, e) dst->e = (__typeof__(dst->e))((src)->ARM_##e)
int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
......
......@@ -3,10 +3,4 @@
struct parasite_ctl;
#define ARCH_SI_TRAP TRAP_BRKPT
#define __NR(syscall, compat) __NR_##syscall
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);
#endif
......@@ -105,3 +105,20 @@ void *remote_mmap(struct parasite_ctl *ctl,
return (void *)map;
}
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
regs->ARM_pc = new_ip;
if (stack)
regs->ARM_sp = (unsigned long)stack;
/* Make sure flags are in known state */
regs->ARM_cpsr &= PSR_f | PSR_s | PSR_x | MODE32_BIT;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
/*
* TODO: Add proper check here
*/
return true;
}
......@@ -24,27 +24,6 @@
#include "images/core.pb-c.h"
#include "images/creds.pb-c.h"
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
/*
* OpenPOWER ABI requires that r12 is set to the calling function addressi
* to compute the TOC pointer.
*/
regs->gpr[12] = new_ip;
regs->nip = new_ip;
if (stack)
regs->gpr[1] = (unsigned long) stack;
regs->trap = 0;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
/*
* TODO: We should detect 32bit task when BE support is done.
*/
return true;
}
static UserPpc64FpstateEntry *copy_fp_regs(uint64_t *fpregs)
{
UserPpc64FpstateEntry *fpe;
......
......@@ -3,10 +3,4 @@
struct parasite_ctl;
#define ARCH_SI_TRAP TRAP_BRKPT
#define __NR(syscall, compat) __NR_##syscall
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);
#endif
......@@ -295,3 +295,24 @@ void *remote_mmap(struct parasite_ctl *ctl,
return (void *)map;
}
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
/*
* OpenPOWER ABI requires that r12 is set to the calling function addressi
* to compute the TOC pointer.
*/
regs->gpr[12] = new_ip;
regs->nip = new_ip;
if (stack)
regs->gpr[1] = (unsigned long) stack;
regs->trap = 0;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
/*
* TODO: We should detect 32bit task when BE support is done.
*/
return true;
}
......@@ -7,7 +7,6 @@
#include <sys/auxv.h>
#include "types.h"
#include "asm/processor-flags.h"
#include "asm/parasite-syscall.h"
#include "asm/restorer.h"
#include "asm/fpu.h"
......@@ -30,23 +29,6 @@
#include "images/core.pb-c.h"
#include "images/creds.pb-c.h"
/*
* regs must be inited when calling this function from original context
*/
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
set_user_reg(regs, ip, new_ip);
if (stack)
set_user_reg(regs, sp, (unsigned long) stack);
/* Avoid end of syscall processing */
set_user_reg(regs, orig_ax, -1);
/* Make sure flags are in known state */
set_user_reg(regs, flags, get_user_reg(regs, flags) &
~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF));
}
#ifdef CONFIG_X86_64
/* Remaps 64-bit vDSO on the same addr, where it already is */
int kdat_compat_sigreturn_test(void)
......@@ -72,54 +54,6 @@ int kdat_compat_sigreturn_test(void)
}
#endif /* CONFIG_X86_64 */
static int arch_task_compatible(struct parasite_ctl *ctl)
{
return !user_regs_native(&ctl->orig.regs);
}
#define USER32_CS 0x23
#define USER_CS 0x33
static bool ldt_task_selectors(pid_t pid)
{
unsigned long cs;
errno = 0;
/*
* Offset of register must be from 64-bit set even for
* compatible tasks. Fix this to support native i386 tasks
*/
cs = ptrace(PTRACE_PEEKUSER, pid, offsetof(user_regs_struct64, cs), 0);
if (errno != 0) {
pr_perror("Can't get CS register for %d", pid);
return -1;
}
return cs != USER_CS && cs != USER32_CS;
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
pid_t pid = ctl->rpid;
int ret;
ret = arch_task_compatible(ctl);
if (ret < 0)
return false;
if (ret && !kdat.has_compat_sigreturn) {
pr_err("Can't dump task %d running in 32-bit mode\n", pid);
return false;
}
if (ldt_task_selectors(pid)) {
pr_err("Can't dump task %d with LDT descriptors\n", pid);
return false;
}
return true;
}
int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpregs)
{
CoreEntry *core = x;
......
......@@ -5,10 +5,6 @@
struct parasite_ctl;
#define ARCH_SI_TRAP SI_KERNEL
#define __NR(syscall, compat) ((compat) ? __NR32_##syscall : __NR_##syscall)
/*
* For x86_32 __NR_mmap inside the kernel represents old_mmap system
* call, but since we didn't use it yet lets go further and simply
......@@ -18,6 +14,4 @@ struct parasite_ctl;
#define __NR32_mmap __NR32_mmap2
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);
#endif
......@@ -3,14 +3,19 @@
#include <sys/uio.h>
#include <sys/auxv.h>
#include <sys/mman.h>
#include "asm/processor-flags.h"
#include "asm/parasite-syscall.h"
#include "uapi/std/syscall-codes.h"
#include "compel/include/asm/syscall.h"
#include "err.h"
#include "asm/fpu.h"
#include "asm/types.h"
#include "errno.h"
#include "asm/cpu.h"
#include "parasite-syscall.h"
#include "ptrace.h"
#include "kerndat.h"
#include "infect.h"
#include "infect-priv.h"
......@@ -170,6 +175,77 @@ void *remote_mmap(struct parasite_ctl *ctl,
return (void *)map;
}
/*
* regs must be inited when calling this function from original context
*/
void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs)
{
set_user_reg(regs, ip, new_ip);
if (stack)
set_user_reg(regs, sp, (unsigned long) stack);
/* Avoid end of syscall processing */
set_user_reg(regs, orig_ax, -1);
/* Make sure flags are in known state */
set_user_reg(regs, flags, get_user_reg(regs, flags) &
~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF));
}
#define USER32_CS 0x23
#define USER_CS 0x33
static bool ldt_task_selectors(pid_t pid)
{
unsigned long cs;
errno = 0;
/*
* Offset of register must be from 64-bit set even for
* compatible tasks. Fix this to support native i386 tasks
*/
cs = ptrace(PTRACE_PEEKUSER, pid, offsetof(user_regs_struct64, cs), 0);
if (errno != 0) {
pr_perror("Can't get CS register for %d", pid);
return -1;
}
return cs != USER_CS && cs != USER32_CS;
}
static int arch_task_compatible(pid_t pid)
{
user_regs_struct_t r;
int ret = ptrace_get_regs(pid, &r);
if (ret)
return -1;
return !user_regs_native(&r);
}
bool arch_can_dump_task(struct parasite_ctl *ctl)
{
pid_t pid = ctl->rpid;
int ret;
ret = arch_task_compatible(pid);
if (ret < 0)
return false;
if (ret && !kdat.has_compat_sigreturn) {
pr_err("Can't dump task %d running in 32-bit mode\n", pid);
return false;
}
if (ldt_task_selectors(pid)) {
pr_err("Can't dump task %d with LDT descriptors\n", pid);
return false;
}
return true;
}
int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs)
{
struct iovec iov;
......
......@@ -81,6 +81,7 @@
#include "parasite-syscall.h"
#include "files-reg.h"
#include "uapi/std/syscall-codes.h"
#include "compel/include/asm/syscall.h"
#include "protobuf.h"
#include "images/sa.pb-c.h"
......
......@@ -3,6 +3,8 @@
#include <stdbool.h>
#define BUILTIN_SYSCALL_SIZE 8
/* parasite control block */
struct parasite_ctl {
int rpid; /* Real pid of the victim */
......@@ -46,7 +48,10 @@ extern int compel_syscall(struct parasite_ctl *ctl, int nr, unsigned long *ret,
unsigned long arg5, unsigned long arg6);
extern void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *regs);
extern void *remote_mmap(struct parasite_ctl *ctl,
void *addr, size_t length, int prot,
int flags, int fd, off_t offset);
extern bool arch_can_dump_task(struct parasite_ctl *ctl);
#endif
#ifndef __COMPEL_INFECT_UTIL_H__
#define __COMPEL_INFECT_UTIL_H__
struct parasite_ctl;
extern int compel_util_send_fd(struct parasite_ctl *ctl, int fd);
#endif
......@@ -6,8 +6,6 @@
#include "config.h"
#include "asm/parasite-syscall.h"
#define BUILTIN_SYSCALL_SIZE 8
struct parasite_dump_thread;
struct parasite_dump_misc;
struct parasite_drain_fd;
......@@ -31,8 +29,6 @@ struct proc_posix_timers_stat;
extern int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args,
struct parasite_ctl *ctl, struct pstree_item *);
extern int parasite_send_fd(struct parasite_ctl *ctl, int fd);
extern int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_misc *misc);
extern int parasite_dump_creds(struct parasite_ctl *ctl, struct _CredsEntry *ce);
extern int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, struct _CoreEntry *core);
......@@ -59,6 +55,4 @@ extern struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int
extern int parasite_init_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item);
extern int parasite_fini_threads_seized(struct parasite_ctl *ctl);
extern bool arch_can_dump_task(struct parasite_ctl *ctl);
#endif /* __CR_PARASITE_SYSCALL_H__ */
#include "int.h"
#include "log.h"
#include "common/bug.h"
#include "lock.h"
#include "util-pie.h"
#include "infect-rpc.h"
#include "infect-util.h"
int compel_util_send_fd(struct parasite_ctl *ctl, int fd)
{
int sk;
sk = compel_rpc_sock(ctl);
if (send_fd(sk, NULL, 0, fd) < 0) {
pr_perror("Can't send file descriptor");
return -1;
}
return 0;
}
......@@ -6,16 +6,18 @@
#include <signal.h>
#include <linux/seccomp.h>
#include "compel/include/asm/ptrace.h"
#include "compel/include/asm/syscall.h"
#include "infect.h"
#include "ptrace.h"
#include "restorer.h"
#include "parasite-syscall.h"
#include "pie-relocs.h"
#include "parasite-blob.h"
#include "sigframe.h"
#include "criu-log.h"
#include "infect-rpc.h"
#include "infect-priv.h"
#include "infect-util.h"
#define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - \
(size_t)((struct sockaddr_un *) 0)->sun_path)
......@@ -556,7 +558,7 @@ static int parasite_init_daemon(struct parasite_ctl *ctl)
if (accept_tsock(ctl) < 0)
goto err;
if (parasite_send_fd(ctl, log_get_fd()))
if (compel_util_send_fd(ctl, log_get_fd()))
goto err;
pr_info("Wait for parasite being daemonized...\n");
......
......@@ -27,6 +27,7 @@
#include "fault-injection.h"
#include "infect.h"
#include "infect-rpc.h"
#include "infect-util.h"
#include "protobuf.h"
#include "images/pagemap.pb-c.h"
......@@ -236,7 +237,7 @@ static int drain_pages(struct page_pipe *pp, struct parasite_ctl *ctl,
ret = compel_rpc_call(PARASITE_CMD_DUMPPAGES, ctl);
if (ret < 0)
return -1;
ret = parasite_send_fd(ctl, ppb->p[1]);
ret = compel_util_send_fd(ctl, ppb->p[1]);
if (ret)
return -1;
......
......@@ -68,18 +68,6 @@ unsigned long get_exec_start(struct vm_area_list *vmas)
return 0;
}
int parasite_send_fd(struct parasite_ctl *ctl, int fd)
{
int sk;
sk = compel_rpc_sock(ctl);
if (send_fd(sk, NULL, 0, fd) < 0) {
pr_perror("Can't send file descriptor");
return -1;
}
return 0;
}
/*
* We need to detect parasite crashes not to hang on socket operations.
* Since CRIU holds parasite with ptrace, it will receive SIGCHLD if the
......
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