[CRIU] [PATCHv2 04/17] cr-exec: add non-generated sys-exec-tbl for x86

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


Impact: search sys-exec-tbl-32.c for compatible tasks.

Rename task_in_compat_mode to arch_task_compatible and use it in
find_syscall for 64-bit to check compatible task's syscall nr.
It still will not execute syscall in 32-tasks, as we still do not
have 32-bit pie (arch_can_dump_task will return false for these tasks).

NOTE: be sure to `make mrproper` on criu directory before applying this
patch, as before `criu/arch/x86/sys-exec-tbl.c` was autogenerated,
it will make conflict if you try to apply this patch on dirty directory.

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 .gitignore                      |  2 ++
 criu/arch/x86/Makefile.syscalls | 18 ---------------
 criu/arch/x86/crtools.c         |  4 ++--
 criu/arch/x86/sys-exec-tbl.c    | 50 +++++++++++++++++++++++++++++++++++++++++
 criu/cr-exec.c                  |  7 ++++--
 5 files changed, 59 insertions(+), 22 deletions(-)
 create mode 100644 criu/arch/x86/sys-exec-tbl.c

diff --git a/.gitignore b/.gitignore
index 6e1c265cec03..54c94eb93a21 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,8 @@ images/google/protobuf/*.h
 .gitid
 criu/criu
 criu/arch/*/sys-exec-tbl*.c
+# x86 syscalls-table is not generated
+!criu/arch/x86/sys-exec-tbl.c
 criu/arch/*/syscalls*.S
 criu/include/config.h
 criu/include/syscall-codes*.h
diff --git a/criu/arch/x86/Makefile.syscalls b/criu/arch/x86/Makefile.syscalls
index 79c58be3a0c0..0506c1f2b117 100644
--- a/criu/arch/x86/Makefile.syscalls
+++ b/criu/arch/x86/Makefile.syscalls
@@ -4,7 +4,6 @@ CFLAGS			:= $(filter-out -pg $(CFLAGS-GCOV),$(CFLAGS))
 CFLAGS			:= $(filter-out -DCONFIG_X86_64,$(CFLAGS))
 
 SYS-PROTO-GENERIC	:= $(obj)/../../include/syscall.h
-SYS-EXEC-TBL-GENERIC	:= sys-exec-tbl.c
 
 SYS-CODES-GENERIC	= $(obj)/../../include/syscall-codes.h
 SYS-CODES		= $(obj)/../../include/syscall-codes-$(1).h
@@ -155,23 +154,6 @@ $(SYS-PROTO-GENERIC): $(strip $(call map,SYS-PROTO,$(SYS-BITS)))
 	$(Q) echo "#endif /* __ASM_CR_SYSCALL_PROTO_H__ */"		>> $@
 mrproper-y		+= $(SYS-PROTO-GENERIC)
 
-$(obj)/$(SYS-EXEC-TBL-GENERIC):
-	$(Q) echo "/* Autogenerated, don't edit */"			>  $@
-	$(Q) echo "static struct syscall_exec_desc sc_exec_table[] = {" >> $@
-ifeq ($(ARCH),x86)
-	$(Q) echo '#include "sys-exec-tbl-64.c"'			>> $@
-	$(Q) echo "	{ }, /* terminator */"				>> $@
-	$(Q) echo "};"							>> $@
-	$(Q) echo ""							>> $@
-# FIXME: uncomment to support 32-bit task
-#	$(Q) echo "static struct syscall_exec_desc sc_exec_table_32[] = {" >> $@
-endif
-#	$(Q) echo '#include "sys-exec-tbl-32.c"'			>> $@
-#	$(Q) echo "	{ }, /* terminator */"				>> $@
-#	$(Q) echo "};"							>> $@
-mrproper-y		+= $(obj)/$(SYS-EXEC-TBL-GENERIC)
-all-y			+= $(obj)/$(SYS-EXEC-TBL-GENERIC)
-
 $(eval $(call map,gen-rule-sys-codes,$(SYS-BITS)))
 $(eval $(call map,gen-rule-sys-proto,$(SYS-BITS)))
 $(eval $(call map,gen-rule-sys-asm,$(SYS-BITS)))
