Xenomai  3.0-rc3
assert.h
1 /*
2  * Copyright (C) 2006 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_KERNEL_ASSERT_H
20 #define _COBALT_KERNEL_ASSERT_H
21 
22 #include <cobalt/kernel/trace.h>
23 #include <cobalt/kernel/ancillaries.h>
24 
25 #define XENO_INFO KERN_INFO "[Xenomai] "
26 #define XENO_WARN KERN_WARNING "[Xenomai] "
27 #define XENO_ERR KERN_ERR "[Xenomai] "
28 
29 #define XENO_DEBUG(__subsys) \
30  (CONFIG_XENO_OPT_DEBUG_##__subsys > 0)
31 
32 #define XENO_ASSERT(__subsys, __cond) \
33  ({ \
34  int __ret = !XENO_DEBUG(__subsys) || (__cond); \
35  if (unlikely(!__ret)) \
36  __xnsys_assert_failed(__FILE__, __LINE__, (#__cond)); \
37  __ret; \
38  })
39 
40 #define XENO_BUGON(__subsys, __cond) \
41  do { \
42  if (unlikely(XENO_DEBUG(__subsys) && (__cond))) \
43  xnsys_fatal("bug at %s:%d (%s)", \
44  __FILE__, __LINE__, (#__cond)); \
45  } while (0)
46 
47 #define XENO_BUG(__subsys) XENO_BUGON(__subsys, 1)
48 
49 #define XENO_WARNON(__subsys, __cond) \
50  do { \
51  if (unlikely(XENO_DEBUG(__subsys) && (__cond))) \
52  printk(XENO_WARN "assertion failed at %s:%d (%s)", \
53  __FILE__, __LINE__, (#__cond)); \
54  } while (0)
55 
56 #ifndef CONFIG_XENO_OPT_DEBUG_COBALT
57 #define CONFIG_XENO_OPT_DEBUG_COBALT 0
58 #endif
59 
60 #ifndef CONFIG_XENO_OPT_DEBUG_CONTEXT
61 #define CONFIG_XENO_OPT_DEBUG_CONTEXT 0
62 #endif
63 
64 #ifndef CONFIG_XENO_OPT_DEBUG_LOCKING
65 #define CONFIG_XENO_OPT_DEBUG_LOCKING 0
66 #endif
67 
68 #ifndef CONFIG_XENO_OPT_DEBUG_USER
69 #define CONFIG_XENO_OPT_DEBUG_USER 0
70 #endif
71 
72 #define primary_mode_only() XENO_BUGON(CONTEXT, ipipe_root_p)
73 #define secondary_mode_only() XENO_BUGON(CONTEXT, !ipipe_root_p)
74 #define interrupt_only() XENO_BUGON(CONTEXT, !xnsched_interrupt_p())
75 #define realtime_cpu_only() XENO_BUGON(CONTEXT, !xnsched_supported_cpu(ipipe_processor_id()))
76 #define thread_only() XENO_BUGON(CONTEXT, xnsched_interrupt_p())
77 #if XENO_DEBUG(LOCKING)
78 #define atomic_only() XENO_BUGON(CONTEXT, (xnlock_is_owner(&nklock) && hard_irqs_disabled()) == 0)
79 #define preemptible_only() XENO_BUGON(CONTEXT, xnlock_is_owner(&nklock) || hard_irqs_disabled())
80 #else
81 #define atomic_only() XENO_BUGON(CONTEXT, hard_irqs_disabled() == 0)
82 #define preemptible_only() XENO_BUGON(CONTEXT, hard_irqs_disabled() != 0)
83 #endif
84 
85 void __xnsys_assert_failed(const char *file, int line, const char *msg);
86 
87 void __xnsys_fatal(const char *format, ...);
88 
89 #define xnsys_fatal(__fmt, __args...) nkpanic(KERN_ERR __fmt, ##__args)
90 
91 extern void (*nkpanic)(const char *format, ...);
92 
93 #endif /* !_COBALT_KERNEL_ASSERT_H */