[igt-dev] [PATCH i-g-t 2/2] stubs: provide implementation for memfd_create

Lucas De Marchi lucas.demarchi at intel.com
Fri Jul 20 19:06:18 UTC 2018


On Thu, Jul 19, 2018 at 05:41:55PM -0700, Lucas De Marchi wrote:
> On Thu, Jul 19, 2018 at 4:20 PM Antonio Argenziano
> <antonio.argenziano at intel.com> wrote:
> >
> >
> >
> > On 19/07/18 13:54, Lucas De Marchi wrote:
> > > When libc misses memfd_create(), provide a stub implementation to go
> > > through the syscall() route. Syscall numbers are provided for platforms
> > > currently supported by i-g-t only.
> > >
> > > Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
> > > ---
> > >   lib/stubs/syscall/sys/mman.h | 37 ++++++++++++++++++++++++++++++++++++
> > >   meson.build                  |  3 +++
> > >   2 files changed, 40 insertions(+)
> > >   create mode 100644 lib/stubs/syscall/sys/mman.h
> > >
> > > diff --git a/lib/stubs/syscall/sys/mman.h b/lib/stubs/syscall/sys/mman.h
> > > new file mode 100644
> > > index 00000000..36060bda
> > > --- /dev/null
> > > +++ b/lib/stubs/syscall/sys/mman.h
> > > @@ -0,0 +1,37 @@
> > > +/* SPDX-License-Identifier: MIT */
> > > +
> > > +#pragma once
> > > +
> > > +#include_next <sys/mman.h>
> > > +
> > > +#if !HAVE_MEMFD_CREATE
> >
> > Maybe include <linux/memfd.h> conditionally. I don't think we need it
> > for anything else.
> 
> oh... I added it to sys/mman.h when in reality should have added to
> sys/memfd.h it seems?
> 
> and the man page is wrong?
> 
> NAME
>        memfd_create - create an anonymous file
> 
> SYNOPSIS
>        #include <sys/memfd.h>
> 
>        int memfd_create(const char *name, unsigned int flags);
> 
> Interesting that it worked as is. Where's my coffee?

patch to fix the man page was sent. I will spin a new version of this
patch to deal with the memfd.h header.

Lucas De Marchi

> 
> Lucas De Marchi
> 
> >
> > Thanks,
> > Antonio
> >
> > > +#include <errno.h>
> > > +#include <sys/syscall.h>
> > > +#include <sys/types.h>
> > > +#include <unistd.h>
> > > +
> > > +#ifndef __NR_memfd_create
> > > +#if defined __x86_64__
> > > +#define __NR_memfd_create 319
> > > +#elif defined __i386__
> > > +#define __NR_memfd_create 356
> > > +#elif defined __arm__
> > > +#define __NR_memfd_create 385
> > > +#else
> > > +#warning "__NR_memfd_create unknown for your architecture"
> > > +#endif
> > > +#endif
> > > +
> > > +static inline int missing_memfd_create(const char *name, unsigned int flags)
> > > +{
> > > +#ifdef __NR_memfd_create
> > > +     return syscall(__NR_memfd_create, name, flags);
> > > +#else
> > > +     errno = ENOSYS;
> > > +     return -1;
> > > +#endif
> > > +}
> > > +
> > > +#define memfd_create missing_memfd_create
> > > +
> > > +#endif
> > > diff --git a/meson.build b/meson.build
> > > index c24a3cf4..188301ca 100644
> > > --- a/meson.build
> > > +++ b/meson.build
> > > @@ -196,6 +196,9 @@ if cc.has_member('struct sysinfo', 'totalram',
> > >       config.set('HAVE_STRUCT_SYSINFO_TOTALRAM', 1)
> > >   endif
> > >
> > > +have = cc.has_function('memfd_create', prefix : '''#include <sys/mman.h>''', args : '-D_GNU_SOURCE')
> > > +config.set10('HAVE_MEMFD_CREATE', have)
> > > +
> > >   add_project_arguments('-D_GNU_SOURCE', language : 'c')
> > >   add_project_arguments('-include', 'config.h', language : 'c')
> > >
> > >
> > _______________________________________________
> > igt-dev mailing list
> > igt-dev at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/igt-dev
> 
> 
> 
> -- 
> Lucas De Marchi


More information about the igt-dev mailing list