67 lines
1.9 KiB
C
67 lines
1.9 KiB
C
#ifndef __LINUX_KERNEL_WRAPPER_H
|
|
#define __LINUX_KERNEL_WRAPPER_H 1
|
|
|
|
#include_next <linux/kernel.h>
|
|
#include <linux/config.h>
|
|
|
|
/**
|
|
* container_of - cast a member of a structure out to the containing structure
|
|
* @ptr: the pointer to the member.
|
|
* @type: the type of the container struct this is embedded in.
|
|
* @member: the name of the member within the struct.
|
|
*
|
|
*/
|
|
#define container_of(ptr, type, member) ({ \
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
|
/*
|
|
* Check at compile time that something is of a particular type.
|
|
* Always evaluates to 1 so you may use it easily in comparisons.
|
|
*/
|
|
#define typecheck(type,x) \
|
|
({ type __dummy; \
|
|
typeof(x) __dummy2; \
|
|
(void)(&__dummy == &__dummy2); \
|
|
1; \
|
|
})
|
|
|
|
/*
|
|
* Check at compile time that 'function' is a certain type, or is a pointer
|
|
* to that type (needs to use typedef for the function type.)
|
|
*/
|
|
#define typecheck_fn(type,function) \
|
|
({ typeof(type) __tmp = function; \
|
|
(void)__tmp; \
|
|
})
|
|
|
|
int vprintk(const char *msg, ...)
|
|
__attribute__((format(printf, 1, 0)));
|
|
|
|
/* Force a compilation error if condition is true */
|
|
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
|
|
|
|
/**
|
|
* might_sleep - annotation for functions that can sleep
|
|
*
|
|
* this macro will print a stack trace if it is executed in an atomic
|
|
* context (spinlock, irq-handler, ...).
|
|
*
|
|
* This is a useful debugging help to be able to catch problems early and not
|
|
* be bitten later when the calling function happens to sleep when it is not
|
|
* supposed to.
|
|
*/
|
|
#define might_resched() do { } while (0)
|
|
|
|
#ifdef CONFIG_DEBUG_SPINLOCK
|
|
void __might_sleep(char *file, int line);
|
|
# define might_sleep() \
|
|
do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0)
|
|
#else
|
|
# define might_sleep() do { might_resched(); } while (0)
|
|
#endif
|
|
|
|
#define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
|
|
|
|
#endif
|