Changeset View
Changeset View
Standalone View
Standalone View
lib/libvmmapi/vmmapi.c
| Show First 20 Lines • Show All 674 Lines • ▼ Show 20 Lines | |||||
| int | int | ||||
| vm_reinit(struct vmctx *ctx) | vm_reinit(struct vmctx *ctx) | ||||
| { | { | ||||
| return (ioctl(ctx->fd, VM_REINIT, 0)); | return (ioctl(ctx->fd, VM_REINIT, 0)); | ||||
| } | } | ||||
| int | int | ||||
| vm_inject_exception(struct vcpu *vcpu, int vector, int errcode_valid, | |||||
| uint32_t errcode, int restart_instruction) | |||||
| { | |||||
| struct vm_exception exc; | |||||
| exc.vector = vector; | |||||
| exc.error_code = errcode; | |||||
| exc.error_code_valid = errcode_valid; | |||||
| exc.restart_instruction = restart_instruction; | |||||
| return (vcpu_ioctl(vcpu, VM_INJECT_EXCEPTION, &exc)); | |||||
| } | |||||
| int | |||||
| vm_readwrite_kernemu_device(struct vcpu *vcpu, vm_paddr_t gpa, | |||||
| bool write, int size, uint64_t *value) | |||||
| { | |||||
| struct vm_readwrite_kernemu_device irp = { | |||||
| .access_width = fls(size) - 1, | |||||
| .gpa = gpa, | |||||
| .value = write ? *value : ~0ul, | |||||
| }; | |||||
| long cmd = (write ? VM_SET_KERNEMU_DEV : VM_GET_KERNEMU_DEV); | |||||
| int rc; | |||||
| rc = vcpu_ioctl(vcpu, cmd, &irp); | |||||
| if (rc == 0 && !write) | |||||
| *value = irp.value; | |||||
| return (rc); | |||||
| } | |||||
| int | |||||
| vm_capability_name2type(const char *capname) | vm_capability_name2type(const char *capname) | ||||
| { | { | ||||
| int i; | int i; | ||||
| for (i = 0; i < VM_CAP_MAX; i++) { | for (i = 0; i < VM_CAP_MAX; i++) { | ||||
| if (vm_capstrmap[i] != NULL && | if (vm_capstrmap[i] != NULL && | ||||
| strcmp(vm_capstrmap[i], capname) == 0) | strcmp(vm_capstrmap[i], capname) == 0) | ||||
| return (i); | return (i); | ||||
| ▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | vm_get_stat_desc(struct vmctx *ctx, int index) | ||||
| statdesc.index = index; | statdesc.index = index; | ||||
| if (ioctl(ctx->fd, VM_STAT_DESC, &statdesc) == 0) | if (ioctl(ctx->fd, VM_STAT_DESC, &statdesc) == 0) | ||||
| return (statdesc.desc); | return (statdesc.desc); | ||||
| else | else | ||||
| return (NULL); | return (NULL); | ||||
| } | } | ||||
| int | int | ||||
| vm_get_x2apic_state(struct vcpu *vcpu, enum x2apic_state *state) | |||||
| { | |||||
| int error; | |||||
| struct vm_x2apic x2apic; | |||||
| bzero(&x2apic, sizeof(x2apic)); | |||||
| error = vcpu_ioctl(vcpu, VM_GET_X2APIC_STATE, &x2apic); | |||||
| *state = x2apic.state; | |||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_set_x2apic_state(struct vcpu *vcpu, enum x2apic_state state) | |||||
| { | |||||
| int error; | |||||
| struct vm_x2apic x2apic; | |||||
| bzero(&x2apic, sizeof(x2apic)); | |||||
| x2apic.state = state; | |||||
| error = vcpu_ioctl(vcpu, VM_SET_X2APIC_STATE, &x2apic); | |||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_get_gpa_pmap(struct vmctx *ctx, uint64_t gpa, uint64_t *pte, int *num) | vm_get_gpa_pmap(struct vmctx *ctx, uint64_t gpa, uint64_t *pte, int *num) | ||||
| { | { | ||||
| int error, i; | int error, i; | ||||
| struct vm_gpa_pte gpapte; | struct vm_gpa_pte gpapte; | ||||
| bzero(&gpapte, sizeof(gpapte)); | bzero(&gpapte, sizeof(gpapte)); | ||||
| gpapte.gpa = gpa; | gpapte.gpa = gpa; | ||||
| error = ioctl(ctx->fd, VM_GET_GPA_PMAP, &gpapte); | error = ioctl(ctx->fd, VM_GET_GPA_PMAP, &gpapte); | ||||
| if (error == 0) { | if (error == 0) { | ||||
| *num = gpapte.ptenum; | *num = gpapte.ptenum; | ||||
| for (i = 0; i < gpapte.ptenum; i++) | for (i = 0; i < gpapte.ptenum; i++) | ||||
| pte[i] = gpapte.pte[i]; | pte[i] = gpapte.pte[i]; | ||||
| } | } | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | int | ||||
| vm_get_hpet_capabilities(struct vmctx *ctx, uint32_t *capabilities) | |||||
| { | |||||
| int error; | |||||
| struct vm_hpet_cap cap; | |||||
| bzero(&cap, sizeof(struct vm_hpet_cap)); | |||||
| error = ioctl(ctx->fd, VM_GET_HPET_CAPABILITIES, &cap); | |||||
| if (capabilities != NULL) | |||||
| *capabilities = cap.capabilities; | |||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging, | vm_gla2gpa(struct vcpu *vcpu, struct vm_guest_paging *paging, | ||||
| uint64_t gla, int prot, uint64_t *gpa, int *fault) | 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.prot = prot; | gg.prot = prot; | ||||
| ▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | |||||
| vm_set_intinfo(struct vcpu *vcpu, uint64_t info1) | vm_set_intinfo(struct vcpu *vcpu, uint64_t info1) | ||||
| { | { | ||||
| struct vm_intinfo vmii; | struct vm_intinfo vmii; | ||||
| int error; | int error; | ||||
| bzero(&vmii, sizeof(struct vm_intinfo)); | bzero(&vmii, sizeof(struct vm_intinfo)); | ||||
| vmii.info1 = info1; | vmii.info1 = info1; | ||||
| error = vcpu_ioctl(vcpu, VM_SET_INTINFO, &vmii); | error = vcpu_ioctl(vcpu, VM_SET_INTINFO, &vmii); | ||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_rtc_write(struct vmctx *ctx, int offset, uint8_t value) | |||||
| { | |||||
| struct vm_rtc_data rtcdata; | |||||
| int error; | |||||
| bzero(&rtcdata, sizeof(struct vm_rtc_data)); | |||||
| rtcdata.offset = offset; | |||||
| rtcdata.value = value; | |||||
| error = ioctl(ctx->fd, VM_RTC_WRITE, &rtcdata); | |||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_rtc_read(struct vmctx *ctx, int offset, uint8_t *retval) | |||||
| { | |||||
| struct vm_rtc_data rtcdata; | |||||
| int error; | |||||
| bzero(&rtcdata, sizeof(struct vm_rtc_data)); | |||||
| rtcdata.offset = offset; | |||||
| error = ioctl(ctx->fd, VM_RTC_READ, &rtcdata); | |||||
| if (error == 0) | |||||
| *retval = rtcdata.value; | |||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_rtc_settime(struct vmctx *ctx, time_t secs) | |||||
| { | |||||
| struct vm_rtc_time rtctime; | |||||
| int error; | |||||
| bzero(&rtctime, sizeof(struct vm_rtc_time)); | |||||
| rtctime.secs = secs; | |||||
| error = ioctl(ctx->fd, VM_RTC_SETTIME, &rtctime); | |||||
| return (error); | |||||
| } | |||||
| int | |||||
| vm_rtc_gettime(struct vmctx *ctx, time_t *secs) | |||||
| { | |||||
| struct vm_rtc_time rtctime; | |||||
| int error; | |||||
| bzero(&rtctime, sizeof(struct vm_rtc_time)); | |||||
| error = ioctl(ctx->fd, VM_RTC_GETTIME, &rtctime); | |||||
| if (error == 0) | |||||
| *secs = rtctime.secs; | |||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | int | ||||
| vm_restart_instruction(struct vcpu *vcpu) | vm_restart_instruction(struct vcpu *vcpu) | ||||
| { | { | ||||
| int arg; | int arg; | ||||
| ▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines | |||||