Changeset View
Changeset View
Standalone View
Standalone View
lib/libvmmapi/vmmapi.c
Show First 20 Lines • Show All 1,410 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
vm_restart_instruction(void *arg, int vcpu) | vm_restart_instruction(void *arg, int vcpu) | ||||
{ | { | ||||
struct vmctx *ctx = arg; | struct vmctx *ctx = arg; | ||||
return (ioctl(ctx->fd, VM_RESTART_INSTRUCTION, &vcpu)); | return (ioctl(ctx->fd, VM_RESTART_INSTRUCTION, &vcpu)); | ||||
} | } | ||||
int | |||||
vm_get_device_fd(struct vmctx *ctx) | |||||
{ | |||||
grehan: minor style(9) nit - an extra blank line should be inserted here (also matches other one-line… | |||||
return (ctx->fd); | |||||
} | |||||
Not Done Inline ActionsAs above, this can be cap_ioctl_t grehan: As above, this can be cap_ioctl_t | |||||
const cap_ioctl_t * | |||||
vm_get_ioctls(size_t *len) | |||||
{ | |||||
cap_ioctl_t *cmds; | |||||
/* keep in sync with machine/vmm_dev.h */ | |||||
static const cap_ioctl_t vm_ioctl_cmds[] = { VM_RUN, VM_SUSPEND, VM_REINIT, | |||||
oshogboUnsubmitted Not Done Inline ActionsNot getting this part why we just don't do a global from that? oshogbo: Not getting this part why we just don't do a global from that? | |||||
emasteUnsubmitted Not Done Inline ActionsAPI refinement suggested by @jhb in https://lists.freebsd.org/pipermail/svn-src-all/2017-February/139587.html I wonder if instead of doing this in the executable and exposing vm_get_ioctls, etc. if the API shouldn't really be something like 'vm_limit_rights(ctx)' and this code should be in that function in libvmmapi? It would be something like (assuming you drop vm_get_ioctls() entirely and expose vm_ioctl_cmds[] as a static global in the library): int vm_limit_rights(struct vm_ctx *ctx) { ... cap_rights_init(&rights, CAP_IOCTL, CAP_MMAP_RW); if (cap_rights_limit(ctx->fd, &rights) == -1) { if (errno == ENOSYS) return (0); else return (-1); } /* Shouldn't get ENOSYS here if cap_rights_limit worked. */ return (cap_ioctls_limit(ctx->fd, vm_ioctl_cmds, nitems(vm_ioctl_cmds)); } You wouldn't need vm_get_device_fd() either in this API. emaste: API refinement suggested by @jhb in https://lists.freebsd.org/pipermail/svn-src-all/2017… | |||||
VM_ALLOC_MEMSEG, VM_GET_MEMSEG, VM_MMAP_MEMSEG, VM_MMAP_MEMSEG, | |||||
VM_MMAP_GETNEXT, VM_SET_REGISTER, VM_GET_REGISTER, | |||||
VM_SET_SEGMENT_DESCRIPTOR, VM_GET_SEGMENT_DESCRIPTOR, | |||||
VM_INJECT_EXCEPTION, VM_LAPIC_IRQ, VM_LAPIC_LOCAL_IRQ, | |||||
VM_LAPIC_MSI, VM_IOAPIC_ASSERT_IRQ, VM_IOAPIC_DEASSERT_IRQ, | |||||
VM_IOAPIC_PULSE_IRQ, VM_IOAPIC_PINCOUNT, VM_ISA_ASSERT_IRQ, | |||||
VM_ISA_DEASSERT_IRQ, VM_ISA_PULSE_IRQ, VM_ISA_SET_IRQ_TRIGGER, | |||||
VM_SET_CAPABILITY, VM_GET_CAPABILITY, VM_BIND_PPTDEV, | |||||
VM_UNBIND_PPTDEV, VM_MAP_PPTDEV_MMIO, VM_PPTDEV_MSI, | |||||
VM_PPTDEV_MSIX, VM_INJECT_NMI, VM_STATS, VM_STAT_DESC, | |||||
VM_SET_X2APIC_STATE, VM_GET_X2APIC_STATE, | |||||
VM_GET_HPET_CAPABILITIES, VM_GET_GPA_PMAP, VM_GLA2GPA, | |||||
VM_ACTIVATE_CPU, VM_GET_CPUS, VM_SET_INTINFO, VM_GET_INTINFO, | |||||
VM_RTC_WRITE, VM_RTC_READ, VM_RTC_SETTIME, VM_RTC_GETTIME, | |||||
VM_RESTART_INSTRUCTION }; | |||||
if (len == NULL) { | |||||
Not Done Inline ActionsMight be best to pass in a length param - if NULL, the length would be returned but no copy done, similar to how sysctl works. This allows the caller to determine the size of it's buffer. grehan: Might be best to pass in a length param - if NULL, the length would be returned but no copy… | |||||
Not Done Inline ActionsCan I keep the static allocation of the table and just pass a pointer to it or would you prefer dynamic allocation and forcing caller to free() it? kaktus: Can I keep the static allocation of the table and just pass a pointer to it or would you prefer… | |||||
Not Done Inline ActionsNot a lot of prior art in libc :(, but my preference would be to return a const pointer (and size param). grehan: Not a lot of prior art in libc :(, but my preference would be to return a const pointer (and… | |||||
cmds = malloc(sizeof(vm_ioctl_cmds)); | |||||
if (cmds == NULL) | |||||
return (NULL); | |||||
Not Done Inline ActionsMinor style nit: bcopy is used in all other routines in this file. grehan: Minor style nit: bcopy is used in all other routines in this file. | |||||
bcopy(vm_ioctl_cmds, cmds, sizeof(vm_ioctl_cmds)); | |||||
return (cmds); | |||||
} | |||||
*len = nitems(vm_ioctl_cmds); | |||||
return (NULL); | |||||
} | |||||
minor style(9) nit - an extra blank line should be inserted here (also matches other one-line functions in the file).