From patchwork Wed Jul 31 13:59:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 20731 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D8F1CBDC71 for ; Wed, 31 Jul 2024 14:00:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9236C63377; Wed, 31 Jul 2024 16:00:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="u5gvqy8x"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B587763373 for ; Wed, 31 Jul 2024 16:00:00 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BE1FDF85 for ; Wed, 31 Jul 2024 15:59:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1722434353; bh=77zpJSFoPZJqYJyQ1SYf77gaxo8dLAeY+OC+qai2asY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=u5gvqy8x/hQ+CYPw+JMV3Xqb18+xCSvc8kD1ZnWlkLd3mELNfU8l9oVK0er0Aonho PD1y/agMgs9+gz5nIeLF1U1AEisM1MZrvZyWTnD+TpWQlXH8so19PpBI48gMLi7nGK Ge/6aeVLf7/Lj0Sph/Fx28ze6MTOhJ4gjhJtjbH8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc compatibility with function wrapper Date: Wed, 31 Jul 2024 16:59:34 +0300 Message-ID: <20240731135936.2105-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240731135936.2105-1-laurent.pinchart@ideasonboard.com> References: <20240731135936.2105-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Nicolas Dufresne Reviewed-by: Hans de Goede --- src/libcamera/base/memfd.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libcamera/base/memfd.cpp b/src/libcamera/base/memfd.cpp index 72474307af09..d95adb91615c 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 + +#ifndef 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)