summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_compat.cpp
AgeCommit message (Collapse)Author
20 hoursv4l2: v4l2_compat: Move `open*()` flag check into functionHEADmasterBarnabás Pőcze
This commit moves the check that determines whether the mode argument of `open*()` exists into a separate function. With that, the check is fixed because previously it failed to account for the fact that `O_TMPFILE` is not a power of two. Furthermore, add `assert()`s in the fortified variants that ensure that no mode is required by the specified flags. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
20 hoursv4l2: v4l2_compat: Fix redirect from `__open(at)64_2()`Barnabás Pőcze
To avoid confusion, have `__open64_2()` and `__openat64_2()` delegate to `open64()` and `openat64()`, respectively, instead of `open()` and `openat()`. This does not change the behaviour because `V4L2CompatManager::instance()->openat()` calls `openat64()` internally, and that adds the `O_LARGEFILE` flag unconditionally. Fixes: 1023107b6405 ("v4l2: v4l2_compat: Intercept open64, openat64, and mmap64") Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2024-05-08libcamera: Drop file name from header comment blocksLaurent Pinchart
Source files in libcamera start by a comment block header, which includes the file name and a one-line description of the file contents. While the latter is useful to get a quick overview of the file contents at a glance, the former is mostly a source of inconvenience. The name in the comments can easily get out of sync with the file name when files are renamed, and copy & paste during development have often lead to incorrect names being used to start with. Readers of the source code are expected to know which file they're looking it. Drop the file name from the header comment block. The change was generated with the following script: ---------------------------------------- dirs="include/libcamera src test utils" declare -rA patterns=( ['c']=' \* ' ['cpp']=' \* ' ['h']=' \* ' ['py']='# ' ['sh']='# ' ) for ext in ${!patterns[@]} ; do files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done) pattern=${patterns[${ext}]} for file in $files ; do name=$(basename ${file}) sed -i "s/^\(${pattern}\)${name} - /\1/" "$file" done done ---------------------------------------- This misses several files that are out of sync with the comment block header. Those will be addressed separately and manually. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
2021-12-01libcamera: Correct include headers for Mutex classesHirokazu Honda
Mutex classes are defined in mutex.h. This replaces thread.h include for the Mutex classes with mutex.h. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-19v4l2: v4l2_compat: Intercept open64, openat64, and mmap64Paul Elder
Some applications (eg. Firefox, Google Chrome, Skype) use open64, openat64, and mmap64 instead of their non-64 versions that we currently intercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to be set so that the 64-bit symbols are available and not synonymous to the non-64-bit versions on 64-bit systems. Also, since we set _FILE_OFFSET_BITS to 32 to force the various open and mmap symbols that we export to not be the 64-bit versions, our dlsym to get the original open and mmap calls will not automatically be converted to their 64-bit versions. Since we intercept both 32-bit and 64-bit versions of open and mmap, we should be using the 64-bit version to service both. Fetch the 64-bit versions of openat and mmap directly. musl defines the 64-bit symbols as macros that are equivalent to the non-64-bit symbols, so we put compile guards that check if the 64-bit symbols are defined. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # Compile with musl Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-05-28v4l2: Relicense V4L2 compatibility layer under LGPLLaurent Pinchart
The V4L2 compatibility layer is licensed under the GPL. It is compiled as a binary separate from libcamera.so, and is loaded into the address space of processes through LD_PRELOAD to intercept calls to the C library. It is our understanding and intent that the GPL license doesn't propagate to the binaries whose calls are intercepted, considering those binaries are not derivative work of the V4L2 compatibility layer and are not designed to be linked to the V4L2 compatibility layer. There is however a possibly grey area if binaries are packaged with a shell script wrapper that loads the V4L2 compatibility layer. This could lead to license-related issues if such packaging is performed by Linux distributions or system integrators. To clarify the intent and lift the doubts, relicense the V4L2 compatibility layer under the LGPL. The V4L2 compatibility layer code itself still benefits from the license protection, while its usage with third-party binaries is clearly allowed as intended. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Acked-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
2020-01-04v4l2: Fix compilation of __open_2() and __openat_2() with gccLaurent Pinchart
The __open_2() and __openat_2() functions are defined by glibc as taking 2 and 3 arguments respectively, with variadic arguments for the file mode as open() and openat() do. The V4L2 compatibility layer defines them as aliases for open() and openat(), which results in compilation failures with gcc: ../../src/v4l2/v4l2_compat.cpp: In function ‘int __openat_2(int, const char*, int)’: ../../src/v4l2/v4l2_compat.cpp:58:14: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive] 58 | return open(dirfd, path, oflag); | ^~~~~ | | | int ../../src/v4l2/v4l2_compat.cpp:31:39: note: initializing argument 1 of ‘int open(const char*, int, ...)’ 31 | LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...) | ~~~~~~~~~~~~^~~~ ../../src/v4l2/v4l2_compat.cpp:58:21: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive] 58 | return open(dirfd, path, oflag); | ^~~~ | | | const char* ../../src/v4l2/v4l2_compat.cpp:31:49: note: initializing argument 2 of ‘int open(const char*, int, ...)’ 31 | LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...) | Fix this by defining the two functions as wrappers around open() and openat() without variadic arguments. Fixes: 0ce8f2390b52 ("v4l2: v4l2_compat: Add V4L2 compatibility layer") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-03v4l2: v4l2_compat: Add V4L2 compatibility layerPaul Elder
Add libcamera V4L2 compatibility layer. This initial implementation supports the minimal set of V4L2 operations, which allows getting, setting, and enumerating formats, and streaming frames from a video device. Some data about the wrapped V4L2 video device are hardcoded. Add a build option named 'v4l2' and adjust the build system to selectively compile the V4L2 compatibility layer. For now we match the V4L2 device node to a libcamera camera based on a devnum that a pipeline handler may optionally map to a libcamera camera. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>