Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libvmmapi/vmmapi.c
Show All 34 Lines | |||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/_iovec.h> | #include <sys/_iovec.h> | ||||
#include <sys/cpuset.h> | #include <sys/cpuset.h> | ||||
#include <x86/segments.h> | #include <x86/segments.h> | ||||
#include <machine/specialreg.h> | #include <machine/specialreg.h> | ||||
#include <machine/param.h> | #include <machine/param.h> | ||||
#include <errno.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <libutil.h> | #include <libutil.h> | ||||
▲ Show 20 Lines • Show All 902 Lines • ▼ Show 20 Lines | vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities) | ||||
bzero(&cap, sizeof(struct vm_hpet_cap)); | bzero(&cap, sizeof(struct vm_hpet_cap)); | ||||
error = ioctl(ctx->fd, VM_GET_HPET_CAPABILITIES, &cap); | error = ioctl(ctx->fd, VM_GET_HPET_CAPABILITIES, &cap); | ||||
if (capabilities != NULL) | if (capabilities != NULL) | ||||
*capabilities = cap.capabilities; | *capabilities = cap.capabilities; | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | int | ||||
gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, | vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, | ||||
uint64_t gla, int prot, int *fault, uint64_t *gpa) | uint64_t gla, int prot, uint64_t *gpa, int *fault) | ||||
{ | { | ||||
struct vm_gla2gpa gg; | struct vm_gla2gpa gg; | ||||
int error; | int error; | ||||
bzero(&gg, sizeof(struct vm_gla2gpa)); | bzero(&gg, sizeof(struct vm_gla2gpa)); | ||||
gg.vcpuid = vcpu; | gg.vcpuid = vcpu; | ||||
gg.prot = prot; | gg.prot = prot; | ||||
gg.gla = gla; | gg.gla = gla; | ||||
gg.paging = *paging; | gg.paging = *paging; | ||||
error = ioctl(ctx->fd, VM_GLA2GPA, &gg); | error = ioctl(ctx->fd, VM_GLA2GPA, &gg); | ||||
if (error == 0) { | if (error == 0) { | ||||
*fault = gg.fault; | *fault = gg.fault; | ||||
*gpa = gg.gpa; | *gpa = gg.gpa; | ||||
} | } | ||||
return (error); | return (error); | ||||
} | } | ||||
int | |||||
vm_gla2gpa(struct vmctx *ctx, int vcpu, struct vm_guest_paging *paging, | |||||
uint64_t gla, int prot, uint64_t *gpa) | |||||
{ | |||||
int error, fault; | |||||
error = gla2gpa(ctx, vcpu, paging, gla, prot, &fault, gpa); | |||||
if (fault) | |||||
error = fault; | |||||
return (error); | |||||
} | |||||
#ifndef min | #ifndef min | ||||
#define min(a,b) (((a) < (b)) ? (a) : (b)) | #define min(a,b) (((a) < (b)) ? (a) : (b)) | ||||
#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) | |||||
{ | { | ||||
void *va; | void *va; | ||||
uint64_t gpa; | uint64_t gpa; | ||||
int error, fault, i, n, off; | int error, i, n, off; | ||||
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 = gla2gpa(ctx, vcpu, paging, gla, prot, &fault, &gpa); | error = vm_gla2gpa(ctx, vcpu, paging, gla, prot, &gpa, fault); | ||||
if (error) | if (error || *fault) | ||||
return (-1); | return (error); | ||||
if (fault) | |||||
return (1); | |||||
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 (-1); | 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; | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |