fatalerror.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 fatal error handlers. They all post fatal errors regardless of build
  24. * type.
  25. */
  26. #ifndef _FATALERROR_H
  27. #define _FATALERROR_H
  28. #define INCLUDE_ALLOW_MVPD
  29. #define INCLUDE_ALLOW_VMX
  30. #define INCLUDE_ALLOW_MODULE
  31. #define INCLUDE_ALLOW_MONITOR
  32. #define INCLUDE_ALLOW_PV
  33. #define INCLUDE_ALLOW_HOSTUSER
  34. #define INCLUDE_ALLOW_GUESTUSER
  35. #define INCLUDE_ALLOW_WORKSTATION
  36. #define INCLUDE_ALLOW_GPL
  37. #include "include_check.h"
  38. #include "mvp_compiler.h"
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. enum FECode {
  43. FECodeMisc, /**< generic FATAL() call of sorts */
  44. FECodeOOM, /**< FATAL_OOM() call of sorts */
  45. FECodeAssert, /**< ASSERT() call of sorts */
  46. FECodeNR, /**< NOT_REACHED() call of sorts */
  47. FECodeNI, /**< NOT_IMPLEMENTED() call of sorts */
  48. FECodeNT, /**< NOT_TESTED() call of sorts */
  49. FECodeCF /**< COMPILE_FAIL() call of sorts */
  50. };
  51. typedef enum FECode FECode;
  52. #define FATAL() FatalError(__FILE__, __LINE__, FECodeMisc, 0, NULL)
  53. #define FATAL_IF(x) do { if (UNLIKELY(x)) FATAL(); } while (0)
  54. #define FATAL_OOM() FatalError(__FILE__, __LINE__, FECodeOOM, 0, NULL)
  55. #define FATAL_OOM_IF(x) do { if (UNLIKELY(x)) FATAL_OOM(); } while (0)
  56. extern _Bool FatalError_hit;
  57. void NORETURN
  58. FatalError(char const *file,
  59. int line,
  60. FECode feCode,
  61. int bugno,
  62. char const *fmt,
  63. ...) FORMAT(printf, 5, 6);
  64. #define FATALERROR_COMMON(printFunc, \
  65. printFuncV, \
  66. file, \
  67. line, \
  68. feCode, \
  69. bugno, \
  70. fmt) \
  71. { \
  72. va_list ap; \
  73. \
  74. printFunc("FatalError: %s:%d, code %d, bugno %d\n", \
  75. file, line, feCode, bugno); \
  76. if (fmt != NULL) { \
  77. va_start(ap, fmt); \
  78. printFuncV(fmt, ap); \
  79. va_end(ap); \
  80. } \
  81. }
  82. #if defined IN_HOSTUSER || defined IN_GUESTUSER || defined IN_WORKSTATION
  83. #define FATALERROR_POSIX_USER \
  84. void \
  85. FatalError_VErrPrintf(const char *fmt, \
  86. va_list ap) \
  87. { \
  88. vfprintf(stderr, fmt, ap); \
  89. } \
  90. \
  91. void \
  92. FatalError_ErrPrintf(const char *fmt, ...) \
  93. { \
  94. va_list ap; \
  95. va_start(ap, fmt); \
  96. FatalError_VErrPrintf(fmt, ap); \
  97. va_end(ap); \
  98. } \
  99. \
  100. void NORETURN \
  101. FatalError(char const *file, \
  102. int line, \
  103. FECode feCode, \
  104. int bugno, \
  105. const char *fmt, \
  106. ...) \
  107. { \
  108. FATALERROR_COMMON(FatalError_ErrPrintf, \
  109. FatalError_VErrPrintf,\
  110. file, line, feCode, \
  111. bugno, fmt); \
  112. exit(EXIT_FAILURE); \
  113. }
  114. #endif
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif