Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
Unified IOCTL definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandro Sanchez Bach <[email protected]>
  • Loading branch information
AlexAltea committed Nov 12, 2018
1 parent 6cbfdc4 commit b144c47
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 135 deletions.
51 changes: 15 additions & 36 deletions include/darwin/hax_interface_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,21 @@

#include <mach/mach_types.h>

/* The mac specific interface to qemu because of mac's
* special handling like hax tunnel allocation etc */
/* HAX model level ioctl */
#define HAX_IOCTL_VERSION _IOWR(0, 0x20, struct hax_module_version)
#define HAX_IOCTL_CREATE_VM _IOWR(0, 0x21, uint32_t)
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)

// Only for backward compatibility with old Qemu.
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)

#define HAX_VM_IOCTL_VCPU_CREATE _IOWR(0, 0x80, uint32_t)
#define HAX_VM_IOCTL_ALLOC_RAM _IOWR(0, 0x81, struct hax_alloc_ram_info)
#define HAX_VM_IOCTL_SET_RAM _IOWR(0, 0x82, struct hax_set_ram_info)
#define HAX_VM_IOCTL_VCPU_DESTROY _IOR(0, 0x83, uint32_t)
#define HAX_VM_IOCTL_ADD_RAMBLOCK _IOW(0, 0x85, struct hax_ramblock_info)
#define HAX_VM_IOCTL_SET_RAM2 _IOWR(0, 0x86, struct hax_set_ram_info2)
#define HAX_VM_IOCTL_PROTECT_RAM _IOWR(0, 0x87, struct hax_protect_ram_info)

#define HAX_VCPU_IOCTL_RUN _IO(0, 0xc0)
#define HAX_VCPU_IOCTL_SET_MSRS _IOWR(0, 0xc1, struct hax_msr_data)
#define HAX_VCPU_IOCTL_GET_MSRS _IOWR(0, 0xc2, struct hax_msr_data)

#define HAX_VCPU_IOCTL_SET_FPU _IOW(0, 0xc3, struct fx_layout)
#define HAX_VCPU_IOCTL_GET_FPU _IOR(0, 0xc4, struct fx_layout)

#define HAX_VCPU_IOCTL_SETUP_TUNNEL _IOWR(0, 0xc5, struct hax_tunnel_info)
#define HAX_VCPU_IOCTL_INTERRUPT _IOWR(0, 0xc6, uint32_t)
#define HAX_VCPU_IOCTL_SET_REGS _IOWR(0, 0xc7, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_GET_REGS _IOWR(0, 0xc8, struct vcpu_state_t)

/* API 2.0 */
#define HAX_VM_IOCTL_NOTIFY_QEMU_VERSION _IOW(0, 0x84, struct hax_qemu_version)

#define HAX_VCPU_IOCTL_DEBUG _IOW(0, 0xc9, struct hax_debug_t)
#define HAX_IOCTL_GROUP 'H'

#define HAX_IOCTL_HAX_IO(code, type) \
_IO(HAX_IOCTL_GROUP, code)
#define HAX_IOCTL_HAX_IOR(code, type) \
_IOR(HAX_IOCTL_GROUP, code, type)
#define HAX_IOCTL_HAX_IOW(code, type) \
_IOW(HAX_IOCTL_GROUP, code, type)
#define HAX_IOCTL_HAX_IOWR(code, type) \
_IOWR(HAX_IOCTL_GROUP, code, type)

#define HAX_LEGACY_IOCTL(access, code_posix, code_windows, type) \
HAX_IOCTL_##access(code_posix, type)
#define HAX_IOCTL(access, code, type) \
HAX_IOCTL_##access(code, type)

#define HAX_KERNEL64_CS 0x80
#define HAX_KERNEL32_CS 0x08
Expand Down
100 changes: 100 additions & 0 deletions include/hax_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,106 @@
#include "windows/hax_interface_windows.h"
#endif

/* Legacy API */
#define HAX_IOCTL_VERSION__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x20, 0x900, struct hax_module_version)
#define HAX_IOCTL_CREATE_VM__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x21, 0x901, uint32_t)
#define HAX_IOCTL_DESTROY_VM__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOW, 0x22, 0x902, uint32_t)
#define HAX_IOCTL_CAPABILITY__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOR, 0x23, 0x910, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x24, 0x911, struct hax_set_memlimit)

