ia64/xen-unstable

view xen/include/xen/lib.h @ 14054:43e9952b07ea

x86: Better BUG() and ASSERT() logging.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Feb 21 14:40:37 2007 +0000 (2007-02-21)
parents 4990b2236f06
children 070cf119a7ec
line source
1 #ifndef __LIB_H__
2 #define __LIB_H__
4 #include <xen/inttypes.h>
5 #include <xen/stdarg.h>
6 #include <xen/config.h>
7 #include <xen/types.h>
8 #include <xen/xmalloc.h>
9 #include <xen/string.h>
10 #include <asm/bug.h>
12 void __bug(char *file, int line) __attribute__((noreturn));
14 #define BUG_ON(_p) do { if (_p) BUG(); } while ( 0 )
16 /* Force a compilation error if condition is true */
17 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
19 #ifndef assert_failed
20 #define assert_failed(p) \
21 do { \
22 printk("Assertion '%s' failed, line %d, file %s\n", #p , \
23 __LINE__, __FILE__); \
24 BUG(); \
25 } while (0)
26 #endif
28 #ifndef NDEBUG
29 #define ASSERT(p) \
30 do { if ( unlikely(!(p)) ) assert_failed(p); } while (0)
31 #else
32 #define ASSERT(p) ((void)0)
33 #endif
35 #define SWAP(_a, _b) \
36 do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
38 #define DIV_ROUND(x, y) (((x) + (y) / 2) / (y))
40 #define reserve_bootmem(_p,_l) ((void)0)
42 struct domain;
44 void cmdline_parse(char *cmdline);
46 /*#define DEBUG_TRACE_DUMP*/
47 #ifdef DEBUG_TRACE_DUMP
48 extern void debugtrace_dump(void);
49 extern void debugtrace_printk(const char *fmt, ...);
50 #else
51 #define debugtrace_dump() ((void)0)
52 #define debugtrace_printk(_f, ...) ((void)0)
53 #endif
55 /* Allows us to use '%p' as general-purpose machine-word format char. */
56 #define _p(_x) ((void *)(unsigned long)(_x))
57 extern void printk(const char *format, ...)
58 __attribute__ ((format (printf, 1, 2)));
59 extern void panic(const char *format, ...)
60 __attribute__ ((format (printf, 1, 2)));
61 extern long vm_assist(struct domain *, unsigned int, unsigned int);
62 extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
63 extern int printk_ratelimit(void);
65 /* vsprintf.c */
66 #define sprintf __xen_has_no_sprintf__
67 #define vsprintf __xen_has_no_vsprintf__
68 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
69 __attribute__ ((format (printf, 3, 4)));
70 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
71 __attribute__ ((format (printf, 3, 0)));
72 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
73 __attribute__ ((format (printf, 3, 4)));
74 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
75 __attribute__ ((format (printf, 3, 0)));
77 long simple_strtol(
78 const char *cp,const char **endp, unsigned int base);
79 unsigned long simple_strtoul(
80 const char *cp,const char **endp, unsigned int base);
81 long long simple_strtoll(
82 const char *cp,const char **endp, unsigned int base);
83 unsigned long long simple_strtoull(
84 const char *cp,const char **endp, unsigned int base);
86 unsigned long long parse_size_and_unit(const char *s, const char **ps);
88 #define TAINT_UNSAFE_SMP (1<<0)
89 #define TAINT_MACHINE_CHECK (1<<1)
90 #define TAINT_BAD_PAGE (1<<2)
91 #define TAINT_SYNC_CONSOLE (1<<3)
92 extern int tainted;
93 #define TAINT_STRING_MAX_LEN 20
94 extern char *print_tainted(char *str);
95 extern void add_taint(unsigned);
97 #endif /* __LIB_H__ */