From: Marc-André Lureau <marcandre.lur...@redhat.com> Do not compile potentially panicking code, instead check memfd API is present during configure time.
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> Message-Id: <20201125100640.366523-7-marcandre.lur...@redhat.com> Reviewed-by: Michael S. Tsirkin <m...@redhat.com> Signed-off-by: Michael S. Tsirkin <m...@redhat.com> --- subprojects/libvhost-user/libvhost-user.c | 6 ------ subprojects/libvhost-user/meson.build | 12 ++++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index fab7ca17ee..09741a7b49 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1616,7 +1616,6 @@ vu_inflight_queue_size(uint16_t queue_size) sizeof(uint16_t), INFLIGHT_ALIGNMENT); } -#ifdef MFD_ALLOW_SEALING static void * memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd) { @@ -1648,7 +1647,6 @@ memfd_alloc(const char *name, size_t size, unsigned int flags, int *fd) return ptr; } -#endif static bool vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) @@ -1672,13 +1670,9 @@ vu_get_inflight_fd(VuDev *dev, VhostUserMsg *vmsg) mmap_size = vu_inflight_queue_size(queue_size) * num_queues; -#ifdef MFD_ALLOW_SEALING addr = memfd_alloc("vhost-inflight", mmap_size, F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL, &fd); -#else - vu_panic(dev, "Not implemented: memfd support is missing"); -#endif if (!addr) { vu_panic(dev, "Failed to alloc vhost inflight area"); diff --git a/subprojects/libvhost-user/meson.build b/subprojects/libvhost-user/meson.build index f9ecc534cf..ac228b5ba6 100644 --- a/subprojects/libvhost-user/meson.build +++ b/subprojects/libvhost-user/meson.build @@ -2,7 +2,19 @@ project('libvhost-user', 'c', license: 'GPL-2.0-or-later', default_options: ['c_std=gnu99']) +cc = meson.get_compiler('c') + glib = dependency('glib-2.0') +foreach h, syms: { + 'sys/mman.h': ['memfd_create', 'MFD_ALLOW_SEALING'], + 'sys/fcntl.h': ['F_SEAL_GROW', 'F_SEAL_SHRINK', 'F_SEAL_SEAL'] } + foreach sym: syms + cc.has_header_symbol(h, sym, + args: ['-D_GNU_SOURCE'], + required: true) + endforeach +endforeach + inc = include_directories('../../include', '../../linux-headers') vhost_user = static_library('vhost-user', -- MST