ia64/xen-unstable

annotate xen/include/xen/lib.h @ 19629: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
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@14590 13 void __warn(char *file, int line);
kfraser@14021 14
keir@19473 15 #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
keir@19473 16 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
kaf24@3848 17
kaf24@9878 18 /* Force a compilation error if condition is true */
keir@18909 19 #define BUILD_BUG_ON(condition) ((void)sizeof(struct { int:-!!(condition); }))
kaf24@9878 20
keir@19629 21 /* Force a compilation error if condition is true, but also produce a
keir@19629 22 result (of value 0 and type size_t), so the expression can be used
keir@19629 23 e.g. in a structure initializer (or where-ever else comma expressions
keir@19629 24 aren't permitted). */
keir@19629 25 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
keir@19629 26
kfraser@14054 27 #ifndef assert_failed
kfraser@14054 28 #define assert_failed(p) \
kfraser@14054 29 do { \
kfraser@14054 30 printk("Assertion '%s' failed, line %d, file %s\n", #p , \
kfraser@14054 31 __LINE__, __FILE__); \
kfraser@14054 32 BUG(); \
kfraser@14054 33 } while (0)
kfraser@14054 34 #endif
kfraser@14054 35
kaf24@1210 36 #ifndef NDEBUG
kfraser@14054 37 #define ASSERT(p) \
kfraser@14054 38 do { if ( unlikely(!(p)) ) assert_failed(p); } while (0)
kaf24@1210 39 #else
kfraser@14054 40 #define ASSERT(p) ((void)0)
kaf24@1210 41 #endif
kaf24@1210 42
kaf24@2635 43 #define SWAP(_a, _b) \
kaf24@2635 44 do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
kaf24@2635 45
iap10@4606 46 #define DIV_ROUND(x, y) (((x) + (y) / 2) / (y))
arun@3920 47
kaf24@3354 48 #define reserve_bootmem(_p,_l) ((void)0)
kaf24@1210 49
cl349@2448 50 struct domain;
cl349@2448 51
kaf24@3338 52 void cmdline_parse(char *cmdline);
kaf24@3338 53
kfraser@11212 54 /*#define DEBUG_TRACE_DUMP*/
kfraser@11212 55 #ifdef DEBUG_TRACE_DUMP
kaf24@3875 56 extern void debugtrace_dump(void);
kaf24@3827 57 extern void debugtrace_printk(const char *fmt, ...);
kaf24@3827 58 #else
kaf24@3875 59 #define debugtrace_dump() ((void)0)
kaf24@3875 60 #define debugtrace_printk(_f, ...) ((void)0)
kaf24@3827 61 #endif
kaf24@3827 62
kaf24@4654 63 /* Allows us to use '%p' as general-purpose machine-word format char. */
kaf24@4654 64 #define _p(_x) ((void *)(unsigned long)(_x))
kfraser@11947 65 extern void printk(const char *format, ...)
kaf24@4654 66 __attribute__ ((format (printf, 1, 2)));
kaf24@9454 67 extern void panic(const char *format, ...)
kaf24@9454 68 __attribute__ ((format (printf, 1, 2)));
kaf24@4654 69 extern long vm_assist(struct domain *, unsigned int, unsigned int);
kaf24@12030 70 extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
kaf24@12030 71 extern int printk_ratelimit(void);
kaf24@1210 72
kaf24@1210 73 /* vsprintf.c */
keir@13756 74 #define sprintf __xen_has_no_sprintf__
kfraser@13697 75 #define vsprintf __xen_has_no_vsprintf__
kaf24@1210 76 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
kaf24@4654 77 __attribute__ ((format (printf, 3, 4)));
kaf24@8520 78 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
kaf24@8520 79 __attribute__ ((format (printf, 3, 0)));
kaf24@8520 80 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
kaf24@8520 81 __attribute__ ((format (printf, 3, 4)));
kaf24@8520 82 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
kaf24@8520 83 __attribute__ ((format (printf, 3, 0)));
kfraser@15816 84 extern int sscanf(const char * buf, const char * fmt, ...)
kfraser@15816 85 __attribute__ ((format (scanf, 2, 3)));
kfraser@15816 86 extern int vsscanf(const char * buf, const char * fmt, va_list args)
kfraser@15816 87 __attribute__ ((format (scanf, 2, 0)));
kaf24@1210 88
kaf24@4850 89 long simple_strtol(
kfraser@13156 90 const char *cp,const char **endp, unsigned int base);
kaf24@4850 91 unsigned long simple_strtoul(
kfraser@13156 92 const char *cp,const char **endp, unsigned int base);
kaf24@4850 93 long long simple_strtoll(
kfraser@13156 94 const char *cp,const char **endp, unsigned int base);
kaf24@4850 95 unsigned long long simple_strtoull(
kfraser@13156 96 const char *cp,const char **endp, unsigned int base);
kaf24@4850 97
kfraser@13156 98 unsigned long long parse_size_and_unit(const char *s, const char **ps);
kaf24@1210 99
kaf24@8846 100 #define TAINT_UNSAFE_SMP (1<<0)
kaf24@8846 101 #define TAINT_MACHINE_CHECK (1<<1)
kaf24@8846 102 #define TAINT_BAD_PAGE (1<<2)
kaf24@10500 103 #define TAINT_SYNC_CONSOLE (1<<3)
keir@19373 104 #define TAINT_ERROR_INJECT (1<<4)
kaf24@8846 105 extern int tainted;
kaf24@8846 106 #define TAINT_STRING_MAX_LEN 20
kaf24@8846 107 extern char *print_tainted(char *str);
kaf24@8846 108 extern void add_taint(unsigned);
kaf24@8846 109
kaf24@1210 110 #endif /* __LIB_H__ */