[{"id":5236,"web_url":"https://patchwork.libcamera.org/comment/5236/","msgid":"<20200617115857.GC2850317@oden.dyn.berto.se>","date":"2020-06-17T11:58:57","subject":"Re: [libcamera-devel] [PATCH v2] v4l2: v4l2_compat: Intercept\n\topen64, openat64, and mmap64","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Paul,\n\nThanks for your work.\n\nOn 2020-06-17 18:05:18 +0900, Paul Elder wrote:\n> Some applications (eg. Firefox, Google Chrome, Skype) use open64,\n> openat64, and mmap64 instead of their non-64 versions that we currently\n> intercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to\n> be set so that the 64-bit symbols are available and not synonymous to\n> the non-64-bit versions on 64-bit systems.\n> \n> Also, since we set _FILE_OFFSET_BITS to 32 to force the various open and\n> mmap symbols that we export to not be the 64-bit versions, our dlsym to\n> get the original open and mmap calls will not automatically be converted\n> to their 64-bit versions. Since we intercept both 32-bit and 64-bit\n> versions of open and mmap, we should be using the 64-bit version to\n> service both. Fetch the 64-bit versions of openat and mmap directly.\n> \n> musl defines the 64-bit symbols as macros that are equivalent to the\n> non-64-bit symbols, so we put compile guards that check if the 64-bit\n> symbols are defined.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nI feel I lack the skill to judge the musl special case, but for the rest \nI think it looks good.\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> \n> ---\n> Changes in v2:\n> - squash intercept 64-bit calls and use 64-bit calls into\n>   this one patch\n> - use off64_t instead of __off64_t\n> - add compile guard to get musl to play nicely with the 64-bit calls\n>   coexisting with the non-64-bit calls\n> ---\n>  src/v4l2/meson.build             |  1 +\n>  src/v4l2/v4l2_camera_proxy.cpp   |  2 +-\n>  src/v4l2/v4l2_camera_proxy.h     |  3 ++-\n>  src/v4l2/v4l2_compat.cpp         | 33 ++++++++++++++++++++++++++++++++\n>  src/v4l2/v4l2_compat_manager.cpp |  6 +++---\n>  src/v4l2/v4l2_compat_manager.h   |  5 +++--\n>  6 files changed, 43 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build\n> index 0fb941e..f2e4aaf 100644\n> --- a/src/v4l2/meson.build\n> +++ b/src/v4l2/meson.build\n> @@ -15,6 +15,7 @@ v4l2_compat_cpp_args = [\n>      # file operations, disable transparent large file support.\n>      '-U_FILE_OFFSET_BITS',\n>      '-D_FILE_OFFSET_BITS=32',\n> +    '-D_LARGEFILE64_SOURCE',\n>      '-fvisibility=hidden',\n>  ]\n>  \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index d7f14e6..7425029 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -75,7 +75,7 @@ void V4L2CameraProxy::close()\n>  }\n>  \n>  void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,\n> -\t\t\t    off_t offset)\n> +\t\t\t    off64_t offset)\n>  {\n>  \tLOG(V4L2Compat, Debug) << \"Servicing mmap\";\n>  \n> diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\n> index 7c65c88..27d3e50 100644\n> --- a/src/v4l2/v4l2_camera_proxy.h\n> +++ b/src/v4l2/v4l2_camera_proxy.h\n> @@ -11,6 +11,7 @@\n>  #include <linux/videodev2.h>\n>  #include <map>\n>  #include <memory>\n> +#include <sys/mman.h>\n>  #include <sys/types.h>\n>  #include <vector>\n>  \n> @@ -28,7 +29,7 @@ public:\n>  \tint open(bool nonBlocking);\n>  \tvoid dup();\n>  \tvoid close();\n> -\tvoid *mmap(void *addr, size_t length, int prot, int flags, off_t offset);\n> +\tvoid *mmap(void *addr, size_t length, int prot, int flags, off64_t offset);\n>  \tint munmap(void *addr, size_t length);\n>  \n>  \tint ioctl(unsigned long request, void *arg);\n> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\n> index 2a9a176..7d45ffe 100644\n> --- a/src/v4l2/v4l2_compat.cpp\n> +++ b/src/v4l2/v4l2_compat.cpp\n> @@ -38,6 +38,18 @@ LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)\n>  \t\t\t\t\t\t     oflag, mode);\n>  }\n>  \n> +#ifndef open64\n> +LIBCAMERA_PUBLIC int open64(const char *path, int oflag, ...)\n> +{\n> +\tmode_t mode = 0;\n> +\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n> +\t\textract_va_arg(mode_t, mode, oflag);\n> +\n> +\treturn V4L2CompatManager::instance()->openat(AT_FDCWD, path,\n> +\t\t\t\t\t\t     oflag | O_LARGEFILE, mode);\n> +}\n> +#endif\n> +\n>  /* _FORTIFY_SOURCE redirects open to __open_2 */\n>  LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)\n>  {\n> @@ -53,6 +65,18 @@ LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)\n>  \treturn V4L2CompatManager::instance()->openat(dirfd, path, oflag, mode);\n>  }\n>  \n> +#ifndef openat64\n> +LIBCAMERA_PUBLIC int openat64(int dirfd, const char *path, int oflag, ...)\n> +{\n> +\tmode_t mode = 0;\n> +\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n> +\t\textract_va_arg(mode_t, mode, oflag);\n> +\n> +\treturn V4L2CompatManager::instance()->openat(dirfd, path,\n> +\t\t\t\t\t\t     oflag | O_LARGEFILE, mode);\n> +}\n> +#endif\n> +\n>  LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)\n>  {\n>  \treturn openat(dirfd, path, oflag);\n> @@ -75,6 +99,15 @@ LIBCAMERA_PUBLIC void *mmap(void *addr, size_t length, int prot, int flags,\n>  \t\t\t\t\t\t   fd, offset);\n>  }\n>  \n> +#ifndef mmap64\n> +LIBCAMERA_PUBLIC void *mmap64(void *addr, size_t length, int prot, int flags,\n> +\t\t\t      int fd, off64_t offset)\n> +{\n> +\treturn V4L2CompatManager::instance()->mmap(addr, length, prot, flags,\n> +\t\t\t\t\t\t   fd, offset);\n> +}\n> +#endif\n> +\n>  LIBCAMERA_PUBLIC int munmap(void *addr, size_t length)\n>  {\n>  \treturn V4L2CompatManager::instance()->munmap(addr, length);\n> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\n> index 56533c4..8da3316 100644\n> --- a/src/v4l2/v4l2_compat_manager.cpp\n> +++ b/src/v4l2/v4l2_compat_manager.cpp\n> @@ -39,11 +39,11 @@ void get_symbol(T &func, const char *name)\n>  V4L2CompatManager::V4L2CompatManager()\n>  \t: cm_(nullptr)\n>  {\n> -\tget_symbol(fops_.openat, \"openat\");\n> +\tget_symbol(fops_.openat, \"openat64\");\n>  \tget_symbol(fops_.dup, \"dup\");\n>  \tget_symbol(fops_.close, \"close\");\n>  \tget_symbol(fops_.ioctl, \"ioctl\");\n> -\tget_symbol(fops_.mmap, \"mmap\");\n> +\tget_symbol(fops_.mmap, \"mmap64\");\n>  \tget_symbol(fops_.munmap, \"munmap\");\n>  }\n>  \n> @@ -200,7 +200,7 @@ int V4L2CompatManager::close(int fd)\n>  }\n>  \n>  void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags,\n> -\t\t\t      int fd, off_t offset)\n> +\t\t\t      int fd, off64_t offset)\n>  {\n>  \tV4L2CameraProxy *proxy = getProxy(fd);\n>  \tif (!proxy)\n> diff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h\n> index 14338a5..3d4e512 100644\n> --- a/src/v4l2/v4l2_compat_manager.h\n> +++ b/src/v4l2/v4l2_compat_manager.h\n> @@ -11,6 +11,7 @@\n>  #include <fcntl.h>\n>  #include <map>\n>  #include <memory>\n> +#include <sys/mman.h>\n>  #include <sys/types.h>\n>  #include <vector>\n>  \n> @@ -30,7 +31,7 @@ public:\n>  \t\tusing close_func_t = int (*)(int fd);\n>  \t\tusing ioctl_func_t = int (*)(int fd, unsigned long request, ...);\n>  \t\tusing mmap_func_t = void *(*)(void *addr, size_t length, int prot,\n> -\t\t\t\t\t      int flags, int fd, off_t offset);\n> +\t\t\t\t\t      int flags, int fd, off64_t offset);\n>  \t\tusing munmap_func_t = int (*)(void *addr, size_t length);\n>  \n>  \t\topenat_func_t openat;\n> @@ -51,7 +52,7 @@ public:\n>  \tint dup(int oldfd);\n>  \tint close(int fd);\n>  \tvoid *mmap(void *addr, size_t length, int prot, int flags,\n> -\t\t   int fd, off_t offset);\n> +\t\t   int fd, off64_t offset);\n>  \tint munmap(void *addr, size_t length);\n>  \tint ioctl(int fd, unsigned long request, void *arg);\n>  \n> -- \n> 2.27.0\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 991FD603BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Jun 2020 13:58:59 +0200 (CEST)","by mail-lj1-x243.google.com with SMTP id n24so2469601lji.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Jun 2020 04:58:59 -0700 (PDT)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tl5sm4335042lfp.9.2020.06.17.04.58.57\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 17 Jun 2020 04:58:57 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com header.b=\"YPp1xN/y\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=Cd8gn8TVwZ3PSydqpGNI3REp3Bls5azAPFLnmvicF1A=;\n\tb=YPp1xN/yURxwGIlOoZLVfFwuJ50gB7zSQfytGKJveSzbQSjYZIBr1kicNyhzlwAzkz\n\tbKp+mrFOZ4oVLSHDAge4IRLrBcknh30hGRbl5DHFVzdL8hsDYE0hUgzLf+Wb78OMsxHn\n\tfeEMwIDs2bdUQF/21OGZPrOQ2Za/FmvPaZuNjMxzt758Mb5nDKKvLfAjy3wTE14Wi/9o\n\tnqMjecpGAjPS4GpqbOd4JGjoIrebm6JVJkmoL7ukTm4Lw5yOjdNYVE31O4GcCILZDC9G\n\tgVG7UCf8c8QozOkzJifh2MmrMdpjp4DCtK7bb1MdF2MuGbHHnsuIYfaFsAlGaWuDMYa5\n\t3DVw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=Cd8gn8TVwZ3PSydqpGNI3REp3Bls5azAPFLnmvicF1A=;\n\tb=dt2M1KlwC1USDu7r6mc15362giiy21RgbaC2AXdDc9tpRbM86kLuKEEjSN2ygvBdGA\n\triOclo5T1VqS/VbQK7E8MftkgHwsKqHc2oU9gNkUVo13eojXA9o87ShUVGvedeiWhzyF\n\tELH0Rda9A96hm0ZuqPyOzRseg7/7lSJR5kcwz8086QQzquD5rpP7ZDpp1NfV3357UJ+f\n\tbZmqvU2NCQ7zXyevbGhVjvS0mLUP6yqMo4Nbtlzo0AZaUzpQCec2oWZIyG2OQh6cFy5A\n\tr62VpMWp23t30ASRDkD/unnYLO8JMrZr74B6jI9BgBwiY2PZ9/9wGL8Ylzy1FPdvyuIn\n\tqu0w==","X-Gm-Message-State":"AOAM533H23fJ1OnIlc9OXFqZKydQAgjW2DJJ7JC/8JAMoYgndGu8+jFA\n\tEzGjnoc4SZbFWeefDjFQk3P7GBOEims=","X-Google-Smtp-Source":"ABdhPJyr/VHhzoPMq9CIOkg3xuOT6ZRulGKUHpAT4hishwXAfUMC8Mg1NQEX7Y2XwdwUBieIOcMaBQ==","X-Received":"by 2002:a2e:87c2:: with SMTP id v2mr3841920ljj.147.1592395138797;\n\tWed, 17 Jun 2020 04:58:58 -0700 (PDT)","Date":"Wed, 17 Jun 2020 13:58:57 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200617115857.GC2850317@oden.dyn.berto.se>","References":"<20200617090518.40244-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200617090518.40244-1-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2] v4l2: v4l2_compat: Intercept\n\topen64, openat64, and mmap64","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>","X-List-Received-Date":"Wed, 17 Jun 2020 11:58:59 -0000"}},{"id":5244,"web_url":"https://patchwork.libcamera.org/comment/5244/","msgid":"<20200617150204.GE5838@pendragon.ideasonboard.com>","date":"2020-06-17T15:02:04","subject":"Re: [libcamera-devel] [PATCH v2] v4l2: v4l2_compat: Intercept\n\topen64, openat64, and mmap64","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Wed, Jun 17, 2020 at 06:05:18PM +0900, Paul Elder wrote:\n> Some applications (eg. Firefox, Google Chrome, Skype) use open64,\n> openat64, and mmap64 instead of their non-64 versions that we currently\n> intercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to\n> be set so that the 64-bit symbols are available and not synonymous to\n> the non-64-bit versions on 64-bit systems.\n> \n> Also, since we set _FILE_OFFSET_BITS to 32 to force the various open and\n> mmap symbols that we export to not be the 64-bit versions, our dlsym to\n> get the original open and mmap calls will not automatically be converted\n> to their 64-bit versions. Since we intercept both 32-bit and 64-bit\n> versions of open and mmap, we should be using the 64-bit version to\n> service both. Fetch the 64-bit versions of openat and mmap directly.\n> \n> musl defines the 64-bit symbols as macros that are equivalent to the\n> non-64-bit symbols, so we put compile guards that check if the 64-bit\n> symbols are defined.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nTested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # Compile with musl\n\nDid you test compilation with musl yourself ?\n\nI'm afraid you'll also need __open64_2 and __openat64_2. With that\nadded (which you can condition on #ifndef open64 and #ifndef openat64),\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> Changes in v2:\n> - squash intercept 64-bit calls and use 64-bit calls into\n>   this one patch\n> - use off64_t instead of __off64_t\n> - add compile guard to get musl to play nicely with the 64-bit calls\n>   coexisting with the non-64-bit calls\n> ---\n>  src/v4l2/meson.build             |  1 +\n>  src/v4l2/v4l2_camera_proxy.cpp   |  2 +-\n>  src/v4l2/v4l2_camera_proxy.h     |  3 ++-\n>  src/v4l2/v4l2_compat.cpp         | 33 ++++++++++++++++++++++++++++++++\n>  src/v4l2/v4l2_compat_manager.cpp |  6 +++---\n>  src/v4l2/v4l2_compat_manager.h   |  5 +++--\n>  6 files changed, 43 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build\n> index 0fb941e..f2e4aaf 100644\n> --- a/src/v4l2/meson.build\n> +++ b/src/v4l2/meson.build\n> @@ -15,6 +15,7 @@ v4l2_compat_cpp_args = [\n>      # file operations, disable transparent large file support.\n>      '-U_FILE_OFFSET_BITS',\n>      '-D_FILE_OFFSET_BITS=32',\n> +    '-D_LARGEFILE64_SOURCE',\n>      '-fvisibility=hidden',\n>  ]\n>  \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index d7f14e6..7425029 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -75,7 +75,7 @@ void V4L2CameraProxy::close()\n>  }\n>  \n>  void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,\n> -\t\t\t    off_t offset)\n> +\t\t\t    off64_t offset)\n>  {\n>  \tLOG(V4L2Compat, Debug) << \"Servicing mmap\";\n>  \n> diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\n> index 7c65c88..27d3e50 100644\n> --- a/src/v4l2/v4l2_camera_proxy.h\n> +++ b/src/v4l2/v4l2_camera_proxy.h\n> @@ -11,6 +11,7 @@\n>  #include <linux/videodev2.h>\n>  #include <map>\n>  #include <memory>\n> +#include <sys/mman.h>\n>  #include <sys/types.h>\n>  #include <vector>\n>  \n> @@ -28,7 +29,7 @@ public:\n>  \tint open(bool nonBlocking);\n>  \tvoid dup();\n>  \tvoid close();\n> -\tvoid *mmap(void *addr, size_t length, int prot, int flags, off_t offset);\n> +\tvoid *mmap(void *addr, size_t length, int prot, int flags, off64_t offset);\n>  \tint munmap(void *addr, size_t length);\n>  \n>  \tint ioctl(unsigned long request, void *arg);\n> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\n> index 2a9a176..7d45ffe 100644\n> --- a/src/v4l2/v4l2_compat.cpp\n> +++ b/src/v4l2/v4l2_compat.cpp\n> @@ -38,6 +38,18 @@ LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)\n>  \t\t\t\t\t\t     oflag, mode);\n>  }\n>  \n> +#ifndef open64\n> +LIBCAMERA_PUBLIC int open64(const char *path, int oflag, ...)\n> +{\n> +\tmode_t mode = 0;\n> +\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n> +\t\textract_va_arg(mode_t, mode, oflag);\n> +\n> +\treturn V4L2CompatManager::instance()->openat(AT_FDCWD, path,\n> +\t\t\t\t\t\t     oflag | O_LARGEFILE, mode);\n> +}\n> +#endif\n> +\n>  /* _FORTIFY_SOURCE redirects open to __open_2 */\n>  LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)\n>  {\n> @@ -53,6 +65,18 @@ LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)\n>  \treturn V4L2CompatManager::instance()->openat(dirfd, path, oflag, mode);\n>  }\n>  \n> +#ifndef openat64\n> +LIBCAMERA_PUBLIC int openat64(int dirfd, const char *path, int oflag, ...)\n> +{\n> +\tmode_t mode = 0;\n> +\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n> +\t\textract_va_arg(mode_t, mode, oflag);\n> +\n> +\treturn V4L2CompatManager::instance()->openat(dirfd, path,\n> +\t\t\t\t\t\t     oflag | O_LARGEFILE, mode);\n> +}\n> +#endif\n> +\n>  LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)\n>  {\n>  \treturn openat(dirfd, path, oflag);\n> @@ -75,6 +99,15 @@ LIBCAMERA_PUBLIC void *mmap(void *addr, size_t length, int prot, int flags,\n>  \t\t\t\t\t\t   fd, offset);\n>  }\n>  \n> +#ifndef mmap64\n> +LIBCAMERA_PUBLIC void *mmap64(void *addr, size_t length, int prot, int flags,\n> +\t\t\t      int fd, off64_t offset)\n> +{\n> +\treturn V4L2CompatManager::instance()->mmap(addr, length, prot, flags,\n> +\t\t\t\t\t\t   fd, offset);\n> +}\n> +#endif\n> +\n>  LIBCAMERA_PUBLIC int munmap(void *addr, size_t length)\n>  {\n>  \treturn V4L2CompatManager::instance()->munmap(addr, length);\n> diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\n> index 56533c4..8da3316 100644\n> --- a/src/v4l2/v4l2_compat_manager.cpp\n> +++ b/src/v4l2/v4l2_compat_manager.cpp\n> @@ -39,11 +39,11 @@ void get_symbol(T &func, const char *name)\n>  V4L2CompatManager::V4L2CompatManager()\n>  \t: cm_(nullptr)\n>  {\n> -\tget_symbol(fops_.openat, \"openat\");\n> +\tget_symbol(fops_.openat, \"openat64\");\n>  \tget_symbol(fops_.dup, \"dup\");\n>  \tget_symbol(fops_.close, \"close\");\n>  \tget_symbol(fops_.ioctl, \"ioctl\");\n> -\tget_symbol(fops_.mmap, \"mmap\");\n> +\tget_symbol(fops_.mmap, \"mmap64\");\n>  \tget_symbol(fops_.munmap, \"munmap\");\n>  }\n>  \n> @@ -200,7 +200,7 @@ int V4L2CompatManager::close(int fd)\n>  }\n>  \n>  void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags,\n> -\t\t\t      int fd, off_t offset)\n> +\t\t\t      int fd, off64_t offset)\n>  {\n>  \tV4L2CameraProxy *proxy = getProxy(fd);\n>  \tif (!proxy)\n> diff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h\n> index 14338a5..3d4e512 100644\n> --- a/src/v4l2/v4l2_compat_manager.h\n> +++ b/src/v4l2/v4l2_compat_manager.h\n> @@ -11,6 +11,7 @@\n>  #include <fcntl.h>\n>  #include <map>\n>  #include <memory>\n> +#include <sys/mman.h>\n>  #include <sys/types.h>\n>  #include <vector>\n>  \n> @@ -30,7 +31,7 @@ public:\n>  \t\tusing close_func_t = int (*)(int fd);\n>  \t\tusing ioctl_func_t = int (*)(int fd, unsigned long request, ...);\n>  \t\tusing mmap_func_t = void *(*)(void *addr, size_t length, int prot,\n> -\t\t\t\t\t      int flags, int fd, off_t offset);\n> +\t\t\t\t\t      int flags, int fd, off64_t offset);\n>  \t\tusing munmap_func_t = int (*)(void *addr, size_t length);\n>  \n>  \t\topenat_func_t openat;\n> @@ -51,7 +52,7 @@ public:\n>  \tint dup(int oldfd);\n>  \tint close(int fd);\n>  \tvoid *mmap(void *addr, size_t length, int prot, int flags,\n> -\t\t   int fd, off_t offset);\n> +\t\t   int fd, off64_t offset);\n>  \tint munmap(void *addr, size_t length);\n>  \tint ioctl(int fd, unsigned long request, void *arg);\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 C2BF9603BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Jun 2020 17:02:27 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 32910F9;\n\tWed, 17 Jun 2020 17:02:27 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"PQjgd/Ea\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1592406147;\n\tbh=htNmAd7qyPngrIOHAm6dJGGGzrSvdUuS12AQeMrxA64=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=PQjgd/EaeLwAL4l/DF7c5BuwhqfC80rBXtXlUrDWokJ/lb2bGFyLq/RKCJXL6fFWu\n\tqYBA33jtxAZoUZmmYXUmGVlvejUdvRcwnPp8zxE5FWcCJ+7p/2Pfmf8SCkoGQh998r\n\t1rE0ThW5GqdZiLP6hYA9CrSrQzXSSdehShsXKHrs=","Date":"Wed, 17 Jun 2020 18:02:04 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200617150204.GE5838@pendragon.ideasonboard.com>","References":"<20200617090518.40244-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200617090518.40244-1-paul.elder@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2] v4l2: v4l2_compat: Intercept\n\topen64, openat64, and mmap64","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>","X-List-Received-Date":"Wed, 17 Jun 2020 15:02:28 -0000"}},{"id":5273,"web_url":"https://patchwork.libcamera.org/comment/5273/","msgid":"<20200618095750.GD2095@jade.amanokami.net>","date":"2020-06-18T09:57:50","subject":"Re: [libcamera-devel] [PATCH v2] v4l2: v4l2_compat: Intercept\n\topen64, openat64, and mmap64","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Wed, Jun 17, 2020 at 06:02:04PM +0300, Laurent Pinchart wrote:\n> Hi Paul,\n> \n> Thank you for the patch.\n> \n> On Wed, Jun 17, 2020 at 06:05:18PM +0900, Paul Elder wrote:\n> > Some applications (eg. Firefox, Google Chrome, Skype) use open64,\n> > openat64, and mmap64 instead of their non-64 versions that we currently\n> > intercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to\n> > be set so that the 64-bit symbols are available and not synonymous to\n> > the non-64-bit versions on 64-bit systems.\n> > \n> > Also, since we set _FILE_OFFSET_BITS to 32 to force the various open and\n> > mmap symbols that we export to not be the 64-bit versions, our dlsym to\n> > get the original open and mmap calls will not automatically be converted\n> > to their 64-bit versions. Since we intercept both 32-bit and 64-bit\n> > versions of open and mmap, we should be using the 64-bit version to\n> > service both. Fetch the 64-bit versions of openat and mmap directly.\n> > \n> > musl defines the 64-bit symbols as macros that are equivalent to the\n> > non-64-bit symbols, so we put compile guards that check if the 64-bit\n> > symbols are defined.\n> > \n> > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # Compile with musl\n> \n> Did you test compilation with musl yourself ?\n\nYeah, I did.\n\n> I'm afraid you'll also need __open64_2 and __openat64_2. With that\n> added (which you can condition on #ifndef open64 and #ifndef openat64),\n\nAlright.\n\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nThanks,\n\nPaul\n\n> > ---\n> > Changes in v2:\n> > - squash intercept 64-bit calls and use 64-bit calls into\n> >   this one patch\n> > - use off64_t instead of __off64_t\n> > - add compile guard to get musl to play nicely with the 64-bit calls\n> >   coexisting with the non-64-bit calls\n> > ---\n> >  src/v4l2/meson.build             |  1 +\n> >  src/v4l2/v4l2_camera_proxy.cpp   |  2 +-\n> >  src/v4l2/v4l2_camera_proxy.h     |  3 ++-\n> >  src/v4l2/v4l2_compat.cpp         | 33 ++++++++++++++++++++++++++++++++\n> >  src/v4l2/v4l2_compat_manager.cpp |  6 +++---\n> >  src/v4l2/v4l2_compat_manager.h   |  5 +++--\n> >  6 files changed, 43 insertions(+), 7 deletions(-)\n> > \n> > diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build\n> > index 0fb941e..f2e4aaf 100644\n> > --- a/src/v4l2/meson.build\n> > +++ b/src/v4l2/meson.build\n> > @@ -15,6 +15,7 @@ v4l2_compat_cpp_args = [\n> >      # file operations, disable transparent large file support.\n> >      '-U_FILE_OFFSET_BITS',\n> >      '-D_FILE_OFFSET_BITS=32',\n> > +    '-D_LARGEFILE64_SOURCE',\n> >      '-fvisibility=hidden',\n> >  ]\n> >  \n> > diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> > index d7f14e6..7425029 100644\n> > --- a/src/v4l2/v4l2_camera_proxy.cpp\n> > +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> > @@ -75,7 +75,7 @@ void V4L2CameraProxy::close()\n> >  }\n> >  \n> >  void *V4L2CameraProxy::mmap(void *addr, size_t length, int prot, int flags,\n> > -\t\t\t    off_t offset)\n> > +\t\t\t    off64_t offset)\n> >  {\n> >  \tLOG(V4L2Compat, Debug) << \"Servicing mmap\";\n> >  \n> > diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\n> > index 7c65c88..27d3e50 100644\n> > --- a/src/v4l2/v4l2_camera_proxy.h\n> > +++ b/src/v4l2/v4l2_camera_proxy.h\n> > @@ -11,6 +11,7 @@\n> >  #include <linux/videodev2.h>\n> >  #include <map>\n> >  #include <memory>\n> > +#include <sys/mman.h>\n> >  #include <sys/types.h>\n> >  #include <vector>\n> >  \n> > @@ -28,7 +29,7 @@ public:\n> >  \tint open(bool nonBlocking);\n> >  \tvoid dup();\n> >  \tvoid close();\n> > -\tvoid *mmap(void *addr, size_t length, int prot, int flags, off_t offset);\n> > +\tvoid *mmap(void *addr, size_t length, int prot, int flags, off64_t offset);\n> >  \tint munmap(void *addr, size_t length);\n> >  \n> >  \tint ioctl(unsigned long request, void *arg);\n> > diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\n> > index 2a9a176..7d45ffe 100644\n> > --- a/src/v4l2/v4l2_compat.cpp\n> > +++ b/src/v4l2/v4l2_compat.cpp\n> > @@ -38,6 +38,18 @@ LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)\n> >  \t\t\t\t\t\t     oflag, mode);\n> >  }\n> >  \n> > +#ifndef open64\n> > +LIBCAMERA_PUBLIC int open64(const char *path, int oflag, ...)\n> > +{\n> > +\tmode_t mode = 0;\n> > +\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n> > +\t\textract_va_arg(mode_t, mode, oflag);\n> > +\n> > +\treturn V4L2CompatManager::instance()->openat(AT_FDCWD, path,\n> > +\t\t\t\t\t\t     oflag | O_LARGEFILE, mode);\n> > +}\n> > +#endif\n> > +\n> >  /* _FORTIFY_SOURCE redirects open to __open_2 */\n> >  LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)\n> >  {\n> > @@ -53,6 +65,18 @@ LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)\n> >  \treturn V4L2CompatManager::instance()->openat(dirfd, path, oflag, mode);\n> >  }\n> >  \n> > +#ifndef openat64\n> > +LIBCAMERA_PUBLIC int openat64(int dirfd, const char *path, int oflag, ...)\n> > +{\n> > +\tmode_t mode = 0;\n> > +\tif (oflag & O_CREAT || oflag & O_TMPFILE)\n> > +\t\textract_va_arg(mode_t, mode, oflag);\n> > +\n> > +\treturn V4L2CompatManager::instance()->openat(dirfd, path,\n> > +\t\t\t\t\t\t     oflag | O_LARGEFILE, mode);\n> > +}\n> > +#endif\n> > +\n> >  LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)\n> >  {\n> >  \treturn openat(dirfd, path, oflag);\n> > @@ -75,6 +99,15 @@ LIBCAMERA_PUBLIC void *mmap(void *addr, size_t length, int prot, int flags,\n> >  \t\t\t\t\t\t   fd, offset);\n> >  }\n> >  \n> > +#ifndef mmap64\n> > +LIBCAMERA_PUBLIC void *mmap64(void *addr, size_t length, int prot, int flags,\n> > +\t\t\t      int fd, off64_t offset)\n> > +{\n> > +\treturn V4L2CompatManager::instance()->mmap(addr, length, prot, flags,\n> > +\t\t\t\t\t\t   fd, offset);\n> > +}\n> > +#endif\n> > +\n> >  LIBCAMERA_PUBLIC int munmap(void *addr, size_t length)\n> >  {\n> >  \treturn V4L2CompatManager::instance()->munmap(addr, length);\n> > diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\n> > index 56533c4..8da3316 100644\n> > --- a/src/v4l2/v4l2_compat_manager.cpp\n> > +++ b/src/v4l2/v4l2_compat_manager.cpp\n> > @@ -39,11 +39,11 @@ void get_symbol(T &func, const char *name)\n> >  V4L2CompatManager::V4L2CompatManager()\n> >  \t: cm_(nullptr)\n> >  {\n> > -\tget_symbol(fops_.openat, \"openat\");\n> > +\tget_symbol(fops_.openat, \"openat64\");\n> >  \tget_symbol(fops_.dup, \"dup\");\n> >  \tget_symbol(fops_.close, \"close\");\n> >  \tget_symbol(fops_.ioctl, \"ioctl\");\n> > -\tget_symbol(fops_.mmap, \"mmap\");\n> > +\tget_symbol(fops_.mmap, \"mmap64\");\n> >  \tget_symbol(fops_.munmap, \"munmap\");\n> >  }\n> >  \n> > @@ -200,7 +200,7 @@ int V4L2CompatManager::close(int fd)\n> >  }\n> >  \n> >  void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags,\n> > -\t\t\t      int fd, off_t offset)\n> > +\t\t\t      int fd, off64_t offset)\n> >  {\n> >  \tV4L2CameraProxy *proxy = getProxy(fd);\n> >  \tif (!proxy)\n> > diff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h\n> > index 14338a5..3d4e512 100644\n> > --- a/src/v4l2/v4l2_compat_manager.h\n> > +++ b/src/v4l2/v4l2_compat_manager.h\n> > @@ -11,6 +11,7 @@\n> >  #include <fcntl.h>\n> >  #include <map>\n> >  #include <memory>\n> > +#include <sys/mman.h>\n> >  #include <sys/types.h>\n> >  #include <vector>\n> >  \n> > @@ -30,7 +31,7 @@ public:\n> >  \t\tusing close_func_t = int (*)(int fd);\n> >  \t\tusing ioctl_func_t = int (*)(int fd, unsigned long request, ...);\n> >  \t\tusing mmap_func_t = void *(*)(void *addr, size_t length, int prot,\n> > -\t\t\t\t\t      int flags, int fd, off_t offset);\n> > +\t\t\t\t\t      int flags, int fd, off64_t offset);\n> >  \t\tusing munmap_func_t = int (*)(void *addr, size_t length);\n> >  \n> >  \t\topenat_func_t openat;\n> > @@ -51,7 +52,7 @@ public:\n> >  \tint dup(int oldfd);\n> >  \tint close(int fd);\n> >  \tvoid *mmap(void *addr, size_t length, int prot, int flags,\n> > -\t\t   int fd, off_t offset);\n> > +\t\t   int fd, off64_t offset);\n> >  \tint munmap(void *addr, size_t length);\n> >  \tint ioctl(int fd, unsigned long request, void *arg);\n> >  \n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","headers":{"Return-Path":"<paul.elder@ideasonboard.com>","Received":["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 EBD0861167\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2020 11:57:59 +0200 (CEST)","from jade.amanokami.net (unknown\n\t[IPv6:2400:4051:61:600:a17c:96b8:ddb0:63b7])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 743A5F9;\n\tThu, 18 Jun 2020 11:57:58 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"r3ai5+Qw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1592474279;\n\tbh=XfJCmbpHm+FnSSCPwW2aQfEeuqeuDDDpZqf5W8tr4/c=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=r3ai5+QwQjFM31Sbnn0SyfH7LmVGtr55rk6x7OLbDgYI+Gha0b8X7l+j54/Wa45zR\n\tY8ObNTU4MATKfbQ65CudRpteBgK2FY4FmopOVQWFm3fwOuEcKYfFaZ1DgaBtaeUyUi\n\td1X6e5cLR8hHNodBM2ujs7iAx4c8OaFhHf9I33gY=","Date":"Thu, 18 Jun 2020 18:57:50 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200618095750.GD2095@jade.amanokami.net>","References":"<20200617090518.40244-1-paul.elder@ideasonboard.com>\n\t<20200617150204.GE5838@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20200617150204.GE5838@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2] v4l2: v4l2_compat: Intercept\n\topen64, openat64, and mmap64","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>","X-List-Received-Date":"Thu, 18 Jun 2020 09:58:00 -0000"}}]