[CRIU] [PATCH 2/2] memfd: Use CONFIG_HAS_MEMFD to not fail on old kernels

Cyrill Gorcunov gorcunov at openvz.org
Mon Feb 8 07:32:33 PST 2016


memfd is available since 3.16 kernel so don't fail
building criu on earlier kernels but simply don't
use it on older kernels.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 kerndat.c          | 8 ++++++++
 parasite-syscall.c | 8 ++++++++
 shmem.c            | 3 +++
 3 files changed, 19 insertions(+)

diff --git a/kerndat.c b/kerndat.c
index d03fdb3028ed..6e3f12ba6aae 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -20,6 +20,7 @@
 #include "util.h"
 #include "lsm.h"
 #include "proc_parse.h"
+#include "config.h"
 
 struct kerndat_s kdat = {
 	/*
@@ -381,6 +382,7 @@ static int get_last_cap(void)
 	return sysctl_op(req, ARRAY_SIZE(req), CTL_READ, 0);
 }
 
+#ifdef CONFIG_HAS_MEMFD
 static bool kerndat_has_memfd_create(void)
 {
 	int ret;
@@ -398,6 +400,12 @@ static bool kerndat_has_memfd_create(void)
 
 	return 0;
 }
+#else
+static bool kerndat_has_memfd_create(void)
+{
+	kdat.has_memfd = false;
+}
+#endif
 
 static int get_task_size(void)
 {
diff --git a/parasite-syscall.c b/parasite-syscall.c
index ee6bfef0e3bc..feb77b53b93d 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -21,6 +21,7 @@
 #include "crtools.h"
 #include "namespaces.h"
 #include "kerndat.h"
+#include "config.h"
 #include "pstree.h"
 #include "posix-timer.h"
 #include "net.h"
@@ -1181,6 +1182,7 @@ static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size)
 	return 0;
 }
 
+#ifdef CONFIG_HAS_MEMFD
 static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size)
 {
 	void *where = (void *)ctl->syscall_ip + BUILTIN_SYSCALL_SIZE;
@@ -1254,6 +1256,12 @@ err_cure:
 	syscall_seized(ctl, __NR_close, &sret, fd, 0, 0, 0, 0, 0);
 	return -1;
 }
+#else
+static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size)
+{
+	return 1;
+}
+#endif
 
 int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size)
 {
diff --git a/shmem.c b/shmem.c
index 0f9da630ccc5..ad3cdbbdeedd 100644
--- a/shmem.c
+++ b/shmem.c
@@ -12,6 +12,7 @@
 #include "page-xfer.h"
 #include "rst-malloc.h"
 #include "vma.h"
+#include "config.h"
 
 #include "protobuf.h"
 #include "protobuf/pagemap.pb-c.h"
@@ -215,6 +216,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
 		return dup(si->fd);
 
 	flags = MAP_SHARED;
+#ifdef CONFIG_HAS_MEMFD
 	if (kdat.has_memfd) {
 		f = syscall(SYS_memfd_create, "", 0);
 		if (f < 0) {
@@ -228,6 +230,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
 		}
 		flags |= MAP_FILE;
 	} else
+#endif
 		flags |= MAP_ANONYMOUS;
 
 	/*
-- 
2.5.0



More information about the CRIU mailing list