Changeset View
Changeset View
Standalone View
Standalone View
lib/libvmmapi/vmmapi.c
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int | int | ||||
vm_create(const char *name) | vm_create(const char *name) | ||||
{ | { | ||||
/* Try to load vmm(4) module before creating a guest. */ | /* Try to load vmm(4) module before creating a guest. */ | ||||
if (modfind("vmm") < 0) | if (modfind("vmm") < 0) | ||||
kldload("vmm"); | kldload("vmm"); | ||||
return (CREATE((char *)name)); | return (CREATE(name)); | ||||
} | } | ||||
struct vmctx * | struct vmctx * | ||||
vm_open(const char *name) | vm_open(const char *name) | ||||
{ | { | ||||
struct vmctx *vm; | struct vmctx *vm; | ||||
int saved_errno; | int saved_errno; | ||||
Show All 25 Lines | vm_destroy(struct vmctx *vm) | ||||
if (vm->fd >= 0) | if (vm->fd >= 0) | ||||
close(vm->fd); | close(vm->fd); | ||||
DESTROY(vm->name); | DESTROY(vm->name); | ||||
free(vm); | free(vm); | ||||
} | } | ||||
int | int | ||||
vm_parse_memsize(const char *optarg, size_t *ret_memsize) | vm_parse_memsize(const char *opt, size_t *ret_memsize) | ||||
{ | { | ||||
char *endptr; | char *endptr; | ||||
size_t optval; | size_t optval; | ||||
int error; | int error; | ||||
optval = strtoul(optarg, &endptr, 0); | optval = strtoul(opt, &endptr, 0); | ||||
if (*optarg != '\0' && *endptr == '\0') { | if (*opt != '\0' && *endptr == '\0') { | ||||
/* | /* | ||||
* For the sake of backward compatibility if the memory size | * For the sake of backward compatibility if the memory size | ||||
* specified on the command line is less than a megabyte then | * specified on the command line is less than a megabyte then | ||||
* it is interpreted as being in units of MB. | * it is interpreted as being in units of MB. | ||||
*/ | */ | ||||
if (optval < MB) | if (optval < MB) | ||||
optval *= MB; | optval *= MB; | ||||
*ret_memsize = optval; | *ret_memsize = optval; | ||||
error = 0; | error = 0; | ||||
} else | } else | ||||
error = expand_number(optarg, ret_memsize); | error = expand_number(opt, ret_memsize); | ||||
return (error); | return (error); | ||||
} | } | ||||
uint32_t | uint32_t | ||||
vm_get_lowmem_limit(struct vmctx *ctx) | vm_get_lowmem_limit(struct vmctx *ctx) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 541 Lines • ▼ Show 20 Lines | vm_inject_exception(struct vmctx *ctx, int vcpu, int vector, int errcode_valid, | ||||
exc.error_code = errcode; | exc.error_code = errcode; | ||||
exc.error_code_valid = errcode_valid; | exc.error_code_valid = errcode_valid; | ||||
exc.restart_instruction = restart_instruction; | exc.restart_instruction = restart_instruction; | ||||
return (ioctl(ctx->fd, VM_INJECT_EXCEPTION, &exc)); | return (ioctl(ctx->fd, VM_INJECT_EXCEPTION, &exc)); | ||||
} | } | ||||
int | int | ||||
vm_apicid2vcpu(struct vmctx *ctx, int apicid) | vm_apicid2vcpu(struct vmctx *ctx __unused, int apicid) | ||||
{ | { | ||||
/* | /* | ||||
* The apic id associated with the 'vcpu' has the same numerical value | * The apic id associated with the 'vcpu' has the same numerical value | ||||
* as the 'vcpu' itself. | * as the 'vcpu' itself. | ||||
*/ | */ | ||||
return (apicid); | return (apicid); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | static const char *capstrmap[] = { | ||||
[VM_CAP_BPT_EXIT] = "bpt_exit", | [VM_CAP_BPT_EXIT] = "bpt_exit", | ||||
}; | }; | ||||
int | int | ||||
vm_capability_name2type(const char *capname) | vm_capability_name2type(const char *capname) | ||||
{ | { | ||||
int i; | int i; | ||||
for (i = 0; i < nitems(capstrmap); i++) { | for (i = 0; i < (int)nitems(capstrmap); i++) { | ||||
if (strcmp(capstrmap[i], capname) == 0) | if (strcmp(capstrmap[i], capname) == 0) | ||||
return (i); | return (i); | ||||
} | } | ||||
return (-1); | return (-1); | ||||
} | } | ||||
const char * | const char * | ||||
vm_capability_type2name(int type) | vm_capability_type2name(int type) | ||||
{ | { | ||||
if (type >= 0 && type < nitems(capstrmap)) | if (type >= 0 && type < (int)nitems(capstrmap)) | ||||
return (capstrmap[type]); | return (capstrmap[type]); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
int | int | ||||
vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, | vm_get_capability(struct vmctx *ctx, int vcpu, enum vm_cap_type cap, | ||||
int *retval) | int *retval) | ||||
▲ Show 20 Lines • Show All 431 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
int | int | ||||
vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, | vm_copy_setup(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, | ||||
uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt, | uint64_t gla, size_t len, int prot, struct iovec *iov, int iovcnt, | ||||
int *fault) | int *fault) | ||||
{ | { | ||||
void *va; | void *va; | ||||
uint64_t gpa; | uint64_t gpa, off; | ||||
int error, i, n, off; | int error, i, n; | ||||
for (i = 0; i < iovcnt; i++) { | for (i = 0; i < iovcnt; i++) { | ||||
iov[i].iov_base = 0; | iov[i].iov_base = 0; | ||||
iov[i].iov_len = 0; | iov[i].iov_len = 0; | ||||
} | } | ||||
while (len) { | while (len) { | ||||
assert(iovcnt > 0); | assert(iovcnt > 0); | ||||
error = vm_gla2gpa(ctx, vcpu, paging, gla, prot, &gpa, fault); | error = vm_gla2gpa(ctx, vcpu, paging, gla, prot, &gpa, fault); | ||||
if (error || *fault) | if (error || *fault) | ||||
return (error); | return (error); | ||||
off = gpa & PAGE_MASK; | off = gpa & PAGE_MASK; | ||||
n = min(len, PAGE_SIZE - off); | n = MIN(len, PAGE_SIZE - off); | ||||
va = vm_map_gpa(ctx, gpa, n); | va = vm_map_gpa(ctx, gpa, n); | ||||
if (va == NULL) | if (va == NULL) | ||||
return (EFAULT); | return (EFAULT); | ||||
iov->iov_base = va; | iov->iov_base = va; | ||||
iov->iov_len = n; | iov->iov_len = n; | ||||
iov++; | iov++; | ||||
iovcnt--; | iovcnt--; | ||||
gla += n; | gla += n; | ||||
len -= n; | len -= n; | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
void | void | ||||
vm_copy_teardown(struct vmctx *ctx, int vcpu, struct iovec *iov, int iovcnt) | vm_copy_teardown(struct vmctx *ctx __unused, int vcpu __unused, | ||||
struct iovec *iov __unused, int iovcnt __unused) | |||||
{ | { | ||||
return; | |||||
} | } | ||||
void | void | ||||
vm_copyin(struct vmctx *ctx, int vcpu, struct iovec *iov, void *vp, size_t len) | vm_copyin(struct vmctx *ctx __unused, int vcpu __unused, struct iovec *iov, | ||||
void *vp, size_t len) | |||||
{ | { | ||||
const char *src; | const char *src; | ||||
char *dst; | char *dst; | ||||
size_t n; | size_t n; | ||||
dst = vp; | dst = vp; | ||||
while (len) { | while (len) { | ||||
assert(iov->iov_len); | assert(iov->iov_len); | ||||
n = min(len, iov->iov_len); | n = min(len, iov->iov_len); | ||||
src = iov->iov_base; | src = iov->iov_base; | ||||
bcopy(src, dst, n); | bcopy(src, dst, n); | ||||
iov++; | iov++; | ||||
dst += n; | dst += n; | ||||
len -= n; | len -= n; | ||||
} | } | ||||
} | } | ||||
void | void | ||||
vm_copyout(struct vmctx *ctx, int vcpu, const void *vp, struct iovec *iov, | vm_copyout(struct vmctx *ctx __unused, int vcpu __unused, const void *vp, | ||||
size_t len) | struct iovec *iov, size_t len) | ||||
{ | { | ||||
const char *src; | const char *src; | ||||
char *dst; | char *dst; | ||||
size_t n; | size_t n; | ||||
src = vp; | src = vp; | ||||
while (len) { | while (len) { | ||||
assert(iov->iov_len); | assert(iov->iov_len); | ||||
▲ Show 20 Lines • Show All 271 Lines • Show Last 20 Lines |