1 #ifndef __LINUX_KERNEL_WRAPPER_H
2 #define __LINUX_KERNEL_WRAPPER_H 1
4 #include_next <linux/kernel.h>
5 #include <linux/config.h>
9 * container_of - cast a member of a structure out to the containing structure
10 * @ptr: the pointer to the member.
11 * @type: the type of the container struct this is embedded in.
12 * @member: the name of the member within the struct.
15 #define container_of(ptr, type, member) ({ \
16 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
17 (type *)( (char *)__mptr - offsetof(type,member) );})
20 * Check at compile time that something is of a particular type.
21 * Always evaluates to 1 so you may use it easily in comparisons.
23 #define typecheck(type,x) \
26 (void)(&__dummy == &__dummy2); \
31 * Check at compile time that 'function' is a certain type, or is a pointer
32 * to that type (needs to use typedef for the function type.)
34 #define typecheck_fn(type,function) \
35 ({ typeof(type) __tmp = function; \
39 int vprintk(const char *msg, ...)
40 __attribute__((format(printf, 1, 0)));
42 /* Force a compilation error if condition is true */
43 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
46 * might_sleep - annotation for functions that can sleep
48 * this macro will print a stack trace if it is executed in an atomic
49 * context (spinlock, irq-handler, ...).
51 * This is a useful debugging help to be able to catch problems early and not
52 * be bitten later when the calling function happens to sleep when it is not
55 #define might_resched() do { } while (0)
57 #ifdef CONFIG_DEBUG_SPINLOCK
58 void __might_sleep(char *file, int line);
59 # define might_sleep() \
60 do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0)
62 # define might_sleep() do { might_resched(); } while (0)
65 #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)