whpx 0.1.0

Idiomatic Rust Bindings of Windows Hypervisor Platform
Documentation
// Windows Hypervisor Platform APIs

use core::{ffi::c_void, mem::transmute};

use super::{winhvplatformdefs::*, *};

#[derive(Default, Debug, Clone, Copy)]
#[repr(C)] pub struct WHvPartitionHandle(*mut c_void);

#[derive(Default, Debug, Clone, Copy)]
#[repr(C)] pub struct WHvTriggerHandle(*mut c_void);

#[derive(Default, Debug, Clone, Copy)]
#[repr(C)] pub struct WHvNotificationPortHandle(*mut c_void);

// Platform Capabilities
whv_binding!(WHV_GET_CAPABILITY,WHvGetCapability,whpx_default_get_capability,(capability_code:WHvCapabilityCode,capability_buffer:*mut WHvCapability,buffer_size:u32,written_size:*mut u32));

// Partition Management
whv_binding!(WHV_CREATE_PARTITION,WHvCreatePartition,whpx_default_create_partition,(partition:*mut WHvPartitionHandle));
whv_binding!(WHV_SETUP_PARTITION,WHvSetupPartition,whpx_default_setup_partition,(partition:WHvPartitionHandle));
whv_binding!(WHV_RESET_PARTITION,WHvResetPartition,whpx_default_reset_partition,(partition:WHvPartitionHandle));
whv_binding!(WHV_DELETE_PARTITION,WHvDeletePartition,whpx_default_delete_partition,(partition:WHvPartitionHandle));
whv_binding!(WHV_GET_PARTITION_PROPERTY,WHvGetPartitionProperty,whpx_default_get_partition_property,(partition:WHvPartitionHandle,property_code:WHvPartitionPropertyCode,property_buffer:*mut WHVPartitionProperty,buffer_size:u32,written_size:*mut u32));
whv_binding!(WHV_SET_PARTITION_PROPERTY,WHvSetPartitionProperty,whpx_default_set_partition_property,(partition:WHvPartitionHandle,property_code:WHvPartitionPropertyCode,property_buffer:*const WHVPartitionProperty,buffer_size:u32));
whv_binding!(WHV_SUSPEND_PARTITION_TIME,WHvSuspendPartitionTime,whpx_default_suspend_partition_time,(partition:WHvPartitionHandle));
whv_binding!(WHV_RESUME_PARTITION_TIME,WHvResumePartitionTime,whpx_default_resume_partition_time,(partition:WHvPartitionHandle));
whv_binding!(WHV_GET_PARTITION_COUNTERS,WHvGetPartitionCounters,whpx_default_get_partition_counters,(partition:WHvPartitionHandle,counter_set:WHvPartitionCounterSet,counters_buffer:*mut c_void,buffer_size:u32,written_size:*mut u32));
whv_binding!(WHV_REGISTER_PARTITION_DOORBELL_EVENT,WHvRegisterPartitionDoorbellEvent,whpx_default_register_partition_doorbell_event,(partition:WHvPartitionHandle,match_data:*const WHvDoorbellMatchData,event_handle:*mut c_void));
whv_binding!(WHV_UNREGISTER_PARTITION_DOORBELL_EVENT,WHvUnregisterPartitionDoorbellEvent,whpx_default_unregister_partition_doorbell_event,(partition:WHvPartitionHandle,match_data:*const WHvDoorbellMatchData));

// Memory Management
whv_binding!(WHV_MAP_GPA_RANGE,WHvMapGpaRange,whpx_default_map_gpa_range,(partition:WHvPartitionHandle,source_address:*mut c_void,guest_address:u64,size_in_bytes:u64,flags:WHvMapGpaRangeFlags));
whv_binding!(WHV_UNMAP_GPA_RANGE,WHvUnmapGpaRange,whpx_default_unmap_gpa_range,(partition:WHvPartitionHandle,guest_address:u64,size_in_bytes:u64));
whv_binding!(WHV_MAP_GPA_RANGE2,WHvMapGpaRange2,whpx_default_map_gpa_range2,(partition:WHvPartitionHandle,process:*mut c_void,source_address:*mut c_void,guest_address:u64,size_in_bytes:u64,flags:WHvMapGpaRangeFlags));
whv_binding!(WHV_TRANSLATE_GVA,WHvTranslateGva,whpx_default_translate_gva,(partition:WHvPartitionHandle,vp_index:u32,gva:u64,translation_flags:WHvTranslateGvaFlags,translation_result:*mut WHvTranslateGvaResult,gpa:*mut u64));
whv_binding!(WHV_ADVISE_GPA_RANGE,WHvAdviseGpaRange,whpx_default_advise_gpa_range,(partition:WHvPartitionHandle,gpa_ranges:*const WHvMemoryRangeEntry,gpa_range_count:u32,advice_buffer:*const c_void,advice_size:u32));
whv_binding!(WHV_READ_GPA_RANGE,WHvReadGpaRange,whpx_default_read_gpa_range,(partition:WHvPartitionHandle,vp_index:u32,guest_address:u64,controls:WHvAccessGpaControls,buffer:*mut c_void,size_in_bytes:u64));
whv_binding!(WHV_WRITE_GPA_RANGE,WHvWriteGpaRange,whpx_default_write_gpa_range,(partition:WHvPartitionHandle,vp_index:u32,guest_address:u64,controls:WHvAccessGpaControls,buffer:*const c_void,size_in_bytes:u64));

