github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/trial_exec.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 _TRIAL_EXEC_H_
    16  #define _TRIAL_EXEC_H_
    17  
    18  #include "hw_setjmp.h"
    19  
    20  typedef struct _TRIAL_DATA {
    21      struct _TRIAL_DATA *prev;
    22      SETJMP_BUFFER      *saved_env;
    23      UINT32              error_code;     // output
    24      VECTOR_ID           fault_vector;   // output
    25      UINT8               pad[3];
    26  } TRIAL_DATA;
    27  
    28  
    29  void        trial_execution_push(TRIAL_DATA *p_trial_data, SETJMP_BUFFER *p_env);
    30  TRIAL_DATA *trial_execution_pop(void);
    31  TRIAL_DATA *trial_execution_get_last(void);
    32  
    33  /*
    34   * TRY/CATCH/END_TRY macros together build the construction 
    35   * for trial(safe) execution.
    36   *  They must be used together and only in that order.
    37   *  Note: Use __p_catch_data carefully, because is declared before TRY/CATCH/END_TRY,
    38   *  but it points to buffer, which is invalid out of TRY... construction.
    39   */
    40  
    41  #define TRY {                                                                  \
    42      TRIAL_DATA      __trial_data;                                              \
    43      SETJMP_BUFFER   __env;                                                     \
    44      if (0 == setjmp(&__env))                                                   \
    45      {                                                                          \
    46          trial_execution_push(&__trial_data, &__env);
    47  
    48  #define CATCH(__p_catch_data)                                                  \
    49          trial_execution_pop();                                                 \
    50      }                                                                          \
    51      else                                                                       \
    52      {                                                                          \
    53          __p_catch_data = trial_execution_pop();
    54  
    55  #define END_TRY                                                                \
    56      }                                                                          \
    57  }
    58  
    59  #endif // _TRIAL_EXEC_H_
    60