qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Shu-Chun Weng via Qemu-devel <qemu-devel@nongnu.org>
To: marcandre.lureau@gmail.com
Cc: arunkaly@google.com, Shu-Chun Weng <scw@google.com>,
	riku.voipio@iki.fi, qemu-devel@nongnu.org, laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v2] linux-user: add memfd_create
Date: Mon, 19 Aug 2019 11:08:31 -0700	[thread overview]
Message-ID: <20190819180831.179075-1-scw@google.com> (raw)
In-Reply-To: <CAFEAcA-GWR6_wGCMWkMHttU3ARJPqfADvNTnqQUU_OzcWgHHuQ@mail.gmail.com>

Add support for the memfd_create syscall. If the host does not have the
libc wrapper, translate to a direct syscall with NC-macro.

Buglink: https://bugs.launchpad.net/qemu/+bug/1734792
Signed-off-by: Shu-Chun Weng <scw@google.com>
---
 include/qemu/memfd.h |  4 ++++
 linux-user/syscall.c | 11 +++++++++++
 util/memfd.c         |  2 +-
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
index d551c28b68..975b6bdb77 100644
--- a/include/qemu/memfd.h
+++ b/include/qemu/memfd.h
@@ -32,6 +32,10 @@
 #define MFD_HUGE_SHIFT 26
 #endif
 
+#if defined CONFIG_LINUX && !defined CONFIG_MEMFD
+int memfd_create(const char *name, unsigned int flags);
+#endif
+
 int qemu_memfd_create(const char *name, size_t size, bool hugetlb,
                       uint64_t hugetlbsize, unsigned int seals, Error **errp);
 bool qemu_memfd_alloc_check(void);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8367cb138d..b506c1f40e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/path.h"
+#include "qemu/memfd.h"
 #include <elf.h>
 #include <endian.h>
 #include <grp.h>
@@ -11938,6 +11939,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
         /* PowerPC specific.  */
         return do_swapcontext(cpu_env, arg1, arg2, arg3);
 #endif
+#ifdef TARGET_NR_memfd_create
+    case TARGET_NR_memfd_create:
+        p = lock_user_string(arg1);
+        if (!p) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(memfd_create(p, arg2));
+        unlock_user(p, arg1, 0);
+        return ret;
+#endif
 
     default:
         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
diff --git a/util/memfd.c b/util/memfd.c
index 00334e5b21..4a3c07e0be 100644
--- a/util/memfd.c
+++ b/util/memfd.c
@@ -35,7 +35,7 @@
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-static int memfd_create(const char *name, unsigned int flags)
+int memfd_create(const char *name, unsigned int flags)
 {
 #ifdef __NR_memfd_create
     return syscall(__NR_memfd_create, name, flags);
-- 
2.23.0.rc1.153.gdeed80330f-goog



  reply	other threads:[~2019-08-19 18:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 21:10 [Qemu-devel] [PATCH] linux-user: add memfd_create Shu-Chun Weng via Qemu-devel
2019-08-18 21:57 ` Philippe Mathieu-Daudé
2019-08-19  7:12 ` Marc-André Lureau
2019-08-19 11:56 ` Peter Maydell
2019-08-19 18:08   ` Shu-Chun Weng via Qemu-devel [this message]
2019-08-19 18:09   ` [Qemu-devel] [PATCH v3] " Shu-Chun Weng via Qemu-devel
2019-08-23 16:48     ` Laurent Vivier
2019-09-10 16:49     ` Laurent Vivier
2019-08-23 16:42   ` [Qemu-devel] [PATCH] " Laurent Vivier
2019-09-10  8:16 ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190819180831.179075-1-scw@google.com \
    --to=qemu-devel@nongnu.org \
    --cc=arunkaly@google.com \
    --cc=laurent@vivier.eu \
    --cc=marcandre.lureau@gmail.com \
    --cc=riku.voipio@iki.fi \
    --cc=scw@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).