1 /* Microsoft Reference Implementation for TPM 2.0 2 * 3 * The copyright in this software is being made available under the BSD License, 4 * included below. This software may be subject to other third party and 5 * contributor rights, including patent rights, and no such rights are granted 6 * under this license. 7 * 8 * Copyright (c) Microsoft Corporation 9 * 10 * All rights reserved. 11 * 12 * BSD License 13 * 14 * Redistribution and use in source and binary forms, with or without modification, 15 * are permitted provided that the following conditions are met: 16 * 17 * Redistributions of source code must retain the above copyright notice, this list 18 * of conditions and the following disclaimer. 19 * 20 * Redistributions in binary form must reproduce the above copyright notice, this 21 * list of conditions and the following disclaimer in the documentation and/or 22 * other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 // This file contains the build switches. This contains switches for multiple 36 // versions of the crypto-library so some may not apply to your environment. 37 // 38 39 #ifndef _COMPILER_DEPENDENCIES_H_ 40 #define _COMPILER_DEPENDENCIES_H_ 41 42 #ifdef GCC 43 # undef _MSC_VER 44 # undef WIN32 45 #endif 46 47 #ifdef _MSC_VER 48 // These definitions are for the Microsoft compiler 49 50 // Endian conversion for aligned structures 51 # define REVERSE_ENDIAN_16(_Number) _byteswap_ushort(_Number) 52 # define REVERSE_ENDIAN_32(_Number) _byteswap_ulong(_Number) 53 # define REVERSE_ENDIAN_64(_Number) _byteswap_uint64(_Number) 54 55 // Avoid compiler warning for in line of stdio (or not) 56 //#define _NO_CRT_STDIO_INLINE 57 58 // This macro is used to handle LIB_EXPORT of function and variable names in lieu 59 // of a .def file. Visual Studio requires that functions be explicitly exported and 60 // imported. 61 # define LIB_EXPORT __declspec(dllexport) // VS compatible version 62 # define LIB_IMPORT __declspec(dllimport) 63 64 // This is defined to indicate a function that does not return. Microsoft compilers 65 // do not support the _Noretrun function parameter. 66 # define NORETURN __declspec(noreturn) 67 # if _MSC_VER >= 1400 // SAL processing when needed 68 # include <sal.h> 69 # endif 70 71 # ifdef _WIN64 72 # define _INTPTR 2 73 # else 74 # define _INTPTR 1 75 # endif 76 77 78 #define NOT_REFERENCED(x) (x) 79 80 // Lower the compiler error warning for system include 81 // files. They tend not to be that clean and there is no 82 // reason to sort through all the spurious errors that they 83 // generate when the normal error level is set to /Wall 84 # define _REDUCE_WARNING_LEVEL_(n) \ 85 __pragma(warning(push, n)) 86 // Restore the compiler warning level 87 # define _NORMAL_WARNING_LEVEL_ \ 88 __pragma(warning(pop)) 89 # include <stdint.h> 90 #endif 91 92 #ifndef _MSC_VER 93 #ifndef WINAPI 94 # define WINAPI 95 #endif 96 # define __pragma(x) 97 # define REVERSE_ENDIAN_16(_Number) __builtin_bswap16(_Number) 98 # define REVERSE_ENDIAN_32(_Number) __builtin_bswap32(_Number) 99 # define REVERSE_ENDIAN_64(_Number) __builtin_bswap64(_Number) 100 #endif 101 102 #if defined(__GNUC__) 103 # define NORETURN __attribute__((noreturn)) 104 # include <stdint.h> 105 #endif 106 107 // Things that are not defined should be defined as NULL 108 #ifndef NORETURN 109 # define NORETURN 110 #endif 111 #ifndef LIB_EXPORT 112 # define LIB_EXPORT 113 #endif 114 #ifndef LIB_IMPORT 115 # define LIB_IMPORT 116 #endif 117 #ifndef _REDUCE_WARNING_LEVEL_ 118 # define _REDUCE_WARNING_LEVEL_(n) 119 #endif 120 #ifndef _NORMAL_WARNING_LEVEL_ 121 # define _NORMAL_WARNING_LEVEL_ 122 #endif 123 #ifndef NOT_REFERENCED 124 # define NOT_REFERENCED(x) (x = x) 125 #endif 126 127 #ifdef _POSIX_ 128 typedef int SOCKET; 129 #endif 130 131 132 #endif // _COMPILER_DEPENDENCIES_H_