1 #ifndef _LINUX_KERNEL_H
2 #define _LINUX_KERNEL_H
3 
4 /*
5  * 'kernel.h' contains some often-used function prototypes etc
6  */
7 
8 #include <xen/types.h>
9 
10 /*
11  * min()/max() macros that also do
12  * strict type-checking.. See the
13  * "unnecessary" pointer comparison.
14  */
15 #define min(x,y) ({ \
16         const typeof(x) _x = (x);       \
17         const typeof(y) _y = (y);       \
18         (void) (&_x == &_y);            \
19         _x < _y ? _x : _y; })
20 
21 #define max(x,y) ({ \
22         const typeof(x) _x = (x);       \
23         const typeof(y) _y = (y);       \
24         (void) (&_x == &_y);            \
25         _x > _y ? _x : _y; })
26 
27 /*
28  * ..and if you can't take the strict
29  * types, you can specify one yourself.
30  *
31  * Or not use min/max at all, of course.
32  */
33 #define min_t(type,x,y) \
34         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
35 #define max_t(type,x,y) \
36         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
37 
38 /*
39  * pre-processor, array size, and bit field width suitable variants;
40  * please don't use in "normal" expressions.
41  */
42 #define MIN(x,y) ((x) < (y) ? (x) : (y))
43 #define MAX(x,y) ((x) > (y) ? (x) : (y))
44 
45 /**
46  * container_of - cast a member of a structure out to the containing structure
47  *
48  * @ptr:	the pointer to the member.
49  * @type:	the type of the container struct this is embedded in.
50  * @member:	the name of the member within the struct.
51  *
52  */
53 #define container_of(ptr, type, member) ({                      \
54         typeof( ((type *)0)->member ) *__mptr = (ptr);          \
55         (type *)( (char *)__mptr - offsetof(type,member) );})
56 
57 /*
58  * Check at compile time that something is of a particular type.
59  * Always evaluates to 1 so you may use it easily in comparisons.
60  */
61 #define typecheck(type,x)                       \
62 ({	type __dummy;                           \
63 	typeof(x) __dummy2;                     \
64 	(void)(&__dummy == &__dummy2);          \
65 	1;                                      \
66 })
67 
68 extern char _start[], _end[], start[];
69 #define is_kernel(p) ({                         \
70     char *__p = (char *)(unsigned long)(p);     \
71     (__p >= _start) && (__p < _end);            \
72 })
73 
74 extern char _stext[], _etext[];
75 #define is_kernel_text(p) ({                    \
76     char *__p = (char *)(unsigned long)(p);     \
77     (__p >= _stext) && (__p < _etext);          \
78 })
79 
80 extern const char _srodata[], _erodata[];
81 #define is_kernel_rodata(p) ({                  \
82     const char *__p = (const char *)(unsigned long)(p);     \
83     (__p >= _srodata) && (__p < _erodata);      \
84 })
85 
86 extern char _sinittext[], _einittext[];
87 #define is_kernel_inittext(p) ({                \
88     char *__p = (char *)(unsigned long)(p);     \
89     (__p >= _sinittext) && (__p < _einittext);  \
90 })
91 
92 extern enum system_state {
93     SYS_STATE_early_boot,
94     SYS_STATE_boot,
95     SYS_STATE_smp_boot,
96     SYS_STATE_active,
97     SYS_STATE_suspend,
98     SYS_STATE_resume
99 } system_state;
100 
101 bool_t is_active_kernel_text(unsigned long addr);
102 
103 #endif /* _LINUX_KERNEL_H */
104 
105