Commit bcb37a9b authored by Lucas De Marchi's avatar Lucas De Marchi Committed by Rodrigo Vivi

build: provide stub implementation for memfd_create

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.

v2: add support to autotools
Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Acked-by: Antonio Argenziano's avatarAntonio Argenziano <antonio.argenziano@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
parent 31ea7dd5
......@@ -81,6 +81,9 @@ AC_CHECK_FUNCS(timer_create, [], [
])
AC_SUBST(TIMER_LIBS)
dnl Check for memfd_create
AC_CHECK_FUNCS(memfd_create)
dnl Check for CPUID
cpuid="yes"
AC_TRY_LINK([
......
/* SPDX-License-Identifier: MIT */
#pragma once
#include_next <sys/mman.h>
#if !defined(HAVE_MEMFD_CREATE) || !HAVE_MEMFD_CREATE
#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
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment