[CRIU] [PATCH 18/22] cr-dump.c: introduced the multiarch support.

Alexander Kartashov alekskartashov at parallels.com
Thu Dec 27 01:51:09 EST 2012


* Introduced the macro CORE_ENTRY__MARCH to represent the target architecture.

* Introduced the macro CORE_THREAD_INFO to access the machine-specific
  part of CoreEntry.

* Introduced the macro TI_SP to access the stack pointer resgister
  in a machine-independent way.

* Introduced the macro put_core_tls to store the thread TLS value
  in a machine-independent way.

Signed-off-by: Alexander Kartashov <alekskartashov at parallels.com>
---
 arch/x86/include/asm/dump.h  |    6 ++++++
 arch/x86/include/asm/types.h |    6 ++++++
 cr-dump.c                    |   26 +++++++++++++++++---------
 3 files changed, 29 insertions(+), 9 deletions(-)
 create mode 100644 arch/x86/include/asm/dump.h

diff --git a/arch/x86/include/asm/dump.h b/arch/x86/include/asm/dump.h
new file mode 100644
index 0000000..e002c1f
--- /dev/null
+++ b/arch/x86/include/asm/dump.h
@@ -0,0 +1,6 @@
+#ifndef __CR_ASM_DUMP_H__
+#define __CR_ASM_DUMP_H__
+
+#define core_put_tls(core, tls)
+
+#endif
diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
index 2b9f3ec..79ef52e 100644
--- a/arch/x86/include/asm/types.h
+++ b/arch/x86/include/asm/types.h
@@ -254,6 +254,12 @@ typedef struct { } UserFPState;
 
 #define TASK_SIZE ((1UL << 47) - 1)
 
+#define CORE_ENTRY__MARCH CORE_ENTRY__MARCH__X86_64
+
+#define CORE_THREAD_INFO(core) core->thread_info
+
 typedef uint64_t auxv_t;
 
+#define TI_SP(core) ((core)->thread_info->gpregs->sp)
+
 #endif /* __CR_TYPES_H__ */
diff --git a/cr-dump.c b/cr-dump.c
index ecbb72d..54d2d8d 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -64,13 +64,15 @@
 #include "fpu.h"
 #include "elf.h"
 
-#ifndef CONFIG_X86_64
-# error No x86-32 support yet
-#endif
+#include "asm/dump.h"
 
 static char loc_buf[PAGE_SIZE];
 static int pidns_proc = -1;
 
+int get_task_regs(pid_t pid, CoreEntry *core, const struct parasite_ctl *ctl);
+int arch_alloc_thread_info(CoreEntry *core);
+void core_entry_free(CoreEntry *core);
+
 void free_mappings(struct list_head *vma_area_list)
 {
 	struct vma_area *vma_area, *p;
@@ -550,10 +552,10 @@ static int get_task_auxv(pid_t pid, MmEntry *mm, size_t *size)
 
 	for (i = 0; i < AT_VECTOR_SIZE; i++) {
 		ret = read(fd, &mm->mm_saved_auxv[i],
-			   sizeof(mm->mm_saved_auxv[0]));
+			   sizeof(auxv_t));
 		if (ret == 0)
 			break;
-		else if (ret != sizeof(mm->mm_saved_auxv[0])) {
+		else if (ret != sizeof(auxv_t)) {
 			ret = -1;
 			pr_perror("Error readind %d's auxv[%d]",
 				  pid, i);
@@ -707,7 +709,7 @@ static CoreEntry *core_entry_alloc(int alloc_thread_info,
 		return NULL;
 	core_entry__init(core);
 
-	core->mtype = CORE_ENTRY__MARCH__X86_64;
+	core->mtype = CORE_ENTRY__MARCH;
 
 	if (alloc_thread_info) {
 		if (arch_alloc_thread_info(core))
@@ -766,7 +768,7 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
 	if (ret)
 		goto err_free;
 
-	mark_stack_vma(core->thread_info->gpregs->sp, vma_area_list);
+	mark_stack_vma(TI_SP(core), vma_area_list);
 
 	ret = get_task_futex_robust_list(pid, core->thread_core);
 	if (ret)
@@ -788,6 +790,8 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
 	if (ret)
 		goto err_free;
 
+	core_put_tls(core, parasite_get_tls_seized(ctl));
+
 	ret = pb_write_one(fd_core, core, PB_CORE);
 	if (ret < 0)
 		goto err_free;
@@ -1154,6 +1158,7 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, struct pid *tid)
 	int ret = -1, fd_core;
 	unsigned int *taddr;
 	pid_t pid = tid->real;
+	u32 tls;
 
 	pr_info("\n");
 	pr_info("Dumping core for thread (pid: %d)\n", pid);
@@ -1172,16 +1177,19 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, struct pid *tid)
 		goto err_free;
 
 	ret = parasite_dump_thread_seized(parasite_ctl, pid, &taddr,
-					  &tid->virt, &core->thread_core->blk_sigset);
+					  &tid->virt, &core->thread_core->blk_sigset,
+					  &tls);
+
 	if (ret) {
 		pr_err("Can't dump thread for pid %d\n", pid);
 		goto err_free;
 	}
 	core->thread_core->has_blk_sigset = true;
+	core_put_tls(core, tls);
 
 	pr_info("%d: virt_pid=%d tid_address=%p sig_blocked=0x%lx\n", pid,
 			tid->virt, taddr, core->thread_core->blk_sigset);
-	core->thread_info->clear_tid_addr = (u64) taddr;
+	CORE_THREAD_INFO(core)->clear_tid_addr = (u64) taddr;
 
 	ret = dump_sched_info(pid, core->thread_core);
 	if (ret)
-- 
1.7.10.4



More information about the CRIU mailing list