[PATCH] libcamera: dma_buf_allocator: Work around lack of memfd_create() in uClibc
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Wed Jun 5 10:55:22 CEST 2024
On Wed, Jun 05, 2024 at 09:49:26AM +0100, Kieran Bingham wrote:
> Quoting Laurent Pinchart (2024-06-05 09:37:57)
> > uClibc doesn't provide a memfd_create() implementation. Fix it by using
> > a direct syscall when the function isn't available.
>
> I presume the fact these are only coming up now means we don't yet have
> uClibc in CI?
That's right. musl would be relatively easy to add with an Alpine
container, but uClibc would be harder.
> > Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> > ---
> > I should have bundled this in a series with "[PATCH] libcamera:
> > dma_buf_allocator: Work around lack of file seals in uClibc", sorry
> > about that.
> > ---
> > src/libcamera/dma_buf_allocator.cpp | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
> > index 5ec29949c66a..d7d08e188a62 100644
> > --- a/src/libcamera/dma_buf_allocator.cpp
> > +++ b/src/libcamera/dma_buf_allocator.cpp
> > @@ -13,6 +13,7 @@
> > #include <sys/ioctl.h>
> > #include <sys/mman.h>
> > #include <sys/stat.h>
> > +#include <sys/syscall.h>
> > #include <sys/types.h>
> > #include <unistd.h>
> >
> > @@ -132,7 +133,11 @@ UniqueFD DmaBufAllocator::allocFromUDmaBuf(const char *name, std::size_t size)
> > std::size_t pageMask = sysconf(_SC_PAGESIZE) - 1;
> > size = (size + pageMask) & ~pageMask;
> >
> > +#if HAVE_MEMFD_CREATE
> > int ret = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
> > +#else
> > + int ret = syscall(SYS_memfd_create, name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
> > +#endif
>
> Is there any benefit to going through memfd_create at all in that case?
I think it's best to use what the libc provides, that lowers the risk of
breakages in the future.
We already have a similar construct in
src/libcamera/shared_mem_object.cpp by the way, see commit acf61456cc55
("libcamera: shared_mem_object: Fix compilation with uClibc").
> But this is fine otherwise.
>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
>
> > if (ret < 0) {
> > ret = errno;
> > LOG(DmaBufAllocator, Error)
> >
> > base-commit: 98071d3109c131820439f61d9380c0bd4cd2119a
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list