sel_ldr: Remove support for rodata segment at start of executable
[nativeclient.git] / service_runtime / nacl_check.h
blobee743b1a44bc956f9eedcb05357410321ec58741
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * NaCl service runtime, check macros.
36 #ifndef NATIVE_CLIENT_SERVICE_RUNTIME_NACL_CHECK_H_
37 #define NATIVE_CLIENT_SERVICE_RUNTIME_NACL_CHECK_H_
39 #include "native_client/service_runtime/nacl_log.h"
42 * We cannot use variadic macros since not all preprocessors provide
43 * them. Instead, we require uses of the CHECK and DCHECK macro write
44 * code in the following manner:
46 * CHECK(a == b);
48 * or
50 * VCHECK(a == b, ("a = %d, b = %d, c = %s\n", a, b, some_cstr));
52 * depending on whether a printf-like, more detailed message in
53 * addition to the invariance failure should be printed.
55 * NB: BEWARE of printf arguments the evaluation of which have
56 * side-effects. Any such will cause the program to behave
57 * differently depending on whether debug mode is enabled or not.
59 #define CHECK(bool_expr) do { \
60 if (!(bool_expr)) { \
61 NaClLog(LOG_FATAL, "Fatal error in file %s, line %d: !(%s)\n", \
62 __FILE__, __LINE__, #bool_expr); \
63 } \
64 } while (0)
66 #define DCHECK(bool_expr) do { \
67 if (nacl_check_debug_mode && !(bool_expr)) { \
68 NaClLog(LOG_FATAL, "Fatal error in file %s, line %d: !(%s)\n", \
69 __FILE__, __LINE__, #bool_expr); \
70 } \
71 } while (0)
73 #define VCHECK(bool_expr, fn_arg) do { \
74 if (!(bool_expr)) { \
75 NaClLog(LOG_ERROR, "Fatal error in file %s, line %d: !(%s)\n", \
76 __FILE__, __LINE__, #bool_expr); \
77 NaClCheckIntern fn_arg; \
78 } \
79 } while (0)
81 #define DVCHECK(bool_expr, fn_arg) do { \
82 if (nacl_check_debug_mode && !(bool_expr)) { \
83 NaClLog(LOG_ERROR, "Fatal error in file %s, line %d: !(%s)\n", \
84 __FILE__, __LINE__, #bool_expr); \
85 NaClCheckIntern fn_arg; \
86 } \
87 } while (0)
90 * By default, nacl_check_debug mode is 0, so DCHECKs are not
91 * performed. CHECKs are always performed.
93 extern void NaClCheckSetDebugMode(int mode);
96 * This is a private variable, needed for the macro. Do not reference
97 * directly.
99 extern int nacl_check_debug_mode;
102 * This is a private function, used by the macros above. Do not
103 * reference directly.
105 extern void NaClCheckIntern(char *fmt, ...);
107 #endif