github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/guest_cpu_vmenter_event.h (about)

     1  /*
     2   * Copyright (c) 2013 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *     http://www.apache.org/licenses/LICENSE-2.0
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11   * See the License for the specific language governing permissions and
    12   * limitations under the License.
    13   */
    14  
    15  #ifndef _GUEST_CPU_VMENTER_EVENT_H_
    16  #define _GUEST_CPU_VMENTER_EVENT_H_
    17  
    18  #include "vmm_objects.h"
    19  
    20  typedef struct {
    21      IA32_VMX_VMCS_VM_ENTER_INTERRUPT_INFO   interrupt_info;
    22      UINT32                                  instruction_length;
    23      ADDRESS                                 error_code;
    24  } VMENTER_EVENT;
    25  
    26  #ifdef INCLUDE_UNUSED_CODE
    27  // FUNCTION : gcpu_nmi_injection_allowed
    28  // PURPOSE  : Checks if NMI injection is allowed for the guest CPU
    29  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    30  // RETURNS  : TRUE if event injection allowed
    31  BOOLEAN gcpu_nmi_injection_allowed(const  GUEST_CPU_HANDLE gcpu);
    32  #endif
    33  
    34  
    35  // FUNCTION : gcpu_inject_event
    36  // PURPOSE  : Inject interrupt/exception into guest if allowed, otherwise
    37  //          : set NMI/Interrupt window
    38  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    39  //          : VMENTER_EVENT *p_event
    40  // RETURNS  : TRUE if event was injected, FALSE
    41  // NOTES    : no checkings are done for event validity
    42  BOOLEAN gcpu_inject_event(
    43      GUEST_CPU_HANDLE    gcpu,
    44      VMENTER_EVENT       *p_event);
    45  
    46  #ifdef INCLUDE_UNUSED_CODE
    47  
    48  // FUNCTION : gcpu_inject_native_pf
    49  // PURPOSE  : Inject native PF
    50  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    51  //            UINT64 pf_address - gva
    52  //          : UINT64 pfec - error code
    53  // RETURNS  : TRUE if event was injected, FALSE
    54  BOOLEAN gcpu_inject_native_pf(GUEST_CPU_HANDLE    gcpu,
    55                                UINT64 pf_address, UINT64 pfec);
    56  #endif
    57  
    58  
    59  // FUNCTION : gcpu_inject_gp0
    60  // PURPOSE  : Inject GP with error code 0
    61  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    62  // RETURNS  : TRUE if event was injected, FALSE
    63  BOOLEAN gcpu_inject_gp0(GUEST_CPU_HANDLE gcpu);
    64  
    65  
    66  // FUNCTION : gcpu_inject_fault
    67  // PURPOSE  : Inject a fault to guest CPU
    68  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    69  //            int vec - fault vector
    70  //            UINT32 code - error code pushed on guest stack
    71  // RETURNS  : TRUE if event was injected, FALSE
    72  BOOLEAN gcpu_inject_fault( GUEST_CPU_HANDLE gcpu, int vec, UINT32 code);
    73  
    74  
    75  // FUNCTION : gcpu_inject_nmi
    76  // PURPOSE  : Inject NMI into guest if allowed, otherwise set NMI window
    77  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    78  // RETURNS  : TRUE if event was injected, FALSE
    79  BOOLEAN gcpu_inject_nmi(GUEST_CPU_HANDLE gcpu);
    80  
    81  #ifdef INCLUDE_UNUSED_CODE
    82  
    83  // FUNCTION : gcpu_inject_external_interrupt
    84  // PURPOSE  : Inject external interrupt into guest if allowed,
    85  //          :  otherwise set Interruption window
    86  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    87  //          : VECTOR_ID vector_id
    88  // RETURNS  : TRUE if event was injected, FALSE
    89  BOOLEAN gcpu_inject_external_interrupt(
    90      GUEST_CPU_HANDLE    gcpu,
    91      VECTOR_ID           vector_id);
    92  #endif
    93  
    94  
    95  // FUNCTION : gcpu_inject_double_fault
    96  // PURPOSE  : Inject Double Fault exception into guest if allowed,
    97  //          :  otherwise set Interruption window
    98  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
    99  // RETURNS  : TRUE if event was injected, FALSE
   100  BOOLEAN gcpu_inject_double_fault(GUEST_CPU_HANDLE gcpu);
   101  
   102  
   103  // FUNCTION : gcpu_set_pending_nmi
   104  // PURPOSE  : Cause NMI VMEXIT be invoked immediately when NMI blocking finished
   105  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
   106  //          : BOOLEAN value
   107  // RETURNS  : void
   108  void gcpu_set_pending_nmi( GUEST_CPU_HANDLE gcpu, BOOLEAN value);
   109  
   110  #ifdef INCLUDE_UNUSED_CODE
   111  
   112  // FUNCTION : gcpu_get_pending_nmi
   113  // PURPOSE  : Get NMI pending state
   114  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
   115  // RETURNS  : BOOLEAN - TRUE if NMI is pended
   116  BOOLEAN gcpu_get_pending_nmi(GUEST_CPU_HANDLE gcpu);
   117  #endif
   118  
   119  
   120  // FUNCTION : gcpu_vmexit_exception_resolve
   121  // PURPOSE  : Called if exception, caused VMEXIT was resolved by VMM code
   122  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
   123  // RETURNS  : void
   124  void gcpu_vmexit_exception_resolve(GUEST_CPU_HANDLE gcpu);
   125  
   126  
   127  // FUNCTION : gcpu_vmexit_exception_reflect
   128  // PURPOSE  : Reflect exception to guest.
   129  //          : Called if exception, caused VMEXIT was caused by Guest SW
   130  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
   131  // RETURNS  : void
   132  void gcpu_vmexit_exception_reflect(GUEST_CPU_HANDLE gcpu);
   133  
   134  #ifdef ENABLE_VTLB
   135  
   136  // FUNCTION : gcpu_update_current_exception_error_code
   137  // PURPOSE  : Changes exception error code in current (merged) VMCS,
   138  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
   139  //            error_code - new error code
   140  void gcpu_update_current_exception_error_code(
   141      GUEST_CPU_HANDLE    gcpu,
   142      UINT32 error_code);
   143  #endif
   144  
   145  #ifdef VMCALL_NOT_ALLOWED_FROM_RING_1_TO_3
   146  // FUNCTION : gcpu_inject_invalid_opcode_exception
   147  // PURPOSE  : Inject invalid opcode exception
   148  // ARGUMENTS: GUEST_CPU_HANDLE gcpu - guest CPU
   149  // RETURNS  : TRUE if event was injected, FALSE if event was not injected.
   150  BOOLEAN gcpu_inject_invalid_opcode_exception(GUEST_CPU_HANDLE    gcpu);
   151  #endif
   152  
   153  #define gcpu_inject_ts(gcpu, code) \
   154      gcpu_inject_fault( \
   155          gcpu, \
   156          (int)IA32_EXCEPTION_VECTOR_INVALID_TASK_SEGMENT_SELECTOR, \
   157          code \
   158          );
   159  
   160  #define gcpu_inject_ss(gcpu, code) \
   161      gcpu_inject_fault( \
   162          gcpu, \
   163          (int)IA32_EXCEPTION_VECTOR_STACK_SEGMENT_FAULT, \
   164          code \
   165          );
   166  
   167  #define gcpu_inject_np(gcpu, code) \
   168      gcpu_inject_fault( \
   169          gcpu, \
   170          (int)IA32_EXCEPTION_VECTOR_SEGMENT_NOT_PRESENT, \
   171          code \
   172          );
   173  
   174  #define gcpu_inject_db(gcpu) \
   175      gcpu_inject_fault( \
   176          gcpu, \
   177          (int)IA32_EXCEPTION_VECTOR_DEBUG_BREAKPOINT, \
   178          0 \
   179          );
   180  
   181  #endif // _GUEST_CPU_VMENTER_EVENT_H_
   182