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/macros.h> 9 #include <xen/types.h> 10 11 /** 12 * container_of - cast a member of a structure out to the containing structure 13 * 14 * @ptr: the pointer to the member. 15 * @type: the type of the container struct this is embedded in. 16 * @member: the name of the member within the struct. 17 * 18 */ 19 #define container_of(ptr, type, member) ({ \ 20 typeof_field(type, member) *__mptr = (ptr); \ 21 (type *)( (char *)__mptr - offsetof(type,member) );}) 22 23 /** 24 * __struct_group() - Create a mirrored named and anonyomous struct 25 * 26 * @TAG: The tag name for the named sub-struct (usually empty) 27 * @NAME: The identifier name of the mirrored sub-struct 28 * @ATTRS: Any struct attributes (usually empty) 29 * @MEMBERS: The member declarations for the mirrored structs 30 * 31 * Used to create an anonymous union of two structs with identical layout 32 * and size: one anonymous and one named. The former's members can be used 33 * normally without sub-struct naming, and the latter can be used to 34 * reason about the start, end, and size of the group of struct members. 35 * The named struct can also be explicitly tagged for layer reuse, as well 36 * as both having struct attributes appended. 37 */ 38 #define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ 39 union { \ 40 struct { MEMBERS } ATTRS; \ 41 struct TAG { MEMBERS } ATTRS NAME; \ 42 } ATTRS 43 44 /* 45 * Check at compile time that something is of a particular type. 46 * Always evaluates to 1 so you may use it easily in comparisons. 47 */ 48 #define typecheck(type,x) \ 49 ({ type __dummy; \ 50 typeof(x) __dummy2; \ 51 (void)(&__dummy == &__dummy2); \ 52 1; \ 53 }) 54 55 /* SAF-0-safe */ 56 extern char _start[], _end[]; 57 #define is_kernel(p) ({ \ 58 char *__p = (char *)(unsigned long)(p); \ 59 (__p >= _start) && (__p < _end); \ 60 }) 61 62 /* SAF-0-safe */ 63 extern char _stext[], _etext[]; 64 #define is_kernel_text(p) ({ \ 65 char *__p = (char *)(unsigned long)(p); \ 66 (__p >= _stext) && (__p < _etext); \ 67 }) 68 69 /* SAF-0-safe */ 70 extern const char _srodata[], _erodata[]; 71 #define is_kernel_rodata(p) ({ \ 72 const char *__p = (const char *)(unsigned long)(p); \ 73 (__p >= _srodata) && (__p < _erodata); \ 74 }) 75 76 /* SAF-0-safe */ 77 extern char _sinittext[], _einittext[]; 78 #define is_kernel_inittext(p) ({ \ 79 char *__p = (char *)(unsigned long)(p); \ 80 (__p >= _sinittext) && (__p < _einittext); \ 81 }) 82 83 extern enum system_state { 84 SYS_STATE_early_boot, 85 SYS_STATE_boot, 86 SYS_STATE_smp_boot, 87 SYS_STATE_active, 88 SYS_STATE_suspend, 89 SYS_STATE_resume 90 } system_state; 91 92 bool is_active_kernel_text(unsigned long addr); 93 94 extern const char xen_config_data[]; 95 extern const unsigned int xen_config_data_size; 96 97 struct cpu_user_regs; 98 struct vcpu; 99 100 void cf_check show_execution_state(const struct cpu_user_regs *regs); 101 void vcpu_show_execution_state(struct vcpu *v); 102 103 #endif /* _LINUX_KERNEL_H */ 104 105