[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 7/9] memfd: split qemu_memfd_alloc()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH 7/9] memfd: split qemu_memfd_alloc() |
Date: |
Tue, 12 Apr 2016 13:55:27 +0200 |
From: Marc-André Lureau <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
---
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
- [Qemu-devel] [PATCH 0/9] RFC: add memfd memory backend, marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 1/9] exec: check kvm mmu notifiers earlier, marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 2/9] exec: split file_ram_alloc(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 3/9] exec: split qemu_ram_alloc_from_file(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 5/9] RFC: ivshmem: use ram_from_fd(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 4/9] Add memory_region_init_ram_from_fd(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 6/9] exec: remove qemu_set_ram_fd(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 7/9] memfd: split qemu_memfd_alloc(),
marcandre . lureau <=
- [Qemu-devel] [PATCH 8/9] Add memfd based hostmem, marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 9/9] tests: use memfd in vhost-user-test, marcandre . lureau, 2016/04/12