The Pedigree Project  0.1
assert.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_ASSERT_H
21 #define KERNEL_ASSERT_H
22 
23 #ifdef UTILITY_LINUX
24 // Redirect to system assert.h
25 #include <assert.h>
26 #else
27 #include "pedigree/kernel/compiler.h"
28 #include <stdint.h>
29 
36 #if defined(DEBUGGER) || defined(ASSERTS)
37 #define assert(x) \
38  do \
39  { \
40  bool __pedigree_assert_chk = (x); \
41  if (UNLIKELY(!__pedigree_assert_chk)) \
42  _assert( \
43  __pedigree_assert_chk, __FILE__, __LINE__, \
44  __PRETTY_FUNCTION__); \
45  } while (0)
46 
47 #ifndef USE_DEBUG_ALLOCATOR
48 #define assert_heap_ptr_valid(x) \
49  _assert( \
50  _assert_ptr_valid(reinterpret_cast<uintptr_t>(x)), __FILE__, __LINE__, \
51  __PRETTY_FUNCTION__)
52 #else
53 #define assert_heap_ptr_valid
54 #endif
55 
56 #elif !defined(assert)
57 #define assert(x)
58 #define assert_heap_ptr_valid(x)
59 #endif
60 
61 #ifndef __cplusplus
62 #define bool char
63 #endif
64 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 void EXPORTED_PUBLIC
72 _assert(bool b, const char *file, int line, const char *func);
73 bool _assert_ptr_valid(uintptr_t x);
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 #endif
79 
82 #endif
void EXPORTED_PUBLIC _assert(bool b, const char *file, int line, const char *func)
Definition: assert.cc:24