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#include <config.h>
23
24#if UTILITY_LINUX
25// Redirect to system assert.h
26#include <assert.h>
27#else
28#include "pedigree/kernel/compiler.h"
29
30#include <stdint.h>
31
38#if DEBUGGER || ASSERTS
39#define assert(x) \
40 do { \
41 bool __pedigree_assert_chk = (x); \
42 if (UNLIKELY(!__pedigree_assert_chk)) \
43 _assert(__pedigree_assert_chk, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
44 } while (0)
45
46#if !USE_DEBUG_ALLOCATOR
47#define assert_heap_ptr_valid(x) \
48 _assert(_assert_ptr_valid(reinterpret_cast<uintptr_t>(x)), __FILE__, __LINE__, \
49 __PRETTY_FUNCTION__)
50#else
51#define assert_heap_ptr_valid
52#endif
53
54#elif !defined(assert)
55#define assert(x) ((void)0)
56#define assert_heap_ptr_valid(x) ((void)0)
57#endif
58
59#ifndef __cplusplus
60#define bool char
61#endif
62
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69void EXPORTED_PUBLIC _assert(bool b, const char* file, int line, const char* func);
70bool _assert_ptr_valid(uintptr_t x);
71
72#ifdef __cplusplus
73}
74#endif
75#endif
76
79#endif
void EXPORTED_PUBLIC _assert(bool b, const char *file, int line, const char *func)
Definition assert.cc:27