config: Make memfd_create optional

`memfd_create` doesn't seem to be supported on
all platforms (e.g. ubuntu 18 has trouble with it).
Even though, I was able to substitute `memfd_create`
with a direct system call, I was not able to get
the `MFD_CLOXEC` flag (from fcntl.h) working cleanly
(there were redefinitions/conflicts for other
structures when trying to use <linux/*> headers).
Making it optional for time being till we have
figured out how to make it work broadly.
This commit is contained in:
Salman Malik 2023-03-25 23:22:01 +00:00
parent 8b7fb73bfd
commit a438e46e18
5 changed files with 15 additions and 3 deletions

View file

@ -51,6 +51,9 @@ config_h = configuration_data()
config_h.set('_GNU_SOURCE', '1')
config_h.set_quoted('EI_VERSION', meson.project_version())
config_h.set_quoted('EIS_VERSION', meson.project_version())
if cc.has_function('memfd_create', prefix: '#define _GNU_SOURCE\n#include <sys/mman.h>')
config_h.set10('HAVE_MEMFD_CREATE', true)
endif
dep_libxkbcommon = dependency('xkbcommon', required: false)
config_h.set10('HAVE_LIBXKBCOMMON', dep_libxkbcommon.found())

View file

@ -26,9 +26,12 @@
#include <stddef.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#if HAVE_MEMFD_CREATE
#include <sys/mman.h>
#endif
#include "util-memfile.h"
#include "util-mem.h"
#include "util-io.h"
@ -55,6 +58,7 @@ OBJECT_IMPLEMENT_REF(memfile);
OBJECT_IMPLEMENT_GETTER(memfile, fd, int);
OBJECT_IMPLEMENT_GETTER(memfile, size, size_t);
#if HAVE_MEMFD_CREATE
struct memfile *
memfile_new(const char *data, size_t sz) {
_unref_(memfile) *memfile = memfile_create(NULL);
@ -81,3 +85,4 @@ memfile_new(const char *data, size_t sz) {
return steal(&memfile);
}
#endif

View file

@ -28,8 +28,10 @@
struct memfile;
#if HAVE_MEMFD_CREATE
struct memfile *
memfile_new(const char *data, size_t sz);
#endif
struct memfile *
memfile_ref(struct memfile *memfile);

View file

@ -1015,6 +1015,7 @@ MUNIT_TEST(test_ei_device_multitouch)
return MUNIT_OK;
}
#if HAVE_MEMFD_CREATE
MUNIT_TEST(test_ei_keymap_invalid)
{
_unref_(peck) *peck = peck_new();
@ -1121,6 +1122,7 @@ MUNIT_TEST(test_ei_keymap_set)
return MUNIT_OK;
}
#endif
MUNIT_TEST(test_ei_keyboard_modifiers)
{

View file

@ -179,7 +179,7 @@ colorprint(const char *format, ...)
va_end(args);
}
#if HAVE_LIBXKBCOMMON
#if HAVE_MEMFD_CREATE && HAVE_LIBXKBCOMMON
DEFINE_UNREF_CLEANUP_FUNC(xkb_context);
DEFINE_UNREF_CLEANUP_FUNC(xkb_keymap);
DEFINE_UNREF_CLEANUP_FUNC(xkb_state);
@ -188,7 +188,7 @@ DEFINE_UNREF_CLEANUP_FUNC(xkb_state);
static void
setup_keymap(struct eis_demo_server *server, struct eis_device *device)
{
#if HAVE_LIBXKBCOMMON
#if HAVE_MEMFD_CREATE && HAVE_LIBXKBCOMMON
colorprint("Using server layout: %s\n", server->layout);
_unref_(xkb_context) *ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!ctx)