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

Commit

Permalink
Fixed ioctl access codes
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 13, 2018
1 parent eb55883 commit 18887e9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
36 changes: 16 additions & 20 deletions include/hax_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,50 +120,46 @@
* - HAX_IOCTL_EXTENSION (0x80) Extension-specific ioctl.
* - type: User argument type.
*/
#define HAX_IOCTL_VERSION \
HAX_IOCTL(HAX_IOWR, 0x00, struct hax_module_version)
#define HAX_IOCTL_GET_API_VERSION \
HAX_IOCTL(HAX_IOR, 0x00, struct hax_module_version)
#define HAX_IOCTL_CREATE_VM \
HAX_IOCTL(HAX_IOWR, 0x01, uint32_t)
HAX_IOCTL(HAX_IOR, 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_CREATE_VCPU \
HAX_IOCTL(HAX_IOW, 0x00, uint32_t)
#define HAX_VM_IOCTL_DESTROY_VCPU \
HAX_IOCTL(HAX_IOW, 0x01, uint32_t)
#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)
HAX_IOCTL(HAX_IOW, 0x02, struct hax_set_ram_info)
#define HAX_VM_IOCTL_ADD_RAMBLOCK \
HAX_IOCTL(HAX_IOW, 0x04, struct hax_ramblock_info)
HAX_IOCTL(HAX_IOW, 0x03, struct hax_ramblock_info)
#define HAX_VM_IOCTL_SET_RAM2 \
HAX_IOCTL(HAX_IOWR, 0x05, struct hax_set_ram_info2)
HAX_IOCTL(HAX_IOW, 0x04, struct hax_set_ram_info2)
#define HAX_VM_IOCTL_PROTECT_RAM \
HAX_IOCTL(HAX_IOWR, 0x06, struct hax_protect_ram_info)
HAX_IOCTL(HAX_IOW, 0x05, 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)
HAX_IOCTL(HAX_IOR, 0x01, struct hax_tunnel_info)
#define HAX_VCPU_IOCTL_GET_REGS \
HAX_IOCTL(HAX_IOWR, 0x02, struct vcpu_state_t)
HAX_IOCTL(HAX_IOR, 0x02, struct vcpu_state_t)
#define HAX_VCPU_IOCTL_SET_REGS \
HAX_IOCTL(HAX_IOWR, 0x03, struct vcpu_state_t)
HAX_IOCTL(HAX_IOW, 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)
HAX_IOCTL(HAX_IOW, 0x07, struct hax_msr_data)
#define HAX_VCPU_IOCTL_INTERRUPT \
HAX_IOCTL(HAX_IOWR, 0x08, uint32_t)
HAX_IOCTL(HAX_IOW, 0x08, uint32_t)
#define HAX_VCPU_IOCTL_DEBUG \
HAX_IOCTL(HAX_IOW, 0x09, struct hax_debug_t)

Expand Down
13 changes: 11 additions & 2 deletions include/windows/hax_interface_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@

#define HAX_DEVICE_TYPE 0x8000

#define HAX_IO \
(FILE_ANY_ACCESS)
#define HAX_IOR \
(FILE_READ_DATA)
#define HAX_IOW \
(FILE_WRITE_DATA)
#define HAX_IOWR \
(FILE_WRITE_DATA | FILE_READ_DATA)

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

/*
* This is for MAC compatible mode, so should not be used
Expand Down
8 changes: 3 additions & 5 deletions platforms/darwin/com_intel_hax_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +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: {
case HAX_VM_IOCTL_ALLOC_RAM__LEGACY: {
struct hax_alloc_ram_info *info;
info = (struct hax_alloc_ram_info *)data;
hax_info("IOCTL_ALLOC_RAM: vm_id=%d, va=0x%llx, size=0x%x,"
Expand Down Expand Up @@ -525,7 +524,7 @@ static int hax_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag,

switch (cmd) {
case HAX_IOCTL_VERSION__LEGACY:
case HAX_IOCTL_VERSION: {
case HAX_IOCTL_GET_API_VERSION: {
struct hax_module_version *version;
version = (struct hax_module_version *)data;
version->cur_version = HAX_CUR_VERSION;
Expand All @@ -539,8 +538,7 @@ static int hax_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag,
hax_get_capability(capab, sizeof(struct hax_capabilityinfo), NULL);
break;
}
case HAX_IOCTL_SET_MEMLIMIT__LEGACY:
case HAX_IOCTL_SET_MEMLIMIT: {
case HAX_IOCTL_SET_MEMLIMIT__LEGACY: {
struct hax_set_memlimit *memlimit;
memlimit = (struct hax_set_memlimit*)data;
ret = hax_set_memlimit(memlimit, sizeof(struct hax_set_memlimit),
Expand Down
3 changes: 1 addition & 2 deletions platforms/linux/components.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ static long hax_vm_ioctl(struct file *filp, unsigned int cmd,
}
break;
}
case HAX_VM_IOCTL_ALLOC_RAM__LEGACY:
case HAX_VM_IOCTL_ALLOC_RAM: {
case HAX_VM_IOCTL_ALLOC_RAM__LEGACY: {
struct hax_alloc_ram_info info;
if (copy_from_user(&info, argp, sizeof(info))) {
ret = -EFAULT;
Expand Down
5 changes: 2 additions & 3 deletions platforms/linux/hax_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static long hax_dev_ioctl(struct file *filp, unsigned int cmd,

switch (cmd) {
case HAX_IOCTL_VERSION__LEGACY:
case HAX_IOCTL_VERSION: {
case HAX_IOCTL_GET_API_VERSION: {
struct hax_module_version version = {};
version.cur_version = HAX_CUR_VERSION;
version.compat_version = HAX_COMPAT_VERSION;
Expand All @@ -86,8 +86,7 @@ static long hax_dev_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT;
break;
}
case HAX_IOCTL_SET_MEMLIMIT__LEGACY:
case HAX_IOCTL_SET_MEMLIMIT: {
case HAX_IOCTL_SET_MEMLIMIT__LEGACY: {
struct hax_set_memlimit memlimit = {};
if (copy_from_user(&memlimit, argp, sizeof(memlimit)))
return -EFAULT;
Expand Down
8 changes: 3 additions & 5 deletions platforms/windows/hax_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ NTSTATUS HaxVmControl(PDEVICE_OBJECT DeviceObject, struct hax_vm_windows *ext,

switch (irpSp->Parameters.DeviceIoControl.IoControlCode) {
case HAX_VM_IOCTL_VCPU_CREATE__LEGACY:
case HAX_VM_IOCTL_VCPU_CREATE: {
case HAX_VM_IOCTL_CREATE_VCPU: {
if (inBufLength < sizeof(uint32_t)) {
ret = STATUS_INVALID_PARAMETER;
goto done;
Expand All @@ -500,8 +500,7 @@ NTSTATUS HaxVmControl(PDEVICE_OBJECT DeviceObject, struct hax_vm_windows *ext,
ret = STATUS_SUCCESS;
break;
}
case HAX_VM_IOCTL_ALLOC_RAM__LEGACY:
case HAX_VM_IOCTL_ALLOC_RAM: {
case HAX_VM_IOCTL_ALLOC_RAM__LEGACY: {
struct hax_alloc_ram_info *info;
if (inBufLength < sizeof(struct hax_alloc_ram_info)) {
ret = STATUS_INVALID_PARAMETER;
Expand Down Expand Up @@ -651,7 +650,7 @@ NTSTATUS HaxDeviceControl(PDEVICE_OBJECT DeviceObject,

switch (irpSp->Parameters.DeviceIoControl.IoControlCode) {
case HAX_IOCTL_VERSION__LEGACY:
case HAX_IOCTL_VERSION:
case HAX_IOCTL_GET_API_VERSION:
if (outBufLength < sizeof(struct hax_module_version)) {
ret = STATUS_INVALID_PARAMETER;
goto done;
Expand Down Expand Up @@ -679,7 +678,6 @@ NTSTATUS HaxDeviceControl(PDEVICE_OBJECT DeviceObject,
break;

case HAX_IOCTL_SET_MEMLIMIT__LEGACY:
case HAX_IOCTL_SET_MEMLIMIT:
if (inBufLength < sizeof(struct hax_set_memlimit)) {
ret = STATUS_INVALID_PARAMETER;
goto done;
Expand Down

0 comments on commit 18887e9

Please sign in to comment.