Message ID | 20240503025205.2814-3-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Commit | acf61456cc55441a0f09b361a531d628d390031b |
Headers | show |
Series |
|
Related | show |
Hi Laurent, Thank you for the patch On 03/05/24 8:22 am, Laurent Pinchart wrote: > uClibc doesn't provide a memfd_create() implementation. Fix it by using > a direct syscall when the function isn't available. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> > --- > meson.build | 4 ++++ > src/libcamera/shared_mem_object.cpp | 6 ++++++ > 2 files changed, 10 insertions(+) > > diff --git a/meson.build b/meson.build > index 740ead1be85f..39e4947f8c97 100644 > --- a/meson.build > +++ b/meson.build > @@ -82,6 +82,10 @@ if cc.has_header_symbol('locale.h', 'locale_t', prefix : '#define _GNU_SOURCE') > config_h.set('HAVE_LOCALE_T', 1) > endif > > +if cc.has_header_symbol('sys/mman.h', 'memfd_create', prefix : '#define _GNU_SOURCE') > + config_h.set('HAVE_MEMFD_CREATE', 1) > +endif > + > if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE') > config_h.set('HAVE_SECURE_GETENV', 1) > endif > diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp > index b018fb3bc0a5..e8cb59f7a90f 100644 > --- a/src/libcamera/shared_mem_object.cpp > +++ b/src/libcamera/shared_mem_object.cpp > @@ -12,6 +12,8 @@ > > #include <stddef.h> > #include <stdint.h> > +#include <sys/mman.h> > +#include <sys/syscall.h> > #include <sys/types.h> > #include <unistd.h> > > @@ -56,7 +58,11 @@ SharedMem::SharedMem() = default; > */ > SharedMem::SharedMem(const std::string &name, std::size_t size) > { > +#if HAVE_MEMFD_CREATE > int fd = memfd_create(name.c_str(), MFD_CLOEXEC); > +#else > + int fd = syscall(SYS_memfd_create, name.c_str(), MFD_CLOEXEC); > +#endif > if (fd < 0) > return; >
Hi Laurent, thanks for the patch. On Fri, May 03, 2024 at 05:52:03AM +0300, Laurent Pinchart wrote: > uClibc doesn't provide a memfd_create() implementation. Fix it by using Ahh that answeres my previous question :-) > a direct syscall when the function isn't available. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> Cheers, Stefan > --- > meson.build | 4 ++++ > src/libcamera/shared_mem_object.cpp | 6 ++++++ > 2 files changed, 10 insertions(+) > > diff --git a/meson.build b/meson.build > index 740ead1be85f..39e4947f8c97 100644 > --- a/meson.build > +++ b/meson.build > @@ -82,6 +82,10 @@ if cc.has_header_symbol('locale.h', 'locale_t', prefix : '#define _GNU_SOURCE') > config_h.set('HAVE_LOCALE_T', 1) > endif > > +if cc.has_header_symbol('sys/mman.h', 'memfd_create', prefix : '#define _GNU_SOURCE') > + config_h.set('HAVE_MEMFD_CREATE', 1) > +endif > + > if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE') > config_h.set('HAVE_SECURE_GETENV', 1) > endif > diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp > index b018fb3bc0a5..e8cb59f7a90f 100644 > --- a/src/libcamera/shared_mem_object.cpp > +++ b/src/libcamera/shared_mem_object.cpp > @@ -12,6 +12,8 @@ > > #include <stddef.h> > #include <stdint.h> > +#include <sys/mman.h> > +#include <sys/syscall.h> > #include <sys/types.h> > #include <unistd.h> > > @@ -56,7 +58,11 @@ SharedMem::SharedMem() = default; > */ > SharedMem::SharedMem(const std::string &name, std::size_t size) > { > +#if HAVE_MEMFD_CREATE > int fd = memfd_create(name.c_str(), MFD_CLOEXEC); > +#else > + int fd = syscall(SYS_memfd_create, name.c_str(), MFD_CLOEXEC); > +#endif > if (fd < 0) > return; > > -- > Regards, > > Laurent Pinchart >
diff --git a/meson.build b/meson.build index 740ead1be85f..39e4947f8c97 100644 --- a/meson.build +++ b/meson.build @@ -82,6 +82,10 @@ if cc.has_header_symbol('locale.h', 'locale_t', prefix : '#define _GNU_SOURCE') config_h.set('HAVE_LOCALE_T', 1) endif +if cc.has_header_symbol('sys/mman.h', 'memfd_create', prefix : '#define _GNU_SOURCE') + config_h.set('HAVE_MEMFD_CREATE', 1) +endif + if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE') config_h.set('HAVE_SECURE_GETENV', 1) endif diff --git a/src/libcamera/shared_mem_object.cpp b/src/libcamera/shared_mem_object.cpp index b018fb3bc0a5..e8cb59f7a90f 100644 --- a/src/libcamera/shared_mem_object.cpp +++ b/src/libcamera/shared_mem_object.cpp @@ -12,6 +12,8 @@ #include <stddef.h> #include <stdint.h> +#include <sys/mman.h> +#include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> @@ -56,7 +58,11 @@ SharedMem::SharedMem() = default; */ SharedMem::SharedMem(const std::string &name, std::size_t size) { +#if HAVE_MEMFD_CREATE int fd = memfd_create(name.c_str(), MFD_CLOEXEC); +#else + int fd = syscall(SYS_memfd_create, name.c_str(), MFD_CLOEXEC); +#endif if (fd < 0) return;
uClibc doesn't provide a memfd_create() implementation. Fix it by using a direct syscall when the function isn't available. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- meson.build | 4 ++++ src/libcamera/shared_mem_object.cpp | 6 ++++++ 2 files changed, 10 insertions(+)