5 * 'kernel.h' contains some often used function prototypes etc
9 #include <lwk/linkage.h>
10 #include <lwk/stddef.h>
11 #include <lwk/types.h>
12 #include <lwk/compiler.h>
14 #include <lwk/errno.h>
15 #include <lwk/utsname.h>
16 #include <lwk/print.h>
17 #include <arch/byteorder.h>
20 extern const char lwk_banner[];
21 extern struct utsname linux_utsname;
23 #define INT_MAX ((int)(~0U>>1))
24 #define INT_MIN (-INT_MAX - 1)
25 #define UINT_MAX (~0U)
26 #define LONG_MAX ((long)(~0UL>>1))
27 #define LONG_MIN (-LONG_MAX - 1)
28 #define ULONG_MAX (~0UL)
30 #define STACK_MAGIC 0xdeadbeef
32 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
33 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
34 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
36 void panic(const char * fmt, ...);
38 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
39 extern long simple_strtol(const char *,char **,unsigned int);
40 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
41 extern long long simple_strtoll(const char *,char **,unsigned int);
42 extern int get_option(char **str, int *pint);
43 extern char *get_options(const char *str, int nints, int *ints);
44 extern unsigned long long memparse(char *ptr, char **retptr);
47 * min()/max() macros that also do
48 * strict type-checking.. See the
49 * "unnecessary" pointer comparison.
54 (void) (&_x == &_y); \
60 (void) (&_x == &_y); \
64 * ..and if you can't take the strict
65 * types, you can specify one yourself.
67 * Or not use min/max at all, of course.
69 #define min_t(type,x,y) \
70 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
71 #define max_t(type,x,y) \
72 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
75 * Round x up to the nearest y aligned boundary. y must be a power of two.
77 #define round_up(x,y) (((x) + (y) - 1) & ~((y)-1))
80 * Round x down to the nearest y aligned boundary. y must be a power of two.
82 #define round_down(x,y) ((x) & ~((y)-1))
85 * container_of - cast a member of a structure out to the containing structure
86 * @ptr: the pointer to the member.
87 * @type: the type of the container struct this is embedded in.
88 * @member: the name of the member within the struct.
90 #define container_of(ptr, type, member) ({ \
91 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
92 (type *)( (char *)__mptr - offsetof(type,member) );})
95 * Check at compile time that something is of a particular type.
96 * Always evaluates to 1 so you may use it easily in comparisons.
98 #define typecheck(type,x) \
100 typeof(x) __dummy2; \
101 (void)(&__dummy == &__dummy2); \
106 * Check at compile time that 'function' is a certain type, or is a pointer
107 * to that type (needs to use typedef for the function type.)
109 #define typecheck_fn(type,function) \
110 ({ typeof(type) __tmp = function; \
115 * Check at compile time that 'type' is a multiple of align.
117 #define aligncheck(type,align) \
118 extern int __align_check[ (sizeof(type) % (align) == 0 ? 0 : 1/0) ]
121 * Check at compile time that the type 'type' has the expected 'size'.
122 * NOTE: 'type' must be a single word, so this doesn't work for structures.
123 * For structures, use sizecheck_struct().
125 #define sizecheck(type,size) \
126 extern int __size_check_##type[ (sizeof(type) == (size) ? 0 : 1/0) ]
129 * Check at compile time that the structure 'name' has the expected size 'size'.
131 #define sizecheck_struct(name,size) \
132 extern int __size_check_struct_##name[ (sizeof(struct name) == (size) ? 0 : 1/0) ]
135 * Force a compilation error if condition is true
137 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))