From 6a8b1eb58304d3599b0ddcb57d8340deac56f139 Mon Sep 17 00:00:00 2001 From: neel Date: Sat, 27 Oct 2012 22:58:02 +0000 Subject: Present the bvm dbgport to the guest only when explicitly requested via the "-g" command line option. Suggested by: grehan Obtained from: NetApp --- usr.sbin/bhyve/dbgport.c | 67 +++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/usr.sbin/bhyve/dbgport.c b/usr.sbin/bhyve/dbgport.c index 55efdad..034531c 100644 --- a/usr.sbin/bhyve/dbgport.c +++ b/usr.sbin/bhyve/dbgport.c @@ -44,37 +44,12 @@ __FBSDID("$FreeBSD$"); #include "dbgport.h" #define BVM_DBG_PORT 0x224 +#define BVM_DBG_SIG ('B' << 8 | 'V') static int listen_fd, conn_fd; static struct sockaddr_in sin; -void -init_dbgport(int sport) -{ - conn_fd = -1; - - if ((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("socket"); - exit(1); - } - - sin.sin_len = sizeof(sin); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = htonl(INADDR_ANY); - sin.sin_port = htons(sport); - - if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - perror("bind"); - exit(1); - } - - if (listen(listen_fd, 1) < 0) { - perror("listen"); - exit(1); - } -} - static int dbg_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) @@ -82,6 +57,11 @@ dbg_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, char ch; int nwritten, nread, printonce; + if (bytes == 2 && in) { + *eax = BVM_DBG_SIG; + return (0); + } + if (bytes != 4) return (-1); @@ -122,4 +102,37 @@ again: return (0); } -INOUT_PORT(dbg, BVM_DBG_PORT, IOPORT_F_INOUT, dbg_handler); +static struct inout_port dbgport = { + "bvmdbg", + BVM_DBG_PORT, + IOPORT_F_INOUT, + dbg_handler +}; + +void +init_dbgport(int sport) +{ + conn_fd = -1; + + if ((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("socket"); + exit(1); + } + + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_ANY); + sin.sin_port = htons(sport); + + if (bind(listen_fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + perror("bind"); + exit(1); + } + + if (listen(listen_fd, 1) < 0) { + perror("listen"); + exit(1); + } + + register_inout(&dbgport); +} -- cgit v1.1