// Virtual Processor Management
whv_binding!(WHV_CREATE_VIRTUAL_PROCESSOR,WHvCreateVirtualProcessor,whpx_default_create_virtual_processor,(partition:WHvPartitionHandle,vp_index:u32,flags:u32));
whv_binding!(WHV_CREATE_VIRTUAL_PROCESSOR2,WHvCreateVirtualProcessor2,whpx_default_create_virtual_processor2,(partition:WHvPartitionHandle,vp_index:u32,flags:u32,properties:*const WHvVirtualProcessorProperty,property_count:u32));
whv_binding!(WHV_DELETE_VIRTUAL_PROCESSOR,WHvDeleteVirtualProcessor,whpx_default_delete_virtual_processor,(partition:WHvPartitionHandle,vp_index:u32));
whv_binding!(WHV_RUN_VIRTUAL_PROCESSOR,WHvRunVirtualProcessor,whpx_default_run_virtual_processor,(partition:WHvPartitionHandle,vp_index:u32,exit_context:*mut WHvRunVpExitContext,exit_context_size:u32));
whv_binding!(WHV_CANCEL_VIRTUAL_PROCESSOR_RUN,WHvCancelVirtualProcessorRun,whpx_default_cancel_virtual_processor_run,(partition:WHvPartitionHandle,vp_index:u32,flags:u32));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_REGISTERS,WHvGetVirtualProcessorRegisters,whpx_default_get_virtual_processor_registers,(partition:WHvPartitionHandle,vp_index:u32,register_name:*const WHvRegisterName,register_count:u32,register_values:*mut WHvRegisterValue));
whv_binding!(WHV_SET_VIRTUAL_PROCESSOR_REGISTERS,WHvSetVirtualProcessorRegisters,whpx_default_set_virtual_processor_registers,(partition:WHvPartitionHandle,vp_index:u32,register_name:*const WHvRegisterName,register_count:u32,register_values:*const WHvRegisterValue));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE,WHvGetVirtualProcessorInterruptControllerState,whpx_default_get_virtual_processor_interrupt_controller_state,(partition:WHvPartitionHandle,vp_index:u32,state:*mut c_void,state_size:u32,written_size:*mut u32));
whv_binding!(WHV_SET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE,WHvSetVirtualProcessorInterruptControllerState,whpx_default_set_virtual_processor_interrupt_controller_state,(partition:WHvPartitionHandle,vp_index:u32,state:*const WHvX64InterruptControl,state_size:u32));
whv_binding!(WHV_REQUEST_INTERRUPT,WHvRequestInterrupt,whpx_default_request_interrupt,(partition:WHvPartitionHandle,interrupt:*const WHvX64InterruptControl,interrupt_control_size:u32));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_XSAVE_STATE,WHvGetVirtualProcessorXsaveState,whpx_default_get_virtual_processor_xsave_state,(partition:WHvPartitionHandle,vp_index:u32,xsave_state:*mut c_void,xsave_state_size:u32,written_size:*mut u32));
whv_binding!(WHV_SET_VIRTUAL_PROCESSOR_XSAVE_STATE,WHvSetVirtualProcessorXsaveState,whpx_default_set_virtual_processor_xsave_state,(partition:WHvPartitionHandle,vp_index:u32,xsave_state:*const c_void,xsave_state_size:u32));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_COUNTERS,WHvGetVirtualProcessorCounters,whpx_default_get_virtual_processor_counters,(partition:WHvPartitionHandle,vp_index:u32,counter_set:WHvProcessorCounterSet,counters_buffer:*mut c_void,buffer_size:u32,written_size:*mut u32));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE2,WHvGetVirtualProcessorInterruptControllerState2,whpx_default_get_virtual_processor_interrupt_controller_state2,(partition:WHvPartitionHandle,vp_index:u32,state:*mut c_void,state_size:u32,written_size:*mut u32));
whv_binding!(WHV_SET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE2,WHvSetVirtualProcessorInterruptControllerState2,whpx_default_set_virtual_processor_interrupt_controller_state2,(partition:WHvPartitionHandle,vp_index:u32,state:*const c_void,state_size:u32));
whv_binding!(WHV_SIGNAL_VIRTUAL_PROCESSOR_SYNIC_EVENT,WHvSignalVirtualProcessorSynicEvent,whpx_default_signal_virtual_processor_synic_event,(partition:WHvPartitionHandle,synic_event:WHvSynicEventParameters,newly_signaled:*mut bool));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_STATE,WHvGetVirtualProcessorState,whpx_default_get_virtual_processor_state,(partition:WHvPartitionHandle,vp_index:u32,state_type:WHvVirtualProcessorStateType,state_buffer:*mut c_void,state_buffer_size:u32,written_size:*mut u32));
whv_binding!(WHV_SET_VIRTUAL_PROCESSOR_STATE,WHvSetVirtualProcessorState,whpx_default_set_virtual_processor_state,(partition:WHvPartitionHandle,vp_index:u32,state_type:WHvVirtualProcessorStateType,state_buffer:*const c_void,state_buffer_size:u32));
whv_binding!(WHV_GET_VIRTUAL_PROCESSOR_CPUID_OUTPUT,WHvGetVirtualProcessorCpuidOutput,whpx_default_get_virtual_processor_cpuid_output,(partition:WHvPartitionHandle,vp_index:u32,eax:u32,ecx:u32,cpuid_output:*mut WHvCpuidOutput));
whv_binding!(WHV_GET_INTERRUPT_TARGET_VP_SET,WHvGetInterruptTargetVpSet,whpx_default_get_interrupt_target_vp_set,(partition:WHvPartitionHandle,destination:u64,destination_mode:u32,target_vps:*mut u32,vp_count:u32,target_vp_count:*mut u32));
whv_binding!(WHV_POST_VIRTUAL_PROCESSOR_SYNIC_MESSAGE,WHvPostVirtualProcessorSynicMessage,whpx_default_post_virtual_processor_synic_message,(partition:WHvPartitionHandle,vp_index:u32,sint_index:u32,message:*const c_void,message_size:u32));

