[{"id":30444,"web_url":"https://patchwork.libcamera.org/comment/30444/","msgid":"<172163617207.2376022.16947855722319325589@ping.linuxembedded.co.uk>","date":"2024-07-22T08:16:12","subject":"Re: [PATCH] v4l2: v4l2_compat: Fix ioctl() prototype with musl C\n\tlibrary","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-21 22:31:11)\n> The musl C library, as well as the POSIX standard, define the ioctl()\n> function's request argument as an int. glibc and uclibc, on the other\n> hand, define it as an unsigned long.\n\nI love how standards make things ... all the same ...\n\n> This difference between the function prototype and the implementation in\n> the V4L2 adaptation layer causes a compilation error with musl. Fix it\n> by detecting the function prototype and declaring the libcamera ioctl()\n> handler accordingly.\n\nI guess we need an alpine linux target in our CI matrix...\n\n\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  meson.build              | 9 +++++++++\n>  src/v4l2/v4l2_compat.cpp | 4 ++++\n>  2 files changed, 13 insertions(+)\n> \n> diff --git a/meson.build b/meson.build\n> index 2acd8c3e8cfe..ccd766a1e98c 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -90,6 +90,15 @@ if cc.has_header_symbol('sys/mman.h', 'memfd_create', prefix : '#define _GNU_SOU\n>      config_h.set('HAVE_MEMFD_CREATE', 1)\n>  endif\n>  \n> +ioctl_posix_test = '''\n> +#include <sys/ioctl.h>\n> +int ioctl (int, int, ...);\n> +'''\n> +\n> +if cc.compiles(ioctl_posix_test)\n> +    config_h.set('HAVE_POSIX_IOCTL', 1)\n> +endif\n> +\n\nI think we should start thinking about how to make our top level\nmeson.build more modular with so much 'compatibility' checks ... but\nthat's a tomorrow problem.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')\n>      config_h.set('HAVE_SECURE_GETENV', 1)\n>  endif\n> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\n> index 66468bf38d5b..6c9dca7201a3 100644\n> --- a/src/v4l2/v4l2_compat.cpp\n> +++ b/src/v4l2/v4l2_compat.cpp\n> @@ -154,7 +154,11 @@ LIBCAMERA_PUBLIC int munmap(void *addr, size_t length)\n>         return V4L2CompatManager::instance()->munmap(addr, length);\n>  }\n>  \n> +#if HAVE_POSIX_IOCTL\n> +LIBCAMERA_PUBLIC int ioctl(int fd, int request, ...)\n> +#else\n>  LIBCAMERA_PUBLIC int ioctl(int fd, unsigned long request, ...)\n> +#endif\n>  {\n>         void *arg;\n>         extract_va_arg(void *, arg, request);\n> \n> base-commit: 4661a7eedf81f00212956f0d396196b3eb4a417b\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 54BD6C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Jul 2024 08:16:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 656896336F;\n\tMon, 22 Jul 2024 10:16:16 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 087F1619A0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 22 Jul 2024 10:16:15 +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 975142B3;\n\tMon, 22 Jul 2024 10:15:33 +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=\"UILzrlk9\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1721636133;\n\tbh=uaxIMrhXAK0bacU0JWo51IHd2BjofHmb/ZLAGyT+PIE=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=UILzrlk9rtycc3UgOT1vJ3pxGgfeOCImWkWvJNDgUDkFj10QXKrJagbT9uVb0vYGH\n\t4lzyPjQ1cdpbrNJqEkHeK11yw382pRGtVrM1wzGrg/UPfR1aPacQ/I78BxvA9kpGfp\n\t/TRMeJXnHinuqW7P0diVwVACtOuMwp6TpVKy7Uuc=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240721213111.24638-1-laurent.pinchart@ideasonboard.com>","References":"<20240721213111.24638-1-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH] v4l2: v4l2_compat: Fix ioctl() prototype with musl C\n\tlibrary","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 22 Jul 2024 09:16:12 +0100","Message-ID":"<172163617207.2376022.16947855722319325589@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":30476,"web_url":"https://patchwork.libcamera.org/comment/30476/","msgid":"<ZqH-NPuq5noehcIJ@pyrite.rasen.tech>","date":"2024-07-25T07:26:44","subject":"Re: [PATCH] v4l2: v4l2_compat: Fix ioctl() prototype with musl C\n\tlibrary","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Mon, Jul 22, 2024 at 12:31:11AM +0300, Laurent Pinchart wrote:\n> The musl C library, as well as the POSIX standard, define the ioctl()\n> function's request argument as an int. glibc and uclibc, on the other\n> hand, define it as an unsigned long.\n> \n> This difference between the function prototype and the implementation in\n> the V4L2 adaptation layer causes a compilation error with musl. Fix it\n> by detecting the function prototype and declaring the libcamera ioctl()\n> handler accordingly.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  meson.build              | 9 +++++++++\n>  src/v4l2/v4l2_compat.cpp | 4 ++++\n>  2 files changed, 13 insertions(+)\n> \n> diff --git a/meson.build b/meson.build\n> index 2acd8c3e8cfe..ccd766a1e98c 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -90,6 +90,15 @@ if cc.has_header_symbol('sys/mman.h', 'memfd_create', prefix : '#define _GNU_SOU\n>      config_h.set('HAVE_MEMFD_CREATE', 1)\n>  endif\n>  \n> +ioctl_posix_test = '''\n> +#include <sys/ioctl.h>\n> +int ioctl (int, int, ...);\n> +'''\n> +\n> +if cc.compiles(ioctl_posix_test)\n> +    config_h.set('HAVE_POSIX_IOCTL', 1)\n> +endif\n> +\n>  if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')\n>      config_h.set('HAVE_SECURE_GETENV', 1)\n>  endif\n> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\n> index 66468bf38d5b..6c9dca7201a3 100644\n> --- a/src/v4l2/v4l2_compat.cpp\n> +++ b/src/v4l2/v4l2_compat.cpp\n> @@ -154,7 +154,11 @@ LIBCAMERA_PUBLIC int munmap(void *addr, size_t length)\n>  \treturn V4L2CompatManager::instance()->munmap(addr, length);\n>  }\n>  \n> +#if HAVE_POSIX_IOCTL\n> +LIBCAMERA_PUBLIC int ioctl(int fd, int request, ...)\n> +#else\n>  LIBCAMERA_PUBLIC int ioctl(int fd, unsigned long request, ...)\n> +#endif\n>  {\n>  \tvoid *arg;\n>  \textract_va_arg(void *, arg, request);\n> \n> base-commit: 4661a7eedf81f00212956f0d396196b3eb4a417b","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 00B0ABDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Jul 2024 07:26:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A87FA63371;\n\tThu, 25 Jul 2024 09:26:52 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 978066199A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Jul 2024 09:26:51 +0200 (CEST)","from pyrite.rasen.tech (h175-177-049-024.catv02.itscom.jp\n\t[175.177.49.24])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 446B51237;\n\tThu, 25 Jul 2024 09:26:07 +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=\"XGmlvZai\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1721892368;\n\tbh=Zbg5DdlsbMQht9+BL6ZqYp39t46Ta6D/1S92OGSYw9U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=XGmlvZaiDjHIE071Ni0uXkFAEuWuoG+wgMf63OziCg6/6adF8p8Brk5wKb3nfZTCV\n\tOiGVGDXS9HsK0+7fU8ORFynoE/bdusYE2l92Bo5qFUsV6Wdn72DA6Z8g0JJ30Fo9kA\n\tNgz6HLwYEUEGhigo7x6m6sPfwhY5pr2kV+lETbcs=","Date":"Thu, 25 Jul 2024 16:26:44 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH] v4l2: v4l2_compat: Fix ioctl() prototype with musl C\n\tlibrary","Message-ID":"<ZqH-NPuq5noehcIJ@pyrite.rasen.tech>","References":"<20240721213111.24638-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20240721213111.24638-1-laurent.pinchart@ideasonboard.com>","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>"}}]