{"id":4079,"url":"https://patchwork.libcamera.org/api/1.1/patches/4079/?format=json","web_url":"https://patchwork.libcamera.org/patch/4079/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200619053117.17865-1-paul.elder@ideasonboard.com>","date":"2020-06-19T05:31:17","name":"[libcamera-devel,v4] v4l2: v4l2_compat: Intercept open64, openat64, and mmap64","commit_ref":"1023107b6405266d480ce9c08cd82a30449a505b","pull_url":null,"state":"accepted","archived":false,"hash":"9a0486181d90498283650493eab0682e185dcc78","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/4079/mbox/","series":[{"id":1016,"url":"https://patchwork.libcamera.org/api/1.1/series/1016/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1016","date":"2020-06-19T05:31:17","name":"[libcamera-devel,v4] v4l2: v4l2_compat: Intercept open64, openat64, and mmap64","version":4,"mbox":"https://patchwork.libcamera.org/series/1016/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/4079/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/4079/checks/","tags":{},"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 E885F603BF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Jun 2020 07:31:31 +0200 (CEST)","from jade.flets-east.jp (unknown\n\t[IPv6:2400:4051:61:600:e972:d773:e99a:4f79])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A00E6552;\n\tFri, 19 Jun 2020 07:31:29 +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=\"AB77RhS5\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1592544691;\n\tbh=gRv74LVKKOiSL+WSEDn3ss5AU3XWkLm5ZaayGEqDIB0=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=AB77RhS5CZreiIi/6uNYVCTWF8NQ+O9C09M9IHaedUD4sCy3TD+lmy/oAjZc3GCi8\n\t2lbda6KkxUbx8XYckP7uBOc7i0RoVONX/n4r+j3Ye72+z0TTy5TBhWKOQevPd6ja3u\n\tRGalTLGgPtY3qagwV+m9PuFn9SU59ZxCidoafPAg=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 19 Jun 2020 14:31:17 +0900","Message-Id":"<20200619053117.17865-1-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4] v4l2: v4l2_compat: Intercept open64,\n\topenat64, 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":"Fri, 19 Jun 2020 05:31:32 -0000"},"content":"Some applications (eg. Firefox, Google Chrome, Skype) use open64,\nopenat64, and mmap64 instead of their non-64 versions that we currently\nintercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to\nbe set so that the 64-bit symbols are available and not synonymous to\nthe non-64-bit versions on 64-bit systems.\n\nAlso, since we set _FILE_OFFSET_BITS to 32 to force the various open and\nmmap symbols that we export to not be the 64-bit versions, our dlsym to\nget the original open and mmap calls will not automatically be converted\nto their 64-bit versions. Since we intercept both 32-bit and 64-bit\nversions of open and mmap, we should be using the 64-bit version to\nservice both. Fetch the 64-bit versions of openat and mmap directly.\n\nmusl defines the 64-bit symbols as macros that are equivalent to the\nnon-64-bit symbols, so we put compile guards that check if the 64-bit\nsymbols are defined.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nTested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # Compile with musl\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v4:\n- fix compile guard for __open64_2 and __openat64_2 to be #ifndef open64\n  and openat64, respectively\n\nChanges in v3:\n- add __open64_2 and __openat64_2\n\nChanges 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         | 43 ++++++++++++++++++++++++++++++++\n src/v4l2/v4l2_compat_manager.cpp |  6 ++---\n src/v4l2/v4l2_compat_manager.h   |  5 ++--\n 6 files changed, 53 insertions(+), 7 deletions(-)","diff":"diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build\nindex 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 \ndiff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex 19b300f..bf47aa7 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -76,7 +76,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 \ndiff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\nindex 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);\ndiff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp\nindex 2a9a176..fd73381 100644\n--- a/src/v4l2/v4l2_compat.cpp\n+++ b/src/v4l2/v4l2_compat.cpp\n@@ -44,6 +44,23 @@ LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)\n \treturn open(path, oflag);\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+\n+LIBCAMERA_PUBLIC int __open64_2(const char *path, int oflag)\n+{\n+\treturn open(path, oflag);\n+}\n+#endif\n+\n LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)\n {\n \tmode_t mode = 0;\n@@ -58,6 +75,23 @@ LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)\n \treturn openat(dirfd, path, oflag);\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+\n+LIBCAMERA_PUBLIC int __openat64_2(int dirfd, const char *path, int oflag)\n+{\n+\treturn openat(dirfd, path, oflag);\n+}\n+#endif\n+\n LIBCAMERA_PUBLIC int dup(int oldfd)\n {\n \treturn V4L2CompatManager::instance()->dup(oldfd);\n@@ -75,6 +109,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);\ndiff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp\nindex 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)\ndiff --git a/src/v4l2/v4l2_compat_manager.h b/src/v4l2/v4l2_compat_manager.h\nindex 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","prefixes":["libcamera-devel","v4"]}