[CRIU] [PATCH 42/78] infect: Move ptrace_get/set_regs() into ptrace.c

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:36:27 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

The criu/ptrace.c will also go into compel sources, so
detach the needed code from CRIU as well.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/arch/x86/crtools.c          | 43 ----------------------------------------
 criu/arch/x86/include/asm/dump.h |  4 ----
 criu/arch/x86/infect.c           | 43 ++++++++++++++++++++++++++++++++++++++++
 criu/include/ptrace.h            |  4 ++++
 criu/infect.c                    |  1 -
 criu/parasite-syscall.c          | 20 -------------------
 criu/ptrace.c                    | 20 ++++++++++++++++++-
 7 files changed, 66 insertions(+), 69 deletions(-)

diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index 6834b48a8265..b4674195c864 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -211,49 +211,6 @@ int save_task_regs(void *x, user_regs_struct_t *regs, user_fpregs_struct_t *fpre
 	return 0;
 }
 
-int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs)
-{
-	struct iovec iov;
-	int ret;
-
-	iov.iov_base = &regs->native;
-	iov.iov_len = sizeof(user_regs_struct64);
-
-	ret = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov);
-	if (ret == -1) {
-		pr_perror("PTRACE_GETREGSET failed");
-		return -1;
-	}
-
-	if (iov.iov_len == sizeof(regs->native)) {
-		regs->__is_native = NATIVE_MAGIC;
-		return ret;
-	}
-	if (iov.iov_len == sizeof(regs->compat)) {
-		regs->__is_native = COMPAT_MAGIC;
-		return ret;
-	}
-
-	pr_err("PTRACE_GETREGSET read %zu bytes for pid %d, but native/compat regs sizes are %zu/%zu bytes",
-			iov.iov_len, pid,
-			sizeof(regs->native), sizeof(regs->compat));
-	return -1;
-}
-
-int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs)
-{
-	struct iovec iov;
-
-	if (user_regs_native(regs)) {
-		iov.iov_base = &regs->native;
-		iov.iov_len = sizeof(user_regs_struct64);
-	} else {
-		iov.iov_base = &regs->compat;
-		iov.iov_len = sizeof(user_regs_struct32);
-	}
-	return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov);
-}
-
 static void alloc_tls(ThreadInfoX86 *ti, void **mempool)
 {
 	int i;
diff --git a/criu/arch/x86/include/asm/dump.h b/criu/arch/x86/include/asm/dump.h
index 61e53dced564..ca7cd675f21c 100644
--- a/criu/arch/x86/include/asm/dump.h
+++ b/criu/arch/x86/include/asm/dump.h
@@ -5,10 +5,6 @@ extern int save_task_regs(void *, user_regs_struct_t *, user_fpregs_struct_t *);
 extern int arch_alloc_thread_info(CoreEntry *core);
 extern void arch_free_thread_info(CoreEntry *core);
 
-#define ARCH_HAS_GET_REGS
-extern int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs);
-extern int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs);
-
 static inline void core_put_tls(CoreEntry *core, tls_t tls)
 {
 	ThreadInfoX86 *ti = core->thread_info;
diff --git a/criu/arch/x86/infect.c b/criu/arch/x86/infect.c
index ad3ce267958d..e5ac42e3f8ce 100644
--- a/criu/arch/x86/infect.c
+++ b/criu/arch/x86/infect.c
@@ -169,3 +169,46 @@ void *remote_mmap(struct parasite_ctl *ctl,
 
 	return (void *)map;
 }
+
+int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs)
+{
+	struct iovec iov;
+	int ret;
+
+	iov.iov_base = &regs->native;
+	iov.iov_len = sizeof(user_regs_struct64);
+
+	ret = ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov);
+	if (ret == -1) {
+		pr_perror("PTRACE_GETREGSET failed");
+		return -1;
+	}
+
+	if (iov.iov_len == sizeof(regs->native)) {
+		regs->__is_native = NATIVE_MAGIC;
+		return ret;
+	}
+	if (iov.iov_len == sizeof(regs->compat)) {
+		regs->__is_native = COMPAT_MAGIC;
+		return ret;
+	}
+
+	pr_err("PTRACE_GETREGSET read %zu bytes for pid %d, but native/compat regs sizes are %zu/%zu bytes",
+			iov.iov_len, pid,
+			sizeof(regs->native), sizeof(regs->compat));
+	return -1;
+}
+
+int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs)
+{
+	struct iovec iov;
+
+	if (user_regs_native(regs)) {
+		iov.iov_base = &regs->native;
+		iov.iov_len = sizeof(user_regs_struct64);
+	} else {
+		iov.iov_base = &regs->compat;
+		iov.iov_len = sizeof(user_regs_struct32);
+	}
+	return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov);
+}
diff --git a/criu/include/ptrace.h b/criu/include/ptrace.h
index b3343fdf83a5..af9ced973ecc 100644
--- a/criu/include/ptrace.h
+++ b/criu/include/ptrace.h
@@ -4,6 +4,7 @@
 #include <linux/types.h>
 #include <sys/ptrace.h>
 
