From patchwork Sun Nov 22 22:07:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 29069 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 5ED80C3304 for ; Sun, 22 Nov 2026 22:07:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB2516A98F; Sun, 22 Nov 2026 23:07:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Qj5JHAHV"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 42FC26A980 for ; Sun, 22 Nov 2026 23:07:27 +0100 (CET) Received: from killaraus.ideasonboard.com (2001-14ba-7086-3000--a06.rev.dnainternet.fi [IPv6:2001:14ba:7086:3000::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 89075177; Sun, 22 Nov 2026 23:04:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795385095; bh=irhZeLaypvUByLJPurF3IwWjjXZgSH+WPme8aw4V8d4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qj5JHAHVNKq1O68v1vKIYOtZ4AemmbZogIluIvlUAdWzyFK+4ODXICMlM0qqW+YYL 7NK74hFBWHp5lz7q1OcR902moJvn3XqSg9OjphZcfPDlvkJtOLW3uxGjlyDOVFX/WJ boG6Ciojp8D47pujULtbwtr0TqiS8Vo7jHWT7M7U= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Prasanth R , Paul Elder Subject: [PATCH v4 1/2] v4l2: v4l2_compat: Handle __ioctl_time64 Date: Mon, 23 Nov 2026 00:07:23 +0200 Message-ID: <20261122220724.2951625-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261122220724.2951625-1-laurent.pinchart@ideasonboard.com> References: <20261122220724.2951625-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" From: Paul Elder On 32-bit systems with 64-bit time_t (except x32), ioctl is redirected to __ioctl_time64. The v4l2-compat layer only intercepts the former, we need to intercept and handle the latter as well. In order to correctly support those systems, translation between 32-bit and 64-bit ioctl structures also need to be implemented. This will be done in a subsequent patch. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Tested-by: Prasanth R Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/v4l2/v4l2_compat.cpp | 21 +++++++++++++++++++++ src/v4l2/v4l2_compat_manager.cpp | 10 ++++++++++ src/v4l2/v4l2_compat_manager.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp index ff833f571bde..cc4ea33d949d 100644 --- a/src/v4l2/v4l2_compat.cpp +++ b/src/v4l2/v4l2_compat.cpp @@ -165,4 +165,25 @@ LIBCAMERA_PUBLIC int ioctl(int fd, unsigned long request, ...) return V4L2CompatManager::instance()->ioctl(fd, request, arg); } +/* + * __USE_TIME64_REDIRECTS redirects ioctl to __ioctl_time64. Disable the + * -Wmissing-declarations warnings, as the functions won't be declared if + * __USE_TIME64_REDIRECTS is not in use. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-declarations" + +#if HAVE_POSIX_IOCTL +LIBCAMERA_PUBLIC int __ioctl_time64(int fd, int request, ...) +#else +LIBCAMERA_PUBLIC int __ioctl_time64(int fd, unsigned long request, ...) +#endif +{ + void *arg; + extract_va_arg(void *, arg, request); + + return V4L2CompatManager::instance()->ioctl_time64(fd, request, arg); +} + +#pragma GCC diagnostic pop } diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index b07f865fb2da..65cce7e13c01 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -46,6 +46,7 @@ V4L2CompatManager::V4L2CompatManager() get_symbol(fops_.dup, "dup"); get_symbol(fops_.close, "close"); get_symbol(fops_.ioctl, "ioctl"); + get_symbol(fops_.ioctl_time64, "__ioctl_time64"); get_symbol(fops_.mmap, "mmap64"); get_symbol(fops_.munmap, "munmap"); } @@ -243,3 +244,12 @@ int V4L2CompatManager::ioctl(int fd, unsigned long request, void *arg) return file->proxy()->ioctl(file.get(), request, arg); } + +int V4L2CompatManager::ioctl_time64(int fd, unsigned long request, void *arg) +{ + std::shared_ptr file = cameraFile(fd); + if (!file) + return fops_.ioctl_time64(fd, request, arg); + + return file->proxy()->ioctl(file.get(), request, arg); +} diff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h index 13673d604a63..1093505a090d 100644 --- a/src/v4l2/v4l2_compat_manager.h +++ b/src/v4l2/v4l2_compat_manager.h @@ -34,6 +34,7 @@ public: dup_func_t dup; close_func_t close; ioctl_func_t ioctl; + ioctl_func_t ioctl_time64; mmap_func_t mmap; munmap_func_t munmap; }; @@ -50,6 +51,7 @@ public: int fd, off64_t offset); int munmap(void *addr, size_t length); int ioctl(int fd, unsigned long request, void *arg); + int ioctl_time64(int fd, unsigned long request, void *arg); private: V4L2CompatManager(); From patchwork Sun Nov 22 22:07:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 29070 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 1EF54C3304 for ; Sun, 22 Nov 2026 22:07:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90DA56A98B; Sun, 22 Nov 2026 23:07:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="phCUY7Jb"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8232F6A98D for ; Sun, 22 Nov 2026 23:07:28 +0100 (CET) Received: from killaraus.ideasonboard.com (2001-14ba-7086-3000--a06.rev.dnainternet.fi [IPv6:2001:14ba:7086:3000::a06]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB7C4177; Sun, 22 Nov 2026 23:04:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795385097; bh=mDsjMVRW4gRrUYrIhyZSHJmdTxkIOc8quYC4MJttaDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=phCUY7JbW72u+GWW3ZVOj4XtlwH3bGCfXuDG9fp52Vcl55l8KoGvWQ+DgL1/LwrQ/ 4fs39Imtvqw4qZDMO5i+bGOhmiC08Jjr12N2Yoo3BdHTrea1F1gmgtJywXCth+AAbl ahDmfqmNUSHiFpiXGIKb+5xvQhPBytU7uGUUtVPc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Prasanth R Subject: [PATCH v4 2/2] v4l2: v4l2_compat: Compile compat layer core with native time_t Date: Mon, 23 Nov 2026 00:07:24 +0200 Message-ID: <20261122220724.2951625-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261122220724.2951625-1-laurent.pinchart@ideasonboard.com> References: <20261122220724.2951625-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" On 32-bit systems, the whole libcamera V4L2 compatibility layer is compiled with 32-bit time_t as a consequence of disabling transparent large file support that in turn requires undefining _TIME_BITS. The compatibility layer ends up using the 32-bit time_t layout of V4L2 ioctl structures. This breaks applications compiled with 64-bit time_t support. Fixing this for all use cases requires translating between structures that use 32-bit and 64-bit time_t. A simpler partial solution is however possible for the most common cases. Transparent large file support and time_t impact different parts of the V4L2 compatibility layer. The former is only needed in the entry points, handled in v4l2_compat.cpp, while the latter only impacts the V4L2 ioctl handlers in v4l2_camera_proxy.cpp. We can compile the entry points with transparent large file support disabled (and therefore with 32-bit time_t), and the rest of the compatibility later with the system defaults. Applications using the same time_t size as the system default will work correctly. Two cases will still be unsupported: - Applications using 64-bit time_t on a 32-bit time_t system - Applications using 32-bit time_t on a 64-bit time_t system The former should be very rare, as systems are transitioning to 64-bit time_t. The latter is likely less rare, but is still not a very common use case. Implement the simpler fix for the time being. If hybrid time_t use cases need to be supported, translation between ioctl structures will be implemented. Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/290 Signed-off-by: Laurent Pinchart Tested-by: Prasanth R Tested-by: Barnabás Pőcze Reviewed-by: Paul Elder --- Changes since v3: - Flip libraries around: compile v4l2-compat.cpp in the static library and name it v4l2-compat-interceptor - Set -fvisibility=hidden for the outer library, not the inner library --- src/v4l2/meson.build | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build index 2c0404147183..d0dd19fdaf02 100644 --- a/src/v4l2/meson.build +++ b/src/v4l2/meson.build @@ -6,15 +6,11 @@ if not v4l2_enabled subdir_done() endif -v4l2_compat_sources = files([ - 'v4l2_camera.cpp', - 'v4l2_camera_file.cpp', - 'v4l2_camera_proxy.cpp', +v4l2_compat_interceptors_sources = files([ 'v4l2_compat.cpp', - 'v4l2_compat_manager.cpp', ]) -v4l2_compat_cpp_args = [ +v4l2_compat_interceptors_cpp_args = [ # Meson enables large file support unconditionally, which redirect file # operations to 64-bit versions. This results in some symbols being # renamed, for instance open() being renamed to open64(). As the V4L2 @@ -24,12 +20,29 @@ v4l2_compat_cpp_args = [ '-D_FILE_OFFSET_BITS=32', '-D_LARGEFILE64_SOURCE', '-U_TIME_BITS', +] + +v4l2_compat_interceptors = static_library('v4l2-compat-interceptors', + v4l2_compat_interceptors_sources, + install : false, + dependencies : [libcamera_private], + cpp_args : v4l2_compat_interceptors_cpp_args) + +v4l2_compat_sources = files([ + 'v4l2_camera.cpp', + 'v4l2_camera_file.cpp', + 'v4l2_camera_proxy.cpp', + 'v4l2_compat_manager.cpp', +]) + +v4l2_compat_cpp_args = [ '-fvisibility=hidden', ] v4l2_compat = shared_library('v4l2-compat', v4l2_compat_sources, name_prefix : '', + link_whole : v4l2_compat_interceptors, install : true, install_dir : libcamera_libexecdir, dependencies : [libcamera_private, libdl],