github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/common/include/common_libc.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 _UVMM_COMMON_CRT_H_
    16  #define _UVMM_COMMON_CRT_H_
    17  
    18  #include "vmm_defs.h"
    19  
    20  
    21  // Subset of CRT-like routines to be used in VMM and loader environments
    22  
    23  void *  vmm_memset(void *dest, int filler, size_t count);
    24  void *  vmm_memcpy(void *dest, const void* src, size_t count);
    25  void *  vmm_memmove(void *dest, const void* src, int count);
    26  void *  vmm_lock_memcpy(void *dest, const void* src, size_t count);
    27  size_t  vmm_strlen(const char* string);
    28  char*   vmm_strcpy(char* dst, const char* src);
    29  char*   vmm_strcpy_s(char* dst, size_t dst_length, const char* src);
    30  int     vmm_strcmp(const char* string1, const char* string2);
    31  void    vmm_memcpy_assuming_mmio(UINT8 *dst, UINT8 *src, INT32 count);
    32  int     vmm_memcmp(const void* mem1, const void* mem2, size_t count);
    33  
    34  #define vmm_zeromem(dest_, count_) vmm_memset(dest_, 0, count_);
    35  
    36  // sprintf_s() - secure sprintf. Includes size of input buffer
    37  
    38  
    39  //
    40  // Format specification
    41  //
    42  //  Types:
    43  //      %X - hex uppercase unsigned integer
    44  //      %x - hex lowercase unsigned integer
    45  //      %P - hex uppercase unsigned integer, 32bit on x86 and 64bit on em64t
    46  //           default width - 10 chars, starting with '0x' prefix and including
    47  //           leading zeroes
    48  //      %p - hex lowercase unsigned integer, 32bit on x86 and 64bit on em64t
    49  //           default width - 10 chars, starting with '0x' prefix and including
    50  //           leading zeroes
    51  //      %u - unsigned decimal
    52  //      %d - signed decimal
    53  //      %i - signed decimal
    54  //      %s - ascii string
    55  //      %c - ascii char
    56  //      %g - VMM_GUID*
    57  //      %t - VMM_TIME*
    58  //      %% - %
    59  //
    60  //  Width and flags:
    61  //      '-' - left justify
    62  //      '+' - in numbers: print '+' sign for positives
    63  //      ' ' - fill extra width with spaces
    64  //      ',' - print ',' each 3 digits in numbers
    65  //      '#' - prefix hex numbers with '0x' and fill extra width with 0
    66  //              ex: "%#6x" for "0xf" will result in 0x000f
    67  //      'L'
    68  //      'l' - 64bit integer, ex: "%lx"
    69  //      'I' - size_t value. That is 32bit on x86 and 64bit on em64t
    70  //      '*' - the width is specified in params,
    71  //            ex: ("%*x", 3, 5), 3 - width, 5 - number to print
    72  //      '0' - print leading zeroes
    73  //      positive_number - field width
    74  //
    75  
    76  
    77  int CDECL vmm_sprintf_s( char *buffer, size_t size_of_buffer, const char *format, ...);
    78  int CDECL vmm_vsprintf_s( char *buffer, size_t size_of_buffer, const char *format, va_list argptr );
    79  
    80  // printf() have to be implemented independently in each project
    81  int CDECL vmm_printf( const char *format, ... );
    82  int CDECL vmm_vprintf(const char *format, va_list args);
    83  
    84  extern void vmm_lock_xchg_qword(UINT64 *dst, UINT64 *src);
    85  extern void vmm_lock_xchg_dword(UINT32 *dst, UINT32 *src);
    86  
    87  #ifdef ARCH_ADDRESS_WIDTH
    88  	#if 8 == ARCH_ADDRESS_WIDTH
    89  		#define VMM_LONG UINT64
    90  		#define BIT_SHIFT 3
    91  		#define REM_MASK 7
    92  		#define vmm_lock_xchg_32_64_word(x, y) \
    93  				vmm_lock_xchg_qword((UINT64*)(x), (UINT64*)(y))
    94  	#else
    95  		#define VMM_LONG UINT32
    96  		#define BIT_SHIFT 2
    97  		#define REM_MASK 3
    98  		#define vmm_lock_xchg_32_64_word(x, y) \
    99  				vmm_lock_xchg_dword((UINT32*)(x), (UINT32*)(y))
   100  	#endif
   101  #else
   102  	#define VMM_LONG UINT32
   103  	#define BIT_SHIFT 2
   104  	#define REM_MASK 3
   105  	#define vmm_lock_xchg_32_64_word(x, y) \
   106  			vmm_lock_xchg_dword((UINT32*)(x), (UINT32*)(y))
   107  #endif
   108  
   109  #define COUNT_32_64(x) ((x) >> (BIT_SHIFT))
   110  #define REMAINDER_32_64(x) ((x) & (REM_MASK))
   111  #define SHL_32_64(x) ((x) << (BIT_SHIFT))
   112  
   113  #endif // _UVMM_COMMON_CRT_H_