diff --git a/criu/arch/x86/crtools.c b/criu/arch/x86/crtools.c
index 51eab133f269..4a96d1d0b569 100644
--- a/criu/arch/x86/crtools.c
+++ b/criu/arch/x86/crtools.c
@@ -53,7 +53,7 @@ void parasite_setup_regs(unsigned long new_ip, void *stack, user_regs_struct_t *
 	regs->flags &= ~(X86_EFLAGS_TF | X86_EFLAGS_DF | X86_EFLAGS_IF);
 }
 
-static int task_in_compat_mode(pid_t pid)
+int arch_task_compatible(pid_t pid)
 {
 	unsigned long cs, ds;
 
@@ -77,7 +77,7 @@ static int task_in_compat_mode(pid_t pid)
 
 bool arch_can_dump_task(pid_t pid)
 {
-	if (task_in_compat_mode(pid)) {
+	if (arch_task_compatible(pid)) {
 		pr_err("Can't dump task %d running in 32-bit mode\n", pid);
 		return false;
 	}
diff --git a/criu/arch/x86/sys-exec-tbl.c b/criu/arch/x86/sys-exec-tbl.c
new file mode 100644
index 000000000000..b7f95b98e5a6
--- /dev/null
+++ b/criu/arch/x86/sys-exec-tbl.c
@@ -0,0 +1,50 @@
+
+#ifdef CONFIG_X86_64
+static struct syscall_exec_desc sc_exec_table_64[] = {
+#include "sys-exec-tbl-64.c"
+	{ }, /* terminator */
+};
+#endif
+
+static struct syscall_exec_desc sc_exec_table_32[] = {
+#include "sys-exec-tbl-32.c"
+	{ }, /* terminator */
+};
+
+struct syscall_exec_desc;
+
+static inline struct syscall_exec_desc *
+find_syscall_table(char *name, struct syscall_exec_desc *tbl)
+{
+	int i;
+
+	for (i = 0; tbl[i].name != NULL; i++)
+		if (!strcmp(tbl[i].name, name))
+			return &tbl[i];
+	return NULL;
+}
+
+int __attribute__((weak)) arch_task_compatible(pid_t pid) { return false; }
+#define ARCH_HAS_FIND_SYSCALL
+/* overwrite default to search in two tables above */
+#ifdef CONFIG_X86_64
+struct syscall_exec_desc * find_syscall(char *name, int pid)
+{
+	int err = arch_task_compatible(pid);
+
+	switch(err) {
+		case 0:
+			return find_syscall_table(name, sc_exec_table_64);
+		case 1:
+			return find_syscall_table(name, sc_exec_table_32);
+		default: /* Error */
+			return NULL;
+	}
+}
+#else
+struct syscall_exec_desc *
+find_syscall(char *name, __attribute__((unused)) int pid)
+{
+	return find_syscall_table(name, sc_exec_table_32);
+}
+#endif
diff --git a/criu/cr-exec.c b/criu/cr-exec.c
index 5fa5bff7f782..e595ec19f863 100644
--- a/criu/cr-exec.c
+++ b/criu/cr-exec.c
@@ -17,7 +17,9 @@ struct syscall_exec_desc {
 #include "sys-exec-tbl.c"
 #undef SYSCALL
 
-static struct syscall_exec_desc *find_syscall(char *name)
+#ifndef ARCH_HAS_FIND_SYSCALL
+struct syscall_exec_desc *
+find_syscall(char *name, int __attribute__((unused)) pid)
 {
 	int i;
 
@@ -27,6 +29,7 @@ static struct syscall_exec_desc *find_syscall(char *name)
 
 	return NULL;
 }
+#endif
 
 #define MAX_ARGS	6
 
@@ -122,7 +125,7 @@ int cr_exec(int pid, char **opt)
 		goto out;
 	}
 
-	si = find_syscall(sys_name);
+	si = find_syscall(sys_name, pid);
 	if (!si) {
 		pr_err("Unknown syscall [%s]\n", sys_name);
 		goto out;
-- 
2.8.0



More information about the CRIU mailing list