Show a patch.

GET /api/1.1/patches/4074/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 4074,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/4074/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/4074/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200618100811.22111-1-paul.elder@ideasonboard.com>",
    "date": "2020-06-18T10:08:11",
    "name": "[libcamera-devel,v3] v4l2: v4l2_compat: Intercept open64, openat64, and mmap64",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "292f05fc9dc486c8c78889279e094a43d069ec69",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/4074/mbox/",
    "series": [
        {
            "id": 1013,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1013/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1013",
            "date": "2020-06-18T10:08:11",
            "name": "[libcamera-devel,v3] v4l2: v4l2_compat: Intercept open64, openat64, and mmap64",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/1013/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/4074/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/4074/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 638B561E77\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 18 Jun 2020 12:08:29 +0200 (CEST)",
            "from jade.flets-east.jp (unknown\n\t[IPv6:2400:4051:61:600:a17c:96b8:ddb0:63b7])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D9D5BF9;\n\tThu, 18 Jun 2020 12:08:26 +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=\"iNj4OaF1\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1592474908;\n\tbh=RCvSkIziGh3J+rPtj2HQnHOEdSi658kYyQ9GBqihnAc=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=iNj4OaF1AY1cF65PpDfQKGcEcmhjaBSFAPpSfGEjFDN0epL9Hqg3bdEgrUtPiMP3O\n\t/7pDSNUMLzIPbudMxWvGoV/Os/N/tL2WWzqhOUHOlnNM6Q9zb0J6ovXFyhGSREkBMQ\n\tHnzWrGOBSNwzKjrXZcm01NUqgUdOCvQRYj4pNzNA=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 18 Jun 2020 19:08:11 +0900",
        "Message-Id": "<20200618100811.22111-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 v3] 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": "Thu, 18 Jun 2020 10:08:29 -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 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         | 47 ++++++++++++++++++++++++++++++++\n src/v4l2/v4l2_compat_manager.cpp |  6 ++--\n src/v4l2/v4l2_compat_manager.h   |  5 ++--\n 6 files changed, 57 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 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 \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..2e80de5 100644\n--- a/src/v4l2/v4l2_compat.cpp\n+++ b/src/v4l2/v4l2_compat.cpp\n@@ -38,12 +38,31 @@ 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 \treturn open(path, oflag);\n }\n \n+#ifndef __open64_2\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@@ -53,11 +72,30 @@ 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 }\n \n+#ifndef __openat64_2\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 +113,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",
        "v3"
    ]
}