tools/console: use xenforeigmemory to map console ring

This patch replaces the usage of xc_map_foreign_range with
xenforeignmemory_map from the stable xenforeignmemory library. Note
there are still other uses of libxc functions which prevents removing
the dependency.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Ian Jackson <iwj@xenproject.org>
This commit is contained in:
Roger Pau Monne authored and Ian Jackson committed 2021-10-11 12:05:38 +01:00
1 parent 2fac4e3ea3
commit e8b42a4e88
2 files changed
+22 -7

No files matched your search

+2 -2
View File
@@ -29,9 +29,9 @@ clean:
distclean: clean
daemon/main.o: daemon/_paths.h
daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) $(CONSOLE_CFLAGS-y)
daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) $(CFLAGS_libxenforeignmemory) $(CONSOLE_CFLAGS-y)
xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxenforeignmemory) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
client/main.o: client/_paths.h
xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c))
+20 -5
View File
@@ -22,6 +22,7 @@
#include "utils.h"
#include "io.h"
#include <xenevtchn.h>
#include <xenforeignmemory.h>
#include <xengnttab.h>
#include <xenstore.h>
#include <xen/io/console.h>
@@ -73,6 +74,7 @@ static int log_time_guest_needts = 1;
static int log_hv_fd = -1;
static xengnttab_handle *xgt_handle = NULL;
static xenforeignmemory_handle *xfm_handle;
static struct pollfd *fds;
static unsigned int current_array_size;
@@ -675,7 +677,7 @@ static void console_unmap_interface(struct console *con)
if (xgt_handle && con->ring_ref == -1)
xengnttab_unmap(xgt_handle, con->interface, 1);
else
munmap(con->interface, XC_PAGE_SIZE);
xenforeignmemory_unmap(xfm_handle, con->interface, 1);
con->interface = NULL;
con->ring_ref = -1;
}
@@ -722,11 +724,12 @@ static int console_create_ring(struct console *con)
con->ring_ref = -1;
}
if (!con->interface) {
xen_pfn_t pfn = ring_ref;
/* Fall back to xc_map_foreign_range */
con->interface = xc_map_foreign_range(
xc, dom->domid, XC_PAGE_SIZE,
PROT_READ|PROT_WRITE,
(unsigned long)ring_ref);
con->interface = xenforeignmemory_map(
xfm_handle, dom->domid, PROT_READ|PROT_WRITE, 1,
&pfn, NULL);
if (con->interface == NULL) {
err = EINVAL;
goto out;
@@ -1341,6 +1344,14 @@ void handle_io(void)
errno, strerror(errno));
}
xfm_handle = xenforeignmemory_open(NULL, 0);
if (xfm_handle == NULL) {
dolog(LOG_ERR,
"Failed to open xen foreign memory handle: %d (%s)",
errno, strerror(errno));
goto out;
}
enum_domains();
for (;;) {
@@ -1462,6 +1473,10 @@ void handle_io(void)
xengnttab_close(xgt_handle);
xgt_handle = NULL;
}
if (xfm_handle != NULL) {
xenforeignmemory_close(xfm_handle);
xfm_handle = NULL;
}
log_hv_evtchn = -1;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.