// Virtual PCI
whv_binding!(WHV_ALLOCATE_VPCI_RESOURCE,WHvAllocateVpciResource,whpx_default_allocate_vpci_resource,(provider:*const c_void,flags:WHvAllocateVpciResourceFlags,resource_descriptor:*const c_void,resource_descriptor_size_in_bytes:u32,vpci_resource:*mut *mut c_void));
whv_binding!(WHV_CREATE_VPCI_DEVICE,WHvCreateVpciDevice,whpx_default_create_vpci_device,(partition:WHvPartitionHandle,logical_device_id:u64,vpci_resource:*mut c_void,flags:WHvCreateVpciDeviceFlags,notification_event:*mut c_void));
whv_binding!(WHV_DELETE_VPCI_DEVICE,WHvDeleteVpciDevice,whpx_default_delete_vpci_device,(partition:WHvPartitionHandle,logical_device_id:u64));
whv_binding!(WHV_GET_VPCI_DEVICE_PROPERTY,WHvGetVpciDeviceProperty,whpx_default_get_vpci_device_property,(partition:WHvPartitionHandle,logical_device_id:u64,property_code:WHvVpciDevicePropertyCode,property_buffer:*mut c_void,size_in_bytes:u32,written_size:*mut u32));
whv_binding!(WHV_GET_VPCI_DEVICE_NOTIFICATION,WHvGetVpciDeviceNotification,whpx_default_get_vpci_device_notification,(partition:WHvPartitionHandle,logical_device_id:u64,notification:*mut WHvVpciDeviceNotification,notification_size_in_bytes:u32));
whv_binding!(WHV_MAP_VPCI_DEVICE_MMIO_RANGES,WHvMapVpciDeviceMmioRanges,whpx_default_map_vpci_device_mmio_ranges,(partition:WHvPartitionHandle,logical_device_id:u64,mapping_count:*mut u32,mappings:*mut *mut WHvVpciMmioMapping));
whv_binding!(WHV_UNMAP_VPCI_DEVICE_MMIO_RANGES,WHvUnmapVpciDeviceMmioRanges,whpx_default_unmap_vpci_device_mmio_ranges,(partition:WHvPartitionHandle,logical_device_id:u64));
whv_binding!(WHV_SET_VPCI_DEVICE_POWER_STATE,WHvSetVpciDevicePowerState,whpx_default_set_vpci_device_power_state,(partition:WHvPartitionHandle,logical_device_id:u64,power_state:DevicePowerState));
whv_binding!(WHV_READ_VPCI_DEVICE_REGISTER,WHvReadVpciDeviceRegister,whpx_default_read_vpci_device_register,(partition:WHvPartitionHandle,logical_device_id:u64,register:*const WHvVpciDeviceRegister,data:*mut c_void));
whv_binding!(WHV_WRITE_VPCI_DEVICE_REGISTER,WHvWriteVpciDeviceRegister,whpx_default_write_vpci_device_register,(partition:WHvPartitionHandle,logical_device_id:u64,register:*const WHvVpciDeviceRegister,data:*const c_void));
whv_binding!(WHV_MAP_VPCI_DEVICE_INTERRUPT,WHvMapVpciDeviceInterrupt,whpx_default_map_vpci_device_interrupt,(partition:WHvPartitionHandle,logical_device_id:u64,index:u32,message_count:u32,target:*const WHvVpciInterruptTarget,msi_address:*mut u64,msi_data:*mut u32));
whv_binding!(WHV_UNMAP_VPCI_DEVICE_INTERRUPT,WHvUnmapVpciDeviceInterrupt,whpx_default_unmap_vpci_device_interrupt,(partition:WHvPartitionHandle,logical_device_id:u64,index:u32));
whv_binding!(WHV_RETARGET_VPCI_DEVICE_INTERRUPT,WHvRetargetVpciDeviceInterrupt,whpx_default_retarget_vpci_device_interrupt,(partition:WHvPartitionHandle,logical_device_id:u64,msi_address:u64,msi_data:u32,target:*const WHvVpciInterruptTarget));
whv_binding!(WHV_REQUEST_VPCI_DEVICE_INTERRUPT,WHvRequestVpciDeviceInterrupt,whpx_default_request_vpci_device_interrupt,(partition:WHvPartitionHandle,logical_device_id:u64,msi_address:u64,msi_data:u32));
whv_binding!(WHV_GET_VPCI_DEVICE_INTERRUPT_TARGET,WHvGetVpciDeviceInterruptTarget,whpx_default_get_vpci_device_interrupt_target,(partition:WHvPartitionHandle,logical_device_id:u64,index:u32,multi_message_number:u32,target:*mut WHvVpciInterruptTarget,target_size_in_bytes:u32,bytes_written:*mut u32));

// Triggers
whv_binding!(WHV_CREATE_TRIGGER,WHvCreateTrigger,whpx_default_create_trigger,(partition:WHvPartitionHandle,parameters:*const WHvTriggerParameters,trigger:*mut WHvTriggerHandle,event_handle:*mut *mut c_void));
whv_binding!(WHV_DELETE_TRIGGER,WHvDeleteTrigger,whpx_default_delete_trigger,(partition:WHvPartitionHandle,trigger:WHvTriggerHandle));
whv_binding!(WHV_UPDATE_TRIGGER_PARAMETERS,WHvUpdateTriggerParameters,whpx_default_update_trigger_parameters,(partition:WHvPartitionHandle,parameters:*const WHvTriggerParameters,trigger:WHvTriggerHandle));

// Notification Ports
whv_binding!(WHV_CREATE_NOTIFICATION_PORT,WHvCreateNotificationPort,whpx_default_create_notification_port,(partition:WHvPartitionHandle,parameters:*const WHvNotificationPortParameters,event_handle:*mut c_void,port:*mut WHvNotificationPortHandle));
whv_binding!(WHV_DELETE_NOTIFICATION_PORT,WHvDeleteNotificationPort,whpx_default_delete_notification_port,(partition:WHvPartitionHandle,port:WHvNotificationPortHandle));
whv_binding!(WHV_SET_NOTIFICATION_PORT_PROPERTY,WHvSetNotificationPortProperty,whpx_default_set_notification_port_property,(partition:WHvPartitionHandle,port:WHvNotificationPortHandle,property_code:WHvNotificationPortPropertyCode,property_value:WHvNotificationPortProperty));

