Coverage Report

Created: 2017-10-25 09:10

/root/src/xen/xen/include/xen/kernel.h
Line
Count
Source (jump to first uncovered line)
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
60.6k
#define min(x,y) ({ \
16
0
        const typeof(x) _x = (x);       \
17
1
        const typeof(y) _y = (y);       \
18
60.6k
        (void) (&_x == &_y);            \
19
60.6k
        _x < _y ? _x : _y; })
20
21
1.97k
#define max(x,y) ({ \
22
1.97k
        const typeof(x) _x = (x);       \
23
1.97k
        const typeof(y) _y = (y);       \
24
1.97k
        (void) (&_x == &_y);            \
25
1.96k
        _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
148M
        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
35
#define max_t(type,x,y) \
36
72
        ({ 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
6.74M
#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
96.2M
#define container_of(ptr, type, member) ({                      \
54
96.2M
        typeof( ((type *)0)->member ) *__mptr = (ptr);          \
55
96.2M
        (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
0
#define is_kernel(p) ({                         \
70
0
    char *__p = (char *)(unsigned long)(p);     \
71
0
    (__p >= _start) && (__p < _end);            \
72
0
})
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
0
#define is_kernel_inittext(p) ({                \
88
0
    char *__p = (char *)(unsigned long)(p);     \
89
0
    (__p >= _sinittext) && (__p < _einittext);  \
90
0
})
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