Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bhyve/bhyverun.c
Show All 24 Lines | |||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <sys/capsicum.h> | |||||
#endif | |||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <machine/atomic.h> | #include <machine/atomic.h> | ||||
#include <machine/segments.h> | #include <machine/segments.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <capsicum_helpers.h> | |||||
#endif | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | |||||
#include <libgen.h> | #include <libgen.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#include <sysexits.h> | #include <sysexits.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <machine/vmm.h> | #include <machine/vmm.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <machine/vmm_dev.h> | |||||
#endif | |||||
#include <vmmapi.h> | #include <vmmapi.h> | ||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "acpi.h" | #include "acpi.h" | ||||
#include "atkbdc.h" | #include "atkbdc.h" | ||||
#include "inout.h" | #include "inout.h" | ||||
#include "dbgport.h" | #include "dbgport.h" | ||||
#include "fwctl.h" | #include "fwctl.h" | ||||
▲ Show 20 Lines • Show All 640 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static struct vmctx * | static struct vmctx * | ||||
do_open(const char *vmname) | do_open(const char *vmname) | ||||
{ | { | ||||
struct vmctx *ctx; | struct vmctx *ctx; | ||||
int error; | int error; | ||||
bool reinit, romboot; | bool reinit, romboot; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | |||||
const cap_ioctl_t *cmds; | |||||
size_t ncmds; | |||||
#endif | |||||
reinit = romboot = false; | reinit = romboot = false; | ||||
if (lpc_bootrom()) | if (lpc_bootrom()) | ||||
romboot = true; | romboot = true; | ||||
error = vm_create(vmname); | error = vm_create(vmname); | ||||
if (error) { | if (error) { | ||||
Show All 22 Lines | #endif | ||||
} | } | ||||
ctx = vm_open(vmname); | ctx = vm_open(vmname); | ||||
if (ctx == NULL) { | if (ctx == NULL) { | ||||
perror("vm_open"); | perror("vm_open"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_IOCTL, CAP_MMAP_RW); | |||||
if (cap_rights_limit(vm_get_device_fd(ctx), &rights) == -1 && | |||||
errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
vm_get_ioctls(&ncmds); | |||||
cmds = vm_get_ioctls(NULL); | |||||
if (cmds == NULL) | |||||
errx(EX_OSERR, "out of memory"); | |||||
if (cap_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1 && | |||||
errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
free((cap_ioctl_t *)cmds); | |||||
#endif | |||||
if (reinit) { | if (reinit) { | ||||
error = vm_reinit(ctx); | error = vm_reinit(ctx); | ||||
if (error) { | if (error) { | ||||
perror("vm_reinit"); | perror("vm_reinit"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
} | } | ||||
return (ctx); | return (ctx); | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
if (acpi) { | if (acpi) { | ||||
error = acpi_build(ctx, guest_ncpus); | error = acpi_build(ctx, guest_ncpus); | ||||
assert(error == 0); | assert(error == 0); | ||||
} | } | ||||
if (lpc_bootrom()) | if (lpc_bootrom()) | ||||
fwctl_init(); | fwctl_init(); | ||||
#ifndef WITHOUT_CAPSICUM | |||||
caph_cache_catpages(); | |||||
if (caph_limit_stdout() == -1 || caph_limit_stderr() == -1) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
if (cap_enter() == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "cap_enter() failed"); | |||||
#endif | |||||
/* | /* | ||||
* Change the proc title to include the VM name. | * Change the proc title to include the VM name. | ||||
*/ | */ | ||||
setproctitle("%s", vmname); | setproctitle("%s", vmname); | ||||
/* | /* | ||||
* Add CPU 0 | * Add CPU 0 | ||||
Show All 10 Lines |