ia64/xen-unstable

annotate 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
rev   line source
kaf24@1210 1 #ifndef __LIB_H__
kaf24@1210 2 #define __LIB_H__
kaf24@1210 3
kaf24@4809 4 #include <xen/inttypes.h>
kfraser@11879 5 #include <xen/stdarg.h>
kaf24@3827 6 #include <xen/config.h>
kaf24@1210 7 #include <xen/types.h>
cl349@5285 8 #include <xen/xmalloc.h>
kaf24@1486 9 #include <xen/string.h>
kfraser@14021 10 #include <asm/bug.h>
kaf24@1210 11
kfraser@14021 12 void __bug(char *file, int line) __attribute__((noreturn));
kfraser@14021 13
kaf24@3848 14 #define BUG_ON(_p) do { if (_p) BUG(); } while ( 0 )
kaf24@3848 15
kaf24@9878 16 /* Force a compilation error if condition is true */
kaf24@9878 17 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
kaf24@9878 18
kfraser@14054 19 #ifndef assert_failed
kfraser@14054 20 #define assert_failed(p) \
kfraser@14054 21 do { \
kfraser@14054 22 printk("Assertion '%s' failed, line %d, file %s\n", #p , \
kfraser@14054 23 __LINE__, __FILE__); \
kfraser@14054 24 BUG(); \
kfraser@14054 25 } while (0)
kfraser@14054 26 #endif
kfraser@14054 27
kaf24@1210 28 #ifndef NDEBUG
kfraser@14054 29 #define ASSERT(p) \
kfraser@14054 30 do { if ( unlikely(!(p)) ) assert_failed(p); } while (0)
kaf24@1210 31 #else
kfraser@14054 32 #define ASSERT(p) ((void)0)
kaf24@1210 33 #endif
kaf24@1210 34
kaf24@2635 35 #define SWAP(_a, _b) \
kaf24@2635 36 do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
kaf24@2635 37
iap10@4606 38 #define DIV_ROUND(x, y) (((x) + (y) / 2) / (y))
arun@3920 39
kaf24@3354 40 #define reserve_bootmem(_p,_l) ((void)0)
kaf24@1210 41
cl349@2448 42 struct domain;
cl349@2448 43
kaf24@3338 44 void cmdline_parse(char *cmdline);
kaf24@3338 45
kfraser@11212 46 /*#define DEBUG_TRACE_DUMP*/
kfraser@11212 47 #ifdef DEBUG_TRACE_DUMP
kaf24@3875 48 extern void debugtrace_dump(void);
kaf24@3827 49 extern void debugtrace_printk(const char *fmt, ...);
kaf24@3827 50 #else
kaf24@3875 51 #define debugtrace_dump() ((void)0)
kaf24@3875 52 #define debugtrace_printk(_f, ...) ((void)0)
kaf24@3827 53 #endif
kaf24@3827 54
kaf24@4654 55 /* Allows us to use '%p' as general-purpose machine-word format char. */
kaf24@4654 56 #define _p(_x) ((void *)(unsigned long)(_x))
kfraser@11947 57 extern void printk(const char *format, ...)
kaf24@4654 58 __attribute__ ((format (printf, 1, 2)));
kaf24@9454 59 extern void panic(const char *format, ...)
kaf24@9454 60 __attribute__ ((format (printf, 1, 2)));
kaf24@4654 61 extern long vm_assist(struct domain *, unsigned int, unsigned int);
kaf24@12030 62 extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
kaf24@12030 63 extern int printk_ratelimit(void);
kaf24@1210 64
kaf24@1210 65 /* vsprintf.c */
keir@13756 66 #define sprintf __xen_has_no_sprintf__
kfraser@13697 67 #define vsprintf __xen_has_no_vsprintf__
kaf24@1210 68 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
kaf24@4654 69 __attribute__ ((format (printf, 3, 4)));
kaf24@8520 70 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
kaf24@8520 71 __attribute__ ((format (printf, 3, 0)));
kaf24@8520 72 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
kaf24@8520 73 __attribute__ ((format (printf, 3, 4)));
kaf24@8520 74 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
kaf24@8520 75 __attribute__ ((format (printf, 3, 0)));
kaf24@1210 76
kaf24@4850 77 long simple_strtol(
kfraser@13156 78 const char *cp,const char **endp, unsigned int base);
kaf24@4850 79 unsigned long simple_strtoul(
kfraser@13156 80 const char *cp,const char **endp, unsigned int base);
kaf24@4850 81 long long simple_strtoll(
kfraser@13156 82 const char *cp,const char **endp, unsigned int base);
kaf24@4850 83 unsigned long long simple_strtoull(
kfraser@13156 84 const char *cp,const char **endp, unsigned int base);
kaf24@4850 85
kfraser@13156 86 unsigned long long parse_size_and_unit(const char *s, const char **ps);
kaf24@1210 87
kaf24@8846 88 #define TAINT_UNSAFE_SMP (1<<0)
kaf24@8846 89 #define TAINT_MACHINE_CHECK (1<<1)
kaf24@8846 90 #define TAINT_BAD_PAGE (1<<2)
kaf24@10500 91 #define TAINT_SYNC_CONSOLE (1<<3)
kaf24@8846 92 extern int tainted;
kaf24@8846 93 #define TAINT_STRING_MAX_LEN 20
kaf24@8846 94 extern char *print_tainted(char *str);
kaf24@8846 95 extern void add_taint(unsigned);
kaf24@8846 96
kaf24@1210 97 #endif /* __LIB_H__ */