From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwvE-0004rQ-HW for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apwvC-0008QI-JA for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:56 -0400 Received: from mail-qg0-x230.google.com ([2607:f8b0:400d:c04::230]:36516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwvC-0008QE-9F for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:54 -0400 Received: by mail-qg0-x230.google.com with SMTP id f52so13034850qga.3 for ; Tue, 12 Apr 2016 04:55:54 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Tue, 12 Apr 2016 13:55:27 +0200 Message-Id: <1460462129-17363-8-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> References: <1460462129-17363-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 7/9] memfd: split qemu_memfd_alloc() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- include/qemu/memfd.h | 1 + util/memfd.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/qemu/memfd.h b/include/qemu/memfd.h index 745a8c5..41c24d8 100644 --- a/include/qemu/memfd.h +++ b/include/qemu/memfd.h @@ -16,6 +16,7 @@ #define F_SEAL_WRITE 0x0008 /* prevent writes */ #endif +int qemu_memfd_create(const char *name, size_t size, unsigned int seals); void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, int *fd); void qemu_memfd_free(void *ptr, size_t size, int fd); diff --git a/util/memfd.c b/util/memfd.c index 7c40691..31aaced 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -64,14 +64,10 @@ static int memfd_create(const char *name, unsigned int flags) * memfd with sealing, but may fallback on other methods without * sealing. */ -void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, - int *fd) +int qemu_memfd_create(const char *name, size_t size, unsigned int seals) { - void *ptr; int mfd = -1; - *fd = -1; - #ifdef CONFIG_LINUX if (seals) { mfd = memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC); @@ -117,6 +113,19 @@ void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, } } + return mfd; +} + +void *qemu_memfd_alloc(const char *name, size_t size, unsigned int seals, + int *fd) +{ + void *ptr; + int mfd = qemu_memfd_create(name, size, seals); + + if (mfd == -1) { + return NULL; + } + ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, 0); if (ptr == MAP_FAILED) { perror("mmap"); -- 2.5.5