+#include "types.h"
 #include "config.h"
 
 /* some constants for ptrace */
@@ -77,4 +78,7 @@ extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
 extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
 extern int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes);
 
+extern int ptrace_get_regs(pid_t pid, user_regs_struct_t *regs);
+extern int ptrace_set_regs(pid_t pid, user_regs_struct_t *regs);
+
 #endif /* __CR_PTRACE_H__ */
diff --git a/criu/infect.c b/criu/infect.c
index 90a10493c3a6..cf1cb3d4898f 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -9,7 +9,6 @@
 #include "infect.h"
 #include "ptrace.h"
 #include "asm/parasite-syscall.h"
-#include "asm/dump.h"
 #include "restorer.h"
 #include "parasite-syscall.h"
 #include "pie-relocs.h"
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 5d918c95901a..18f4ef9e9f73 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -68,26 +68,6 @@ unsigned long get_exec_start(struct vm_area_list *vmas)
 	return 0;
 }
 
-#ifndef ARCH_HAS_GET_REGS
-static inline int ptrace_get_regs(int pid, user_regs_struct_t *regs)
-{
-	struct iovec iov;
-
-	iov.iov_base = regs;
-	iov.iov_len = sizeof(user_regs_struct_t);
-	return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov);
-}
-
-static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs)
-{
-	struct iovec iov;
-
-	iov.iov_base = regs;
-	iov.iov_len = sizeof(user_regs_struct_t);
-	return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov);
-}
-#endif
-
 int parasite_send_fd(struct parasite_ctl *ctl, int fd)
 {
 	int sk;
diff --git a/criu/ptrace.c b/criu/ptrace.c
index 15908c17ddb7..8b9e166ec9a8 100644
--- a/criu/ptrace.c
+++ b/criu/ptrace.c
@@ -7,7 +7,8 @@
 #include <stdbool.h>
 #include <limits.h>
 #include <signal.h>
-
+#include <elf.h>
+#include <sys/uio.h>
 #include <sys/ptrace.h>
 #include <sys/types.h>
 #include <sys/time.h>
@@ -82,3 +83,20 @@ int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes)
 
 	return 0;
 }
+
+int __attribute__((weak)) ptrace_get_regs(int pid, user_regs_struct_t *regs) {
+	struct iovec iov;
+
+	iov.iov_base = regs;
+	iov.iov_len = sizeof(user_regs_struct_t);
+	return ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov);
+}
+
+int __attribute__((weak)) ptrace_set_regs(int pid, user_regs_struct_t *regs)
+{
+	struct iovec iov;
+
+	iov.iov_base = regs;
+	iov.iov_len = sizeof(user_regs_struct_t);
+	return ptrace(PTRACE_SETREGSET, pid, NT_PRSTATUS, &iov);
+}
-- 
2.7.4



More information about the CRIU mailing list