test/io_uring_register: fix -Wimplicit-function-declaration of memfd_create

On some systems, there is no `memfd_create` function. This commit
fixes this:
```
       CC io_uring_register
  io_uring_register.c: In function 'test_shmem':
  io_uring_register.c:514:10: warning: implicit declaration of function 'memfd_create' [-Wimplicit-function-declaration]
    memfd = memfd_create("uring-shmem-test", 0);
            ^
```

Fix for this is based on an answer on Stack Overflow [1].

On Jun 16 '19 at 5:12, mosvy wrote:
> On older systems, you'll have to include linux/memfd.h for the MFD_
> defines, and call memfd_create() via the the syscall(2) wrapper
> (and include unistd.h and sys/syscall.h for it work).
>

Link: https://stackoverflow.com/a/56616264/7275114 [1]
Reported-by: Louvian Lyndal <louvianlyndal@gmail.com>
Tested-by: Louvian Lyndal <louvianlyndal@gmail.com>
Signed-off-by: Ammar Faizi <ammarfaizi2@gmail.com>
This commit is contained in:
Ammar Faizi
2021-09-11 13:10:04 +07:00
parent 8eaf96af77
commit ef0679172f
2 changed files with 31 additions and 0 deletions
Vendored
+20
View File
@@ -338,6 +338,23 @@ if compile_prog "" "" "has_ucontext"; then
fi
print_config "has_ucontext" "$has_ucontext"
##########################################
# check for memfd_create(2)
has_memfd_create="no"
cat > $TMPC << EOF
#define _GNU_SOURCE
#include <sys/mman.h>
int main(int argc, char **argv)
{
int memfd = memfd_create("test", 0);
return 0;
}
EOF
if compile_prog "-Werror=implicit-function-declaration" "" "has_memfd_create"; then
has_memfd_create="yes"
fi
print_config "has_memfd_create" "$has_memfd_create"
#############################################################################
@@ -365,6 +382,9 @@ fi
if test "$array_bounds" = "yes"; then
output_sym "CONFIG_HAVE_ARRAY_BOUNDS"
fi
if test "$has_memfd_create" = "yes"; then
output_sym "CONFIG_HAVE_MEMFD_CREATE"
fi
echo "CC=$cc" >> $config_host_mak
print_config "CC" "$cc"
+11
View File
@@ -31,6 +31,17 @@ static int pagesize;
static rlim_t mlock_limit;
static int devnull;
#if !defined(CONFIG_HAVE_MEMFD_CREATE)
#include <sys/syscall.h>
#include <linux/memfd.h>
static int memfd_create(const char *name, unsigned int flags)
{
return (int)syscall(SYS_memfd_create, name, flags);
}
#endif
int
expect_fail(int fd, unsigned int opcode, void *arg,
unsigned int nr_args, int error)