diff options
author | mm <mm@FreeBSD.org> | 2013-03-19 11:09:15 +0000 |
---|---|---|
committer | mm <mm@FreeBSD.org> | 2013-03-19 11:09:15 +0000 |
commit | c94cc27299ba2ab2acf00ca31ec90c92a37b16f7 (patch) | |
tree | dc4e31348d425160553b7ff6655e986ab941fff5 /usr.sbin/bhyveload/bhyveload.c | |
parent | 3a10a36ee8940816a53ed53f8b1ca562b85b68a9 (diff) | |
parent | 38b46fc64e9af0a68fc5ac1ff070b5b90a466812 (diff) | |
download | FreeBSD-src-c94cc27299ba2ab2acf00ca31ec90c92a37b16f7.zip FreeBSD-src-c94cc27299ba2ab2acf00ca31ec90c92a37b16f7.tar.gz |
MFC @248493
Diffstat (limited to 'usr.sbin/bhyveload/bhyveload.c')
-rw-r--r-- | usr.sbin/bhyveload/bhyveload.c | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c index ef12d9f..4cd280c 100644 --- a/usr.sbin/bhyveload/bhyveload.c +++ b/usr.sbin/bhyveload/bhyveload.c @@ -88,8 +88,7 @@ static char *host_base = "/"; static struct termios term, oldterm; static int disk_fd = -1; -static char *vmname, *progname, *membase; -static uint64_t lowmem, highmem; +static char *vmname, *progname; static struct vmctx *ctx; static uint64_t gdtbase, cr3, rsp; @@ -323,30 +322,30 @@ cb_diskioctl(void *arg, int unit, u_long cmd, void *data) static int cb_copyin(void *arg, const void *from, uint64_t to, size_t size) { + char *ptr; to &= 0x7fffffff; - if (to > lowmem) - return (EFAULT); - if (to + size > lowmem) - size = lowmem - to; - memcpy(&membase[to], from, size); + ptr = vm_map_gpa(ctx, to, size); + if (ptr == NULL) + return (EFAULT); + memcpy(ptr, from, size); return (0); } static int cb_copyout(void *arg, uint64_t from, void *to, size_t size) { + char *ptr; from &= 0x7fffffff; - if (from > lowmem) - return (EFAULT); - if (from + size > lowmem) - size = lowmem - from; - memcpy(to, &membase[from], size); + ptr = vm_map_gpa(ctx, from, size); + if (ptr == NULL) + return (EFAULT); + memcpy(to, ptr, size); return (0); } @@ -493,8 +492,8 @@ static void cb_getmem(void *arg, uint64_t *ret_lowmem, uint64_t *ret_highmem) { - *ret_lowmem = lowmem; - *ret_highmem = highmem; + vm_get_memory_seg(ctx, 0, ret_lowmem); + vm_get_memory_seg(ctx, 4 * GB, ret_highmem); } static const char * @@ -551,9 +550,9 @@ static void usage(void) { - printf("usage: %s [-d <disk image path>] [-h <host filesystem path>] " - "[-m <lowmem>][-M <highmem>] " - "<vmname>\n", progname); + fprintf(stderr, + "usage: %s [-m mem-size][-d <disk-path>] [-h <host-path>] " + "<vmname>\n", progname); exit(1); } @@ -562,16 +561,16 @@ main(int argc, char** argv) { void *h; void (*func)(struct loader_callbacks *, void *, int, int); + uint64_t mem_size; int opt, error; char *disk_image; progname = argv[0]; - lowmem = 128 * MB; - highmem = 0; + mem_size = 256 * MB; disk_image = NULL; - while ((opt = getopt(argc, argv, "d:h:m:M:")) != -1) { + while ((opt = getopt(argc, argv, "d:h:m:")) != -1) { switch (opt) { case 'd': disk_image = optarg; @@ -582,13 +581,9 @@ main(int argc, char** argv) break; case 'm': - lowmem = strtoul(optarg, NULL, 0) * MB; + mem_size = strtoul(optarg, NULL, 0) * MB; break; - case 'M': - highmem = strtoul(optarg, NULL, 0) * MB; - break; - case '?': usage(); } @@ -615,20 +610,12 @@ main(int argc, char** argv) exit(1); } - error = vm_setup_memory(ctx, 0, lowmem, &membase); + error = vm_setup_memory(ctx, mem_size, VM_MMAP_ALL); if (error) { - perror("vm_setup_memory(lowmem)"); + perror("vm_setup_memory"); exit(1); } - if (highmem != 0) { - error = vm_setup_memory(ctx, 4 * GB, highmem, NULL); - if (error) { - perror("vm_setup_memory(highmem)"); - exit(1); - } - } - tcgetattr(0, &term); oldterm = term; term.c_lflag &= ~(ICANON|ECHO); |