#define HAX_VM_IOCTL_VCPU_CREATE__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x80, 0x902, uint32_t)
#define HAX_VM_IOCTL_ALLOC_RAM__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x81, 0x903, struct hax_alloc_ram_info)
#define HAX_VM_IOCTL_SET_RAM__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x82, 0x904, struct hax_set_ram_info)
#define HAX_VM_IOCTL_VCPU_DESTROY__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOR, 0x83, 0x905, uint32_t)
#define HAX_VM_IOCTL_ADD_RAMBLOCK__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOW, 0x85, 0x913, struct hax_ramblock_info)
#define HAX_VM_IOCTL_SET_RAM2__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x86, 0x914, struct hax_set_ram_info2)
#define HAX_VM_IOCTL_PROTECT_RAM__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0x87, 0x915, struct hax_protect_ram_info)

#define HAX_VCPU_IOCTL_RUN__LEGACY \
HAX_LEGACY_IOCTL(HAX_IO, 0xc0, 0x906, HAX_UNUSED)
#define HAX_VCPU_IOCTL_SETUP_TUNNEL__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0xc5, 0x90b, struct hax_tunnel_info)
#define HAX_VCPU_IOCTL_GET_REGS__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0xc8, 0x90e, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_SET_REGS__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0xc7, 0x90d, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_GET_FPU__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOR, 0xc4, 0x90a, struct fx_layout)
#define HAX_VCPU_IOCTL_SET_FPU__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOW, 0xc3, 0x909, struct fx_layout)
#define HAX_VCPU_IOCTL_GET_MSRS__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0xc2, 0x908, struct hax_msr_data)
#define HAX_VCPU_IOCTL_SET_MSRS__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0xc1, 0x907, struct hax_msr_data)
#define HAX_VCPU_IOCTL_INTERRUPT__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOWR, 0xc6, 0x90c, uint32_t)

// API 2.0
#define HAX_VM_IOCTL_NOTIFY_QEMU_VERSION__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOW, 0x84, 0x910, struct hax_qemu_version)
#define HAX_VCPU_IOCTL_DEBUG__LEGACY \
HAX_LEGACY_IOCTL(HAX_IOW, 0xc9, 0x916, struct hax_debug_t)

