From nobody Tue Oct 7 03:47:51 2025 Received: from server-vie001.gnuweeb.org (server-vie001.gnuweeb.org [89.58.62.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBA9535975; Tue, 15 Jul 2025 05:06:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.58.62.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752556005; cv=none; b=Ay2agAcX3egmjmVCwYdXH5J/sBGl129eJALbukfW60GtrxeEHq9NxgZHn5oQhCPUbb8ulBV4lAr3E3vr8DEEQB2lb1zh72YvGq8bL3tatTcgdpnM7KHc+jwC2lxLzYh9E6TdVIojLqjfBO3ZetPjCyz2Ddgk63X+Oxvti8COJlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752556005; c=relaxed/simple; bh=WAWa2xKLVGTmrGvKn2wWInzanbVsdNjrixT7OQNpvbw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u2ross00D1JKnV4Ch3YZV/RLbfPLIfOYuPoWDOGmHXhRoEbde5Xwwd/Nhq2kH9VAMYiUttmXcTCGeGxeZagGsPKHEMH/WE4EOFF9DNy1T8LbunuEDIA2HGc2U0saskHKtR/WH1NpwkndWW73ibXt6SHtChikg0PEliO5NReWA60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org; spf=pass smtp.mailfrom=gnuweeb.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b=DHS0+cly; arc=none smtp.client-ip=89.58.62.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b="DHS0+cly" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1752555996; bh=WAWa2xKLVGTmrGvKn2wWInzanbVsdNjrixT7OQNpvbw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=DHS0+clyZVv+weZAlTt5AaGtsH85O4gCIN8jFS5RxBH9kZ8HSouzsTMYMFfv9cddv /M9VNqyNZ+kr1NKBPDd/hqToNalTLQ/kimJ0ezceIKtfkL5eqIhiE9hzAByvQ5by6I xOCKbyL7X4VS1NjQV/3YDZYtKnQutBTBxBmdjcfcCYAqIA09TWjBGs1mAC411W7Va8 AVbwB00MVcnp8d5T66l9mWqhouOCe6620HsOsMar7eQI+HXEW97ogT9oAymv6oJ3D8 UidXrWRPPeOsi7a3AqcjvGQjjxOfVbi4Mqpj8KycE0xrIg1FyJ93cz1pNpho60E43d hgOKzb8ODUYSA== Received: from server-vie001.gnuweeb.org (unknown [192.168.57.1]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 35BFB2109A36; Tue, 15 Jul 2025 05:06:36 +0000 (UTC) From: Alviro Iskandar Setiawan To: Jens Axboe Cc: Alviro Iskandar Setiawan , Linux Kernel Mailing List , io-uring Mailing List , GNU/Weeb Mailing List , Ammar Faizi Subject: [PATCH liburing 1/3] Revert "test/io_uring_register: kill old memfd test" X-Gw-Bpl: wU/cy49Bu1yAPm0bW2qiliFUIEVf+EkEatAboK6pk2H2LSy2bfWlPAiP3YIeQ5aElNkQEhTV9Q== Date: Tue, 15 Jul 2025 12:06:27 +0700 Message-Id: <20250715050629.1513826-2-alviro.iskandar@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250715050629.1513826-1-alviro.iskandar@gnuweeb.org> References: <20250715050629.1513826-1-alviro.iskandar@gnuweeb.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit 732bf609b670631731765a585a68d14ed3fdc9b7. Bring back `CONFIG_HAVE_MEMFD_CREATE` and the associated memfd test to resolve Android build failures caused by: 93d3a7a70b4a ("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 =3D memfd_create("udmabuf-test", MFD_ALLOW_SEALING); | ^ ``` This reversion is a preparation step for a proper fix by ensuring `memfd_create()` usage is guarded and portable. Issue #620 was initially unclear, but we now suspect it stemmed from improper compiler/linker flag combinations. Co-authored-by: Ammar Faizi Signed-off-by: Ammar Faizi Signed-off-by: Alviro Iskandar Setiawan --- configure | 19 +++++++ test/io_uring_register.c | 119 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) diff --git a/configure b/configure index 552f8ae..3c95214 100755 --- a/configure +++ b/configure @@ -379,6 +379,22 @@ if compile_prog "" "" "has_ucontext"; then fi print_config "has_ucontext" "$has_ucontext" =20 +########################################## +# check for memfd_create(2) +has_memfd_create=3D"no" +cat > $TMPC << EOF +#include +int main(int argc, char **argv) +{ + int memfd =3D memfd_create("test", 0); + return 0; +} +EOF +if compile_prog "-Werror=3Dimplicit-function-declaration" "" "has_memfd_cr= eate"; then + has_memfd_create=3D"yes" +fi +print_config "has_memfd_create" "$has_memfd_create" + ########################################## # Check NVME_URING_CMD support nvme_uring_cmd=3D"no" @@ -539,6 +555,9 @@ fi if test "$array_bounds" =3D "yes"; then output_sym "CONFIG_HAVE_ARRAY_BOUNDS" fi +if test "$has_memfd_create" =3D "yes"; then + output_sym "CONFIG_HAVE_MEMFD_CREATE" +fi if test "$nvme_uring_cmd" =3D "yes"; then output_sym "CONFIG_HAVE_NVME_URING" fi diff --git a/test/io_uring_register.c b/test/io_uring_register.c index b53a67d..f08f0ca 100644 --- a/test/io_uring_register.c +++ b/test/io_uring_register.c @@ -32,6 +32,17 @@ static int pagesize; static rlim_t mlock_limit; static int devnull; =20 +#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 + + static int expect_fail(int fd, unsigned int opcode, void *arg, unsigned int nr_args, int error, int error2) { @@ -466,6 +477,113 @@ static int __test_poll_ringfd(int ring_flags) return status; } =20 +static int test_shmem(void) +{ + const char pattern =3D 0xEA; + const int len =3D 4096; + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + struct io_uring ring; + struct iovec iov; + int memfd, ret, i; + char *mem; + int pipefd[2] =3D {-1, -1}; + + ret =3D io_uring_queue_init(8, &ring, 0); + if (ret) + return 1; + + if (pipe(pipefd)) { + perror("pipe"); + return 1; + } + memfd =3D memfd_create("uring-shmem-test", 0); + if (memfd < 0) { + fprintf(stderr, "memfd_create() failed %i\n", -errno); + return 1; + } + if (ftruncate(memfd, len)) { + fprintf(stderr, "can't truncate memfd\n"); + return 1; + } + mem =3D mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, 0); + if (!mem) { + fprintf(stderr, "mmap failed\n"); + return 1; + } + for (i =3D 0; i < len; i++) + mem[i] =3D pattern; + + iov.iov_base =3D mem; + iov.iov_len =3D len; + ret =3D io_uring_register_buffers(&ring, &iov, 1); + if (ret) { + if (ret =3D=3D -EOPNOTSUPP) { + fprintf(stdout, "memfd registration isn't supported, " + "skip\n"); + goto out; + } + + fprintf(stderr, "buffer reg failed: %d\n", ret); + return 1; + } + + /* check that we can read and write from/to shmem reg buffer */ + sqe =3D io_uring_get_sqe(&ring); + io_uring_prep_write_fixed(sqe, pipefd[1], mem, 512, 0, 0); + sqe->user_data =3D 1; + + ret =3D io_uring_submit(&ring); + if (ret !=3D 1) { + fprintf(stderr, "submit write failed\n"); + return 1; + } + ret =3D io_uring_wait_cqe(&ring, &cqe); + if (ret < 0 || cqe->user_data !=3D 1 || cqe->res !=3D 512) { + fprintf(stderr, "reading from shmem failed\n"); + return 1; + } + io_uring_cqe_seen(&ring, cqe); + + /* clean it, should be populated with the pattern back from the pipe */ + memset(mem, 0, 512); + sqe =3D io_uring_get_sqe(&ring); + io_uring_prep_read_fixed(sqe, pipefd[0], mem, 512, 0, 0); + sqe->user_data =3D 2; + + ret =3D io_uring_submit(&ring); + if (ret !=3D 1) { + fprintf(stderr, "submit write failed\n"); + return 1; + } + ret =3D io_uring_wait_cqe(&ring, &cqe); + if (ret < 0 || cqe->user_data !=3D 2 || cqe->res !=3D 512) { + fprintf(stderr, "reading from shmem failed\n"); + return 1; + } + io_uring_cqe_seen(&ring, cqe); + + for (i =3D 0; i < 512; i++) { + if (mem[i] !=3D pattern) { + fprintf(stderr, "data integrity fail\n"); + return 1; + } + } + + ret =3D io_uring_unregister_buffers(&ring); + if (ret) { + fprintf(stderr, "buffer unreg failed: %d\n", ret); + return 1; + } +out: + io_uring_queue_exit(&ring); + close(pipefd[0]); + close(pipefd[1]); + munmap(mem, len); + close(memfd); + return 0; +} + static int test_poll_ringfd(void) { int ret; @@ -526,6 +644,7 @@ int main(int argc, char **argv) /* uring poll on the uring fd */ status |=3D test_poll_ringfd(); =20 + status |=3D test_shmem(); if (status) fprintf(stderr, "FAIL\n"); =20 --=20 Alviro Iskandar Setiawan From nobody Tue Oct 7 03:47:51 2025 Received: from server-vie001.gnuweeb.org (server-vie001.gnuweeb.org [89.58.62.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBAF8211A35; Tue, 15 Jul 2025 05:06:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.58.62.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752556005; cv=none; b=gimNuQLwmY11K8YpCqaAJb5GIdpCj15G/15GIgYAtYe6ctPyokVm4mBKq0Cm7bcjNu+sHZTDq8zTeSLpB+uX90CAbZqGdNfsUtesPibr26mM8alvW8m0EeFE999wfjFxhCxUdV6rq5hTlSjhAqpnMTdq6d8s/KKunxGzyt/qBwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752556005; c=relaxed/simple; bh=M4kWDyZCqYHuWnsGkdgcYbAx+5ci5psYJKq6L5JYEH4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ulHkdY1Yk/ajwohgQdeoSP0rdRnnWM1AfNocNpL4qIwtWaW4ubmiPahUl8B40q8/9m/IeAAx9h0m1FVnn1IxwxvvXJnJA6GJ0SSHkCioqtE7bVU5g9Q2XKt5sSDiOGbglWelr5bHHWtSz5PFQHGWZZuXsJ3jsUa2KPs5V3YHGhY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org; spf=pass smtp.mailfrom=gnuweeb.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b=ZIhi5pfT; arc=none smtp.client-ip=89.58.62.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b="ZIhi5pfT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1752555996; bh=M4kWDyZCqYHuWnsGkdgcYbAx+5ci5psYJKq6L5JYEH4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=ZIhi5pfTkYwr5WPSGDV9MMUub7QPY1/ty6c+SJ4fEBsuTolic3DQDJtHu/6tDyqAz ZO9t9zKb/rRZSEgcWRpRz5EnIUfmmTTKTzJ08+mSH1Uu89VWWTABo4uO7H1ohY8A40 snyeEVIwYif6vmzE+HRZqKyhbCYuTDpGfWG0BA8Be9xNRvHMepLWXJ1zkBk2hlVqhq MpnChGp/M7Y+gy7b24leJHbwTEL9JFfQBgLy7++5RkaXHiKPi8X8zeb3IK+TnONvtc f/JvPd/NW2b0ZSr2MnusmRoBQx+T4pUwnZNX/6E58SOLkkLQWT+tFdPIxXq1S7QjCw X+KoBKI3GNOHg== Received: from server-vie001.gnuweeb.org (unknown [192.168.57.1]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 526C52109A3A; Tue, 15 Jul 2025 05:06:36 +0000 (UTC) From: Alviro Iskandar Setiawan To: Jens Axboe Cc: Alviro Iskandar Setiawan , Linux Kernel Mailing List , io-uring Mailing List , GNU/Weeb Mailing List , Ammar Faizi Subject: [PATCH liburing 2/3] test: Move `memfd_create()` to helpers.c, make it accessible for all tests X-Gw-Bpl: wU/cy49Bu1yAPm0bW2qiliFUIEVf+EkEatAboK6pk2H2LSy2bfWlPAiP3YIeQ5aElNkQEhTV9Q== Date: Tue, 15 Jul 2025 12:06:28 +0700 Message-Id: <20250715050629.1513826-3-alviro.iskandar@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250715050629.1513826-1-alviro.iskandar@gnuweeb.org> References: <20250715050629.1513826-1-alviro.iskandar@gnuweeb.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously, the static definition of `memfd_create()` was limited to io_uring_register.c. Now, promote it to a shared location accessible to all test cases, ensuring that future tests using `memfd_create()` do not trigger build failures on Android targets where the syscall is undefined in the standard headers. It improves portability and prevents regressions across test builds. Co-authored-by: Ammar Faizi Signed-off-by: Ammar Faizi Signed-off-by: Alviro Iskandar Setiawan --- test/helpers.c | 8 ++++++++ test/helpers.h | 5 +++++ test/io_uring_register.c | 11 ----------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/test/helpers.c b/test/helpers.c index 0589548..f1d4477 100644 --- a/test/helpers.c +++ b/test/helpers.c @@ -18,6 +18,14 @@ #include "helpers.h" #include "liburing.h" =20 +#ifndef CONFIG_HAVE_MEMFD_CREATE +#include +int memfd_create(const char *name, unsigned int flags) +{ + return (int)syscall(SYS_memfd_create, name, flags); +} +#endif + /* * Helper for allocating memory in tests. */ diff --git a/test/helpers.h b/test/helpers.h index 3f0c11a..8ab0920 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -122,6 +122,11 @@ unsigned long long mtime_since_now(struct timeval *tv); unsigned long long utime_since(const struct timeval *s, const struct timev= al *e); unsigned long long utime_since_now(struct timeval *tv); =20 +#ifndef CONFIG_HAVE_MEMFD_CREATE +#include +#endif +int memfd_create(const char *name, unsigned int flags); + #ifdef __cplusplus } #endif diff --git a/test/io_uring_register.c b/test/io_uring_register.c index f08f0ca..c36c4d8 100644 --- a/test/io_uring_register.c +++ b/test/io_uring_register.c @@ -32,17 +32,6 @@ static int pagesize; static rlim_t mlock_limit; static int devnull; =20 -#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 - - static int expect_fail(int fd, unsigned int opcode, void *arg, unsigned int nr_args, int error, int error2) { --=20 Alviro Iskandar Setiawan From nobody Tue Oct 7 03:47:51 2025 Received: from server-vie001.gnuweeb.org (server-vie001.gnuweeb.org [89.58.62.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBB5A258CF2; Tue, 15 Jul 2025 05:06:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.58.62.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752556005; cv=none; b=Q4Onn8a4KtkTQ7DJTClBz12pkCtQM4DDTRHOvU07AjeDj1RVF9i9RBvNUB2tWvq5OhhSo43kSpHNskm99aEi1H9c1ERQwoYXcQyXcEmF4kBUnB/aKvMwphMheASZStToO5Nt/sRWFmVC38anrwqOZ7NRKuGkQa2fJwZXDjJ/aNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752556005; c=relaxed/simple; bh=soufQIX6TYMmC/348jS3xW4pvirGNiNwAJl7GhmX8LY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n3SR/hvHN5Tq20cAXokwtLAY2HOrMIs8P8YrqAuv3LKK/hrw+dfMsuvNPSznCpWJ3LzgoIP/7McmVsgXTXPMMLxx9XFTlKD2/fPuYSoHLO0Ni2VbQjbkMF5T5gdHUZRcxNupgCEL3Vhdt2F7wsohixllJ5f6Pg5/LTXiHzr06qw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org; spf=pass smtp.mailfrom=gnuweeb.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b=VwPXuDtp; arc=none smtp.client-ip=89.58.62.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b="VwPXuDtp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1752555996; bh=soufQIX6TYMmC/348jS3xW4pvirGNiNwAJl7GhmX8LY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From: Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date: Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type: Content-Transfer-Encoding; b=VwPXuDtp0zGuGgujQQNYxkzW6Z55i4yLmNobzT1hpwnIJLeU99Vm+JJOzmXBV6clL gTDlykdvM0dahSdZol+9NMFLK4oznNOEk/YKWyBJ46v0xJQJM5y7785YYqajOPquIu FMX+WNod3MSJGwfTtZeLaqtWmN74vo+zpOKUdkUSjik5K8VyI3QbOJf2SU72N/2caE 30Oj9MV13eECqJVATyXnk1K0fDnvesHFP4b3rhJQugVqAPLyxTvgzPBMmxfZ6PSBZG SP/79UhSKkcDYJwC+WSJIKVVD/VRg0HgPV+VSkAJ8FALlVyffQGQKMJ2W3V/JwBN60 A3T73aUQZqA8w== Received: from server-vie001.gnuweeb.org (unknown [192.168.57.1]) by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id 6D31D2109A3B; Tue, 15 Jul 2025 05:06:36 +0000 (UTC) From: Alviro Iskandar Setiawan To: Jens Axboe Cc: Alviro Iskandar Setiawan , Linux Kernel Mailing List , io-uring Mailing List , GNU/Weeb Mailing List , Ammar Faizi Subject: [PATCH liburing 3/3] examples: Add `memfd_create()` helper X-Gw-Bpl: wU/cy49Bu1yAPm0bW2qiliFUIEVf+EkEatAboK6pk2H2LSy2bfWlPAiP3YIeQ5aElNkQEhTV9Q== Date: Tue, 15 Jul 2025 12:06:29 +0700 Message-Id: <20250715050629.1513826-4-alviro.iskandar@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250715050629.1513826-1-alviro.iskandar@gnuweeb.org> References: <20250715050629.1513826-1-alviro.iskandar@gnuweeb.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add `memfd_create()` helper to handle missing defintion on an environment where `CONFIG_HAVE_MEMFD_CREATE` is not defined. Co-authored-by: Ammar Faizi Signed-off-by: Ammar Faizi Signed-off-by: Alviro Iskandar Setiawan --- examples/helpers.c | 8 ++++++++ examples/helpers.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/examples/helpers.c b/examples/helpers.c index 483ddee..8c112f1 100644 --- a/examples/helpers.c +++ b/examples/helpers.c @@ -13,6 +13,14 @@ =20 #include "helpers.h" =20 +#ifndef CONFIG_HAVE_MEMFD_CREATE +#include +int memfd_create(const char *name, unsigned int flags) +{ + return (int)syscall(SYS_memfd_create, name, flags); +} +#endif + int setup_listening_socket(int port, int ipv6) { struct sockaddr_in srv_addr =3D { }; diff --git a/examples/helpers.h b/examples/helpers.h index 44543e1..0b6f15f 100644 --- a/examples/helpers.h +++ b/examples/helpers.h @@ -17,4 +17,9 @@ void *t_aligned_alloc(size_t alignment, size_t size); =20 void t_error(int status, int errnum, const char *format, ...); =20 +#ifndef CONFIG_HAVE_MEMFD_CREATE +#include +#endif +int memfd_create(const char *name, unsigned int flags); + #endif --=20 Alviro Iskandar Setiawan