From 4fd6614e8f1225082b638f5759c87abbbfc91266 Mon Sep 17 00:00:00 2001 From: Alexandro Sanchez Bach Date: Thu, 8 Nov 2018 16:11:14 +0100 Subject: [PATCH] Unified IOCTL definitions Signed-off-by: Alexandro Sanchez Bach --- include/darwin/hax_interface_mac.h | 47 +++++-------------- include/hax_interface.h | 60 +++++++++++++++++++++++++ include/linux/hax_interface_linux.h | 47 +++++-------------- include/windows/hax_interface_windows.h | 5 +++ platforms/windows/hax_entry.h | 56 ----------------------- 5 files changed, 87 insertions(+), 128 deletions(-) diff --git a/include/darwin/hax_interface_mac.h b/include/darwin/hax_interface_mac.h index d6b6b692..a5bb82b9 100644 --- a/include/darwin/hax_interface_mac.h +++ b/include/darwin/hax_interface_mac.h @@ -33,42 +33,17 @@ #include -/* 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_HAX_IO(access, code, type) \ + _IO(0, code) +#define HAX_IOCTL_HAX_IOR(access, code, type) \ + _IOR(0, code, type) +#define HAX_IOCTL_HAX_IOW(access, code, type) \ + _IOW(0, code, type) +#define HAX_IOCTL_HAX_IOWR(access, code, type) \ + _IOWR(0, code, type) + +#define HAX_IOCTL(access, code, type) \ + HAX_IOCTL_##access(0, code, type) #define HAX_KERNEL64_CS 0x80 #define HAX_KERNEL32_CS 0x08 diff --git a/include/hax_interface.h b/include/hax_interface.h index 00951dbe..367f255d 100644 --- a/include/hax_interface.h +++ b/include/hax_interface.h @@ -49,6 +49,66 @@ #include "windows/hax_interface_windows.h" #endif +#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) + +// Only for backward compatibility with old Qemu. +#define HAX_VM_IOCTL_VCPU_CREATE_ORIG \ + HAX_IOCTL(HAX_IOR, 0x40, int) + +#define HAX_VM_IOCTL_VCPU_CREATE \ + HAX_IOCTL(HAX_IOWR, 0x40, uint32_t) +#define HAX_VM_IOCTL_ALLOC_RAM \ + HAX_IOCTL(HAX_IOWR, 0x41, struct hax_alloc_ram_info) +#define HAX_VM_IOCTL_SET_RAM \ + HAX_IOCTL(HAX_IOWR, 0x42, struct hax_set_ram_info) +#define HAX_VM_IOCTL_VCPU_DESTROY \ + HAX_IOCTL(HAX_IOR, 0x43, uint32_t) +#define HAX_VM_IOCTL_ADD_RAMBLOCK \ + HAX_IOCTL(HAX_IOW, 0x45, struct hax_ramblock_info) +#define HAX_VM_IOCTL_SET_RAM2 \ + HAX_IOCTL(HAX_IOWR, 0x46, struct hax_set_ram_info2) +#define HAX_VM_IOCTL_PROTECT_RAM \ + HAX_IOCTL(HAX_IOWR, 0x47, struct hax_protect_ram_info) + +#define HAX_VCPU_IOCTL_RUN \ + HAX_IOCTL(HAX_IO, 0x80, void*) +#define HAX_VCPU_IOCTL_SET_MSRS \ + HAX_IOCTL(HAX_IOWR, 0x81, struct hax_msr_data) +#define HAX_VCPU_IOCTL_GET_MSRS \ + HAX_IOCTL(HAX_IOWR, 0x82, struct hax_msr_data) + +#define HAX_VCPU_IOCTL_SET_FPU \ + HAX_IOCTL(HAX_IOW, 0x83, struct fx_layout) +#define HAX_VCPU_IOCTL_GET_FPU \ + HAX_IOCTL(HAX_IOR, 0x84, struct fx_layout) + +#define HAX_VCPU_IOCTL_SETUP_TUNNEL \ + HAX_IOCTL(HAX_IOWR, 0x85, struct hax_tunnel_info) +#define HAX_VCPU_IOCTL_INTERRUPT \ + HAX_IOCTL(HAX_IOWR, 0x86, uint32_t) +#define HAX_VCPU_IOCTL_SET_REGS \ + HAX_IOCTL(HAX_IOWR, 0x87, struct vcpu_state_t) +#define HAX_VCPU_IOCTL_GET_REGS \ + HAX_IOCTL(HAX_IOWR, 0x88, struct vcpu_state_t) +#define HAX_VCPU_IOCTL_KICKOFF \ + HAX_IOCTL(HAX_IO, 0x89, void*) + +/* API 2.0 */ +#define HAX_VM_IOCTL_NOTIFY_QEMU_VERSION \ + HAX_IOCTL(HAX_IOW, 0x48, struct hax_qemu_version) + +#define HAX_VCPU_IOCTL_DEBUG \ + HAX_IOCTL(HAX_IOW, 0x90, struct hax_debug_t) + #include "vcpu_state.h" struct vmx_msr { diff --git a/include/linux/hax_interface_linux.h b/include/linux/hax_interface_linux.h index a41d29e2..0694301d 100644 --- a/include/linux/hax_interface_linux.h +++ b/include/linux/hax_interface_linux.h @@ -34,42 +34,17 @@ #include -/* 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_HAX_IO(access, code, type) \ + _IO(0, code) +#define HAX_IOCTL_HAX_IOR(access, code, type) \ + _IOR(0, code, type) +#define HAX_IOCTL_HAX_IOW(access, code, type) \ + _IOW(0, code, type) +#define HAX_IOCTL_HAX_IOWR(access, code, type) \ + _IOWR(0, code, type) + +#define HAX_IOCTL(access, code, type) \ + HAX_IOCTL_##access(0, code, type) #define HAX_KERNEL64_CS 0x80 #define HAX_KERNEL32_CS 0x08 diff --git a/include/windows/hax_interface_windows.h b/include/windows/hax_interface_windows.h index 603aad04..e87e97d8 100644 --- a/include/windows/hax_interface_windows.h +++ b/include/windows/hax_interface_windows.h @@ -31,6 +31,11 @@ #ifndef HAX_WINDOWS_HAX_INTERFACE_WINDOWS_H_ #define HAX_WINDOWS_HAX_INTERFACE_WINDOWS_H_ +#define HAX_DEVICE_TYPE 0x4000 + +#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?? diff --git a/platforms/windows/hax_entry.h b/platforms/windows/hax_entry.h index 7e5f44c6..291a0240 100644 --- a/platforms/windows/hax_entry.h +++ b/platforms/windows/hax_entry.h @@ -110,60 +110,4 @@ int smpc_dpc_exit(void); extern PDRIVER_OBJECT HaxDriverObject; -#define HAX_DEVICE_TYPE 0x4000 - -#define HAX_IOCTL_VERSION \ - CTL_CODE(HAX_DEVICE_TYPE, 0x900, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_IOCTL_CREATE_VM \ - CTL_CODE(HAX_DEVICE_TYPE, 0x901, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_IOCTL_CAPABILITY \ - CTL_CODE(HAX_DEVICE_TYPE, 0x910, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_IOCTL_SET_MEMLIMIT \ - CTL_CODE(HAX_DEVICE_TYPE, 0x911, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define HAX_VM_IOCTL_VCPU_CREATE \ - CTL_CODE(HAX_DEVICE_TYPE, 0x902, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VM_IOCTL_ALLOC_RAM \ - CTL_CODE(HAX_DEVICE_TYPE, 0x903, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VM_IOCTL_SET_RAM \ - CTL_CODE(HAX_DEVICE_TYPE, 0x904, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VM_IOCTL_VCPU_DESTROY \ - CTL_CODE(HAX_DEVICE_TYPE, 0x905, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VM_IOCTL_ADD_RAMBLOCK \ - CTL_CODE(HAX_DEVICE_TYPE, 0x913, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VM_IOCTL_SET_RAM2 \ - CTL_CODE(HAX_DEVICE_TYPE, 0x914, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VM_IOCTL_PROTECT_RAM \ - CTL_CODE(HAX_DEVICE_TYPE, 0x915, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define HAX_VCPU_IOCTL_RUN \ - CTL_CODE(HAX_DEVICE_TYPE, 0x906, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_SET_MSRS \ - CTL_CODE(HAX_DEVICE_TYPE, 0x907, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_GET_MSRS \ - CTL_CODE(HAX_DEVICE_TYPE, 0x908, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define HAX_VCPU_IOCTL_SET_FPU \ - CTL_CODE(HAX_DEVICE_TYPE, 0x909, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_GET_FPU \ - CTL_CODE(HAX_DEVICE_TYPE, 0x90a, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define HAX_VCPU_IOCTL_SETUP_TUNNEL \ - CTL_CODE(HAX_DEVICE_TYPE, 0x90b, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_INTERRUPT \ - CTL_CODE(HAX_DEVICE_TYPE, 0x90c, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_SET_REGS \ - CTL_CODE(HAX_DEVICE_TYPE, 0x90d, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_GET_REGS \ - CTL_CODE(HAX_DEVICE_TYPE, 0x90e, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define HAX_VCPU_IOCTL_KICKOFF \ - CTL_CODE(HAX_DEVICE_TYPE, 0x90f, METHOD_BUFFERED, FILE_ANY_ACCESS) - -/* API version 2.0 */ -#define HAX_VM_IOCTL_NOTIFY_QEMU_VERSION \ - CTL_CODE(HAX_DEVICE_TYPE, 0x910, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define HAX_VCPU_IOCTL_DEBUG \ - CTL_CODE(HAX_DEVICE_TYPE, 0x916, METHOD_BUFFERED, FILE_ANY_ACCESS) - #endif // HAX_WINDOWS_HAX_ENTRY_H_