From ef0679172fcb5763db4d243745d79dbaa205cb30 Mon Sep 17 00:00:00 2001 From: Ammar Faizi Date: Sat, 11 Sep 2021 13:10:04 +0700 Subject: [PATCH] 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 Tested-by: Louvian Lyndal Signed-off-by: Ammar Faizi --- configure | 20 ++++++++++++++++++++ test/io_uring_register.c | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/configure b/configure index afccef1a..a7caa070 100755 --- a/configure +++ b/configure @@ -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 +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" diff --git a/test/io_uring_register.c b/test/io_uring_register.c index da7bc0dd..b8a4ea57 100644 --- a/test/io_uring_register.c +++ b/test/io_uring_register.c @@ -31,6 +31,17 @@ static int pagesize; static rlim_t mlock_limit; static int devnull; +#if !defined(CONFIG_HAVE_MEMFD_CREATE) +#include +#include + +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)