CompilerDependencies.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /********************************************************************************/
  2. /* */
  3. /* Compiler Dependencies */
  4. /* Written by Ken Goldman */
  5. /* IBM Thomas J. Watson Research Center */
  6. /* $Id: CompilerDependencies.h 1453 2019-04-05 16:43:36Z kgoldman $ */
  7. /* */
  8. /* Licenses and Notices */
  9. /* */
  10. /* 1. Copyright Licenses: */
  11. /* */
  12. /* - Trusted Computing Group (TCG) grants to the user of the source code in */
  13. /* this specification (the "Source Code") a worldwide, irrevocable, */
  14. /* nonexclusive, royalty free, copyright license to reproduce, create */
  15. /* derivative works, distribute, display and perform the Source Code and */
  16. /* derivative works thereof, and to grant others the rights granted herein. */
  17. /* */
  18. /* - The TCG grants to the user of the other parts of the specification */
  19. /* (other than the Source Code) the rights to reproduce, distribute, */
  20. /* display, and perform the specification solely for the purpose of */
  21. /* developing products based on such documents. */
  22. /* */
  23. /* 2. Source Code Distribution Conditions: */
  24. /* */
  25. /* - Redistributions of Source Code must retain the above copyright licenses, */
  26. /* this list of conditions and the following disclaimers. */
  27. /* */
  28. /* - Redistributions in binary form must reproduce the above copyright */
  29. /* licenses, this list of conditions and the following disclaimers in the */
  30. /* documentation and/or other materials provided with the distribution. */
  31. /* */
  32. /* 3. Disclaimers: */
  33. /* */
  34. /* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
  35. /* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
  36. /* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
  37. /* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */
  38. /* Contact TCG Administration (admin@trustedcomputinggroup.org) for */
  39. /* information on specification licensing rights available through TCG */
  40. /* membership agreements. */
  41. /* */
  42. /* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */
  43. /* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */
  44. /* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */
  45. /* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */
  46. /* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */
  47. /* */
  48. /* - Without limitation, TCG and its members and licensors disclaim all */
  49. /* liability, including liability for infringement of any proprietary */
  50. /* rights, relating to use of information in this specification and to the */
  51. /* implementation of this specification, and TCG disclaims all liability for */
  52. /* cost of procurement of substitute goods or services, lost profits, loss */
  53. /* of use, loss of data or any incidental, consequential, direct, indirect, */
  54. /* or special damages, whether under contract, tort, warranty or otherwise, */
  55. /* arising in any way out of use or reliance upon this specification or any */
  56. /* information herein. */
  57. /* */
  58. /* (c) Copyright IBM Corp. and others, 2016 - 2019 */
  59. /* */
  60. /********************************************************************************/
  61. #ifndef COMPILERDEPEDENCIES_H
  62. #define COMPILERDEPEDENCIES_H
  63. /* kgold - Not in the original code. A user reported that it was required for a non-Visual Studio
  64. environment.
  65. */
  66. #ifdef TPM_WINDOWS
  67. #include <windows.h>
  68. #include <winsock.h>
  69. #endif
  70. /* 5.10 CompilerDependencies.h */
  71. #ifdef GCC
  72. # undef _MSC_VER
  73. # undef WIN32
  74. #endif
  75. #ifdef _MSC_VER
  76. // These definitions are for the Microsoft compiler Endian conversion for aligned structures
  77. # define REVERSE_ENDIAN_16(_Number) _byteswap_ushort(_Number)
  78. # define REVERSE_ENDIAN_32(_Number) _byteswap_ulong(_Number)
  79. # define REVERSE_ENDIAN_64(_Number) _byteswap_uint64(_Number)
  80. // Avoid compiler warning for in line of stdio (or not)
  81. // #define _NO_CRT_STDIO_INLINE
  82. // This macro is used to handle LIB_EXPORT of function and variable names in lieu of a .def
  83. // file. Visual Studio requires that functions be explicitly exported and imported.
  84. # define LIB_EXPORT __declspec(dllexport) // VS compatible version
  85. # define LIB_IMPORT __declspec(dllimport)
  86. // This is defined to indicate a function that does not return. Microsoft compilers do not
  87. // support the _Noretrun() function parameter.
  88. # define NORETURN __declspec(noreturn)
  89. # if _MSC_VER >= 1400 // SAL processing when needed
  90. # include <sal.h>
  91. # endif
  92. # ifdef _WIN64
  93. # define _INTPTR 2
  94. # else
  95. # define _INTPTR 1
  96. # endif
  97. # define NOT_REFERENCED(x) (x)
  98. // Lower the compiler error warning for system include files. They tend not to be that clean and
  99. // there is no reason to sort through all the spurious errors that they generate when the normal
  100. // error level is set to /Wall
  101. # define _REDUCE_WARNING_LEVEL_(n) \
  102. __pragma(warning(push, n))
  103. // Restore the compiler warning level
  104. # define _NORMAL_WARNING_LEVEL_ \
  105. __pragma(warning(pop))
  106. # include <stdint.h>
  107. #endif // _MSC_VER
  108. #ifndef _MSC_VER
  109. #ifndef WINAPI
  110. # define WINAPI
  111. #endif
  112. # define __pragma(x)
  113. # define REVERSE_ENDIAN_16(_Number) __builtin_bswap16(_Number)
  114. # define REVERSE_ENDIAN_32(_Number) __builtin_bswap32(_Number)
  115. # define REVERSE_ENDIAN_64(_Number) __builtin_bswap64(_Number)
  116. #endif
  117. #if defined(__GNUC__)
  118. # define NORETURN __attribute__((noreturn))
  119. # include <stdint.h>
  120. #endif
  121. // Things that are not defined should be defined as NULL
  122. #ifndef NORETURN
  123. # define NORETURN
  124. #endif
  125. #ifndef LIB_EXPORT
  126. # define LIB_EXPORT
  127. #endif
  128. #ifndef LIB_IMPORT
  129. # define LIB_IMPORT
  130. #endif
  131. #ifndef _REDUCE_WARNING_LEVEL_
  132. # define _REDUCE_WARNING_LEVEL_(n)
  133. #endif
  134. #ifndef _NORMAL_WARNING_LEVEL_
  135. # define _NORMAL_WARNING_LEVEL_
  136. #endif
  137. #ifndef NOT_REFERENCED
  138. # define NOT_REFERENCED(x) (x = x)
  139. #endif
  140. #ifdef _POSIX_
  141. typedef int SOCKET;
  142. #endif
  143. // #ifdef TPM_POSIX
  144. // typedef int SOCKET;
  145. // #endif
  146. #endif // _COMPILER_DEPENDENCIES_H_