-
Notifications
You must be signed in to change notification settings - Fork 18
/
xhyve.patch
273 lines (247 loc) · 6.62 KB
/
xhyve.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
diff --git a/include/xhyve/mevent.h b/include/xhyve/mevent.h
index 48866bd..d09ed2e 100644
--- a/include/xhyve/mevent.h
+++ b/include/xhyve/mevent.h
@@ -43,5 +43,5 @@ int mevent_enable(struct mevent *evp);
int mevent_disable(struct mevent *evp);
int mevent_delete(struct mevent *evp);
int mevent_delete_close(struct mevent *evp);
-
-void mevent_dispatch(void);
+int mevent_dispatch(void);
+void mevent_exit(void);
diff --git a/include/xhyve/uart_emul.h b/include/xhyve/uart_emul.h
index a4851a1..0cf1b3c 100644
--- a/include/xhyve/uart_emul.h
+++ b/include/xhyve/uart_emul.h
@@ -40,3 +40,5 @@ int uart_legacy_alloc(int unit, int *ioaddr, int *irq);
uint8_t uart_read(struct uart_softc *sc, int offset);
void uart_write(struct uart_softc *sc, int offset, uint8_t value);
int uart_set_backend(struct uart_softc *sc, const char *backend, const char *devname);
+
+extern void go_set_pty_name(char *name);
diff --git a/include/xhyve/xhyve.h b/include/xhyve/xhyve.h
index 5464b2e..ac7f526 100644
--- a/include/xhyve/xhyve.h
+++ b/include/xhyve/xhyve.h
@@ -29,6 +29,7 @@
#pragma once
#include <stdint.h>
+#include <stdbool.h>
#include <xhyve/support/segments.h>
#ifndef CTASSERT /* Allow lint to override */
@@ -44,6 +45,7 @@ extern int guest_ncpus;
extern int print_mac;
extern char *guest_uuid_str;
extern char *vmname;
+extern bool exit_mevent_dispatch_loop;
void xh_vm_inject_fault(int vcpu, int vector, int errcode_valid,
uint32_t errcode);
@@ -79,3 +81,5 @@ void vcpu_add(int fromcpu, int newcpu, uint64_t rip);
int fbsdrun_vmexit_on_hlt(void);
int fbsdrun_vmexit_on_pause(void);
int fbsdrun_virtio_msix(void);
+int run_xhyve(int argc, char *argv[]);
+extern void go_callback_exit(int status);
diff --git a/src/mevent.c b/src/mevent.c
index 34a7d0e..977abcb 100644
--- a/src/mevent.c
+++ b/src/mevent.c
@@ -27,7 +27,7 @@
*/
/*
- * Micro event library for FreeBSD, designed for a single i/o thread
+ * Micro event library for FreeBSD, designed for a single i/o thread
* using kqueue, and having events be persistent by default.
*/
@@ -35,6 +35,7 @@
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
@@ -52,6 +53,7 @@
#define MEV_DEL_PENDING 4
extern char *vmname;
+extern bool exit_mevent_dispatch_loop;
static pthread_t mevent_tid;
static int mevent_timid = 43;
@@ -103,11 +105,11 @@ mevent_pipe_read(int fd, UNUSED enum ev_type type, UNUSED void *param)
} while (status == MEVENT_MAX);
}
-static void
+void
mevent_notify(void)
{
char c;
-
+
/*
* If calling from outside the i/o thread, write a byte on the
* pipe to force the i/o thread to exit the blocking kevent call.
@@ -117,6 +119,12 @@ mevent_notify(void)
}
}
+void mevent_exit(void)
+{
+ char c;
+ write(mevent_pipefd[1], &c, 1);
+}
+
static int
mevent_kq_filter(struct mevent *mevp)
{
@@ -309,7 +317,7 @@ mevent_update(struct mevent *evp, int newstate)
*/
if (evp->me_state == newstate)
return (0);
-
+
mevent_qlock();
evp->me_state = newstate;
@@ -387,8 +395,7 @@ mevent_set_name(void)
{
}
-__attribute__ ((noreturn)) void
-mevent_dispatch(void)
+int mevent_dispatch(void)
{
struct kevent changelist[MEVENT_MAX];
struct kevent eventlist[MEVENT_MAX];
@@ -411,7 +418,8 @@ mevent_dispatch(void)
ret = pipe(mevent_pipefd);
if (ret < 0) {
perror("pipe");
- exit(0);
+ return EPIPE;
+ //exit(0);
}
/*
@@ -421,6 +429,9 @@ mevent_dispatch(void)
assert(pipev != NULL);
for (;;) {
+ if (exit_mevent_dispatch_loop) {
+ break;
+ }
/*
* Build changelist if required.
* XXX the changelist can be put into the blocking call
@@ -442,10 +453,11 @@ mevent_dispatch(void)
if (ret == -1 && errno != EINTR) {
perror("Error return from kevent monitor");
}
-
+
/*
* Handle reported events
*/
mevent_handle(eventlist, ret);
- }
+ }
+ return 0;
}
diff --git a/src/uart_emul.c b/src/uart_emul.c
index d185f74..a8dcd7e 100644
--- a/src/uart_emul.c
+++ b/src/uart_emul.c
@@ -667,6 +667,10 @@ uart_set_backend(struct uart_softc *sc, const char *backend, const char *devname
}
fprintf(stdout, "%s connected to %s\n", devname, ptyname);
+
+ // Sends to Go land the device path name for the slave pseudo-terminal.
+ go_set_pty_name(ptyname);
+
sc->tty.fd = ptyfd;
sc->tty.name = ptyname;
sc->tty.opened = true;
diff --git a/src/xhyve.c b/src/xhyve.c
index aaee5fb..7bc6e89 100644
--- a/src/xhyve.c
+++ b/src/xhyve.c
@@ -76,6 +76,7 @@ typedef int (*vmexit_handler_t)(struct vm_exit *, int *vcpu);
extern int vmexit_task_switch(struct vm_exit *, int *vcpu);
char *vmname = "vm";
+bool exit_mevent_dispatch_loop = FALSE;
int guest_ncpus;
int print_mac;
@@ -156,7 +157,7 @@ usage(int code)
__attribute__ ((noreturn)) static void
show_version()
{
- fprintf(stderr, "%s: %s\n\n%s\n",progname, VERSION,
+ fprintf(stderr, "%s: %s\n\n%s\n",progname, "VERSION",
"xhyve is a port of FreeBSD's bhyve hypervisor to OS X that\n"
"works entirely in userspace and has no other dependencies.\n\n"
"Homepage: https://github.com/mist64/xhyve\n"
@@ -265,8 +266,6 @@ vcpu_thread(void *param)
vcpu_loop(vcpu, vmexit[vcpu].rip);
- /* not reached */
- exit(1);
return (NULL);
}
@@ -521,16 +520,21 @@ vmexit_suspend(struct vm_exit *vme, int *pvcpu)
switch ((int) (how)) {
case VM_SUSPEND_RESET:
- exit(0);
+ go_callback_exit(0);
+ return 0;
case VM_SUSPEND_POWEROFF:
- exit(1);
+ go_callback_exit(1);
+ return 1;
case VM_SUSPEND_HALT:
- exit(2);
+ go_callback_exit(2);
+ return 2;
case VM_SUSPEND_TRIPLEFAULT:
- exit(3);
+ go_callback_exit(3);
+ return 3;
default:
fprintf(stderr, "vmexit_suspend: invalid reason %d\n", how);
- exit(100);
+ go_callback_exit(100);
+ return 100;
}
}
@@ -617,18 +621,22 @@ vcpu_loop(int vcpu, uint64_t startrip)
exit(1);
}
- rc = (*handler[exitcode])(&vmexit[vcpu], &vcpu);
+ rc = (*handler[exitcode])(&vmexit[vcpu], &vcpu);
switch (rc) {
case VMEXIT_CONTINUE:
break;
case VMEXIT_ABORT:
abort();
+ case VM_SUSPEND_HALT:
+ case VM_SUSPEND_POWEROFF:
+ case VM_SUSPEND_RESET:
+ break;
default:
+ fprintf(stderr, "vm_run error %d, errno %d\n", error, errno);
exit(1);
}
}
- fprintf(stderr, "vm_run error %d, errno %d\n", error, errno);
}
static int
@@ -776,7 +784,7 @@ fail:
}
int
-main(int argc, char *argv[])
+run_xhyve(int argc, char* argv[])
{
int c, error, gdb_port, bvmcons, fw;
int dump_guest_memory, max_vcpus, mptgen;
@@ -951,7 +959,7 @@ main(int argc, char *argv[])
/*
* Head off to the main event dispatch loop
*/
- mevent_dispatch();
+ error = mevent_dispatch();
- exit(1);
+ return error;
}