github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/common/include/event_mgr.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  /*
    16   *  Event delivery mechanism
    17   *  Based on the 'Observer' pattern
    18   */
    19  
    20  #pragma once
    21  #include "vmm_startup.h"
    22  
    23  #define EVENT_MGR_ERROR         (UINT32)-1
    24  
    25  /*
    26   *	CALLBACK
    27   */
    28  typedef BOOLEAN (*event_callback) (
    29      GUEST_CPU_HANDLE    gcpu,
    30      void                *pv
    31      );
    32  
    33  /*
    34   *	EVENTS
    35   *
    36   *  This enumeration specify the supported UVMM events.
    37   *  Note that for every event there should be an entry in EVENT_CHARACTERISTICS
    38   *  characterizing the event in event_mgr.c.
    39   *
    40   *  failing to add entry in EVENT_CHARACTERISTICS triggers assertion at the
    41   *  event_initialize_event_manger entry point
    42   */
    43  #ifndef UVMM_EVENT_INTERNAL
    44  typedef enum {
    45      // emulator
    46      EVENT_EMULATOR_BEFORE_MEM_WRITE = 0,
    47      EVENT_EMULATOR_AFTER_MEM_WRITE,
    48      EVENT_EMULATOR_AS_GUEST_ENTER,
    49      EVENT_EMULATOR_AS_GUEST_LEAVE,
    50  
    51      // guest cpu CR writes
    52      EVENT_GCPU_AFTER_GUEST_CR0_WRITE,
    53      EVENT_GCPU_AFTER_GUEST_CR3_WRITE,
    54      EVENT_GCPU_AFTER_GUEST_CR4_WRITE,
    55  
    56      // guest cpu invalidate page
    57      EVENT_GCPU_INVALIDATE_PAGE,
    58      EVENT_GCPU_PAGE_FAULT,
    59  
    60      // guest cpu msr writes
    61      EVENT_GCPU_AFTER_EFER_MSR_WRITE,
    62      EVENT_GCPU_AFTER_PAT_MSR_WRITE,
    63      EVENT_GCPU_AFTER_MTRR_MSR_WRITE,
    64  
    65      // guest activity state
    66      EVENT_GCPU_ACTIVITY_STATE_CHANGE,
    67      EVENT_GCPU_ENTERING_S3,
    68      EVENT_GCPU_RETURNED_FROM_S3,
    69  
    70      // ept events
    71      EVENT_GCPU_EPT_MISCONFIGURATION,
    72      EVENT_GCPU_EPT_VIOLATION,
    73  
    74      // mtf events
    75      EVENT_GCPU_MTF,
    76  
    77      // GPM modification
    78      EVENT_BEGIN_GPM_MODIFICATION_BEFORE_CPUS_STOPPED,
    79      EVENT_BEGIN_GPM_MODIFICATION_AFTER_CPUS_STOPPED,
    80      EVENT_END_GPM_MODIFICATION_BEFORE_CPUS_RESUMED,
    81      EVENT_END_GPM_MODIFICATION_AFTER_CPUS_RESUMED,
    82  
    83      // guest memory modification
    84      EVENT_BEGIN_GUEST_MEMORY_MODIFICATION,
    85      EVENT_END_GUEST_MEMORY_MODIFICATION,
    86  
    87      // guest lifecycle
    88      EVENT_GUEST_CREATE,
    89      EVENT_GUEST_DESTROY,
    90  
    91      // gcpu lifecycle
    92      EVENT_GCPU_ADD,
    93      EVENT_GCPU_REMOVE,
    94  
    95      EVENT_GUEST_LAUNCH,
    96  
    97      EVENT_GUEST_CPU_BREAKPOINT,
    98      EVENT_GUEST_CPU_SINGLE_STEP,
    99  
   100      EVENTS_COUNT
   101  } UVMM_EVENT_INTERNAL;
   102  #endif
   103  
   104  typedef enum {
   105      EVENT_GLOBAL_SCOPE = 1,
   106      EVENT_GUEST_SCOPE  = 2,
   107      EVENT_GCPU_SCOPE   = 4,
   108      EVENT_ALL_SCOPE    = (EVENT_GLOBAL_SCOPE | EVENT_GUEST_SCOPE  | EVENT_GCPU_SCOPE)
   109  } EVENT_SCOPE;
   110  
   111  
   112  typedef struct _EVENT_CHARACTERISTICS
   113  {
   114      UINT32      specific_observers_limits;
   115      EVENT_SCOPE scope;
   116      CHAR8      *event_str;
   117  } EVENT_CHARACTERISTICS, * PEVENT_CHARACTERISTICS;
   118  
   119  
   120  /*
   121   *	Event Manager Interface
   122   */
   123  
   124  UINT32 event_initialize_event_manger(const VMM_STARTUP_STRUCT* startup_struct);
   125  UINT32 event_manager_initialize(UINT32 num_of_host_cpus);
   126  UINT32 event_manager_guest_initialize(GUEST_ID guest_id);
   127  UINT32 event_manager_gcpu_initialize(GUEST_CPU_HANDLE gcpu);
   128  
   129  void event_cleanup_event_manger(void);
   130  
   131  BOOLEAN event_global_register(
   132      UVMM_EVENT_INTERNAL e,      //  in: event
   133      event_callback      call    //  in: callback to register on event e
   134      );
   135  
   136  BOOLEAN event_guest_register(
   137      UVMM_EVENT_INTERNAL e,      //  in: event
   138      GUEST_HANDLE        guest,  // in:  guest handle
   139      event_callback      call    //  in: callback to register on event e
   140      );
   141  
   142  BOOLEAN event_gcpu_register(
   143      UVMM_EVENT_INTERNAL e,      //  in: event
   144      GUEST_CPU_HANDLE    gcpu,   // in:  guest cpu
   145      event_callback      call    //  in: callback to register on event e
   146      );
   147  
   148  
   149  BOOLEAN event_global_unregister(
   150      UVMM_EVENT_INTERNAL e,      //  in: event
   151      event_callback      call    //  in: callback to unregister from event e
   152      );
   153  
   154  BOOLEAN event_guest_unregister(
   155      UVMM_EVENT_INTERNAL e,      //  in: event
   156      GUEST_HANDLE        guest,  // in:  guest handle
   157      event_callback      call    //  in: callback to unregister from event e
   158      );
   159  
   160  BOOLEAN event_gcpu_unregister(
   161      UVMM_EVENT_INTERNAL e,      //  in: event
   162      GUEST_CPU_HANDLE    gcpu,   // in:  guest cpu
   163      event_callback      call    //  in: callback to unregister from event e
   164      );
   165  
   166  typedef enum {
   167      EVENT_NO_HANDLERS_REGISTERED,
   168      EVENT_HANDLED,
   169      EVENT_NOT_HANDLED,
   170  } RAISE_EVENT_RETVAL;
   171  
   172  // returns counter of executed observers
   173  BOOLEAN event_raise(
   174      UVMM_EVENT_INTERNAL e,      // in:  event
   175      GUEST_CPU_HANDLE    gcpu,   // in:  guest cpu
   176      void                *p      // in:  pointer to event specific structure
   177      );
   178  
   179  BOOLEAN event_is_registered(
   180          UVMM_EVENT_INTERNAL e,      // in:  event
   181          GUEST_CPU_HANDLE    gcpu,   // in:  guest cpu
   182          event_callback      call    // in:  callback to check
   183          );
   184