debuggers.hg

view xen/include/xen/lib.h @ 19667:5369133d772c

Introduce __must_be_array

Cloning the similar construct from Linux, allowing to detect improper
uses of ARRAY_SIZE() at build time.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed May 20 15:29:25 2009 +0100 (2009-05-20)
parents 2fa1d38097da
children f210a633571c
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));
13 void __warn(char *file, int line);
15 #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
16 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
18 /* Force a compilation error if condition is true */
19 #define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))
21 /* Force a compilation error if condition is true, but also produce a
22 result (of value 0 and type size_t), so the expression can be used
23 e.g. in a structure initializer (or where-ever else comma expressions
24 aren't permitted). */
25 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
27 #ifndef assert_failed
28 #define assert_failed(p) \
29 do { \
30 printk("Assertion '%s' failed, line %d, file %s\n", #p , \
31 __LINE__, __FILE__); \
32 BUG(); \
33 } while (0)
34 #endif
36 #ifndef NDEBUG
37 #define ASSERT(p) \
38 do { if ( unlikely(!(p)) ) assert_failed(p); } while (0)
39 #else
40 #define ASSERT(p) ((void)0)
41 #endif
43 #define SWAP(_a, _b) \
44 do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
46 #define DIV_ROUND(x, y) (((x) + (y) / 2) / (y))
48 #define reserve_bootmem(_p,_l) ((void)0)
50 struct domain;
52 void cmdline_parse(char *cmdline);
54 /*#define DEBUG_TRACE_DUMP*/
55 #ifdef DEBUG_TRACE_DUMP
56 extern void debugtrace_dump(void);
57 extern void debugtrace_printk(const char *fmt, ...);
58 #else
59 #define debugtrace_dump() ((void)0)
60 #define debugtrace_printk(_f, ...) ((void)0)
61 #endif
63 /* Allows us to use '%p' as general-purpose machine-word format char. */
64 #define _p(_x) ((void *)(unsigned long)(_x))
65 extern void printk(const char *format, ...)
66 __attribute__ ((format (printf, 1, 2)));
67 extern void panic(const char *format, ...)
68 __attribute__ ((format (printf, 1, 2)));
69 extern long vm_assist(struct domain *, unsigned int, unsigned int);
70 extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
71 extern int printk_ratelimit(void);
73 /* vsprintf.c */
74 #define sprintf __xen_has_no_sprintf__
75 #define vsprintf __xen_has_no_vsprintf__
76 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
77 __attribute__ ((format (printf, 3, 4)));
78 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
79 __attribute__ ((format (printf, 3, 0)));
80 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
81 __attribute__ ((format (printf, 3, 4)));
82 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
83 __attribute__ ((format (printf, 3, 0)));
84 extern int sscanf(const char * buf, const char * fmt, ...)
85 __attribute__ ((format (scanf, 2, 3)));
86 extern int vsscanf(const char * buf, const char * fmt, va_list args)
87 __attribute__ ((format (scanf, 2, 0)));
89 long simple_strtol(
90 const char *cp,const char **endp, unsigned int base);
91 unsigned long simple_strtoul(
92 const char *cp,const char **endp, unsigned int base);
93 long long simple_strtoll(
94 const char *cp,const char **endp, unsigned int base);
95 unsigned long long simple_strtoull(
96 const char *cp,const char **endp, unsigned int base);
98 unsigned long long parse_size_and_unit(const char *s, const char **ps);
100 #define TAINT_UNSAFE_SMP (1<<0)
101 #define TAINT_MACHINE_CHECK (1<<1)
102 #define TAINT_BAD_PAGE (1<<2)
103 #define TAINT_SYNC_CONSOLE (1<<3)
104 #define TAINT_ERROR_INJECT (1<<4)
105 extern int tainted;
106 #define TAINT_STRING_MAX_LEN 20
107 extern char *print_tainted(char *str);
108 extern void add_taint(unsigned);
110 #endif /* __LIB_H__ */