btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / debug_paranoia.h
blob0f12dbda6057afe93d562946d7c5335ba4637597
1 /*
2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _KERNEL_DEBUG_PARANOIA_H
6 #define _KERNEL_DEBUG_PARANOIA_H
8 #include <sys/cdefs.h>
10 #include <SupportDefs.h>
12 #include "paranoia_config.h"
15 // How to use: Include the header only from source files. Set
16 // COMPONENT_PARANOIA_LEVEL before. Use the macros defined below and the
17 // ParanoiaChecker class.
19 // paranoia levels
20 #define PARANOIA_NAIVE 0 /* don't do any checks */
21 #define PARANOIA_SUSPICIOUS 1 /* do some checks */
22 #define PARANOIA_OBSESSIVE 2 /* do a lot of checks */
23 #define PARANOIA_INSANE 3 /* do all checks, also very expensive ones */
25 // mode for set_paranoia_check()
26 enum paranoia_set_check_mode {
27 PARANOIA_DONT_FAIL, // succeed, if check for address exists or not
28 PARANOIA_FAIL_IF_EXISTS, // fail, if check for address already exists
29 PARANOIA_FAIL_IF_MISSING // fail, if check for address doesn't exist yet
33 __BEGIN_DECLS
35 #if ENABLE_PARANOIA_CHECKS
37 status_t create_paranoia_check_set(const void* object,
38 const char* description);
39 status_t delete_paranoia_check_set(const void* object);
40 status_t run_paranoia_checks(const void* object);
42 status_t set_paranoia_check(const void* object, const void* address,
43 size_t size, paranoia_set_check_mode mode);
44 status_t remove_paranoia_check(const void* object, const void* address,
45 size_t size);
47 #endif // ENABLE_PARANOIA_CHECKS
49 void debug_paranoia_init();
51 __END_DECLS
54 #if ENABLE_PARANOIA_CHECKS && COMPONENT_PARANOIA_LEVEL
55 # define PARANOIA_ONLY(x) x
56 # define PARANOIA_ONLY_LEVEL(level, x) \
57 if ((level) <= (COMPONENT_PARANOIA_LEVEL)) { \
58 x; \
60 #else
61 # define PARANOIA_ONLY(x)
62 # define PARANOIA_ONLY_LEVEL(level, x)
63 #endif
65 #define CREATE_PARANOIA_CHECK_SET(object, description) \
66 PARANOIA_ONLY(create_paranoia_check_set((object), (description)))
67 #define DELETE_PARANOIA_CHECK_SET(object) \
68 PARANOIA_ONLY(delete_paranoia_check_set((object)))
69 #define RUN_PARANOIA_CHECKS(object) \
70 PARANOIA_ONLY(run_paranoia_checks((object)))
72 #define ADD_PARANOIA_CHECK(level, object, address, size) \
73 PARANOIA_ONLY_LEVEL((level), \
74 set_paranoia_check((object), (address), (size), \
75 PARANOIA_FAIL_IF_EXISTS))
76 #define UPDATE_PARANOIA_CHECK(level, object, address, size) \
77 PARANOIA_ONLY_LEVEL((level), \
78 set_paranoia_check((object), (address), (size), \
79 PARANOIA_FAIL_IF_MISSING))
80 #define SET_PARANOIA_CHECK(level, object, address, size) \
81 PARANOIA_ONLY_LEVEL((level), \
82 set_paranoia_check((object), (address), (size), \
83 PARANOIA_DONT_FAIL))
84 #define REMOVE_PARANOIA_CHECK(level, object, address, size) \
85 PARANOIA_ONLY_LEVEL((level), \
86 remove_paranoia_check((object), (address), (size)))
89 #ifdef __cplusplus
91 class ParanoiaChecker {
92 public:
93 inline ParanoiaChecker(const void* object)
95 PARANOIA_ONLY(fObject = object);
96 RUN_PARANOIA_CHECKS(fObject);
99 inline ~ParanoiaChecker()
101 PARANOIA_ONLY(
102 if (fObject != NULL)
103 RUN_PARANOIA_CHECKS(fObject);
107 inline void Disable()
109 PARANOIA_ONLY(fObject = NULL);
112 private:
113 PARANOIA_ONLY(
114 const void* fObject;
118 #endif // __cplusplus
121 #endif // _KERNEL_DEBUG_PARANOIA_H