From patchwork Fri Oct 23 04:19:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanth Ramesh X-Patchwork-Id: 28568 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 E4A17C3261 for ; Fri, 23 Oct 2026 04:20:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 137B368F9C; Fri, 23 Oct 2026 06:20:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cMW2UbW3"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 592F468E07 for ; Fri, 23 Oct 2026 06:20:09 +0200 (CEST) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-398b3c37877so284568a91.0 for ; Thu, 22 Oct 2026 21:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792729207; x=1793334007; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=/A7l44jRyY42r6s8qOrxQ/1iwBzYyDqf1AQfwX3mCxM=; b=cMW2UbW3+EM12FQCdibWR96Bk//mbVW4dvD3/T6dHiK8KX4Aj0ar8COoCXTD3dXNR4 9Hpo2MosZNGXc3zbNlmQOSHgAttxUykTNvGiPN8Sb0p+XoxCwsNOs6sl/YH/U8abuZ5r kmnLpmDrOd74Q6PkAqmnR74U/vHEWyEQdrO4JjbHkfnqP1O4LiPaK0g5rctEQt5Ixhvz 0rRH9lXsICbTo1K/VyP9R6+goM71VB76LJfqlgqwVy6nAi3XzHd9uKAoNA4+1imiK/Jk UmW0SRsiFtK+YhfMyU6ZmrAYPuOPzx70A6z2mhRy6oJDC6wLu8gVNypuinXw7drnhXi9 J81g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792729207; x=1793334007; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=/A7l44jRyY42r6s8qOrxQ/1iwBzYyDqf1AQfwX3mCxM=; b=2u84nRM4sh65oys2DNovULQYrB6OS2ZDtvGx/miDDeseOgzqAbzY3dy+w96oTOYnka Hsi56D8U3nd5a6n72ZG3xIWAAz15vjUMZO93zgf4tSwqVNv0c8TGoWOfhFVp/1lpBw6F 0X1mcDPuBDX/mlR5PwBZfGbcW9HEe023q8EPQJZmQ2jiFQ61pmYPcMV9NP83f63LfZvN RUEds8SEjJP9X+ETo3Aza0NIgyed67+kXtRDIsJRkeU0GXmA9EaW1AevkQDtU2XYSDBH XQYwDhCfLTrjVMJcCiqDmIaSnIToXE6eJ9TfUAUbSsl+TkABYYs6yAASFEF7YtfbtaAu 7JNQ== X-Gm-Message-State: AFq9FYJijXsC/1btCwkUKu2kVzgaEzHdIpxg+pukd/UcRyG9P19P+aqI J6h6sl+6nR5CXUhK0RDnDnJTnxMamlCYyb2HoEIDOOa84h1nJMwNHiW1Qbip3zX0 X-Gm-Gg: AYBFou2v7g1Yq7fAx0ieHjgg0YuPgq7jhPyRcw8e8XZjN/IS0VdgBlETMO1Q/Bf2ze2 LCv5qjvO9QgKJJQD/0E0SGR6Zze87WD++hfVKipGSHgAb6Bzo3fgqpFvEUilH7Qk0b5oUTm9/X/ yXLs5sQgornei3yv4qoEUHE0jGKssvXnYY/ocE+Z/woin6IFOD40G73gr2JcDdgINVW8IhaQvoq Ah7EKm0J92u+O4lb0kQNwp/HMAqZ3PU4/bd/nfV3Z6pB3CMaWD0ak4i1X3B+ra+J3zIXyzvvtA7 Mq1cdZpUsuPFtCVp8forsz0UitBYIVM6070nve8pqVVVf0nljWh82ZnUkPMXBUNZ/nNbHIzaduU ap8Cy9y+9vZ7kapf9HIw3BwqvD1qJi1MqI630lWwoGVp4ICmvze64FEy+H6u4a+lriI67SQjsmc euiEwXh7gDIOuKDFzQn9+vlLJFlZ9XQXVW04ez3cGHw/XGNxhRQ0r7B+AxfSBJmP1yh6TY6uEmu baiPxc5ISFmJzsNCcpZDSsnD1nOHgE6Em7KJavYg8wJFfshQ0HOf0c51jKdAjF4WcrLE8HOwUcj qf4Q8csonVuw4CnQ X-Received: by 2002:a17:90b:2d8c:b0:3ad:4bfc:1e77 with SMTP id 98e67ed59e1d1-3adce150b14mr830267a91.66.1792729207401; Thu, 22 Oct 2026 21:20:07 -0700 (PDT) Received: from prasanth.alps.lineo.co.jp (vpn1.lineo.co.jp. [203.141.200.204]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ada47f8ff1sm7070741a91.0.2026.10.22.21.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 21:20:06 -0700 (PDT) From: Prasanth R To: libcamera-devel@lists.libcamera.org Cc: laurent.pinchart@ideasonboard.com, paul.elder@ideasonboard.com, kieran.bingham@ideasonboard.com, barnabas.pocze@ideasonboard.com, Prasanth R Subject: [PATCH v2 1/2] v4l2: v4l2_compat: Handle __ioctl_time64 Date: Fri, 23 Oct 2026 13:19:53 +0900 Message-Id: <20261023041954.913108-1-ragaprasanth@gmail.com> X-Mailer: git-send-email 2.34.1 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, ioctl is redirected to __ioctl_time64, so the latter needs to be intercepted and handled as well. Add support for this. Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/290 Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Tested-by: Prasanth R Signed-off-by: Prasanth R --- 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 ff833f57..10421cef 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 b07f865f..65cce7e1 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 13673d60..1093505a 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 Fri Oct 23 04:19:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanth Ramesh X-Patchwork-Id: 28569 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 DBE45C3261 for ; Fri, 23 Oct 2026 04:20:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9945568FA3; Fri, 23 Oct 2026 06:20:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Lkq7bPKQ"; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD3B068E07 for ; Fri, 23 Oct 2026 06:20:14 +0200 (CEST) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-3ac9f49b984so250191a91.1 for ; Thu, 22 Oct 2026 21:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792729213; x=1793334013; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mnS5gBqe6jalcRYEK2CejlPQx07yYwEAOhC2DbBtaEQ=; b=Lkq7bPKQd4q7IPvqaC5Dei48QB9wfu5CoIB6CHgdsFn/UKtDRr1tV4M8xTKHE6MJeU R4G7ZQOpVXMvppq9YI96dgw/2vqailIsRPcTjAepQTBy+rzUugkkYe3nlM6V33lwo5AX ghCgLS0RT3iB/CqRaMooRbtaivSqxp/Xy0BxlXamxUZiW8eUzM9sz08lhzYzgTnjNCtD RjCaabdwQQefJoklteR8KCTDaxM28CJ16ReWJrLnYCNVkzkBzz+DZDEJbiroIKcvdmdY OxKDyShkctJyMm2DkHCaQtLLWhQVfdzjoq9bSsC2jMdyjFrRYa9nPPr+Cmf59mNw8PUm sSeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792729213; x=1793334013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mnS5gBqe6jalcRYEK2CejlPQx07yYwEAOhC2DbBtaEQ=; b=RS63BSu4PHPVi0F0gUGY1OV5xy4AGoMkVXCH20ZAR40upYqxkvbmP1Uq8F9DZ96n+H m+j2k/yNY3Q7x2ntS5/EGrgaRActklob1yYrmisgHDH8XQQrVIMiUaO1honEwtjXxPAO dKusTg9lLhSD1Je7d3UaThlPim6sEnLDdPm2QjyBqbXhQ/RhArJxScRa1gQWkJGpcrn8 GcYWQqh6rCsi0LpgRTr93QFD6lONiFk/hwDOYG1QHRUzaQW/g1nKP6p2WBJrsYJvKLSf FdetL6Rn42B6vOa3zgAKoIuMW2hunuBU75//YVRUOctqrlWrFvRK17q/yKaSLXQv2Z+c FGOw== X-Gm-Message-State: AFq9FYJ42mfcE2tYD+ZLutl9PzndW6VyMIbpLli+kaR1JDgOkPzI38z0 ZiG7ta2IorRz/73F5BtIgQ/tSE412HFazKVRgpeUB91ExraLcPrVES5EC7NAynQ1 X-Gm-Gg: AYBFou3u5scV0r4Z2vFCcwM8BBeHdLJXifkAoA5ec0ESjKyQeYPLSavMgzFT6jXOuy7 OPjbFWqtCbSGj7TA1v8v00k2mesXSGQuyURlWj5rNnlk2glYCsCyMxBEo66bg+ESfHuTZE34SWm FD55zm7c/9O5GOphjp1nvqnHLzHnOUdxQ3SkwZIKwbYvN/nJ5JwC+4slLYBrbvaein4saosKJdc RaTTtAYOVJSG3n1+bsN0A0WftPaJNMEq+KJ5mPFwYl7dyAQ0UpU9s8aBMP4fWdCpI/rCEcU8Rex XJSjrQxo/8SA49EuAZ6wo/CG8+nZDdd+gnEwNMKQ/YLNwU1jPqiTbLSyVZydyJGLbSx7vOASoKv 1dnKNW0A0NB7OWiG3z0C9GqrcegCt3j0Lpxl5xAGYt3TQJJyWYu3CqXr6RD1byuf1mLWUozrMlZ JZB47X5p75ahbidCjCSgTTA8d7PEGalmP4ZgRXAeAF8tI/EmNGpZOM8/Tp2hfEZw0uKiTrAjDgm ZqCLpWpFhQwRgqh3ltvx82LlwxiFvoH8DnIfCBzs66+7NUceyi9fFrZ/+iC0YdYfFmjJiqfxQ7C Rmvl16lnpbZ5lzc= X-Received: by 2002:a17:90b:39b0:b0:3a0:c31d:80c with SMTP id 98e67ed59e1d1-3adce6001e3mr613352a91.9.1792729213113; Thu, 22 Oct 2026 21:20:13 -0700 (PDT) Received: from prasanth.alps.lineo.co.jp (vpn1.lineo.co.jp. [203.141.200.204]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ada47f8ff1sm7070741a91.0.2026.10.22.21.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 21:20:12 -0700 (PDT) From: Prasanth R To: libcamera-devel@lists.libcamera.org Cc: laurent.pinchart@ideasonboard.com, paul.elder@ideasonboard.com, kieran.bingham@ideasonboard.com, barnabas.pocze@ideasonboard.com, Prasanth R Subject: [PATCH v2 2/2] v4l2: v4l2_camera_proxy: Handle 64-bit time_t buffer ioctls Date: Fri, 23 Oct 2026 13:19:54 +0900 Message-Id: <20261023041954.913108-2-ragaprasanth@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261023041954.913108-1-ragaprasanth@gmail.com> References: <20261023041954.913108-1-ragaprasanth@gmail.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 platforms the V4L2 compatibility layer is built with a 32-bit time_t, but applications are now usually built with _TIME_BITS=64. struct v4l2_buffer embeds a struct timeval, so for them it grows from 68 to 80 bytes on 32-bit Arm, and VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF and VIDIOC_PREPARE_BUF get different request numbers. These fail with ENOTTY and streaming does not work. Recognise the 64-bit time_t requests and convert the buffer to and from the native layout around the existing handlers. Only the timestamp differs between the two layouts. Buffer timestamps are monotonic, so they fit in the native timeval. Nothing changes where both layouts are the same. Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/290 Signed-off-by: Prasanth R --- Tested on a Raspberry Pi 4 with a 32-bit userspace built with 64-bit time_t (the OpenEmbedded default for 32-bit Arm) and a UVC camera. src/v4l2/v4l2_camera_proxy.cpp | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 210c8e87..89e95198 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,64 @@ using namespace std::literals::chrono_literals; LOG_DECLARE_CATEGORY(V4L2Compat) +namespace { + +/* + * On 32-bit platforms the V4L2 compatibility layer is built with a 32-bit + * time_t (see src/v4l2/meson.build), while applications are commonly built + * with _TIME_BITS=64. struct v4l2_buffer embeds a struct timeval, so the two + * disagree on the structure size, and thus on the buffer ioctl numbers. Only + * the timestamp differs, the fields before and after it are the same. + */ +struct v4l2_buffer_time64 { + __u8 head[offsetof(struct v4l2_buffer, timestamp)]; + struct { + long long tv_sec; + long long tv_usec; + } timestamp; + __u8 tail[sizeof(struct v4l2_buffer) - offsetof(struct v4l2_buffer, timecode)]; +}; + +/* + * Return the native request for a 64-bit time_t buffer ioctl, or 0 if the + * request is not one or both layouts are the same. + */ +unsigned int bufferRequestFromTime64(unsigned int request) +{ + if (sizeof(struct v4l2_buffer_time64) == sizeof(struct v4l2_buffer)) + return 0; + + switch (request) { + case _IOWR('V', 9, struct v4l2_buffer_time64): /* VIDIOC_QUERYBUF */ + case _IOWR('V', 15, struct v4l2_buffer_time64): /* VIDIOC_QBUF */ + case _IOWR('V', 17, struct v4l2_buffer_time64): /* VIDIOC_DQBUF */ + case _IOWR('V', 93, struct v4l2_buffer_time64): /* VIDIOC_PREPARE_BUF */ + return _IOWR('V', _IOC_NR(request), struct v4l2_buffer); + default: + return 0; + } +} + +void bufferFromTime64(const struct v4l2_buffer_time64 &src, + struct v4l2_buffer *dst) +{ + memcpy(dst, src.head, sizeof(src.head)); + dst->timestamp.tv_sec = src.timestamp.tv_sec; + dst->timestamp.tv_usec = src.timestamp.tv_usec; + memcpy(&dst->timecode, src.tail, sizeof(src.tail)); +} + +void bufferToTime64(const struct v4l2_buffer &src, + struct v4l2_buffer_time64 *dst) +{ + memcpy(dst->head, &src, sizeof(dst->head)); + dst->timestamp.tv_sec = src.timestamp.tv_sec; + dst->timestamp.tv_usec = src.timestamp.tv_usec; + memcpy(dst->tail, &src.timecode, sizeof(dst->tail)); +} + +} /* namespace */ + V4L2CameraProxy::V4L2CameraProxy(unsigned int index, std::shared_ptr camera) : refcount_(0), index_(index), bufferCount_(0), currentBuf_(0), @@ -875,6 +934,20 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long longRequest, void return -1; } + /* + * Translate buffer ioctls from applications built with a 64-bit + * time_t to the native struct v4l2_buffer layout. + */ + struct v4l2_buffer_time64 *buf64 = nullptr; + struct v4l2_buffer buf = {}; + unsigned int bufRequest = bufferRequestFromTime64(request); + if (bufRequest) { + buf64 = static_cast(arg); + bufferFromTime64(*buf64, &buf); + request = bufRequest; + arg = &buf; + } + if (supportedIoctls_.find(request) == supportedIoctls_.end()) { errno = ENOTTY; return -1; @@ -960,6 +1033,9 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long longRequest, void return -1; } + if (buf64) + bufferToTime64(buf, buf64); + return ret; }