/* Current API */
#define HAX_IOCTL_VERSION \
HAX_IOCTL(HAX_IOWR, 0x00, struct hax_module_version)
#define HAX_IOCTL_CREATE_VM \
HAX_IOCTL(HAX_IOWR, 0x01, uint32_t)
#define HAX_IOCTL_DESTROY_VM \
HAX_IOCTL(HAX_IOW, 0x02, uint32_t)
#define HAX_IOCTL_CAPABILITY \
HAX_IOCTL(HAX_IOR, 0x03, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT \
HAX_IOCTL(HAX_IOWR, 0x04, struct hax_set_memlimit)

#define HAX_VM_IOCTL_VCPU_CREATE \
HAX_IOCTL(HAX_IOWR, 0x00, uint32_t)
#define HAX_VM_IOCTL_ALLOC_RAM \
HAX_IOCTL(HAX_IOWR, 0x01, struct hax_alloc_ram_info)
#define HAX_VM_IOCTL_SET_RAM \
HAX_IOCTL(HAX_IOWR, 0x02, struct hax_set_ram_info)
#define HAX_VM_IOCTL_VCPU_DESTROY \
HAX_IOCTL(HAX_IOR, 0x03, uint32_t)
#define HAX_VM_IOCTL_ADD_RAMBLOCK \
HAX_IOCTL(HAX_IOW, 0x04, struct hax_ramblock_info)
#define HAX_VM_IOCTL_SET_RAM2 \
HAX_IOCTL(HAX_IOWR, 0x05, struct hax_set_ram_info2)
#define HAX_VM_IOCTL_PROTECT_RAM \
HAX_IOCTL(HAX_IOWR, 0x06, struct hax_protect_ram_info)

#define HAX_VCPU_IOCTL_RUN \
HAX_IOCTL(HAX_IO, 0x00, HAX_UNUSED)
#define HAX_VCPU_IOCTL_SETUP_TUNNEL \
HAX_IOCTL(HAX_IOWR, 0x01, struct hax_tunnel_info)
#define HAX_VCPU_IOCTL_GET_REGS \
HAX_IOCTL(HAX_IOWR, 0x02, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_SET_REGS \
HAX_IOCTL(HAX_IOWR, 0x03, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_GET_FPU \
HAX_IOCTL(HAX_IOR, 0x04, struct fx_layout)
#define HAX_VCPU_IOCTL_SET_FPU \
HAX_IOCTL(HAX_IOW, 0x05, struct fx_layout)
#define HAX_VCPU_IOCTL_GET_MSRS \
HAX_IOCTL(HAX_IOWR, 0x06, struct hax_msr_data)
#define HAX_VCPU_IOCTL_SET_MSRS \
HAX_IOCTL(HAX_IOWR, 0x07, struct hax_msr_data)
#define HAX_VCPU_IOCTL_INTERRUPT \
HAX_IOCTL(HAX_IOWR, 0x08, uint32_t)
#define HAX_VCPU_IOCTL_DEBUG \
HAX_IOCTL(HAX_IOW, 0x09, struct hax_debug_t)

#include "vcpu_state.h"

struct vmx_msr {
Expand Down
51 changes: 15 additions & 36 deletions include/linux/hax_interface_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,21 @@

#include <asm/ioctl.h>

/* The mac specific interface to qemu because of mac's
* special handling like hax tunnel allocation etc */
/* HAX model level ioctl */
#define HAX_IOCTL_VERSION _IOWR(0, 0x20, struct hax_module_version)
#define HAX_IOCTL_CREATE_VM _IOWR(0, 0x21, uint32_t)
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)

// Only for backward compatibility with old Qemu.
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)

#define HAX_VM_IOCTL_VCPU_CREATE _IOWR(0, 0x80, uint32_t)
#define HAX_VM_IOCTL_ALLOC_RAM _IOWR(0, 0x81, struct hax_alloc_ram_info)
#define HAX_VM_IOCTL_SET_RAM _IOWR(0, 0x82, struct hax_set_ram_info)
#define HAX_VM_IOCTL_VCPU_DESTROY _IOR(0, 0x83, uint32_t)
#define HAX_VM_IOCTL_ADD_RAMBLOCK _IOW(0, 0x85, struct hax_ramblock_info)
#define HAX_VM_IOCTL_SET_RAM2 _IOWR(0, 0x86, struct hax_set_ram_info2)
#define HAX_VM_IOCTL_PROTECT_RAM _IOWR(0, 0x87, struct hax_protect_ram_info)

#define HAX_VCPU_IOCTL_RUN _IO(0, 0xc0)
#define HAX_VCPU_IOCTL_SET_MSRS _IOWR(0, 0xc1, struct hax_msr_data)
#define HAX_VCPU_IOCTL_GET_MSRS _IOWR(0, 0xc2, struct hax_msr_data)

#define HAX_VCPU_IOCTL_SET_FPU _IOW(0, 0xc3, struct fx_layout)
#define HAX_VCPU_IOCTL_GET_FPU _IOR(0, 0xc4, struct fx_layout)

#define HAX_VCPU_IOCTL_SETUP_TUNNEL _IOWR(0, 0xc5, struct hax_tunnel_info)
#define HAX_VCPU_IOCTL_INTERRUPT _IOWR(0, 0xc6, uint32_t)
#define HAX_VCPU_IOCTL_SET_REGS _IOWR(0, 0xc7, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_GET_REGS _IOWR(0, 0xc8, struct vcpu_state_t)

/* API 2.0 */
#define HAX_VM_IOCTL_NOTIFY_QEMU_VERSION _IOW(0, 0x84, struct hax_qemu_version)

#define HAX_VCPU_IOCTL_DEBUG _IOW(0, 0xc9, struct hax_debug_t)
#define HAX_DEVICE_TYPE 'H'

#define HAX_IOCTL_HAX_IO(code, type) \
_IO(HAX_DEVICE_TYPE, code)
#define HAX_IOCTL_HAX_IOR(code, type) \
_IOR(HAX_DEVICE_TYPE, code, type)
#define HAX_IOCTL_HAX_IOW(code, type) \
_IOW(HAX_DEVICE_TYPE, code, type)
#define HAX_IOCTL_HAX_IOWR(code, type) \
_IOWR(HAX_DEVICE_TYPE, code, type)

#define HAX_LEGACY_IOCTL(access, code_posix, code_windows, type) \
HAX_IOCTL_##access(code_posix, type)
#define HAX_IOCTL(access, code, type) \
HAX_IOCTL_##access(code, type)

#define HAX_KERNEL64_CS 0x80
#define HAX_KERNEL32_CS 0x08
Expand Down
7 changes: 7 additions & 0 deletions include/windows/hax_interface_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
#ifndef HAX_WINDOWS_HAX_INTERFACE_WINDOWS_H_
#define HAX_WINDOWS_HAX_INTERFACE_WINDOWS_H_

#define HAX_DEVICE_TYPE 0x8000

#define HAX_LEGACY_IOCTL(access, code_posix, code_windows, type) \
CTL_CODE(0x4000, code, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define HAX_IOCTL(access, code, type) \
CTL_CODE(HAX_DEVICE_TYPE, (0x800 | code), METHOD_BUFFERED, FILE_ANY_ACCESS)

/*
* This is for MAC compatible mode, so should not be used
* But how can we make sure it is really not used??
Expand Down
24 changes: 21 additions & 3 deletions platforms/darwin/com_intel_hax_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ static int hax_vcpu_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
}

switch (cmd) {
case HAX_VCPU_IOCTL_RUN__LEGACY:
case HAX_VCPU_IOCTL_RUN: {
ret = vcpu_execute(cvcpu);
break;
}
case HAX_VCPU_IOCTL_SETUP_TUNNEL__LEGACY:
case HAX_VCPU_IOCTL_SETUP_TUNNEL: {
struct hax_tunnel_info info, *uinfo;
uinfo = (struct hax_tunnel_info *)data;
Expand All @@ -153,6 +155,7 @@ static int hax_vcpu_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
uinfo->size = info.size;
break;
}
case HAX_VCPU_IOCTL_SET_MSRS__LEGACY:
case HAX_VCPU_IOCTL_SET_MSRS: {
struct hax_msr_data *msrs;
struct vmx_msr *msr;
Expand All @@ -177,6 +180,7 @@ static int hax_vcpu_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
msrs->done = i;
break;
}
case HAX_VCPU_IOCTL_GET_MSRS__LEGACY:
case HAX_VCPU_IOCTL_GET_MSRS: {
struct hax_msr_data *msrs;
struct vmx_msr *msr;
Expand All @@ -199,36 +203,42 @@ static int hax_vcpu_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
msrs->done = i;
break;
}
case HAX_VCPU_IOCTL_SET_FPU__LEGACY:
case HAX_VCPU_IOCTL_SET_FPU: {
struct fx_layout *fl;
fl = (struct fx_layout *)data;
ret = vcpu_put_fpu(mvcpu2cvcpu(vcpu), fl);
break;
}
case HAX_VCPU_IOCTL_GET_FPU__LEGACY:
case HAX_VCPU_IOCTL_GET_FPU: {
struct fx_layout *fl;
fl = (struct fx_layout *)data;
ret = vcpu_get_fpu(mvcpu2cvcpu(vcpu), fl);
break;
}
case HAX_VCPU_IOCTL_SET_REGS__LEGACY:
case HAX_VCPU_IOCTL_SET_REGS: {
struct vcpu_state_t *vc_state;
vc_state = (struct vcpu_state_t *)data;
ret = vcpu_set_regs(mvcpu2cvcpu(vcpu), vc_state);
break;
}
case HAX_VCPU_IOCTL_GET_REGS__LEGACY:
case HAX_VCPU_IOCTL_GET_REGS: {
struct vcpu_state_t *vc_state;
vc_state = (struct vcpu_state_t *)data;
ret = vcpu_get_regs(mvcpu2cvcpu(vcpu), vc_state);
break;
}
case HAX_VCPU_IOCTL_INTERRUPT__LEGACY:
case HAX_VCPU_IOCTL_INTERRUPT: {
uint8_t vector;
vector = (uint8_t)(*(uint32_t *)data);
vcpu_interrupt(mvcpu2cvcpu(vcpu), vector);
break;
}
case HAX_VCPU_IOCTL_DEBUG__LEGACY:
case HAX_VCPU_IOCTL_DEBUG: {
struct hax_debug_t *hax_debug;
hax_debug = (struct hax_debug_t *)data;
Expand Down Expand Up @@ -364,8 +374,8 @@ static int hax_vm_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
}

switch (cmd) {
case HAX_VM_IOCTL_VCPU_CREATE:
case HAX_VM_IOCTL_VCPU_CREATE_ORIG: {
case HAX_VM_IOCTL_VCPU_CREATE__LEGACY:
case HAX_VM_IOCTL_VCPU_CREATE: {
uint32_t vcpu_id, vm_id;
struct vcpu_t *cvcpu;

Expand All @@ -381,6 +391,7 @@ static int hax_vm_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
}
break;
}
case HAX_VM_IOCTL_ALLOC_RAM__LEGACY:
case HAX_VM_IOCTL_ALLOC_RAM: {
struct hax_alloc_ram_info *info;
info = (struct hax_alloc_ram_info *)data;
Expand All @@ -390,6 +401,7 @@ static int hax_vm_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
ret = hax_vm_add_ramblock(cvm, info->va, info->size);
break;
}
case HAX_VM_IOCTL_ADD_RAMBLOCK__LEGACY:
case HAX_VM_IOCTL_ADD_RAMBLOCK: {
struct hax_ramblock_info *info;
info = (struct hax_ramblock_info *)data;
Expand All @@ -404,6 +416,7 @@ static int hax_vm_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
ret = hax_vm_add_ramblock(cvm, info->start_va, info->size);
break;
}
case HAX_VM_IOCTL_SET_RAM__LEGACY:
case HAX_VM_IOCTL_SET_RAM: {
struct hax_set_ram_info *info;
info = (struct hax_set_ram_info *)data;
Expand All @@ -423,6 +436,7 @@ static int hax_vm_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
ret = hax_vm_set_ram2(cvm, info);
break;
}
case HAX_VM_IOCTL_PROTECT_RAM__LEGACY:
case HAX_VM_IOCTL_PROTECT_RAM: {
struct hax_protect_ram_info *info;
info = (struct hax_protect_ram_info *)data;
Expand All @@ -435,7 +449,7 @@ static int hax_vm_ioctl(dev_t dev, ulong cmd, caddr_t data, int flag,
break;
}
#endif
case HAX_VM_IOCTL_NOTIFY_QEMU_VERSION: {
case HAX_VM_IOCTL_NOTIFY_QEMU_VERSION__LEGACY: {
int pid;
/* MAXCOMLEN + 1 == 17 (see bsd/sys/param.h) */
char task_name[17];
Expand Down Expand Up @@ -526,26 +540,30 @@ static int hax_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag,
int ret = 0;

switch (cmd) {
case HAX_IOCTL_VERSION__LEGACY:
case HAX_IOCTL_VERSION: {
struct hax_module_version *version;
version = (struct hax_module_version *)data;
version->cur_version = HAX_CUR_VERSION;
version->compat_version = HAX_COMPAT_VERSION;
break;
}
case HAX_IOCTL_CAPABILITY__LEGACY:
case HAX_IOCTL_CAPABILITY: {
struct hax_capabilityinfo *capab;
capab = (struct hax_capabilityinfo *)data;
hax_get_capability(capab, sizeof(struct hax_capabilityinfo), NULL);
break;
}
case HAX_IOCTL_SET_MEMLIMIT__LEGACY:
case HAX_IOCTL_SET_MEMLIMIT: {
struct hax_set_memlimit *memlimit;
memlimit = (struct hax_set_memlimit*)data;
ret = hax_set_memlimit(memlimit, sizeof(struct hax_set_memlimit),
NULL);
break;
}
case HAX_IOCTL_CREATE_VM__LEGACY:
case HAX_IOCTL_CREATE_VM: {
int vm_id;
struct vm_t *cvm;
Expand Down
Loading

0 comments on commit b144c47

Please sign in to comment.