diff --git a/lib/libvmmapi/amd64/vmmapi_machdep.c b/lib/libvmmapi/amd64/vmmapi_machdep.c --- a/lib/libvmmapi/amd64/vmmapi_machdep.c +++ b/lib/libvmmapi/amd64/vmmapi_machdep.c @@ -37,6 +37,20 @@ #include "vmmapi.h" #include "internal.h" +const char *vm_capstrmap[] = { + [VM_CAP_HALT_EXIT] = "hlt_exit", + [VM_CAP_MTRAP_EXIT] = "mtrap_exit", + [VM_CAP_PAUSE_EXIT] = "pause_exit", + [VM_CAP_UNRESTRICTED_GUEST] = "unrestricted_guest", + [VM_CAP_ENABLE_INVPCID] = "enable_invpcid", + [VM_CAP_BPT_EXIT] = "bpt_exit", + [VM_CAP_RDPID] = "rdpid", + [VM_CAP_RDTSCP] = "rdtscp", + [VM_CAP_IPI_EXIT] = "ipi_exit", + [VM_CAP_MASK_HWINTR] = "mask_hwintr", + [VM_CAP_MAX] = NULL, +}; + int vm_set_desc(struct vcpu *vcpu, int reg, uint64_t base, uint32_t limit, uint32_t access) diff --git a/lib/libvmmapi/internal.h b/lib/libvmmapi/internal.h --- a/lib/libvmmapi/internal.h +++ b/lib/libvmmapi/internal.h @@ -24,4 +24,6 @@ int vcpu_ioctl(struct vcpu *vcpu, u_long cmd, void *arg); +extern const char *vm_capstrmap[]; + #endif /* !__VMMAPI_INTERNAL_H__ */ diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -716,22 +716,14 @@ return (rc); } -static const char *capstrmap[] = { - [VM_CAP_HALT_EXIT] = "hlt_exit", - [VM_CAP_MTRAP_EXIT] = "mtrap_exit", - [VM_CAP_PAUSE_EXIT] = "pause_exit", - [VM_CAP_UNRESTRICTED_GUEST] = "unrestricted_guest", - [VM_CAP_ENABLE_INVPCID] = "enable_invpcid", - [VM_CAP_BPT_EXIT] = "bpt_exit", -}; - int vm_capability_name2type(const char *capname) { int i; - for (i = 0; i < (int)nitems(capstrmap); i++) { - if (strcmp(capstrmap[i], capname) == 0) + for (i = 0; i < VM_CAP_MAX; i++) { + if (vm_capstrmap[i] != NULL && + strcmp(vm_capstrmap[i], capname) == 0) return (i); } @@ -741,8 +733,8 @@ const char * vm_capability_type2name(int type) { - if (type >= 0 && type < (int)nitems(capstrmap)) - return (capstrmap[type]); + if (type >= 0 && type < VM_CAP_MAX) + return (vm_capstrmap[type]); return (NULL); }