[{"id":30526,"web_url":"https://patchwork.libcamera.org/comment/30526/","msgid":"<172243608043.392292.8726121245617413450@ping.linuxembedded.co.uk>","date":"2024-07-31T14:28:00","subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2024-07-31 14:59:34)\n> uClibc doesn't provide memfd_create(), which led libcamera to open-code\n> the call using syscall(). Sprinkling the code with #ifdef's isn't the\n> most readable option, so improve it by providing a local implementation\n> of memfd_create(), and call the function unconditionally from\n> MemFd::create(). This makes the main code path more readable.\n> \n> Suggested-by: Nicolas Dufresne <nicolas@ndufresne.ca>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/base/memfd.cpp | 17 ++++++++++++-----\n>  1 file changed, 12 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/libcamera/base/memfd.cpp b/src/libcamera/base/memfd.cpp\n> index 72474307af09..d95adb91615c 100644\n> --- a/src/libcamera/base/memfd.cpp\n> +++ b/src/libcamera/base/memfd.cpp\n> @@ -20,15 +20,26 @@\n>   * \\brief Anonymous file creation\n>   */\n>  \n> -/* uClibc doesn't provide the file sealing API. */\n>  #ifndef __DOXYGEN__\n> +namespace {\n> +\n> +/* uClibc doesn't provide the file sealing API. */\n>  #if not HAVE_FILE_SEALS\n>  #define F_ADD_SEALS            1033\n>  #define F_SEAL_SHRINK          0x0002\n>  #define F_SEAL_GROW            0x0004\n>  #endif\n> +\n> +#ifndef HAVE_MEMFD_CREATE\n> +int memfd_create(const char *name, unsigned int flags)\n> +{\n> +       return syscall(SYS_memfd_create, name, flags);\n> +}\n>  #endif\n>  \n> +} /* namespace */\n> +#endif /* __DOXYGEN__ */\n> +\n>  namespace libcamera {\n>  \n>  LOG_DECLARE_CATEGORY(File)\n> @@ -72,11 +83,7 @@ LOG_DECLARE_CATEGORY(File)\n>   */\n>  UniqueFD MemFd::create(const char *name, std::size_t size, Seals seals)\n>  {\n> -#if HAVE_MEMFD_CREATE\n>         int ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> -#else\n> -       int ret = syscall(SYS_memfd_create, name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> -#endif\n\nYes, this looks neater to me.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>         if (ret < 0) {\n>                 ret = errno;\n>                 LOG(File, Error)\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5CE53C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 14:28:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 089A963374;\n\tWed, 31 Jul 2024 16:28:05 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 67EF56198E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 16:28:03 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 533AA496;\n\tWed, 31 Jul 2024 16:27:15 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"TPC96OJW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722436035;\n\tbh=v+5R4HA/tWjyJ+AwVZ88uLOtn6SariDzmuco/30V2Zc=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=TPC96OJWIcYqO2wrlscF8VmSeMCh3LU/BsMYXA8zT6qr1QFXzXQaK5mIzEKW3aqOC\n\tQ+xqBT0ZFiE3jZzbxzC/PeoCBxUL53RHebth56MPHVhmZEJp95X3bjbpij4+bHlFm/\n\tgzG3+0uDZIUyEVS8QsYpSb8sNwlEem3/Z2FUjmxM=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>","References":"<20240731135936.2105-1-laurent.pinchart@ideasonboard.com>\n\t<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 31 Jul 2024 15:28:00 +0100","Message-ID":"<172243608043.392292.8726121245617413450@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30529,"web_url":"https://patchwork.libcamera.org/comment/30529/","msgid":"<7830472ac4cc196f18689a4fdea6fa1adbbbef4f.camel@ndufresne.ca>","date":"2024-07-31T18:49:25","subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/people/30/","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"content":"Hi,\n\nLe mercredi 31 juillet 2024 à 16:59 +0300, Laurent Pinchart a écrit :\n> uClibc doesn't provide memfd_create(), which led libcamera to open-code\n> the call using syscall(). Sprinkling the code with #ifdef's isn't the\n> most readable option, so improve it by providing a local implementation\n> of memfd_create(), and call the function unconditionally from\n> MemFd::create(). This makes the main code path more readable.\n> \n> Suggested-by: Nicolas Dufresne <nicolas@ndufresne.ca>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/base/memfd.cpp | 17 ++++++++++++-----\n>  1 file changed, 12 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/libcamera/base/memfd.cpp b/src/libcamera/base/memfd.cpp\n> index 72474307af09..d95adb91615c 100644\n> --- a/src/libcamera/base/memfd.cpp\n> +++ b/src/libcamera/base/memfd.cpp\n> @@ -20,15 +20,26 @@\n>   * \\brief Anonymous file creation\n>   */\n>  \n> -/* uClibc doesn't provide the file sealing API. */\n>  #ifndef __DOXYGEN__\n> +namespace {\n> +\n> +/* uClibc doesn't provide the file sealing API. */\n>  #if not HAVE_FILE_SEALS\n>  #define F_ADD_SEALS\t\t1033\n>  #define F_SEAL_SHRINK\t\t0x0002\n>  #define F_SEAL_GROW\t\t0x0004\n>  #endif\n> +\n> +#ifndef HAVE_MEMFD_CREATE\n> +int memfd_create(const char *name, unsigned int flags)\n\nThis is not being exported, so perhaps `static int ..` Or is that the default i\n.cpp ?\n\n> +{\n> +\treturn syscall(SYS_memfd_create, name, flags);\n> +}\n>  #endif\n>  \n> +} /* namespace */\n> +#endif /* __DOXYGEN__ */\n> +\n>  namespace libcamera {\n>  \n>  LOG_DECLARE_CATEGORY(File)\n> @@ -72,11 +83,7 @@ LOG_DECLARE_CATEGORY(File)\n>   */\n>  UniqueFD MemFd::create(const char *name, std::size_t size, Seals seals)\n>  {\n> -#if HAVE_MEMFD_CREATE\n>  \tint ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> -#else\n> -\tint ret = syscall(SYS_memfd_create, name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> -#endif\n>  \tif (ret < 0) {\n>  \t\tret = errno;\n>  \t\tLOG(File, Error)\n\nA lot nicer to me (of course I'm biased from having suggested it).\n\nReviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 7BFE6C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 18:49:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 55F9263375;\n\tWed, 31 Jul 2024 20:49:30 +0200 (CEST)","from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com\n\t[IPv6:2607:f8b0:4864:20::f29])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 47C0C6336F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 20:49:28 +0200 (CEST)","by mail-qv1-xf29.google.com with SMTP id\n\t6a1803df08f44-6b7a4668f1fso36022906d6.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 11:49:28 -0700 (PDT)","from nicolas-tpx395.lan ([2606:6d00:15:820c::580])\n\tby smtp.gmail.com with ESMTPSA id\n\t6a1803df08f44-6bb3fa950a3sm77199096d6.90.2024.07.31.11.49.26\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 31 Jul 2024 11:49:26 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=ndufresne-ca.20230601.gappssmtp.com\n\theader.i=@ndufresne-ca.20230601.gappssmtp.com\n\theader.b=\"HTdWrKmd\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ndufresne-ca.20230601.gappssmtp.com; s=20230601; t=1722451767;\n\tx=1723056567; darn=lists.libcamera.org; \n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=yr+Gl9Ncc4B60VKvUBzoztcav1lsVzJPo9USJrz52sg=;\n\tb=HTdWrKmdyAjez11UUfdqRnqxbexk73Op+e3QXRhINZG3ZW+9sTeA3jrjSFc7zL/lrG\n\t+20X03fueP1P76Y8tgL23nJmMFs0SHX3Urbt2JovYCwZ1E8Q1UY1I3Cwytrsqhd+ZxmR\n\teC8PcK29/NoNmy6xSsFyrM6Y8TWZLzx31v26IiyNoIt1ZOQQW1E7OHdrunvXCWC63bMb\n\t5MAqoRBgXWgp+EKigSQAxcYA3T8VWtWczoXtLbm92ALzxcV3gNxaikF2TlUkFNM9d3XX\n\tlR9xQoLsJVPJ2/6Fx5g2DVjuqtXrrHlUcoV1wbv0mtod1niLN0LfPyVgnIxixNK7VGoV\n\txfAw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1722451767; x=1723056567;\n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=yr+Gl9Ncc4B60VKvUBzoztcav1lsVzJPo9USJrz52sg=;\n\tb=pDKcXH+6KcDsqT8y9dKqt+q6zzzkB/jDRZ4qP9AmQM9hBs+6WgK+ztiAU2MYZcx4Gv\n\thRbv85uqTv2zuIef9YULkDZ0OEg8E6w/Z2GRiEOhRXCktMtHMhZOosvgT/7e/rVvmxfE\n\tJohSwXxw3I34qQa0BKbtQCBT/v2E8JwQqxyEieNPfPgOOpvX+Hsb3Ll1zTI8//0rUwuV\n\thdNkCrc+LgwWS7cSXBiU+QMlEAqjs6a8UrPQIcLJBAPRfS1JKp288A6sI+uyfWuAC1cK\n\tPUoQLyXvL8ED2rWAgZw9Wh5eRe6Ty8SYw8alAOyq6qQrrQ6jxyCNxJYmjZGWdZRm+dso\n\tSgJw==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCWKYdImAYeVFKpCg1OZR6DE9UAANKSSyQxCOp4PKl1Gc5TZ0SxpMN3m8AD+2HEAhMLLWhug5LhV8F932Rs5jqS4eKZhJpDblw+OwMDysQDB1VayuQ==","X-Gm-Message-State":"AOJu0Yyb3slLO+bM7yXrcDwtUtRVA9RsGDLOPjm9s63g/aloJ+KI7BRE\n\tJX5dstpg+s1qATebFV+xRSZognd36eA940v/O8Yo36kfIQcFbAWki3WvELdzyeWxKk07PEyYFq1\n\t4","X-Google-Smtp-Source":"AGHT+IGsWR/dDIgzLBsHtiQB7RZKIuJAfPvX8WqGIfijd4b0KIeMdys/13U1J6a8cebeiWE+gwLNVQ==","X-Received":"by 2002:a05:6214:4b13:b0:6b7:ad32:3815 with SMTP id\n\t6a1803df08f44-6bb8d77bfa2mr2073506d6.14.1722451766946; \n\tWed, 31 Jul 2024 11:49:26 -0700 (PDT)","Message-ID":"<7830472ac4cc196f18689a4fdea6fa1adbbbef4f.camel@ndufresne.ca>","Subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 31 Jul 2024 14:49:25 -0400","In-Reply-To":"<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>","References":"<20240731135936.2105-1-laurent.pinchart@ideasonboard.com>\n\t<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.52.2 (3.52.2-1.fc40) ","MIME-Version":"1.0","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30532,"web_url":"https://patchwork.libcamera.org/comment/30532/","msgid":"<e3d0c5ef-232f-4c0e-802d-d5c07ee72b3f@redhat.com>","date":"2024-07-31T19:00:46","subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","submitter":{"id":102,"url":"https://patchwork.libcamera.org/api/people/102/","name":"Hans de Goede","email":"hdegoede@redhat.com"},"content":"Hi,\n\nOn 7/31/24 3:59 PM, Laurent Pinchart wrote:\n> uClibc doesn't provide memfd_create(), which led libcamera to open-code\n> the call using syscall(). Sprinkling the code with #ifdef's isn't the\n> most readable option, so improve it by providing a local implementation\n> of memfd_create(), and call the function unconditionally from\n> MemFd::create(). This makes the main code path more readable.\n> \n> Suggested-by: Nicolas Dufresne <nicolas@ndufresne.ca>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/base/memfd.cpp | 17 ++++++++++++-----\n>  1 file changed, 12 insertions(+), 5 deletions(-)\n> \n> diff --git a/src/libcamera/base/memfd.cpp b/src/libcamera/base/memfd.cpp\n> index 72474307af09..d95adb91615c 100644\n> --- a/src/libcamera/base/memfd.cpp\n> +++ b/src/libcamera/base/memfd.cpp\n> @@ -20,15 +20,26 @@\n>   * \\brief Anonymous file creation\n>   */\n>  \n> -/* uClibc doesn't provide the file sealing API. */\n>  #ifndef __DOXYGEN__\n> +namespace {\n> +\n> +/* uClibc doesn't provide the file sealing API. */\n>  #if not HAVE_FILE_SEALS\n>  #define F_ADD_SEALS\t\t1033\n>  #define F_SEAL_SHRINK\t\t0x0002\n>  #define F_SEAL_GROW\t\t0x0004\n>  #endif\n> +\n> +#ifndef HAVE_MEMFD_CREATE\n\nHmm below you are removing:\n\n\"#if HAVE_MEMFD_CREATE\"\n\nWhich suggests that HAVE_MEMFD_CREATE is always defined\nas either 0 or 1 and above you use \"#if not HAVE_FILE_SEALS\"\nI would prefer:\n\n#if not HAVE_MEMFD_CREATE\n\nto match the \"#if not HAVE_FILE_SEALS\" for consistency.\n\notherwise this looks good to me:\n\nReviewed-by: Hans de Goede <hdegoede@redhat.com>\n\nRegards,\n\nHans\n\n\n> +int memfd_create(const char *name, unsigned int flags)\n> +{\n> +\treturn syscall(SYS_memfd_create, name, flags);\n> +}\n>  #endif\n>  \n> +} /* namespace */\n> +#endif /* __DOXYGEN__ */\n> +\n>  namespace libcamera {\n>  \n>  LOG_DECLARE_CATEGORY(File)\n> @@ -72,11 +83,7 @@ LOG_DECLARE_CATEGORY(File)\n>   */\n>  UniqueFD MemFd::create(const char *name, std::size_t size, Seals seals)\n>  {\n> -#if HAVE_MEMFD_CREATE\n>  \tint ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> -#else\n> -\tint ret = syscall(SYS_memfd_create, name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> -#endif\n>  \tif (ret < 0) {\n>  \t\tret = errno;\n>  \t\tLOG(File, Error)","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A1E89BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 19:00:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F29C463376;\n\tWed, 31 Jul 2024 21:00:53 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A34C6336F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 21:00:52 +0200 (CEST)","from mail-ej1-f72.google.com (mail-ej1-f72.google.com\n\t[209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-96-UlBzFlDgNcOo9Dsx1JiGQw-1; Wed, 31 Jul 2024 15:00:48 -0400","by mail-ej1-f72.google.com with SMTP id\n\ta640c23a62f3a-a7aa020cef5so540823966b.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 31 Jul 2024 12:00:48 -0700 (PDT)","from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec?\n\t(2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl.\n\t[2001:1c00:c32:7800:5bfa:a036:83f0:f9ec])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-a7acad41185sm805140366b.128.2024.07.31.12.00.46\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tWed, 31 Jul 2024 12:00:46 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"K+cYDCsX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1722452451;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=BiUF4vfNEmmUFMn3ApKynxUvwWaBEQQaHWqnIfWQfa4=;\n\tb=K+cYDCsXahTqOw08nfqjt13zhzcBOH151lWQN6utyFcYO0/Av1QsoYBw9o/IP3MqAnvpzG\n\tjXgbjXMs03F1MRq+kE/GbNarWlCL1NyTJkHPHWflVTVsBJu1HW4T4Fnyz7b56HoCK2BYVM\n\tldCwC4bPbbTrJDlpychAV6qJ6qsfOe0=","X-MC-Unique":"UlBzFlDgNcOo9Dsx1JiGQw-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1722452447; x=1723057247;\n\th=content-transfer-encoding:in-reply-to:from:content-language\n\t:references:to:subject:user-agent:mime-version:date:message-id\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n\tbh=BiUF4vfNEmmUFMn3ApKynxUvwWaBEQQaHWqnIfWQfa4=;\n\tb=qXUCBThJ2cRVi++HoTDHbiWYPs2iYMpZlYvkHJtI/cSIRReZsmlW96azLDg8J7EeYJ\n\tURmfImm7lm6dSGnhRWksdPfwe0ru6be/gG8mNqw1sWOyAOTWL6yiu8hAsXGmrfCxWLSo\n\ts2hHZ8rqFPMDed/5D72M5qz9lNPr9CgfIQ9RJQO1E44R/Otf/RO/13EdQtf7JAuWekSF\n\tplBNY57XBEJ5oA9hQek8ZhivDtIrfIWxnpb7fjf6hvG7TO2vzlSS/uJ/kuc7YGMYxp32\n\t2vxbGwDTLUeqVzq6WfjSwsHAwwcHrUNvAoMU6To2KxT5lUy0PLwNJ4EX63KPWXsn6A8j\n\tB0og==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCWlGGZaSlZ2uoBNxoNhZVd3c2pUyKtZ/XI6rS8ayxgTFakC01757Tc3vVjah4TJhB7VHbLXH1cIQuZKlYqpqtg9rMzJegxPG9Mx2gZiiQB/UXrvwg==","X-Gm-Message-State":"AOJu0Yzovh/GwK0XtJABoNXt9DqvW/NXSTQwtzTXRMU5vloyLCmsY6kR\n\t9IAPLd+EWvUJ8uOQ/IZXSnIQ+W8czGQNk9ouS8Qqo+FBcTUfqrBu3aXfSLbiSXVJhyQyQY9J+ik\n\tT/Fld6C8WPIRCDW0EkVuzhJ5wQZQ+enNs725endYMMsdGEZ+AShXEYDIPjrQOb5LRoxAEPvQ=","X-Received":["by 2002:a17:906:c113:b0:a7a:a30b:7b94 with SMTP id\n\ta640c23a62f3a-a7daf543454mr4026866b.28.1722452447511; \n\tWed, 31 Jul 2024 12:00:47 -0700 (PDT)","by 2002:a17:906:c113:b0:a7a:a30b:7b94 with SMTP id\n\ta640c23a62f3a-a7daf543454mr4025666b.28.1722452447085; \n\tWed, 31 Jul 2024 12:00:47 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IHvjHmtW9jKwcjrHlctL9CDjpDa71nKyF55OuNSLVR3na2aPXWJwHEmoLLqN2ZX+HkizkF33A==","Message-ID":"<e3d0c5ef-232f-4c0e-802d-d5c07ee72b3f@redhat.com>","Date":"Wed, 31 Jul 2024 21:00:46 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20240731135936.2105-1-laurent.pinchart@ideasonboard.com>\n\t<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>","From":"Hans de Goede <hdegoede@redhat.com>","In-Reply-To":"<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US, nl","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"7bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30535,"web_url":"https://patchwork.libcamera.org/comment/30535/","msgid":"<20240731221718.GA5738@pendragon.ideasonboard.com>","date":"2024-07-31T22:17:18","subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas,\n\nOn Wed, Jul 31, 2024 at 02:49:25PM -0400, Nicolas Dufresne wrote:\n> Le mercredi 31 juillet 2024 à 16:59 +0300, Laurent Pinchart a écrit :\n> > uClibc doesn't provide memfd_create(), which led libcamera to open-code\n> > the call using syscall(). Sprinkling the code with #ifdef's isn't the\n> > most readable option, so improve it by providing a local implementation\n> > of memfd_create(), and call the function unconditionally from\n> > MemFd::create(). This makes the main code path more readable.\n> > \n> > Suggested-by: Nicolas Dufresne <nicolas@ndufresne.ca>\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  src/libcamera/base/memfd.cpp | 17 ++++++++++++-----\n> >  1 file changed, 12 insertions(+), 5 deletions(-)\n> > \n> > diff --git a/src/libcamera/base/memfd.cpp b/src/libcamera/base/memfd.cpp\n> > index 72474307af09..d95adb91615c 100644\n> > --- a/src/libcamera/base/memfd.cpp\n> > +++ b/src/libcamera/base/memfd.cpp\n> > @@ -20,15 +20,26 @@\n> >   * \\brief Anonymous file creation\n> >   */\n> >  \n> > -/* uClibc doesn't provide the file sealing API. */\n> >  #ifndef __DOXYGEN__\n> > +namespace {\n> > +\n> > +/* uClibc doesn't provide the file sealing API. */\n> >  #if not HAVE_FILE_SEALS\n> >  #define F_ADD_SEALS\t\t1033\n> >  #define F_SEAL_SHRINK\t\t0x0002\n> >  #define F_SEAL_GROW\t\t0x0004\n> >  #endif\n> > +\n> > +#ifndef HAVE_MEMFD_CREATE\n> > +int memfd_create(const char *name, unsigned int flags)\n> \n> This is not being exported, so perhaps `static int ..` Or is that the default i\n> .cpp ?\n\nThe preferred way to make symbols local in C++ is to enclose them in an\nanonymous namespace:\n\n/* This will be visible outside of the compilation unit */\nint foo()\n{\n\treturn 42;\n}\n\nnamespace {\n\n/* This won't */\n\nint bar()\n{\n\treturn 24;\n}\n\n}\n\n> > +{\n> > +\treturn syscall(SYS_memfd_create, name, flags);\n> > +}\n> >  #endif\n> >  \n> > +} /* namespace */\n> > +#endif /* __DOXYGEN__ */\n> > +\n> >  namespace libcamera {\n> >  \n> >  LOG_DECLARE_CATEGORY(File)\n> > @@ -72,11 +83,7 @@ LOG_DECLARE_CATEGORY(File)\n> >   */\n> >  UniqueFD MemFd::create(const char *name, std::size_t size, Seals seals)\n> >  {\n> > -#if HAVE_MEMFD_CREATE\n> >  \tint ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> > -#else\n> > -\tint ret = syscall(SYS_memfd_create, name, MFD_ALLOW_SEALING | MFD_CLOEXEC);\n> > -#endif\n> >  \tif (ret < 0) {\n> >  \t\tret = errno;\n> >  \t\tLOG(File, Error)\n> \n> A lot nicer to me (of course I'm biased from having suggested it).\n> \n> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 45D9CC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 31 Jul 2024 22:17:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 758F36336F;\n\tThu,  1 Aug 2024 00:17:41 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CCF9E61994\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 Aug 2024 00:17:39 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 71D3E4D1;\n\tThu,  1 Aug 2024 00:16:51 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"F5bDohN0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722464211;\n\tbh=Bavh6BqJY1cDg0ZyuwvRc+3H/7fHYnivhRLLPSINUrg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=F5bDohN09GwvjerhIpTezmJlfb9ION1SJASUL4L2rP8WcJvcAVy//NAYCH9i/4UZ9\n\tcW/uAHW05sYGljhB8cdTNhsp2PuZBr2p325bKwUDZnu9SobcTnVTi7mtaiuxnqzmWI\n\tfU0C4fG5XVeahN5oz4qPTmgtrW3AGcVPsufFnFf8=","Date":"Thu, 1 Aug 2024 01:17:18 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 2/4] libcamera: base: memfd: Handle uClibc\n\tcompatibility with function wrapper","Message-ID":"<20240731221718.GA5738@pendragon.ideasonboard.com>","References":"<20240731135936.2105-1-laurent.pinchart@ideasonboard.com>\n\t<20240731135936.2105-3-laurent.pinchart@ideasonboard.com>\n\t<7830472ac4cc196f18689a4fdea6fa1adbbbef4f.camel@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<7830472ac4cc196f18689a4fdea6fa1adbbbef4f.camel@ndufresne.ca>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]