diff options
-rw-r--r-- | compel/arch/aarch64/src/lib/include/ptrace.h | 11 | ||||
-rw-r--r-- | compel/arch/arm/src/lib/include/ptrace.h | 11 | ||||
-rw-r--r-- | compel/arch/ppc64/src/lib/include/ptrace.h | 11 | ||||
-rw-r--r-- | compel/arch/x86/src/lib/include/ptrace.h | 2 | ||||
-rw-r--r-- | criu/arch/aarch64/include/asm/restorer.h | 10 | ||||
-rw-r--r-- | criu/arch/arm/include/asm/restorer.h | 10 | ||||
-rw-r--r-- | criu/arch/ppc64/include/asm/restorer.h | 10 | ||||
-rw-r--r-- | criu/arch/x86/crtools.c | 59 | ||||
-rw-r--r-- | criu/arch/x86/infect.c | 60 | ||||
-rw-r--r-- | criu/infect.c | 13 |
10 files changed, 106 insertions, 91 deletions
diff --git a/compel/arch/aarch64/src/lib/include/ptrace.h b/compel/arch/aarch64/src/lib/include/ptrace.h index 9cf7d460d..e18454df2 100644 --- a/compel/arch/aarch64/src/lib/include/ptrace.h +++ b/compel/arch/aarch64/src/lib/include/ptrace.h @@ -1,4 +1,15 @@ #ifndef __COMPEL_PTRACE_H__ #define __COMPEL_PTRACE_H__ #define ARCH_SI_TRAP TRAP_BRKPT + +static inline int ptrace_set_breakpoint(pid_t pid, void *addr) +{ + return 0; +} + +static inline int ptrace_flush_breakpoints(pid_t pid) +{ + return 0; +} + #endif diff --git a/compel/arch/arm/src/lib/include/ptrace.h b/compel/arch/arm/src/lib/include/ptrace.h index 9cf7d460d..e18454df2 100644 --- a/compel/arch/arm/src/lib/include/ptrace.h +++ b/compel/arch/arm/src/lib/include/ptrace.h @@ -1,4 +1,15 @@ #ifndef __COMPEL_PTRACE_H__ #define __COMPEL_PTRACE_H__ #define ARCH_SI_TRAP TRAP_BRKPT + +static inline int ptrace_set_breakpoint(pid_t pid, void *addr) +{ + return 0; +} + +static inline int ptrace_flush_breakpoints(pid_t pid) +{ + return 0; +} + #endif diff --git a/compel/arch/ppc64/src/lib/include/ptrace.h b/compel/arch/ppc64/src/lib/include/ptrace.h index 9cf7d460d..0274c2675 100644 --- a/compel/arch/ppc64/src/lib/include/ptrace.h +++ b/compel/arch/ppc64/src/lib/include/ptrace.h @@ -1,4 +1,15 @@ #ifndef __COMPEL_PTRACE_H__ #define __COMPEL_PTRACE_H__ #define ARCH_SI_TRAP TRAP_BRKPT + +static inline int ptrace_set_breakpoint(pid_t pid, void *addr) +{ + return 0; +} + +static inline int ptrace_flush_breakpoints(pid_t pid) +{ + return 0; +} + #endif diff --git a/compel/arch/x86/src/lib/include/ptrace.h b/compel/arch/x86/src/lib/include/ptrace.h index 991f1152a..844ea0efd 100644 --- a/compel/arch/x86/src/lib/include/ptrace.h +++ b/compel/arch/x86/src/lib/include/ptrace.h @@ -1,4 +1,6 @@ #ifndef __COMPEL_PTRACE_H__ #define __COMPEL_PTRACE_H__ #define ARCH_SI_TRAP SI_KERNEL +extern int ptrace_set_breakpoint(pid_t pid, void *addr); +extern int ptrace_flush_breakpoints(pid_t pid); #endif diff --git a/criu/arch/aarch64/include/asm/restorer.h b/criu/arch/aarch64/include/asm/restorer.h index e23ab11fb..b842a74ef 100644 --- a/criu/arch/aarch64/include/asm/restorer.h +++ b/criu/arch/aarch64/include/asm/restorer.h @@ -62,16 +62,6 @@ static inline void restore_tls(tls_t *ptls) asm("msr tpidr_el0, %0" : : "r" (*ptls)); } -static inline int ptrace_set_breakpoint(pid_t pid, void *addr) -{ - return 0; -} - -static inline int ptrace_flush_breakpoints(pid_t pid) -{ - return 0; -} - static inline void *alloc_compat_syscall_stack(void) { return NULL; } static inline void free_compat_syscall_stack(void *stack32) { } static inline int diff --git a/criu/arch/arm/include/asm/restorer.h b/criu/arch/arm/include/asm/restorer.h index 07bf4aeb2..536286d4c 100644 --- a/criu/arch/arm/include/asm/restorer.h +++ b/criu/arch/arm/include/asm/restorer.h @@ -72,16 +72,6 @@ static inline void restore_tls(tls_t *ptls) { ); } -static inline int ptrace_set_breakpoint(pid_t pid, void *addr) -{ - return 0; -} - -static inline int ptrace_flush_breakpoints(pid_t pid) -{ - return 0; -} - static inline void *alloc_compat_syscall_stack(void) { return NULL; } static inline void free_compat_syscall_stack(void *stack32) { } static inline int diff --git a/criu/arch/ppc64/include/asm/restorer.h b/criu/arch/ppc64/include/asm/restorer.h index afd00c519..5342fab68 100644 --- a/criu/arch/ppc64/include/asm/restorer.h +++ b/criu/arch/ppc64/include/asm/restorer.h @@ -55,16 +55,6 @@ int restore_nonsigframe_gpregs(UserPpc64RegsEntry *r); /* Nothing to do, TLS is accessed through r13 */ static inline void restore_tls(tls_t *ptls) { (void)ptls; } -static inline int ptrace_set_breakpoint(pid_t pid, void *addr) -{ - return 0; -} - -static inline int ptrace_flush_breakpoints(pid_t pid) -{ - return 0; -} - /* * Defined in arch/ppc64/syscall-common-ppc64.S */ diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c index 3484455dd..2eb2914a6 100644 --- a/criu/arch/x86/crtools.c +++ b/criu/arch/x86/crtools.c @@ -1,7 +1,6 @@ #include <string.h> #include <unistd.h> #include <elf.h> -#include <sys/user.h> #include <sys/mman.h> #include <sys/syscall.h> #include <sys/auxv.h> @@ -450,61 +449,3 @@ int restore_gpregs(struct rt_sigframe *f, UserX86RegsEntry *r) } #endif -/* Copied from the gdb header gdb/nat/x86-dregs.h */ - -/* Debug registers' indices. */ -#define DR_FIRSTADDR 0 -#define DR_LASTADDR 3 -#define DR_NADDR 4 /* The number of debug address registers. */ -#define DR_STATUS 6 /* Index of debug status register (DR6). */ -#define DR_CONTROL 7 /* Index of debug control register (DR7). */ - -#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ -#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ -#define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ - -/* Locally enable the break/watchpoint in the I'th debug register. */ -#define X86_DR_LOCAL_ENABLE(i) (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))) - -int ptrace_set_breakpoint(pid_t pid, void *addr) -{ - int ret; - - /* Set a breakpoint */ - if (ptrace(PTRACE_POKEUSER, pid, - offsetof(struct user, u_debugreg[DR_FIRSTADDR]), - addr)) { - pr_perror("Unable to setup a breakpoint into %d", pid); - return -1; - } - - /* Enable the breakpoint */ - if (ptrace(PTRACE_POKEUSER, pid, - offsetof(struct user, u_debugreg[DR_CONTROL]), - X86_DR_LOCAL_ENABLE(DR_FIRSTADDR))) { - pr_perror("Unable to enable the breakpoint for %d", pid); - return -1; - } - - ret = ptrace(PTRACE_CONT, pid, NULL, NULL); - if (ret) { - pr_perror("Unable to restart the stopped tracee process %d", pid); - return -1; - } - - return 1; -} - -int ptrace_flush_breakpoints(pid_t pid) -{ - /* Disable the breakpoint */ - if (ptrace(PTRACE_POKEUSER, pid, - offsetof(struct user, u_debugreg[DR_CONTROL]), - 0)) { - pr_perror("Unable to disable the breakpoint for %d", pid); - return -1; - } - - return 0; -} - diff --git a/criu/arch/x86/infect.c b/criu/arch/x86/infect.c index 19d65d76f..515b24294 100644 --- a/criu/arch/x86/infect.c +++ b/criu/arch/x86/infect.c @@ -3,11 +3,13 @@ #include <sys/uio.h> #include <sys/auxv.h> #include <sys/mman.h> +#include <sys/user.h> #include "asm/processor-flags.h" #include "asm/parasite-syscall.h" #include "uapi/std/syscall-codes.h" #include "compel/include/asm/syscall.h" +#include "compel/include/asm/ptrace.h" #include "err.h" #include "asm/fpu.h" #include "asm/types.h" @@ -246,6 +248,64 @@ bool arch_can_dump_task(struct parasite_ctl *ctl) return true; } +/* Copied from the gdb header gdb/nat/x86-dregs.h */ + +/* Debug registers' indices. */ +#define DR_FIRSTADDR 0 +#define DR_LASTADDR 3 +#define DR_NADDR 4 /* The number of debug address registers. */ +#define DR_STATUS 6 /* Index of debug status register (DR6). */ +#define DR_CONTROL 7 /* Index of debug control register (DR7). */ + +#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ +#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ +#define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ + +/* Locally enable the break/watchpoint in the I'th debug register. */ +#define X86_DR_LOCAL_ENABLE(i) (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))) + +int ptrace_set_breakpoint(pid_t pid, void *addr) +{ + int ret; + + /* Set a breakpoint */ + if (ptrace(PTRACE_POKEUSER, pid, + offsetof(struct user, u_debugreg[DR_FIRSTADDR]), + addr)) { + pr_perror("Unable to setup a breakpoint into %d", pid); + return -1; + } + + /* Enable the breakpoint */ + if (ptrace(PTRACE_POKEUSER, pid, + offsetof(struct user, u_debugreg[DR_CONTROL]), + X86_DR_LOCAL_ENABLE(DR_FIRSTADDR))) { + pr_perror("Unable to enable the breakpoint for %d", pid); + return -1; + } + + ret = ptrace(PTRACE_CONT, pid, NULL, NULL); + if (ret) { + pr_perror("Unable to restart the stopped tracee process %d", pid); + return -1; + } + + return 1; +} + +int ptrace_flush_breakpoints(pid_t pid) +{ + /* Disable the breakpoint */ + if (ptrace(PTRACE_POKEUSER, pid, + offsetof(struct user, u_debugreg[DR_CONTROL]), + 0)) { + pr_perror("Unable to disable the breakpoint for %d", pid); + return -1; + } + + return 0; +} + int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs) { struct iovec iov; diff --git a/criu/infect.c b/criu/infect.c index 48ad1effd..fbfda054d 100644 --- a/criu/infect.c +++ b/criu/infect.c @@ -4,21 +4,30 @@ #include <unistd.h> #include <errno.h> #include <signal.h> +#include <sys/mman.h> +#include <stdio.h> #include <linux/seccomp.h> +#include "xmalloc.h" +#include "uapi/std/syscall-codes.h" +#include "uapi/std/asm/syscall-types.h" #include "compel/include/asm/ptrace.h" #include "compel/include/asm/syscall.h" +#include "asm/sigframe.h" #include "infect.h" #include "ptrace.h" -#include "restorer.h" #include "pie-relocs.h" #include "parasite-blob.h" -#include "sigframe.h" #include "criu-log.h" +#include "common/bug.h" +#include "lock.h" #include "infect-rpc.h" #include "infect-priv.h" #include "infect-util.h" +#include <fcntl.h> +#include "util.h" + #define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - \ (size_t)((struct sockaddr_un *) 0)->sun_path) |