// Migration
whv_binding!(WHV_START_PARTITION_MIGRATION,WHvStartPartitionMigration,whpx_default_start_partition_migration,(partition:WHvPartitionHandle,migration_handle:*mut *mut c_void));
whv_binding!(WHV_CANCEL_PARTITION_MIGRATION,WHvCancelPartitionMigration,whpx_default_cancel_partition_migration,(partition:WHvPartitionHandle));
whv_binding!(WHV_COMPLETE_PARTITION_MIGRATION,WHvCompletePartitionMigration,whpx_default_complete_partition_migration,(partition:WHvPartitionHandle));
whv_binding!(WHV_ACCEPT_PARTITION_MIGRATION,WHvAcceptPartitionMigration,whpx_default_accept_partition_migration,(migration_handle:*mut c_void,partition:*mut WHvPartitionHandle));

pub(super) fn init_bindings()->bool
{
	let dll_base=unsafe{LoadLibraryA(c"WinHvPlatform.dll".as_ptr())};
	if dll_base.is_null()
	{
		return false;
	}
	unsafe
	{
		macro_rules! get_proc_address
		{
			($name:expr,$type:expr,$type_name:ty)=>
			{
				let p=GetProcAddress(dll_base,$type.as_ptr());
				if p.is_null()
				{
					core::hint::cold_path();
				}
				else
				{
					$name=transmute::<*const c_void,$type_name>(p);
				}
			};
		}

		get_proc_address!(WHV_GET_CAPABILITY,c"WHvGetCapability",WHvGetCapability);
		get_proc_address!(WHV_CREATE_PARTITION,c"WHvCreatePartition",WHvCreatePartition);
		get_proc_address!(WHV_SETUP_PARTITION,c"WHvSetupPartition",WHvSetupPartition);
		get_proc_address!(WHV_RESET_PARTITION,c"WHvResetPartition",WHvResetPartition);
		get_proc_address!(WHV_DELETE_PARTITION,c"WHvDeletePartition",WHvDeletePartition);
		get_proc_address!(WHV_GET_PARTITION_PROPERTY,c"WHvGetPartitionProperty",WHvGetPartitionProperty);
		get_proc_address!(WHV_SET_PARTITION_PROPERTY,c"WHvSetPartitionProperty",WHvSetPartitionProperty);
		get_proc_address!(WHV_SUSPEND_PARTITION_TIME,c"WHvSuspendPartitionTime",WHvSuspendPartitionTime);
		get_proc_address!(WHV_RESUME_PARTITION_TIME,c"WHvResumePartitionTime",WHvResumePartitionTime);
		get_proc_address!(WHV_GET_PARTITION_COUNTERS,c"WHvGetPartitionCounters",WHvGetPartitionCounters);
		get_proc_address!(WHV_REGISTER_PARTITION_DOORBELL_EVENT,c"WHvRegisterPartitionDoorbellEvent",WHvRegisterPartitionDoorbellEvent);
		get_proc_address!(WHV_UNREGISTER_PARTITION_DOORBELL_EVENT,c"WHvUnregisterPartitionDoorbellEvent",WHvUnregisterPartitionDoorbellEvent);
		get_proc_address!(WHV_MAP_GPA_RANGE,c"WHvMapGpaRange",WHvMapGpaRange);
		get_proc_address!(WHV_UNMAP_GPA_RANGE,c"WHvUnmapGpaRange",WHvUnmapGpaRange);
		get_proc_address!(WHV_MAP_GPA_RANGE2,c"WHvMapGpaRange2",WHvMapGpaRange2);
		get_proc_address!(WHV_TRANSLATE_GVA,c"WHvTranslateGva",WHvTranslateGva);
		get_proc_address!(WHV_ADVISE_GPA_RANGE,c"WHvAdviseGpaRange",WHvAdviseGpaRange);
		get_proc_address!(WHV_READ_GPA_RANGE,c"WHvReadGpaRange",WHvReadGpaRange);
		get_proc_address!(WHV_WRITE_GPA_RANGE,c"WHvWriteGpaRange",WHvWriteGpaRange);
		get_proc_address!(WHV_CREATE_VIRTUAL_PROCESSOR,c"WHvCreateVirtualProcessor",WHvCreateVirtualProcessor);
		get_proc_address!(WHV_CREATE_VIRTUAL_PROCESSOR2,c"WHvCreateVirtualProcessor2",WHvCreateVirtualProcessor2);
		get_proc_address!(WHV_DELETE_VIRTUAL_PROCESSOR,c"WHvDeleteVirtualProcessor",WHvDeleteVirtualProcessor);
		get_proc_address!(WHV_RUN_VIRTUAL_PROCESSOR,c"WHvRunVirtualProcessor",WHvRunVirtualProcessor);
		get_proc_address!(WHV_CANCEL_VIRTUAL_PROCESSOR_RUN,c"WHvCancelVirtualProcessorRun",WHvCancelVirtualProcessorRun);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_REGISTERS,c"WHvGetVirtualProcessorRegisters",WHvGetVirtualProcessorRegisters);
		get_proc_address!(WHV_SET_VIRTUAL_PROCESSOR_REGISTERS,c"WHvSetVirtualProcessorRegisters",WHvSetVirtualProcessorRegisters);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE,c"WHvGetVirtualProcessorInterruptControllerState",WHvGetVirtualProcessorInterruptControllerState);
		get_proc_address!(WHV_SET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE,c"WHvSetVirtualProcessorInterruptControllerState",WHvSetVirtualProcessorInterruptControllerState);
		get_proc_address!(WHV_REQUEST_INTERRUPT,c"WHvRequestInterrupt",WHvRequestInterrupt);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_XSAVE_STATE,c"WHvGetVirtualProcessorXsaveState",WHvGetVirtualProcessorXsaveState);
		get_proc_address!(WHV_SET_VIRTUAL_PROCESSOR_XSAVE_STATE,c"WHvSetVirtualProcessorXsaveState",WHvSetVirtualProcessorXsaveState);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_COUNTERS,c"WHvGetVirtualProcessorCounters",WHvGetVirtualProcessorCounters);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE2,c"WHvGetVirtualProcessorInterruptControllerState2",WHvGetVirtualProcessorInterruptControllerState2);
		get_proc_address!(WHV_SET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE2,c"WHvSetVirtualProcessorInterruptControllerState2",WHvSetVirtualProcessorInterruptControllerState2);
		get_proc_address!(WHV_SIGNAL_VIRTUAL_PROCESSOR_SYNIC_EVENT,c"WHvSignalVirtualProcessorSynicEvent",WHvSignalVirtualProcessorSynicEvent);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_STATE,c"WHvGetVirtualProcessorState",WHvGetVirtualProcessorState);
		get_proc_address!(WHV_SET_VIRTUAL_PROCESSOR_STATE,c"WHvSetVirtualProcessorState",WHvSetVirtualProcessorState);
		get_proc_address!(WHV_GET_VIRTUAL_PROCESSOR_CPUID_OUTPUT,c"WHvGetVirtualProcessorCpuidOutput",WHvGetVirtualProcessorCpuidOutput);
		get_proc_address!(WHV_GET_INTERRUPT_TARGET_VP_SET,c"WHvGetInterruptTargetVpSet",WHvGetInterruptTargetVpSet);
		get_proc_address!(WHV_POST_VIRTUAL_PROCESSOR_SYNIC_MESSAGE,c"WHvPostVirtualProcessorSynicMessage",WHvPostVirtualProcessorSynicMessage);
		get_proc_address!(WHV_ALLOCATE_VPCI_RESOURCE,c"WHvAllocateVpciResource",WHvAllocateVpciResource);
		get_proc_address!(WHV_CREATE_VPCI_DEVICE,c"WHvCreateVpciDevice",WHvCreateVpciDevice);
		get_proc_address!(WHV_DELETE_VPCI_DEVICE,c"WHvDeleteVpciDevice",WHvDeleteVpciDevice);
		get_proc_address!(WHV_GET_VPCI_DEVICE_PROPERTY,c"WHvGetVpciDeviceProperty",WHvGetVpciDeviceProperty);
		get_proc_address!(WHV_GET_VPCI_DEVICE_NOTIFICATION,c"WHvGetVpciDeviceNotification",WHvGetVpciDeviceNotification);
		get_proc_address!(WHV_MAP_VPCI_DEVICE_MMIO_RANGES,c"WHvMapVpciDeviceMmioRanges",WHvMapVpciDeviceMmioRanges);
		get_proc_address!(WHV_UNMAP_VPCI_DEVICE_MMIO_RANGES,c"WHvUnmapVpciDeviceMmioRanges",WHvUnmapVpciDeviceMmioRanges);
		get_proc_address!(WHV_SET_VPCI_DEVICE_POWER_STATE,c"WHvSetVpciDevicePowerState",WHvSetVpciDevicePowerState);
		get_proc_address!(WHV_READ_VPCI_DEVICE_REGISTER,c"WHvReadVpciDeviceRegister",WHvReadVpciDeviceRegister);
		get_proc_address!(WHV_WRITE_VPCI_DEVICE_REGISTER,c"WHvWriteVpciDeviceRegister",WHvWriteVpciDeviceRegister);
		get_proc_address!(WHV_MAP_VPCI_DEVICE_INTERRUPT,c"WHvMapVpciDeviceInterrupt",WHvMapVpciDeviceInterrupt);
		get_proc_address!(WHV_UNMAP_VPCI_DEVICE_INTERRUPT,c"WHvUnmapVpciDeviceInterrupt",WHvUnmapVpciDeviceInterrupt);
		get_proc_address!(WHV_RETARGET_VPCI_DEVICE_INTERRUPT,c"WHvRetargetVpciDeviceInterrupt",WHvRetargetVpciDeviceInterrupt);
		get_proc_address!(WHV_REQUEST_VPCI_DEVICE_INTERRUPT,c"WHvRequestVpciDeviceInterrupt",WHvRequestVpciDeviceInterrupt);
		get_proc_address!(WHV_GET_VPCI_DEVICE_INTERRUPT_TARGET,c"WHvGetVpciDeviceInterruptTarget",WHvGetVpciDeviceInterruptTarget);
		get_proc_address!(WHV_CREATE_TRIGGER,c"WHvCreateTrigger",WHvCreateTrigger);
		get_proc_address!(WHV_DELETE_TRIGGER,c"WHvDeleteTrigger",WHvDeleteTrigger);
		get_proc_address!(WHV_UPDATE_TRIGGER_PARAMETERS,c"WHvUpdateTriggerParameters",WHvUpdateTriggerParameters);
		get_proc_address!(WHV_CREATE_NOTIFICATION_PORT,c"WHvCreateNotificationPort",WHvCreateNotificationPort);
		get_proc_address!(WHV_DELETE_NOTIFICATION_PORT,c"WHvDeleteNotificationPort",WHvDeleteNotificationPort);
		get_proc_address!(WHV_SET_NOTIFICATION_PORT_PROPERTY,c"WHvSetNotificationPortProperty",WHvSetNotificationPortProperty);
		get_proc_address!(WHV_START_PARTITION_MIGRATION,c"WHvStartPartitionMigration",WHvStartPartitionMigration);
		get_proc_address!(WHV_CANCEL_PARTITION_MIGRATION,c"WHvCancelPartitionMigration",WHvCancelPartitionMigration);
		get_proc_address!(WHV_COMPLETE_PARTITION_MIGRATION,c"WHvCompletePartitionMigration",WHvCompletePartitionMigration);
		get_proc_address!(WHV_ACCEPT_PARTITION_MIGRATION,c"WHvAcceptPartitionMigration",WHvAcceptPartitionMigration);
	}
	true
}

