[v2] libcamera: dma_buf_allocator: Work around lack of file seals in uClibc
diff mbox series

Message ID 20240605092211.18954-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit 48cb731d72e2bc54d3bf76eb35c6644fa2f924f2
Headers show
Series
  • [v2] libcamera: dma_buf_allocator: Work around lack of file seals in uClibc
Related show

Commit Message

Laurent Pinchart June 5, 2024, 9:22 a.m. UTC
uClibc doesn't provide the macros defining parameters for the file
sealing API. Define them manually as a work around.

Fixes: ea4baaacc325 ("libcamera: DmaBufAllocator: Support allocating from /dev/udmabuf")
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Silence doxygen warning
- Move defines before function
- Add comment
---
 meson.build                         | 4 ++++
 src/libcamera/dma_buf_allocator.cpp | 8 ++++++++
 2 files changed, 12 insertions(+)


base-commit: 98071d3109c131820439f61d9380c0bd4cd2119a

Patch
diff mbox series

diff --git a/meson.build b/meson.build
index 1902ea2fd3ff..0ef4cdaafd76 100644
--- a/meson.build
+++ b/meson.build
@@ -74,6 +74,10 @@  cc = meson.get_compiler('c')
 cxx = meson.get_compiler('cpp')
 config_h = configuration_data()
 
+if cc.has_header_symbol('fcntl.h', 'F_ADD_SEALS', prefix : '#define _GNU_SOURCE')
+    config_h.set('HAVE_FILE_SEALS', 1)
+endif
+
 if cc.has_header_symbol('unistd.h', 'issetugid')
     config_h.set('HAVE_ISSETUGID', 1)
 endif
diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
index d7d08e188a62..c06eca7d04ec 100644
--- a/src/libcamera/dma_buf_allocator.cpp
+++ b/src/libcamera/dma_buf_allocator.cpp
@@ -127,6 +127,14 @@  DmaBufAllocator::~DmaBufAllocator() = default;
  * \return True if the DmaBufAllocator is valid, false otherwise
  */
 
+/* uClibc doesn't provide the file sealing API. */
+#ifndef __DOXYGEN__
+#if not HAVE_FILE_SEALS
+#define F_ADD_SEALS		1033
+#define F_SEAL_SHRINK		0x0002
+#endif
+#endif
+
 UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size)
 {
 	/* Size must be a multiple of the page size. Round it up. */