From 93d975194522450894a6fe7554b28a14fbfe7214 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Wed, 31 Jul 2024 16:52:18 +0300 Subject: libcamera: base: memfd: Handle uClibc compatibility with function wrapper uClibc doesn't provide memfd_create(), which led libcamera to open-code the call using syscall(). Sprinkling the code with #ifdef's isn't the most readable option, so improve it by providing a local implementation of memfd_create(), and call the function unconditionally from MemFd::create(). This makes the main code path more readable. Suggested-by: Nicolas Dufresne Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Tested-by: Milan Zamazal Tested-by: Hans de Goede Reviewed-by: Hans de Goede Reviewed-by: Nicolas Dufresne --- src/libcamera/base/memfd.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libcamera/base/memfd.cpp b/src/libcamera/base/memfd.cpp index 72474307..ed0b299b 100644 --- a/src/libcamera/base/memfd.cpp +++ b/src/libcamera/base/memfd.cpp @@ -20,15 +20,26 @@ * \brief Anonymous file creation */ -/* uClibc doesn't provide the file sealing API. */ #ifndef __DOXYGEN__ +namespace { + +/* uClibc doesn't provide the file sealing API. */ #if not HAVE_FILE_SEALS #define F_ADD_SEALS 1033 #define F_SEAL_SHRINK 0x0002 #define F_SEAL_GROW 0x0004 #endif + +#if not HAVE_MEMFD_CREATE +int memfd_create(const char *name, unsigned int flags) +{ + return syscall(SYS_memfd_create, name, flags); +} #endif +} /* namespace */ +#endif /* __DOXYGEN__ */ + namespace libcamera { LOG_DECLARE_CATEGORY(File) @@ -72,11 +83,7 @@ LOG_DECLARE_CATEGORY(File) */ UniqueFD MemFd::create(const char *name, std::size_t size, Seals seals) { -#if HAVE_MEMFD_CREATE int ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC); -#else - int ret = syscall(SYS_memfd_create, name, MFD_ALLOW_SEALING | MFD_CLOEXEC); -#endif if (ret < 0) { ret = errno; LOG(File, Error) -- cgit v1.2.1