From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI5RV-0004gk-VS for qemu-devel@nongnu.org; Wed, 22 Jul 2015 21:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZI5RT-0005Z6-SK for qemu-devel@nongnu.org; Wed, 22 Jul 2015 21:37:01 -0400 Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:32876) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZI5RT-0005Yt-LQ for qemu-devel@nongnu.org; Wed, 22 Jul 2015 21:36:59 -0400 Received: by wicmv11 with SMTP id mv11so3272404wic.0 for ; Wed, 22 Jul 2015 18:36:59 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 23 Jul 2015 03:36:39 +0200 Message-Id: <1437615403-13554-3-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1437615403-13554-1-git-send-email-marcandre.lureau@redhat.com> References: <1437615403-13554-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH RFC 2/6] posix: add linux-only memfd fallback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: thibaut.collet@6wind.com, pbonzini@redhat.com, haifeng.lin@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , mst@redhat.com Implement memfd_create() fallback if not available in system libc. memfd_create() is still not included in glibc today, atlhough it's been available since Linux 3.17 in Oct 2014. memfd has numerous advantages over traditional shm/mmap for ipc memory sharing with fd handler, which we are going to make use of for vhost-user logging memory in following patches. Signed-off-by: Marc-André Lureau --- include/qemu/osdep.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 3247364..adc138b 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #ifdef __OpenBSD__ #include @@ -20,6 +21,64 @@ #include +#ifdef CONFIG_LINUX + +#ifndef F_LINUX_SPECIFIC_BASE +#define F_LINUX_SPECIFIC_BASE 1024 +#endif + +#ifndef F_ADD_SEALS +#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */ +#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */ +#define F_SEAL_GROW 0x0004 /* prevent file from growing */ +#define F_SEAL_WRITE 0x0008 /* prevent writes */ +#endif + +#ifndef MFD_ALLOW_SEALING +#define MFD_ALLOW_SEALING 0x0002U +#endif + +#ifndef MFD_CLOEXEC +#define MFD_CLOEXEC 0x0001U +#endif + +#ifndef __NR_memfd_create +# if defined __x86_64__ +# define __NR_memfd_create 319 +# elif defined __arm__ +# define __NR_memfd_create 385 +# elif defined __aarch64__ +# define __NR_memfd_create 279 +# elif defined _MIPS_SIM +# if _MIPS_SIM == _MIPS_SIM_ABI32 +# define __NR_memfd_create 4354 +# endif +# if _MIPS_SIM == _MIPS_SIM_NABI32 +# define __NR_memfd_create 6318 +# endif +# if _MIPS_SIM == _MIPS_SIM_ABI64 +# define __NR_memfd_create 5314 +# endif +# elif defined __i386__ +# define __NR_memfd_create 356 +# else +# warning "__NR_memfd_create unknown for your architecture" +# define __NR_memfd_create 0xffffffff +# endif +#endif + +#ifndef CONFIG_MEMFD +static inline int memfd_create(const char *name, unsigned int flags) +{ + return syscall(__NR_memfd_create, name, flags); +} +#endif + +#endif /* LINUX */ + #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10 /* [u]int_fast*_t not in */ typedef unsigned char uint_fast8_t; -- 2.4.3