+
+static void init_vmcs_field_to_offset_table(void)
+{
+ memset(vmcs_field_to_offset_table,0xff,
+ sizeof(vmcs_field_to_offset_table));
+
+ vmcs_field_to_offset_table[VIRTUAL_PROCESSOR_ID] =
+ offsetof(struct shadow_vmcs, virtual_processor_id);
+ vmcs_field_to_offset_table[GUEST_ES_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_es_selector);
+ vmcs_field_to_offset_table[GUEST_CS_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_cs_selector);
+ vmcs_field_to_offset_table[GUEST_SS_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_ss_selector);
+ vmcs_field_to_offset_table[GUEST_DS_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_ds_selector);
+ vmcs_field_to_offset_table[GUEST_FS_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_fs_selector);
+ vmcs_field_to_offset_table[GUEST_GS_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_gs_selector);
+ vmcs_field_to_offset_table[GUEST_LDTR_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_ldtr_selector);
+ vmcs_field_to_offset_table[GUEST_TR_SELECTOR] =
+ offsetof(struct shadow_vmcs, guest_tr_selector);
+ vmcs_field_to_offset_table[HOST_ES_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_es_selector);
+ vmcs_field_to_offset_table[HOST_CS_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_cs_selector);
+ vmcs_field_to_offset_table[HOST_SS_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_ss_selector);
+ vmcs_field_to_offset_table[HOST_DS_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_ds_selector);
+ vmcs_field_to_offset_table[HOST_FS_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_fs_selector);
+ vmcs_field_to_offset_table[HOST_GS_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_gs_selector);
+ vmcs_field_to_offset_table[HOST_TR_SELECTOR] =
+ offsetof(struct shadow_vmcs, host_tr_selector);
+ vmcs_field_to_offset_table[IO_BITMAP_A] =
+ offsetof(struct shadow_vmcs, io_bitmap_a);
+ vmcs_field_to_offset_table[IO_BITMAP_A_HIGH] =
+ offsetof(struct shadow_vmcs, io_bitmap_a)+4;
+ vmcs_field_to_offset_table[IO_BITMAP_B] =
+ offsetof(struct shadow_vmcs, io_bitmap_b);
+ vmcs_field_to_offset_table[IO_BITMAP_B_HIGH] =
+ offsetof(struct shadow_vmcs, io_bitmap_b)+4;
+ vmcs_field_to_offset_table[MSR_BITMAP] =
+ offsetof(struct shadow_vmcs, msr_bitmap);
+ vmcs_field_to_offset_table[MSR_BITMAP_HIGH] =
+ offsetof(struct shadow_vmcs, msr_bitmap)+4;
+ vmcs_field_to_offset_table[VM_EXIT_MSR_STORE_ADDR] =
+ offsetof(struct shadow_vmcs, vm_exit_msr_store_addr);
+ vmcs_field_to_offset_table[VM_EXIT_MSR_STORE_ADDR_HIGH] =
+ offsetof(struct shadow_vmcs, vm_exit_msr_store_addr)+4;
+ vmcs_field_to_offset_table[VM_EXIT_MSR_LOAD_ADDR] =
+ offsetof(struct shadow_vmcs, vm_exit_msr_load_addr);
+ vmcs_field_to_offset_table[VM_EXIT_MSR_LOAD_ADDR_HIGH] =
+ offsetof(struct shadow_vmcs, vm_exit_msr_load_addr)+4;
+ vmcs_field_to_offset_table[VM_ENTRY_MSR_LOAD_ADDR] =
+ offsetof(struct shadow_vmcs, vm_entry_msr_load_addr);
+ vmcs_field_to_offset_table[VM_ENTRY_MSR_LOAD_ADDR_HIGH] =
+ offsetof(struct shadow_vmcs, vm_entry_msr_load_addr)+4;
+ vmcs_field_to_offset_table[TSC_OFFSET] =
+ offsetof(struct shadow_vmcs, tsc_offset);
+ vmcs_field_to_offset_table[TSC_OFFSET_HIGH] =
+ offsetof(struct shadow_vmcs, tsc_offset)+4;
+ vmcs_field_to_offset_table[VIRTUAL_APIC_PAGE_ADDR] =
+ offsetof(struct shadow_vmcs, virtual_apic_page_addr);
+ vmcs_field_to_offset_table[VIRTUAL_APIC_PAGE_ADDR_HIGH] =
+ offsetof(struct shadow_vmcs, virtual_apic_page_addr)+4;
+ vmcs_field_to_offset_table[APIC_ACCESS_ADDR] =
+ offsetof(struct shadow_vmcs, apic_access_addr);
+ vmcs_field_to_offset_table[APIC_ACCESS_ADDR_HIGH] =
+ offsetof(struct shadow_vmcs, apic_access_addr)+4;
+ vmcs_field_to_offset_table[EPT_POINTER] =
+ offsetof(struct shadow_vmcs, ept_pointer);
+ vmcs_field_to_offset_table[EPT_POINTER_HIGH] =
+ offsetof(struct shadow_vmcs, ept_pointer)+4;
+ vmcs_field_to_offset_table[GUEST_PHYSICAL_ADDRESS] =
+ offsetof(struct shadow_vmcs, guest_physical_address);
+ vmcs_field_to_offset_table[GUEST_PHYSICAL_ADDRESS_HIGH] =
+ offsetof(struct shadow_vmcs, guest_physical_address)+4;
+ vmcs_field_to_offset_table[VMCS_LINK_POINTER] =
+ offsetof(struct shadow_vmcs, vmcs_link_pointer);
+ vmcs_field_to_offset_table[VMCS_LINK_POINTER_HIGH] =
+ offsetof(struct shadow_vmcs, vmcs_link_pointer)+4;
+ vmcs_field_to_offset_table[GUEST_IA32_DEBUGCTL] =
+ offsetof(struct shadow_vmcs, guest_ia32_debugctl);
+ vmcs_field_to_offset_table[GUEST_IA32_DEBUGCTL_HIGH] =
+ offsetof(struct shadow_vmcs, guest_ia32_debugctl)+4;
+ vmcs_field_to_offset_table[GUEST_IA32_PAT] =
+ offsetof(struct shadow_vmcs, guest_ia32_pat);
+ vmcs_field_to_offset_table[GUEST_IA32_PAT_HIGH] =
+ offsetof(struct shadow_vmcs, guest_ia32_pat)+4;
+ vmcs_field_to_offset_table[GUEST_PDPTR0] =
+ offsetof(struct shadow_vmcs, guest_pdptr0);
+ vmcs_field_to_offset_table[GUEST_PDPTR0_HIGH] =
+ offsetof(struct shadow_vmcs, guest_pdptr0)+4;
+ vmcs_field_to_offset_table[GUEST_PDPTR1] =
+ offsetof(struct shadow_vmcs, guest_pdptr1);
+ vmcs_field_to_offset_table[GUEST_PDPTR1_HIGH] =
+ offsetof(struct shadow_vmcs, guest_pdptr1)+4;
+ vmcs_field_to_offset_table[GUEST_PDPTR2] =
+ offsetof(struct shadow_vmcs, guest_pdptr2);
+ vmcs_field_to_offset_table[GUEST_PDPTR2_HIGH] =
+ offsetof(struct shadow_vmcs, guest_pdptr2)+4;
+ vmcs_field_to_offset_table[GUEST_PDPTR3] =
+ offsetof(struct shadow_vmcs, guest_pdptr3);
+ vmcs_field_to_offset_table[GUEST_PDPTR3_HIGH] =
+ offsetof(struct shadow_vmcs, guest_pdptr3)+4;
+ vmcs_field_to_offset_table[HOST_IA32_PAT] =
+ offsetof(struct shadow_vmcs, host_ia32_pat);
+ vmcs_field_to_offset_table[HOST_IA32_PAT_HIGH] =
+ offsetof(struct shadow_vmcs, host_ia32_pat)+4;
+ vmcs_field_to_offset_table[PIN_BASED_VM_EXEC_CONTROL] =
+ offsetof(struct shadow_vmcs, pin_based_vm_exec_control);
+ vmcs_field_to_offset_table[CPU_BASED_VM_EXEC_CONTROL] =
+ offsetof(struct shadow_vmcs, cpu_based_vm_exec_control);
+ vmcs_field_to_offset_table[EXCEPTION_BITMAP] =
+ offsetof(struct shadow_vmcs, exception_bitmap);
+ vmcs_field_to_offset_table[PAGE_FAULT_ERROR_CODE_MASK] =
+ offsetof(struct shadow_vmcs, page_fault_error_code_mask);
+ vmcs_field_to_offset_table[PAGE_FAULT_ERROR_CODE_MATCH] =
+ offsetof(struct shadow_vmcs,
+ page_fault_error_code_match);
+ vmcs_field_to_offset_table[CR3_TARGET_COUNT] =
+ offsetof(struct shadow_vmcs, cr3_target_count);
+ vmcs_field_to_offset_table[VM_EXIT_CONTROLS] =
+ offsetof(struct shadow_vmcs, vm_exit_controls);
+ vmcs_field_to_offset_table[VM_EXIT_MSR_STORE_COUNT] =
+ offsetof(struct shadow_vmcs, vm_exit_msr_store_count);
+ vmcs_field_to_offset_table[VM_EXIT_MSR_LOAD_COUNT] =
+ offsetof(struct shadow_vmcs, vm_exit_msr_load_count);
+ vmcs_field_to_offset_table[VM_ENTRY_CONTROLS] =
+ offsetof(struct shadow_vmcs, vm_entry_controls);
+ vmcs_field_to_offset_table[VM_ENTRY_MSR_LOAD_COUNT] =
+ offsetof(struct shadow_vmcs, vm_entry_msr_load_count);
+ vmcs_field_to_offset_table[VM_ENTRY_INTR_INFO_FIELD] =
+ offsetof(struct shadow_vmcs, vm_entry_intr_info_field);
+ vmcs_field_to_offset_table[VM_ENTRY_EXCEPTION_ERROR_CODE] =
+ offsetof(struct shadow_vmcs,
+ vm_entry_exception_error_code);
+ vmcs_field_to_offset_table[VM_ENTRY_INSTRUCTION_LEN] =
+ offsetof(struct shadow_vmcs, vm_entry_instruction_len);
+ vmcs_field_to_offset_table[TPR_THRESHOLD] =
+ offsetof(struct shadow_vmcs, tpr_threshold);
+ vmcs_field_to_offset_table[SECONDARY_VM_EXEC_CONTROL] =
+ offsetof(struct shadow_vmcs, secondary_vm_exec_control);
+ vmcs_field_to_offset_table[VM_INSTRUCTION_ERROR] =
+ offsetof(struct shadow_vmcs, vm_instruction_error);
+ vmcs_field_to_offset_table[VM_EXIT_REASON] =
+ offsetof(struct shadow_vmcs, vm_exit_reason);
+ vmcs_field_to_offset_table[VM_EXIT_INTR_INFO] =
+ offsetof(struct shadow_vmcs, vm_exit_intr_info);
+ vmcs_field_to_offset_table[VM_EXIT_INTR_ERROR_CODE] =
+ offsetof(struct shadow_vmcs, vm_exit_intr_error_code);
+ vmcs_field_to_offset_table[IDT_VECTORING_INFO_FIELD] =
+ offsetof(struct shadow_vmcs, idt_vectoring_info_field);
+ vmcs_field_to_offset_table[IDT_VECTORING_ERROR_CODE] =
+ offsetof(struct shadow_vmcs, idt_vectoring_error_code);
+ vmcs_field_to_offset_table[VM_EXIT_INSTRUCTION_LEN] =
+ offsetof(struct shadow_vmcs, vm_exit_instruction_len);
+ vmcs_field_to_offset_table[VMX_INSTRUCTION_INFO] =
+ offsetof(struct shadow_vmcs, vmx_instruction_info);
+ vmcs_field_to_offset_table[GUEST_ES_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_es_limit);
+ vmcs_field_to_offset_table[GUEST_CS_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_cs_limit);
+ vmcs_field_to_offset_table[GUEST_SS_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_ss_limit);
+ vmcs_field_to_offset_table[GUEST_DS_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_ds_limit);
+ vmcs_field_to_offset_table[GUEST_FS_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_fs_limit);
+ vmcs_field_to_offset_table[GUEST_GS_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_gs_limit);
+ vmcs_field_to_offset_table[GUEST_LDTR_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_ldtr_limit);
+ vmcs_field_to_offset_table[GUEST_TR_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_tr_limit);
+ vmcs_field_to_offset_table[GUEST_GDTR_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_gdtr_limit);
+ vmcs_field_to_offset_table[GUEST_IDTR_LIMIT] =
+ offsetof(struct shadow_vmcs, guest_idtr_limit);
+ vmcs_field_to_offset_table[GUEST_ES_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_es_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_CS_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_cs_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_SS_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_ss_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_DS_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_ds_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_FS_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_fs_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_GS_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_gs_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_LDTR_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_ldtr_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_TR_AR_BYTES] =
+ offsetof(struct shadow_vmcs, guest_tr_ar_bytes);
+ vmcs_field_to_offset_table[GUEST_INTERRUPTIBILITY_INFO] =
+ offsetof(struct shadow_vmcs,
+ guest_interruptibility_info);
+ vmcs_field_to_offset_table[GUEST_ACTIVITY_STATE] =
+ offsetof(struct shadow_vmcs, guest_activity_state);
+ vmcs_field_to_offset_table[GUEST_SYSENTER_CS] =
+ offsetof(struct shadow_vmcs, guest_sysenter_cs);
+ vmcs_field_to_offset_table[HOST_IA32_SYSENTER_CS] =
+ offsetof(struct shadow_vmcs, host_ia32_sysenter_cs);
+ vmcs_field_to_offset_table[CR0_GUEST_HOST_MASK] =
+ offsetof(struct shadow_vmcs, cr0_guest_host_mask);
+ vmcs_field_to_offset_table[CR4_GUEST_HOST_MASK] =
+ offsetof(struct shadow_vmcs, cr4_guest_host_mask);
+ vmcs_field_to_offset_table[CR0_READ_SHADOW] =
+ offsetof(struct shadow_vmcs, cr0_read_shadow);
+ vmcs_field_to_offset_table[CR4_READ_SHADOW] =
+ offsetof(struct shadow_vmcs, cr4_read_shadow);
+ vmcs_field_to_offset_table[CR3_TARGET_VALUE0] =
+ offsetof(struct shadow_vmcs, cr3_target_value0);
+ vmcs_field_to_offset_table[CR3_TARGET_VALUE1] =
+ offsetof(struct shadow_vmcs, cr3_target_value1);
+ vmcs_field_to_offset_table[CR3_TARGET_VALUE2] =
+ offsetof(struct shadow_vmcs, cr3_target_value2);
+ vmcs_field_to_offset_table[CR3_TARGET_VALUE3] =
+ offsetof(struct shadow_vmcs, cr3_target_value3);
+ vmcs_field_to_offset_table[EXIT_QUALIFICATION] =
+ offsetof(struct shadow_vmcs, exit_qualification);
+ vmcs_field_to_offset_table[GUEST_LINEAR_ADDRESS] =
+ offsetof(struct shadow_vmcs, guest_linear_address);
+ vmcs_field_to_offset_table[GUEST_CR0] =
+ offsetof(struct shadow_vmcs, guest_cr0);
+ vmcs_field_to_offset_table[GUEST_CR3] =
+ offsetof(struct shadow_vmcs, guest_cr3);
+ vmcs_field_to_offset_table[GUEST_CR4] =
+ offsetof(struct shadow_vmcs, guest_cr4);
+ vmcs_field_to_offset_table[GUEST_ES_BASE] =
+ offsetof(struct shadow_vmcs, guest_es_base);
+ vmcs_field_to_offset_table[GUEST_CS_BASE] =
+ offsetof(struct shadow_vmcs, guest_cs_base);
+ vmcs_field_to_offset_table[GUEST_SS_BASE] =
+ offsetof(struct shadow_vmcs, guest_ss_base);
+ vmcs_field_to_offset_table[GUEST_DS_BASE] =
+ offsetof(struct shadow_vmcs, guest_ds_base);
+ vmcs_field_to_offset_table[GUEST_FS_BASE] =
+ offsetof(struct shadow_vmcs, guest_fs_base);
+ vmcs_field_to_offset_table[GUEST_GS_BASE] =
+ offsetof(struct shadow_vmcs, guest_gs_base);
+ vmcs_field_to_offset_table[GUEST_LDTR_BASE] =
+ offsetof(struct shadow_vmcs, guest_ldtr_base);
+ vmcs_field_to_offset_table[GUEST_TR_BASE] =
+ offsetof(struct shadow_vmcs, guest_tr_base);
+ vmcs_field_to_offset_table[GUEST_GDTR_BASE] =
+ offsetof(struct shadow_vmcs, guest_gdtr_base);
+ vmcs_field_to_offset_table[GUEST_IDTR_BASE] =
+ offsetof(struct shadow_vmcs, guest_idtr_base);
+ vmcs_field_to_offset_table[GUEST_DR7] =
+ offsetof(struct shadow_vmcs, guest_dr7);
+ vmcs_field_to_offset_table[GUEST_RSP] =
+ offsetof(struct shadow_vmcs, guest_rsp);
+ vmcs_field_to_offset_table[GUEST_RIP] =
+ offsetof(struct shadow_vmcs, guest_rip);
+ vmcs_field_to_offset_table[GUEST_RFLAGS] =
+ offsetof(struct shadow_vmcs, guest_rflags);
+ vmcs_field_to_offset_table[GUEST_PENDING_DBG_EXCEPTIONS] =
+ offsetof(struct shadow_vmcs,
+ guest_pending_dbg_exceptions);
+ vmcs_field_to_offset_table[GUEST_SYSENTER_ESP] =
+ offsetof(struct shadow_vmcs, guest_sysenter_esp);
+ vmcs_field_to_offset_table[GUEST_SYSENTER_EIP] =
+ offsetof(struct shadow_vmcs, guest_sysenter_eip);
+ vmcs_field_to_offset_table[HOST_CR0] =
+ offsetof(struct shadow_vmcs, host_cr0);
+ vmcs_field_to_offset_table[HOST_CR3] =
+ offsetof(struct shadow_vmcs, host_cr3);
+ vmcs_field_to_offset_table[HOST_CR4] =
+ offsetof(struct shadow_vmcs, host_cr4);
+ vmcs_field_to_offset_table[HOST_FS_BASE] =
+ offsetof(struct shadow_vmcs, host_fs_base);
+ vmcs_field_to_offset_table[HOST_GS_BASE] =
+ offsetof(struct shadow_vmcs, host_gs_base);
+ vmcs_field_to_offset_table[HOST_TR_BASE] =
+ offsetof(struct shadow_vmcs, host_tr_base);
+ vmcs_field_to_offset_table[HOST_GDTR_BASE] =
+ offsetof(struct shadow_vmcs, host_gdtr_base);
+ vmcs_field_to_offset_table[HOST_IDTR_BASE] =
+ offsetof(struct shadow_vmcs, host_idtr_base);
+ vmcs_field_to_offset_table[HOST_IA32_SYSENTER_ESP] =
+ offsetof(struct shadow_vmcs, host_ia32_sysenter_esp);
+ vmcs_field_to_offset_table[HOST_IA32_SYSENTER_EIP] =
+ offsetof(struct shadow_vmcs, host_ia32_sysenter_eip);
+ vmcs_field_to_offset_table[HOST_RSP] =
+ offsetof(struct shadow_vmcs, host_rsp);
+ vmcs_field_to_offset_table[HOST_RIP] =
+ offsetof(struct shadow_vmcs, host_rip);
+}
+