Skip to content

Commit bc8776a

Browse files
alviroiskandarammarfaizi2
authored andcommitted
Bring back CONFIG_HAVE_MEMFD_CREATE to fix Android build error
Commit 732bf60 ("test/io_uring_register: kill old memfd test") removed the `CONFIG_HAVE_MEMFD_CREATE`, which was previously used to conditionally provide `memfd_create()` for an old test in `test/io_uring_register.c`. Reintroduce `CONFIG_HAVE_MEMFD_CREATE` to resolve Android build error caused by commit: 93d3a7a ("examples/zcrx: udmabuf backed areas") It added a call to `memfd_create()`, which is unavailable on some Android toolchains, leading to the following build error: ``` zcrx.c:111:10: error: call to undeclared function 'memfd_create'; ISO C99 and \ later do not support implicit function declarations \ [-Wimplicit-function-declaration] 111 | memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING); | ^ ``` Then, provide memfd_create() in examples/ if `CONFIG_HAVE_MEMFD_CREATE` is not set to fix the build error. v2 -> v3: - Don't bother touching the test/ dir. Link: https://lore.kernel.org/io-uring/3b28fddb-2171-4f2f-9729-0c0ed14d20cc@kernel.dk v1 -> v2: - Omit the old memfd test because it's not needed anymore. Link: https://lore.kernel.org/io-uring/4bc75566-9cb5-42ec-a6b7-16e04062e0c6@kernel.dk Co-authored-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org> Signed-off-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org> Link: https://lore.kernel.org/r/20250716144610.3938579-1-alviro.iskandar@gnuweeb.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent aa9a6b7 commit bc8776a

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

configure

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,22 @@ if compile_prog "" "" "has_ucontext"; then
379379
fi
380380
print_config "has_ucontext" "$has_ucontext"
381381

382+
##########################################
383+
# check for memfd_create(2)
384+
has_memfd_create="no"
385+
cat > $TMPC << EOF
386+
#include <sys/mman.h>
387+
int main(int argc, char **argv)
388+
{
389+
int memfd = memfd_create("test", 0);
390+
return 0;
391+
}
392+
EOF
393+
if compile_prog "-Werror=implicit-function-declaration" "" "has_memfd_create"; then
394+
has_memfd_create="yes"
395+
fi
396+
print_config "has_memfd_create" "$has_memfd_create"
397+
382398
##########################################
383399
# Check NVME_URING_CMD support
384400
nvme_uring_cmd="no"
@@ -539,6 +555,9 @@ fi
539555
if test "$array_bounds" = "yes"; then
540556
output_sym "CONFIG_HAVE_ARRAY_BOUNDS"
541557
fi
558+
if test "$has_memfd_create" = "yes"; then
559+
output_sym "CONFIG_HAVE_MEMFD_CREATE"
560+
fi
542561
if test "$nvme_uring_cmd" = "yes"; then
543562
output_sym "CONFIG_HAVE_NVME_URING"
544563
fi

examples/helpers.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313

1414
#include "helpers.h"
1515

16+
#ifndef CONFIG_HAVE_MEMFD_CREATE
17+
#include <sys/syscall.h>
18+
int memfd_create(const char *name, unsigned int flags)
19+
{
20+
return (int)syscall(SYS_memfd_create, name, flags);
21+
}
22+
#endif
23+
1624
int setup_listening_socket(int port, int ipv6)
1725
{
1826
struct sockaddr_in srv_addr = { };

examples/helpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ void *t_aligned_alloc(size_t alignment, size_t size);
1717

1818
void t_error(int status, int errnum, const char *format, ...);
1919

20+
#ifndef CONFIG_HAVE_MEMFD_CREATE
21+
#include <linux/memfd.h>
22+
#endif
23+
int memfd_create(const char *name, unsigned int flags);
24+
2025
#endif

0 commit comments

Comments
 (0)