Commit d54e7bbf authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

memfd: Use CONFIG_HAS_MEMFD to not fail on old kernels

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent ab5442de
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "util.h" #include "util.h"
#include "lsm.h" #include "lsm.h"
#include "proc_parse.h" #include "proc_parse.h"
#include "config.h"
struct kerndat_s kdat = { struct kerndat_s kdat = {
/* /*
...@@ -381,6 +382,7 @@ static int get_last_cap(void) ...@@ -381,6 +382,7 @@ static int get_last_cap(void)
return sysctl_op(req, ARRAY_SIZE(req), CTL_READ, 0); return sysctl_op(req, ARRAY_SIZE(req), CTL_READ, 0);
} }
#ifdef CONFIG_HAS_MEMFD
static bool kerndat_has_memfd_create(void) static bool kerndat_has_memfd_create(void)
{ {
int ret; int ret;
...@@ -398,6 +400,12 @@ static bool kerndat_has_memfd_create(void) ...@@ -398,6 +400,12 @@ static bool kerndat_has_memfd_create(void)
return 0; return 0;
} }
#else
static bool kerndat_has_memfd_create(void)
{
kdat.has_memfd = false;
}
#endif
static int get_task_size(void) static int get_task_size(void)
{ {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "crtools.h" #include "crtools.h"
#include "namespaces.h" #include "namespaces.h"
#include "kerndat.h" #include "kerndat.h"
#include "config.h"
#include "pstree.h" #include "pstree.h"
#include "posix-timer.h" #include "posix-timer.h"
#include "net.h" #include "net.h"
...@@ -1181,6 +1182,7 @@ static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size) ...@@ -1181,6 +1182,7 @@ static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size)
return 0; return 0;
} }
#ifdef CONFIG_HAS_MEMFD
static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size) static int parasite_memfd_exchange(struct parasite_ctl *ctl, unsigned long size)
{ {
void *where = (void *)ctl->syscall_ip + BUILTIN_SYSCALL_SIZE; void *where = (void *)ctl->syscall_ip + BUILTIN_SYSCALL_SIZE;
...@@ -1254,6 +1256,12 @@ err_cure: ...@@ -1254,6 +1256,12 @@ err_cure:
syscall_seized(ctl, __NR_close, &sret, fd, 0, 0, 0, 0, 0); syscall_seized(ctl, __NR_close, &sret, fd, 0, 0, 0, 0, 0);
return -1; 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) int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size)
{ {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "page-xfer.h" #include "page-xfer.h"
#include "rst-malloc.h" #include "rst-malloc.h"
#include "vma.h" #include "vma.h"
#include "config.h"
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/pagemap.pb-c.h" #include "protobuf/pagemap.pb-c.h"
...@@ -215,6 +216,7 @@ int get_shmem_fd(int pid, VmaEntry *vi) ...@@ -215,6 +216,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
return dup(si->fd); return dup(si->fd);
flags = MAP_SHARED; flags = MAP_SHARED;
#ifdef CONFIG_HAS_MEMFD
if (kdat.has_memfd) { if (kdat.has_memfd) {
f = syscall(SYS_memfd_create, "", 0); f = syscall(SYS_memfd_create, "", 0);
if (f < 0) { if (f < 0) {
...@@ -228,6 +230,7 @@ int get_shmem_fd(int pid, VmaEntry *vi) ...@@ -228,6 +230,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
} }
flags |= MAP_FILE; flags |= MAP_FILE;
} else } else
#endif
flags |= MAP_ANONYMOUS; flags |= MAP_ANONYMOUS;
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment