[CRIU] [PATCH 11/11] compel: plugins,std -- Move in infect code
Cyrill Gorcunov
gorcunov at openvz.org
Fri Nov 11 10:52:08 PST 2016
It didn't go smooth:
- we need to provide log module (either into std plugin,
either as a separate one)
- need to revisit fds plugin, it looks messy
- Providing infect functionality inside std plugin
doesn't look suite for me: the restorer has to define
dummy parasite_daemon_cmd/parasite_trap_cmd/parasite_cleanup
just to be able to compile with it
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
.../arch/aarch64/plugins/std}/parasite-head.S | 0
.../arch/arm/plugins/std}/parasite-head.S | 0
.../arch/ppc64/plugins/std}/parasite-head.S | 0
.../arch/x86/plugins/std/parasite-head-compat.S | 0
.../arch/x86/plugins/std/parasite-head.S | 0
compel/plugins/Makefile | 2 +
compel/plugins/include/uapi/plugin-fds.h | 2 +
compel/plugins/include/uapi/plugin-std.h | 1 +
compel/plugins/include/uapi/std/infect.h | 20 +++++++++
{criu/pie => compel/plugins/std}/infect.c | 52 ++++++++++------------
criu/Makefile | 2 +-
criu/pie/Makefile | 19 +++-----
criu/pie/compat/infect-compat.c | 1 -
criu/pie/restorer.c | 17 +++++++
14 files changed, 73 insertions(+), 43 deletions(-)
rename {criu/arch/aarch64 => compel/arch/aarch64/plugins/std}/parasite-head.S (100%)
rename {criu/arch/arm => compel/arch/arm/plugins/std}/parasite-head.S (100%)
rename {criu/arch/ppc64 => compel/arch/ppc64/plugins/std}/parasite-head.S (100%)
rename criu/arch/x86/parasite-head-32.S => compel/arch/x86/plugins/std/parasite-head-compat.S (100%)
rename criu/arch/x86/parasite-head-64.S => compel/arch/x86/plugins/std/parasite-head.S (100%)
create mode 100644 compel/plugins/include/uapi/std/infect.h
rename {criu/pie => compel/plugins/std}/infect.c (81%)
delete mode 120000 criu/pie/compat/infect-compat.c
diff --git a/criu/arch/aarch64/parasite-head.S b/compel/arch/aarch64/plugins/std/parasite-head.S
similarity index 100%
rename from criu/arch/aarch64/parasite-head.S
rename to compel/arch/aarch64/plugins/std/parasite-head.S
diff --git a/criu/arch/arm/parasite-head.S b/compel/arch/arm/plugins/std/parasite-head.S
similarity index 100%
rename from criu/arch/arm/parasite-head.S
rename to compel/arch/arm/plugins/std/parasite-head.S
diff --git a/criu/arch/ppc64/parasite-head.S b/compel/arch/ppc64/plugins/std/parasite-head.S
similarity index 100%
rename from criu/arch/ppc64/parasite-head.S
rename to compel/arch/ppc64/plugins/std/parasite-head.S
diff --git a/criu/arch/x86/parasite-head-32.S b/compel/arch/x86/plugins/std/parasite-head-compat.S
similarity index 100%
rename from criu/arch/x86/parasite-head-32.S
rename to compel/arch/x86/plugins/std/parasite-head-compat.S
diff --git a/criu/arch/x86/parasite-head-64.S b/compel/arch/x86/plugins/std/parasite-head.S
similarity index 100%
rename from criu/arch/x86/parasite-head-64.S
rename to compel/arch/x86/plugins/std/parasite-head.S
diff --git a/compel/plugins/Makefile b/compel/plugins/Makefile
index 4cfeced4c778..824ebfc5cd78 100644
--- a/compel/plugins/Makefile
+++ b/compel/plugins/Makefile
@@ -49,6 +49,8 @@ shmem-obj-y += shmem/shmem.o
target += std
std-obj-y += std/std.o
std-obj-y += std/string.o
+std-obj-y += std/infect.o
+std-obj-y += ./$(PLUGIN_ARCH_DIR)/std/parasite-head.o
include ./$(PLUGIN_ARCH_DIR)/std/syscalls/Makefile.syscalls
diff --git a/compel/plugins/include/uapi/plugin-fds.h b/compel/plugins/include/uapi/plugin-fds.h
index 3f952c14b2fa..095ae687e7b7 100644
--- a/compel/plugins/include/uapi/plugin-fds.h
+++ b/compel/plugins/include/uapi/plugin-fds.h
@@ -8,6 +8,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+extern int recv_fds(int sock, int *fds, int nr_fds, struct fd_opts *opts);
+
extern int fds_send(int *fds, int nr_fds);
extern int fds_recv(int *fds, int nr_fds);
diff --git a/compel/plugins/include/uapi/plugin-std.h b/compel/plugins/include/uapi/plugin-std.h
index f91e2acbd832..29e6c1b119d5 100644
--- a/compel/plugins/include/uapi/plugin-std.h
+++ b/compel/plugins/include/uapi/plugin-std.h
@@ -4,5 +4,6 @@
#include <compel/plugins.h>
#include <compel/plugins/std/syscall.h>
#include <compel/plugins/std/string.h>
+#include <compel/plugins/std/infect.h>
#endif /* COMPEL_PLUGIN_STD_STD_H__ */
diff --git a/compel/plugins/include/uapi/std/infect.h b/compel/plugins/include/uapi/std/infect.h
new file mode 100644
index 000000000000..800df250954e
--- /dev/null
+++ b/compel/plugins/include/uapi/std/infect.h
@@ -0,0 +1,20 @@
+#ifndef COMPEL_PLUGIN_STD_INFECT_H__
+#define COMPEL_PLUGIN_STD_INFECT_H__
+
+extern int parasite_get_rpc_sock(void);
+extern int parasite_service(unsigned int cmd, void *args);
+
+/*
+ * Must be supplied by user plugins.
+ */
+extern int parasite_daemon_cmd(int cmd, void *args);
+extern int parasite_trap_cmd(int cmd, void *args);
+extern void parasite_cleanup(void);
+
+/*
+ * FIXME: Should be supplied by log module.
+ */
+extern void log_set_fd(int fd);
+extern void log_set_loglevel(unsigned int level);
+
+#endif /* COMPEL_PLUGIN_STD_INFECT_H__ */
diff --git a/criu/pie/infect.c b/compel/plugins/std/infect.c
similarity index 81%
rename from criu/pie/infect.c
rename to compel/plugins/std/infect.c
index 8ba3f897dd53..79cf8b865db7 100644
--- a/criu/pie/infect.c
+++ b/compel/plugins/std/infect.c
@@ -1,14 +1,26 @@
+#include <compel/plugins/std/syscall.h>
+#include <compel/plugins/std/infect.h>
+
+#define SCM_FDSET_HAS_OPTS
+#include "common/scm.h"
+#include "uapi/compel/plugins/plugin-fds.h"
+#include "uapi/compel/plugins/std/string.h"
+
#include "common/compiler.h"
#include "common/lock.h"
-#include "int.h"
-#include "util-pie.h"
-#include "criu-log.h"
+extern void print_on_level(unsigned int loglevel, const char *format, ...);
+
+#define pr_err(fmt, ...) print_on_level(1, fmt, ##__VA_ARGS__)
+#define pr_info(fmt, ...) print_on_level(3, fmt, ##__VA_ARGS__)
+#define pr_debug(fmt, ...) print_on_level(4, fmt, ##__VA_ARGS__)
+
#include "common/bug.h"
-#include "sigframe.h"
-#include "infect-rpc.h"
-#include "infect-pie.h"
-#include "compel/include/rpc-pie-priv.h"
+
+#include "uapi/compel/asm/sigframe.h"
+#include "uapi/compel/infect-rpc.h"
+
+#include "rpc-pie-priv.h"
static int tsock = -1;
@@ -147,7 +159,7 @@ static noinline int unmap_itself(void *data)
static noinline __used int parasite_init_daemon(void *data)
{
struct parasite_init_args *args = data;
- int ret;
+ int ret, fd;
args->sigreturn_addr = (uint64_t)(uintptr_t)fini_sigreturn;
sigframe = (void*)(uintptr_t)args->sigframe;
@@ -166,9 +178,9 @@ static noinline __used int parasite_init_daemon(void *data)
futex_set_and_wake(&args->daemon_connected, 1);
- ret = recv_fd(tsock);
- if (ret >= 0) {
- log_set_fd(ret);
+ ret = recv_fds(tsock, &fd, 1, NULL);
+ if (!ret) {
+ log_set_fd(fd);
log_set_loglevel(args->log_level);
ret = 0;
} else
@@ -201,21 +213,3 @@ int __used __parasite_entry parasite_service(unsigned int cmd, void *args)
return parasite_trap_cmd(cmd, args);
}
-
-/*
- * Mainally, -fstack-protector is disabled for parasite.
- * But we share some object files, compiled for CRIU with parasite.
- * Those files (like cpu.c) may be compiled with stack protector
- * support. We can't use gcc-ld provided stackprotector callback,
- * as Glibc is unmapped. Let's just try to cure application in
- * case of stack smashing in parasite.
- */
-void __stack_chk_fail(void)
-{
- /*
- * Smash didn't happen in printing part, as it's not shared
- * with CRIU, therefore compiled with -fnostack-protector.
- */
- pr_err("Stack smash detected in parasite\n");
- fini();
-}
diff --git a/criu/Makefile b/criu/Makefile
index 9cf07f28ea61..21bc63e0e3c6 100644
--- a/criu/Makefile
+++ b/criu/Makefile
@@ -59,7 +59,7 @@ criu/pie/native.lib.a: $(ARCH-LIB)
#
# PIE code blobs themseves.
-pie: criu/pie/native.lib.a
+pie: criu/pie/native.lib.a compel/plugins/std.built-in.o
$(Q) $(MAKE) $(build)=criu/pie all
.PHONY: pie
diff --git a/criu/pie/Makefile b/criu/pie/Makefile
index da90c6774155..062345258473 100644
--- a/criu/pie/Makefile
+++ b/criu/pie/Makefile
@@ -8,11 +8,11 @@ endif
compel_pack_lds-native := $(SRC_DIR)/compel/arch/$(ARCH)/scripts/compel-pack.lds.S
compel_pack_lds-compat := $(SRC_DIR)/compel/arch/$(ARCH)/scripts/compel-pack-compat.lds.S
+compel_std-native := $(SRC_DIR)/compel/plugins/std.built-in.o
+compel_std-compat := $(SRC_DIR)/compel/plugins/std-compat.built-in.o
native-obj-y += parasite.o
-native-obj-y += infect.o
compat-obj-y += compat/parasite-compat.o
-compat-obj-y += compat/infect-compat.o
restorer-obj-y += restorer.o
restorer-obj-y += ./$(ARCH_DIR)/restorer.o
@@ -25,18 +25,9 @@ ifeq ($(ARCH),x86)
restorer-obj-y += ./$(ARCH_DIR)/sigaction_compat_pie.o
endif
- native-obj-y += ./$(ARCH_DIR)/parasite-head-64.o
native-obj-e += ./compel/plugins/std.built-in.o
- compat-obj-y += ./$(ARCH_DIR)/parasite-head-32.o
- compat-obj-e += ./compel/plugins/std-32.built-in.o
-
- AFLAGS_parasite-head-64.o += -fpie -DCONFIG_X86_64
- AFLAGS_parasite-head-64.d += -fpie -DCONFIG_X86_64
-
- AFLAGS_parasite-head-32.o += -fno-pic -m32 -DCONFIG_X86_32
- AFLAGS_parasite-head-32.d += -fno-pic -m32 -DCONFIG_X86_32
+ compat-obj-e += ./compel/plugins/std-compat.built-in.o
else
- native-obj-y += ./$(ARCH_DIR)/parasite-head.o
native-obj-e += ./compel/plugins/std.built-in.o
restorer-obj-e += ./compel/plugins/std.built-in.o
endif
@@ -112,6 +103,7 @@ ifeq ($(strip $(V)),)
piegen_stdout := >/dev/null
endif
+$(obj)/restorer.built-in.o: $(compel_std-native)
$(obj)/restorer.built-in.bin.o: $(obj)/restorer.built-in.o \
$(obj)/native.lib.a $(compel_pack_lds-native)
$(call msg-gen, $@)
@@ -119,6 +111,7 @@ $(obj)/restorer.built-in.bin.o: $(obj)/restorer.built-in.o \
# $1 - binary mode: native/compat
define gen-rule-built-in.bin.o
+$(obj)/$(1).built-in.o: $(compel_std-$(1))
$(obj)/parasite-$(1).built-in.bin.o: $(obj)/$(1).built-in.o \
$(obj)/$(1).lib.a $(compel_pack_lds-$(1))
$$(call msg-gen, $$@)
@@ -145,6 +138,7 @@ ifeq ($(filter arm aarch64,$(ARCH)),)
endif
define gen-rule-built-in.bin.o
+$(obj)/$(1).built-in.o: $(compel_std-$(1))
$(obj)/parasite-$(1).built-in.bin.o: $(obj)/$(1).built-in.o \
$(compel_pack_lds-$(1)) $(obj)/native.lib.a
$$(call msg-gen, $$@)
@@ -153,6 +147,7 @@ endef
$(eval $(call map,gen-rule-built-in.bin.o,$(parasite_target)))
+$(obj)/restorer.built-in.o: $(compel_std-native)
$(obj)/restorer.built-in.bin.o: $(obj)/restorer.built-in.o \
$(compel_pack_lds-native) $(obj)/native.lib.a
$(call msg-gen, $@)
diff --git a/criu/pie/compat/infect-compat.c b/criu/pie/compat/infect-compat.c
deleted file mode 120000
index 87c7722b6548..000000000000
--- a/criu/pie/compat/infect-compat.c
+++ /dev/null
@@ -1 +0,0 @@
-../infect.c
\ No newline at end of file
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
index b7871c4493c2..d307d79a2bce 100644
--- a/criu/pie/restorer.c
+++ b/criu/pie/restorer.c
@@ -63,11 +63,28 @@ static int n_helpers;
static pid_t *zombies;
static int n_zombies;
+/*
+ * These are stubs for std compel plugin.
+ */
int compel_main(void *arg_p, unsigned int arg_s)
{
return 0;
}
+int parasite_daemon_cmd(int cmd, void *args)
+{
+ return 0;
+}
+
+int parasite_trap_cmd(int cmd, void *args)
+{
+ return 0;
+}
+
+void parasite_cleanup(void)
+{
+}
+
extern void cr_restore_rt (void) asm ("__cr_restore_rt")
__attribute__ ((visibility ("hidden")));
--
2.7.4
More information about the CRIU
mailing list