mvp_assert.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Linux 2.6.32 and later Kernel module for VMware MVP Hypervisor Support
  3. *
  4. * Copyright (C) 2010-2013 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; see the file COPYING. If not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #line 5
  20. /**
  21. * @file
  22. *
  23. * @brief ASSERT() and related macros.
  24. */
  25. #ifndef _MVP_ASSERT_H
  26. #define _MVP_ASSERT_H
  27. #define INCLUDE_ALLOW_MVPD
  28. #define INCLUDE_ALLOW_VMX
  29. #define INCLUDE_ALLOW_MODULE
  30. #define INCLUDE_ALLOW_MONITOR
  31. #define INCLUDE_ALLOW_PV
  32. #define INCLUDE_ALLOW_HOSTUSER
  33. #define INCLUDE_ALLOW_GUESTUSER
  34. #define INCLUDE_ALLOW_WORKSTATION
  35. #define INCLUDE_ALLOW_GPL
  36. #include "include_check.h"
  37. #define ASSERT(_x) ASSERT_BUG((_x), 0)
  38. #ifndef NDEBUG
  39. #define ASSERT_BUG(_x, _tkt) do { \
  40. if (UNLIKELY(!(_x))) \
  41. FatalError(__FILE__, __LINE__, FECodeAssert, _tkt, NULL);\
  42. } while (0)
  43. #define ASSERTF(_x, ...) do { \
  44. if (UNLIKELY(!(_x))) \
  45. FatalError(__FILE__, \
  46. __LINE__, \
  47. FECodeAssert, \
  48. 0, \
  49. __VA_ARGS__); \
  50. } while (0)
  51. #else
  52. #define ASSERT_BUG(_x, _tkt) ((void)sizeof((int)(_x)))
  53. #define ASSERTF(_x, ...) ASSERT_BUG(_x, 0)
  54. #endif
  55. /*
  56. * Compile-time assertions.
  57. *
  58. * ASSERT_ON_COMPILE does not use the common
  59. * switch (0) { case 0: case (e): ; } trick because some compilers (e.g. MSVC)
  60. * generate code for it.
  61. *
  62. * The implementation uses both enum and typedef because the typedef alone is
  63. * insufficient; gcc allows arrays to be declared with non-constant expressions
  64. * (even in typedefs, where it makes no sense).
  65. */
  66. #ifdef __COVERITY__
  67. #define ASSERT_ON_COMPILE(e) ASSERT(e)
  68. #else
  69. #define ASSERT_ON_COMPILE(e) do { \
  70. enum { AssertOnCompileMisused = ((e) ? 1 : -1) }; \
  71. typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
  72. } while (0)
  73. #endif
  74. /*
  75. * To put an ASSERT_ON_COMPILE() outside a function, wrap it
  76. * in MY_ASSERTS(). The first parameter must be unique in
  77. * each .c file where it appears. For example,
  78. *
  79. * MY_ASSERTS(FS3_INT,
  80. * ASSERT_ON_COMPILE(sizeof(FS3_DiskLock) == 128);
  81. * ASSERT_ON_COMPILE(sizeof(FS3_DiskLockReserved) == DISK_BLOCK_SIZE);
  82. * ASSERT_ON_COMPILE(sizeof(FS3_DiskBlock) == DISK_BLOCK_SIZE);
  83. * ASSERT_ON_COMPILE(sizeof(Hardware_DMIUUID) == 16);
  84. * )
  85. *
  86. * Caution: ASSERT() within MY_ASSERTS() is silently ignored.
  87. * The same goes for anything else not evaluated at compile time.
  88. */
  89. #define MY_ASSERTS(name, assertions) \
  90. static inline void name(void) \
  91. { \
  92. assertions \
  93. }
  94. #define KNOWN_BUG(_tkt)
  95. #define NOT_IMPLEMENTED() NOT_IMPLEMENTED_JIRA(0)
  96. #define NOT_IMPLEMENTED_JIRA(_tkt, ...) \
  97. FatalError(__FILE__, __LINE__, FECodeNI, _tkt, NULL)
  98. #define NOT_IMPLEMENTED_IF(_x) NOT_IMPLEMENTED_IF_JIRA((_x), 0)
  99. #define NOT_IMPLEMENTED_IF_JIRA(_x, _tkt, ...) do { \
  100. if (UNLIKELY(_x)) \
  101. NOT_IMPLEMENTED_JIRA(_tkt); \
  102. } while (0)
  103. /*
  104. * All sites tagged with this are @knownjira{MVP-1855}.
  105. */
  106. #define NOT_IMPLEMENTEDF(...) \
  107. FatalError(__FILE__, __LINE__, FECodeNI, 0, __VA_ARGS__)
  108. #define NOT_REACHED() FatalError(__FILE__, __LINE__, FECodeNR, 0, NULL)
  109. #include "fatalerror.h"
  110. #include "nottested.h"
  111. #endif