// Macro for wrappers returning Result<(),HResult>
macro_rules! whv_wrapper
{
	($fn_name:ident,$static_fn:ident,$args:tt,$call:tt)=>
	{
		/// ## Safety
		/// This function is a very simple wrapper of WHPX API. Make sure arguments are valid.
		pub unsafe fn $fn_name $args -> Result<(),HResult> {
			let hr = unsafe {
				$static_fn $call
			};
			match hr {
				HResult::S_OK => Ok(()),
				_ => Err(hr),
			}
		}
	};
}

whv_wrapper!(get_capability,WHV_GET_CAPABILITY,(capability_code:WHvCapabilityCode,capability_buffer:*mut WHvCapability,buffer_size:u32,written_size:*mut u32),(capability_code,capability_buffer,buffer_size,written_size));
whv_wrapper!(create_partition,WHV_CREATE_PARTITION,(partition:*mut WHvPartitionHandle),(partition));
whv_wrapper!(setup_partition,WHV_SETUP_PARTITION,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(reset_partition,WHV_RESET_PARTITION,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(delete_partition,WHV_DELETE_PARTITION,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(get_partition_property,WHV_GET_PARTITION_PROPERTY,(partition:WHvPartitionHandle,property_code:WHvPartitionPropertyCode,property_buffer:*mut WHVPartitionProperty,buffer_size:u32,written_size:*mut u32),(partition,property_code,property_buffer,buffer_size,written_size));
whv_wrapper!(set_partition_property,WHV_SET_PARTITION_PROPERTY,(partition:WHvPartitionHandle,property_code:WHvPartitionPropertyCode,property_buffer:*const WHVPartitionProperty,buffer_size:u32),(partition,property_code,property_buffer,buffer_size));
whv_wrapper!(suspend_partition_time,WHV_SUSPEND_PARTITION_TIME,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(resume_partition_time,WHV_RESUME_PARTITION_TIME,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(get_partition_counters,WHV_GET_PARTITION_COUNTERS,(partition:WHvPartitionHandle,counter_set:WHvPartitionCounterSet,counters_buffer:*mut c_void,buffer_size:u32,written_size:*mut u32),(partition,counter_set,counters_buffer,buffer_size,written_size));
whv_wrapper!(register_partition_doorbell_event,WHV_REGISTER_PARTITION_DOORBELL_EVENT,(partition:WHvPartitionHandle,match_data:*const WHvDoorbellMatchData,event_handle:*mut c_void),(partition,match_data,event_handle));
whv_wrapper!(unregister_partition_doorbell_event,WHV_UNREGISTER_PARTITION_DOORBELL_EVENT,(partition:WHvPartitionHandle,match_data:*const WHvDoorbellMatchData),(partition,match_data));
whv_wrapper!(map_gpa_range,WHV_MAP_GPA_RANGE,(partition:WHvPartitionHandle,source_address:*mut c_void,guest_address:u64,size_in_bytes:u64,flags:WHvMapGpaRangeFlags),(partition,source_address,guest_address,size_in_bytes,flags));
whv_wrapper!(unmap_gpa_range,WHV_UNMAP_GPA_RANGE,(partition:WHvPartitionHandle,guest_address:u64,size_in_bytes:u64),(partition,guest_address,size_in_bytes));
whv_wrapper!(map_gpa_range2,WHV_MAP_GPA_RANGE2,(partition:WHvPartitionHandle,process:*mut c_void,source_address:*mut c_void,guest_address:u64,size_in_bytes:u64,flags:WHvMapGpaRangeFlags),(partition,process,source_address,guest_address,size_in_bytes,flags));
whv_wrapper!(translate_gva,WHV_TRANSLATE_GVA,(partition:WHvPartitionHandle,vp_index:u32,gva:u64,translation_flags:WHvTranslateGvaFlags,translation_result:*mut WHvTranslateGvaResult,gpa:*mut u64),(partition,vp_index,gva,translation_flags,translation_result,gpa));
whv_wrapper!(advise_gpa_range,WHV_ADVISE_GPA_RANGE,(partition:WHvPartitionHandle,gpa_ranges:*const WHvMemoryRangeEntry,gpa_range_count:u32,advice_buffer:*const c_void,advice_size:u32),(partition,gpa_ranges,gpa_range_count,advice_buffer,advice_size));
whv_wrapper!(read_gpa_range,WHV_READ_GPA_RANGE,(partition:WHvPartitionHandle,vp_index:u32,guest_address:u64,controls:WHvAccessGpaControls,buffer:*mut c_void,size_in_bytes:u64),(partition,vp_index,guest_address,controls,buffer,size_in_bytes));
whv_wrapper!(write_gpa_range,WHV_WRITE_GPA_RANGE,(partition:WHvPartitionHandle,vp_index:u32,guest_address:u64,controls:WHvAccessGpaControls,buffer:*const c_void,size_in_bytes:u64),(partition,vp_index,guest_address,controls,buffer,size_in_bytes));
whv_wrapper!(create_virtual_processor,WHV_CREATE_VIRTUAL_PROCESSOR,(partition:WHvPartitionHandle,vp_index:u32,flags:u32),(partition,vp_index,flags));
whv_wrapper!(create_virtual_processor2,WHV_CREATE_VIRTUAL_PROCESSOR2,(partition:WHvPartitionHandle,vp_index:u32,flags:u32,properties:*const WHvVirtualProcessorProperty,property_count:u32),(partition,vp_index,flags,properties,property_count));
whv_wrapper!(delete_virtual_processor,WHV_DELETE_VIRTUAL_PROCESSOR,(partition:WHvPartitionHandle,vp_index:u32),(partition,vp_index));
whv_wrapper!(run_virtual_processor,WHV_RUN_VIRTUAL_PROCESSOR,(partition:WHvPartitionHandle,vp_index:u32,exit_context:*mut WHvRunVpExitContext,exit_context_size:u32),(partition,vp_index,exit_context,exit_context_size));
whv_wrapper!(cancel_virtual_processor_run,WHV_CANCEL_VIRTUAL_PROCESSOR_RUN,(partition:WHvPartitionHandle,vp_index:u32,flags:u32),(partition,vp_index,flags));
whv_wrapper!(get_virtual_processor_registers,WHV_GET_VIRTUAL_PROCESSOR_REGISTERS,(partition:WHvPartitionHandle,vp_index:u32,register_name:*const WHvRegisterName,register_count:u32,register_values:*mut WHvRegisterValue),(partition,vp_index,register_name,register_count,register_values));
whv_wrapper!(set_virtual_processor_registers,WHV_SET_VIRTUAL_PROCESSOR_REGISTERS,(partition:WHvPartitionHandle,vp_index:u32,register_name:*const WHvRegisterName,register_count:u32,register_values:*const WHvRegisterValue),(partition,vp_index,register_name,register_count,register_values));
whv_wrapper!(get_virtual_processor_interrupt_controller_state,WHV_GET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE,(partition:WHvPartitionHandle,vp_index:u32,state:*mut c_void,state_size:u32,written_size:*mut u32),(partition,vp_index,state,state_size,written_size));
whv_wrapper!(set_virtual_processor_interrupt_controller_state,WHV_SET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE,(partition:WHvPartitionHandle,vp_index:u32,state:*const WHvX64InterruptControl,state_size:u32),(partition,vp_index,state,state_size));
whv_wrapper!(request_interrupt,WHV_REQUEST_INTERRUPT,(partition:WHvPartitionHandle,interrupt:*const WHvX64InterruptControl,interrupt_control_size:u32),(partition,interrupt,interrupt_control_size));
whv_wrapper!(get_virtual_processor_xsave_state,WHV_GET_VIRTUAL_PROCESSOR_XSAVE_STATE,(partition:WHvPartitionHandle,vp_index:u32,xsave_state:*mut c_void,xsave_state_size:u32,written_size:*mut u32),(partition,vp_index,xsave_state,xsave_state_size,written_size));
whv_wrapper!(set_virtual_processor_xsave_state,WHV_SET_VIRTUAL_PROCESSOR_XSAVE_STATE,(partition:WHvPartitionHandle,vp_index:u32,xsave_state:*const c_void,xsave_state_size:u32),(partition,vp_index,xsave_state,xsave_state_size));
whv_wrapper!(get_virtual_processor_counters,WHV_GET_VIRTUAL_PROCESSOR_COUNTERS,(partition:WHvPartitionHandle,vp_index:u32,counter_set:WHvProcessorCounterSet,counters_buffer:*mut c_void,buffer_size:u32,written_size:*mut u32),(partition,vp_index,counter_set,counters_buffer,buffer_size,written_size));
whv_wrapper!(get_virtual_processor_interrupt_controller_state2,WHV_GET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE2,(partition:WHvPartitionHandle,vp_index:u32,state:*mut c_void,state_size:u32,written_size:*mut u32),(partition,vp_index,state,state_size,written_size));
whv_wrapper!(set_virtual_processor_interrupt_controller_state2,WHV_SET_VIRTUAL_PROCESSOR_INTERRUPT_CONTROLLER_STATE2,(partition:WHvPartitionHandle,vp_index:u32,state:*const c_void,state_size:u32),(partition,vp_index,state,state_size));
whv_wrapper!(signal_virtual_processor_synic_event,WHV_SIGNAL_VIRTUAL_PROCESSOR_SYNIC_EVENT,(partition:WHvPartitionHandle,synic_event:WHvSynicEventParameters,newly_signaled:*mut bool),(partition,synic_event,newly_signaled));
whv_wrapper!(get_virtual_processor_state,WHV_GET_VIRTUAL_PROCESSOR_STATE,(partition:WHvPartitionHandle,vp_index:u32,state_type:WHvVirtualProcessorStateType,state_buffer:*mut c_void,state_buffer_size:u32,written_size:*mut u32),(partition,vp_index,state_type,state_buffer,state_buffer_size,written_size));
whv_wrapper!(set_virtual_processor_state,WHV_SET_VIRTUAL_PROCESSOR_STATE,(partition:WHvPartitionHandle,vp_index:u32,state_type:WHvVirtualProcessorStateType,state_buffer:*const c_void,state_buffer_size:u32),(partition,vp_index,state_type,state_buffer,state_buffer_size));
whv_wrapper!(get_virtual_processor_cpuid_output,WHV_GET_VIRTUAL_PROCESSOR_CPUID_OUTPUT,(partition:WHvPartitionHandle,vp_index:u32,eax:u32,ecx:u32,cpuid_output:*mut WHvCpuidOutput),(partition,vp_index,eax,ecx,cpuid_output));
whv_wrapper!(get_interrupt_target_vp_set,WHV_GET_INTERRUPT_TARGET_VP_SET,(partition:WHvPartitionHandle,destination:u64,destination_mode:u32,target_vps:*mut u32,vp_count:u32,target_vp_count:*mut u32),(partition,destination,destination_mode,target_vps,vp_count,target_vp_count));
whv_wrapper!(post_virtual_processor_synic_message,WHV_POST_VIRTUAL_PROCESSOR_SYNIC_MESSAGE,(partition:WHvPartitionHandle,vp_index:u32,sint_index:u32,message:*const c_void,message_size:u32),(partition,vp_index,sint_index,message,message_size));
whv_wrapper!(allocate_vpci_resource,WHV_ALLOCATE_VPCI_RESOURCE,(provider_id:*const c_void,flags:WHvAllocateVpciResourceFlags,resource_descriptor:*const c_void,size_in_bytes:u32,vpci_resource:*mut *mut c_void),(provider_id,flags,resource_descriptor,size_in_bytes,vpci_resource));
whv_wrapper!(create_vpci_device,WHV_CREATE_VPCI_DEVICE,(partition:WHvPartitionHandle,logical_device_id:u64,vpci_resource:*mut c_void,flags:WHvCreateVpciDeviceFlags,notification_event:*mut c_void),(partition,logical_device_id,vpci_resource,flags,notification_event));
whv_wrapper!(delete_vpci_device,WHV_DELETE_VPCI_DEVICE,(partition:WHvPartitionHandle,logical_device_id:u64),(partition,logical_device_id));
whv_wrapper!(get_vpci_device_property,WHV_GET_VPCI_DEVICE_PROPERTY,(partition:WHvPartitionHandle,logical_device_id:u64,property_code:WHvVpciDevicePropertyCode,property_buffer:*mut c_void,size_in_bytes:u32,written_size:*mut u32),(partition,logical_device_id,property_code,property_buffer,size_in_bytes,written_size));
whv_wrapper!(get_vpci_device_notification,WHV_GET_VPCI_DEVICE_NOTIFICATION,(partition:WHvPartitionHandle,logical_device_id:u64,notification:*mut WHvVpciDeviceNotification,notification_size_in_bytes:u32),(partition,logical_device_id,notification,notification_size_in_bytes));
whv_wrapper!(map_vpci_device_mmio_ranges,WHV_MAP_VPCI_DEVICE_MMIO_RANGES,(partition:WHvPartitionHandle,logical_device_id:u64,mapping_count:*mut u32,mappings:*mut *mut WHvVpciMmioMapping),(partition,logical_device_id,mapping_count,mappings));
whv_wrapper!(unmap_vpci_device_mmio_ranges,WHV_UNMAP_VPCI_DEVICE_MMIO_RANGES,(partition:WHvPartitionHandle,logical_device_id:u64),(partition,logical_device_id));
whv_wrapper!(set_vpci_device_power_state,WHV_SET_VPCI_DEVICE_POWER_STATE,(partition:WHvPartitionHandle,logical_device_id:u64,power_state:DevicePowerState),(partition,logical_device_id,power_state));
whv_wrapper!(read_vpci_device_register,WHV_READ_VPCI_DEVICE_REGISTER,(partition:WHvPartitionHandle,logical_device_id:u64,register:*const WHvVpciDeviceRegister,data:*mut c_void),(partition,logical_device_id,register,data));
whv_wrapper!(write_vpci_device_register,WHV_WRITE_VPCI_DEVICE_REGISTER,(partition:WHvPartitionHandle,logical_device_id:u64,register:*const WHvVpciDeviceRegister,data:*const c_void),(partition,logical_device_id,register,data));
whv_wrapper!(map_vpci_device_interrupt,WHV_MAP_VPCI_DEVICE_INTERRUPT,(partition:WHvPartitionHandle,logical_device_id:u64,index:u32,message_count:u32,target:*const WHvVpciInterruptTarget,msi_address:*mut u64,msi_data:*mut u32),(partition,logical_device_id,index,message_count,target,msi_address,msi_data));
whv_wrapper!(unmap_vpci_device_interrupt,WHV_UNMAP_VPCI_DEVICE_INTERRUPT,(partition:WHvPartitionHandle,logical_device_id:u64,index:u32),(partition,logical_device_id,index));
whv_wrapper!(retarget_vpci_device_interrupt,WHV_RETARGET_VPCI_DEVICE_INTERRUPT,(partition:WHvPartitionHandle,logical_device_id:u64,msi_address:u64,msi_data:u32,target:*const WHvVpciInterruptTarget),(partition,logical_device_id,msi_address,msi_data,target));
whv_wrapper!(request_vpci_device_interrupt,WHV_REQUEST_VPCI_DEVICE_INTERRUPT,(partition:WHvPartitionHandle,logical_device_id:u64,msi_address:u64,msi_data:u32),(partition,logical_device_id,msi_address,msi_data));
whv_wrapper!(get_vpci_device_interrupt_target,WHV_GET_VPCI_DEVICE_INTERRUPT_TARGET,(partition:WHvPartitionHandle,logical_device_id:u64,index:u32,multi_message_number:u32,target:*mut WHvVpciInterruptTarget,target_size_in_bytes:u32,bytes_written:*mut u32),(partition,logical_device_id,index,multi_message_number,target,target_size_in_bytes,bytes_written));
whv_wrapper!(create_trigger,WHV_CREATE_TRIGGER,(partition:WHvPartitionHandle,parameters:*const WHvTriggerParameters,trigger:*mut WHvTriggerHandle,event_handle:*mut *mut c_void),(partition,parameters,trigger,event_handle));
whv_wrapper!(delete_trigger,WHV_DELETE_TRIGGER,(partition:WHvPartitionHandle,trigger:WHvTriggerHandle),(partition,trigger));
whv_wrapper!(update_trigger_parameters,WHV_UPDATE_TRIGGER_PARAMETERS,(partition:WHvPartitionHandle,parameters:*const WHvTriggerParameters,trigger:WHvTriggerHandle),(partition,parameters,trigger));
whv_wrapper!(create_notification_port,WHV_CREATE_NOTIFICATION_PORT,(partition:WHvPartitionHandle,parameters:*const WHvNotificationPortParameters,event_handle:*mut c_void,port:*mut WHvNotificationPortHandle),(partition,parameters,event_handle,port));
whv_wrapper!(delete_notification_port,WHV_DELETE_NOTIFICATION_PORT,(partition:WHvPartitionHandle,port:WHvNotificationPortHandle),(partition,port));
whv_wrapper!(set_notification_port_property,WHV_SET_NOTIFICATION_PORT_PROPERTY,(partition:WHvPartitionHandle,port:WHvNotificationPortHandle,property_code:WHvNotificationPortPropertyCode,property_value:WHvNotificationPortProperty),(partition,port,property_code,property_value));
whv_wrapper!(start_partition_migration,WHV_START_PARTITION_MIGRATION,(partition:WHvPartitionHandle,migration_handle:*mut *mut c_void),(partition,migration_handle));
whv_wrapper!(cancel_partition_migration,WHV_CANCEL_PARTITION_MIGRATION,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(complete_partition_migration,WHV_COMPLETE_PARTITION_MIGRATION,(partition:WHvPartitionHandle),(partition));
whv_wrapper!(accept_partition_migration,WHV_ACCEPT_PARTITION_MIGRATION,(migration_handle:*mut c_void,partition:*mut WHvPartitionHandle),(migration_handle,partition));