提交 35f9b6ef 编写于 作者: M Marc-André Lureau 提交者: Michael S. Tsirkin

util: add fallback for qemu_memfd_alloc()

Add an open/unlink/mmap fallback for system that do not support
memfd (only available since 3.17, ~1y ago).

This patch may require additional SELinux policies to work for enforced
systems, but should fail gracefully in this case.
Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
Tested-by: NThibaut Collet <thibaut.collet@6wind.com>
上级 d3592199
......@@ -97,8 +97,24 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals,
return NULL;
}
} else {
perror("memfd");
return NULL;
const char *tmpdir = g_get_tmp_dir();
gchar *fname;
fname = g_strdup_printf("%s/memfd-XXXXXX", tmpdir);
mfd = mkstemp(fname);
unlink(fname);
g_free(fname);
if (mfd == -1) {
perror("mkstemp");
return NULL;
}
if (ftruncate(mfd, size) == -1) {
perror("ftruncate");
close(mfd);
return NULL;
}
}
ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册