[CRIU] [PATCHv2 10/17] parasite: refactor macros for compat/native usage

Dmitry Safonov dsafonov at virtuozzo.com
Tue Apr 12 09:10:48 PDT 2016


In code they yet use native parasite type, but in definition
this parameter is not used (will be used at the next patch).

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/cr-restore.c       |  4 ++--
 criu/include/parasite.h |  5 ++++-
 criu/include/restorer.h |  3 +--
 criu/parasite-syscall.c | 13 +++++++------
 criu/pie/Makefile       |  8 +++++++-
 criu/pie/pie-relocs.h   | 18 ++++++++----------
 6 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 4bce02061d4d..34db7f7a360d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -2640,7 +2640,7 @@ static int prepare_restorer_blob(void)
 	 * in turn will lead to set-exe-file prctl to fail with EBUSY.
 	 */
 
-	restorer_len = pie_size(restorer_blob);
+	restorer_len = pie_size(restorer);
 	restorer = mmap(NULL, restorer_len,
 			PROT_READ | PROT_WRITE | PROT_EXEC,
 			MAP_PRIVATE | MAP_ANON, 0, 0);
@@ -2664,7 +2664,7 @@ static int remap_restorer_blob(void *addr)
 		return -1;
 	}
 
-	ELF_RELOCS_APPLY_RESTORER(addr, addr);
+	ELF_RELOCS_APPLY(restorer, addr, addr);
 	return 0;
 }
 
diff --git a/criu/include/parasite.h b/criu/include/parasite.h
index 97e334d77689..52e3c634d66b 100644
--- a/criu/include/parasite.h
+++ b/criu/include/parasite.h
@@ -269,7 +269,10 @@ struct parasite_dump_cgroup_args {
 };
 
 /* the parasite prefix is added by gen_offsets.sh */
-#define parasite_sym(pblob, name) ((void *)(pblob) + parasite_blob_offset__##name)
+#define __pblob_offset(ptype, symbol)					\
+	parasite ## _blob_offset__ ## symbol
+#define parasite_sym(pblob, ptype, symbol)				\
+	((void *)(pblob) + __pblob_offset(ptype, symbol))
 
 #endif /* !__ASSEMBLY__ */
 
diff --git a/criu/include/restorer.h b/criu/include/restorer.h
index d25fe8523dc3..b00c212e02fb 100644
--- a/criu/include/restorer.h
+++ b/criu/include/restorer.h
@@ -237,7 +237,6 @@ enum {
 
 /* the restorer_blob_offset__ prefix is added by gen_offsets.sh */
 #define __blob_offset(name)	restorer_blob_offset__ ## name
-#define _blob_offset(name)	__blob_offset(name)
-#define restorer_sym(rblob, name)	(void*)(rblob + _blob_offset(name))
+#define restorer_sym(rblob, name)	(void*)(rblob + __blob_offset(name))
 
 #endif /* __CR_RESTORER_H__ */
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 2c599950b75d..8f4c04b99553 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -1329,6 +1329,7 @@ static int parasite_start_daemon(struct parasite_ctl *ctl, struct pstree_item *i
 	return 0;
 }
 
+/* FIXME: parasite native/compat */
 struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 		struct vm_area_list *vma_area_list)
 {
@@ -1354,7 +1355,7 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 
 	ctl->args_size = round_up(parasite_args_size, PAGE_SIZE);
 	parasite_args_size = PARASITE_ARG_SIZE_MIN; /* reset for next task */
-	map_exchange_size = pie_size(parasite_blob) + ctl->args_size;
+	map_exchange_size = pie_size(parasite) + ctl->args_size;
 	map_exchange_size += RESTORE_STACK_SIGFRAME + PARASITE_STACK_SIZE;
 	if (item->nr_threads > 1)
 		map_exchange_size += PARASITE_STACK_SIZE;
@@ -1368,14 +1369,14 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
 	pr_info("Putting parasite blob into %p->%p\n", ctl->local_map, ctl->remote_map);
 	memcpy(ctl->local_map, parasite_blob, sizeof(parasite_blob));
 
-	ELF_RELOCS_APPLY_PARASITE(ctl->local_map, ctl->remote_map);
+	ELF_RELOCS_APPLY(parasite, ctl->local_map, ctl->remote_map);
 
 	/* Setup the rest of a control block */
-	ctl->parasite_ip	= (unsigned long)parasite_sym(ctl->remote_map, __export_parasite_head_start);
-	ctl->addr_cmd		= parasite_sym(ctl->local_map, __export_parasite_cmd);
-	ctl->addr_args		= parasite_sym(ctl->local_map, __export_parasite_args);
+	ctl->parasite_ip	= (unsigned long)parasite_sym(ctl->remote_map, native, __export_parasite_head_start);
+	ctl->addr_cmd		= parasite_sym(ctl->local_map, native, __export_parasite_cmd);
+	ctl->addr_args		= parasite_sym(ctl->local_map, native, __export_parasite_args);
 
-	p = pie_size(parasite_blob) + ctl->args_size;
+	p = pie_size(parasite) + ctl->args_size;
 
 	ctl->rsigframe	= ctl->remote_map + p;
 	ctl->sigframe	= ctl->local_map  + p;
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index 0bd03900424a..55a9cff7a356 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -77,7 +77,13 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/native.lib.a $(obj)/$(PIELDS
 
 $(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(obj)/$(PIELDS) $(SRC_DIR)/compel/compel
 	$(call msg-gen, $@)
-	$(Q) $(SRC_DIR)/compel/compel piegen -f $< -v $(call target-name,$@)_relocs -p $(call target-name,$@)_blob_offset__ -s $(call target-name,$@)_blob -u $(SRC_DIR)/compel/include/uapi -o $@ $(piegen_stdout)
+	$(Q) $(SRC_DIR)/compel/compel piegen -f $<		 	\
+		-v $(call target-name,$@)_relocs			\
+		-p $(call target-name,$@)_blob_offset__			\
+		-s $(call target-name,$@)_blob				\
+		-r $(call target-name,$@)_nr_gotpcrel			\
+		-u $(SRC_DIR)/compel/include/uapi			\
+		-o $@ $(piegen_stdout)
 
 else
 
diff --git a/criu/pie/pie-relocs.h b/criu/pie/pie-relocs.h
index bd313f8bfcba..9af029eb8bc0 100644
--- a/criu/pie/pie-relocs.h
+++ b/criu/pie/pie-relocs.h
@@ -10,19 +10,17 @@
 
 extern __maybe_unused void elf_relocs_apply(void *mem, void *vbase, size_t size,
 					    elf_reloc_t *elf_relocs, size_t nr_relocs);
-#define pie_size(__blob_name)	(round_up(sizeof(__blob_name) + nr_gotpcrel * sizeof(long), page_size()))
-#define ELF_RELOCS_APPLY_PARASITE(__mem, __vbase)			\
-	elf_relocs_apply(__mem, __vbase, sizeof(parasite_blob),		\
-			 parasite_relocs, ARRAY_SIZE(parasite_relocs))
-#define ELF_RELOCS_APPLY_RESTORER(__mem, __vbase)			\
-	elf_relocs_apply(__mem, __vbase, sizeof(restorer_blob),		\
-			 restorer_relocs, ARRAY_SIZE(restorer_relocs))
+/* FIXME: native/compat pie's pie_size(), ELF_RELOCS_APPLY() */
+#define pie_size(__pie_name)	(round_up(sizeof(__pie_name##_blob) + \
+			__pie_name ## _nr_gotpcrel * sizeof(long), page_size()))
+#define ELF_RELOCS_APPLY(__pie_name, __mem, __vbase)			\
+	elf_relocs_apply(__mem, __vbase, sizeof(__pie_name##_blob),	\
+			 __pie_name##_relocs, ARRAY_SIZE(__pie_name##_relocs))
 
 #else
 
-#define pie_size(__blob_name)	(round_up(sizeof(__blob_name), page_size()))
-#define ELF_RELOCS_APPLY_PARASITE(__mem, __vbase)
-#define ELF_RELOCS_APPLY_RESTORER(__mem, __vbase)
+#define pie_size(__pie_name)	(round_up(sizeof(__pie_name##_blob), page_size()))
+#define ELF_RELOCS_APPLY(__pie_name, __mem, __vbase)
 
 #endif
 
-- 
2.8.0



More information about the CRIU mailing list