[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 05/15] linux-user: add memfd_create
From: |
Laurent Vivier |
Subject: |
[Qemu-devel] [PULL v2 05/15] linux-user: add memfd_create |
Date: |
Wed, 11 Sep 2019 08:49:10 +0200 |
From: Shu-Chun Weng <address@hidden>
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 <address@hidden>
Reviewed-by: Laurent Vivier <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Laurent Vivier <address@hidden>
---
include/qemu/memfd.h | 4 ++++
linux-user/syscall.c | 12 ++++++++++++
util/memfd.c | 2 +-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h
index d551c28b6850..975b6bdb7797 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 b42f59a32c8d..6928f654ced3 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 "qemu/queue.h"
#include <elf.h>
#include <endian.h>
@@ -11938,6 +11939,17 @@ 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));
+ fd_trans_unregister(ret);
+ 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 00334e5b218f..4a3c07e0bee6 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.21.0
- [Qemu-devel] [PULL v2 00/15] Linux user for 4.2 patches, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 02/15] linux-user: Add AT_HWCAP2 for aarch64-linux-user, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 03/15] linux-user: erroneous fd_trans_unregister call, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 04/15] linux-user: fail and report on bad dfilter specs, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 07/15] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 13/15] linux-user: Add support for FDFLUSH ioctl, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 05/15] linux-user: add memfd_create,
Laurent Vivier <=
- [Qemu-devel] [PULL v2 06/15] linux-user: Pass CPUState to MAX_RESERVED_VA, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 08/15] linux-user: Support gdb 'qOffsets' query for ELF, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 09/15] target/xtensa: linux-user: add call0 ABI support, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 11/15] linux-user: Add support for RNDRESEEDCRNG ioctl, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 01/15] linux-user: remove useless variable, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 10/15] linux-user: drop redundant handling of environment variables, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 12/15] linux-user: Add support for FIOGETOWN and FIOSETOWN ioctls, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 15/15] linux-user: Add support for FDRESET, FDRAWCMD, FDTWADDLE, and FDEJECT ioctls, Laurent Vivier, 2019/09/11
- [Qemu-devel] [PULL v2 14/15] linux-user: Add support for FDMSGON and FDMSGOFF ioctls, Laurent Vivier, 2019/09/11
- Re: [Qemu-devel] [PULL v2 00/15] Linux user for 4.2 patches, Peter Maydell, 2019/09/12