aboutsummaryrefslogtreecommitdiff
path: root/lib/libvmmapi
diff options
context:
space:
mode:
authorVitaliy Gusev <gusev.vitaliy@gmail.com>2022-06-30 21:21:57 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2022-06-30 21:21:57 +0000
commitf0880ab791a510391a12f2ab7b01889b6774bca0 (patch)
tree4bbe042fbc9f83594658b975b4ed4dc4732d1320 /lib/libvmmapi
parent87f49967d3249e0b536beaa9c7fb5604d5a3919a (diff)
downloadsrc-f0880ab791a510391a12f2ab7b01889b6774bca0.tar.gz
src-f0880ab791a510391a12f2ab7b01889b6774bca0.zip
libvmmapi: Add vm_close()
Currently there is no way to safely free a vm structure without leaking the fd. vm_destroy() closes the fd but also destroys the VM whereas in some cases a VM needs to be opened (vm_open) and then closed (vm_close). Reviewed by: jhb Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D35073
Diffstat (limited to 'lib/libvmmapi')
-rw-r--r--lib/libvmmapi/vmmapi.c9
-rw-r--r--lib/libvmmapi/vmmapi.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c
index e92b3199381f..260c2a2439ff 100644
--- a/lib/libvmmapi/vmmapi.c
+++ b/lib/libvmmapi/vmmapi.c
@@ -141,6 +141,15 @@ err:
}
void
+vm_close(struct vmctx *vm)
+{
+ assert(vm != NULL);
+
+ close(vm->fd);
+ free(vm);
+}
+
+void
vm_destroy(struct vmctx *vm)
{
assert(vm != NULL);
diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h
index 87051973225a..438fd582db0e 100644
--- a/lib/libvmmapi/vmmapi.h
+++ b/lib/libvmmapi/vmmapi.h
@@ -33,6 +33,7 @@
#include <sys/param.h>
#include <sys/cpuset.h>
+#include <machine/vmm.h>
#include <machine/vmm_dev.h>
#include <stdbool.h>
@@ -117,6 +118,7 @@ int vm_munmap_memseg(struct vmctx *ctx, vm_paddr_t gpa, size_t len);
int vm_create(const char *name);
int vm_get_device_fd(struct vmctx *ctx);
struct vmctx *vm_open(const char *name);
+void vm_close(struct vmctx *ctx);
void vm_destroy(struct vmctx *ctx);
int vm_parse_memsize(const char *optarg, size_t *memsize);
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);