1 #ifndef _KSPLICE_PATCH_H
2 #define _KSPLICE_PATCH_H
4 enum ksplice_option_type
{
5 KSPLICE_OPTION_ASSUME_RODATA
,
8 struct ksplice_option
{
9 enum ksplice_option_type type
;
15 #include <linux/gfp.h>
18 #define __used __attribute_used__
21 #define ksplice_call_int(name, fn) \
22 static typeof(int (*)(void)) __ksplice_##name##_##fn __used \
23 __attribute__((__section__(".ksplice_call_" #name))) = fn
25 #define ksplice_call_void(name, fn) \
26 static typeof(void (*)(void)) __ksplice_##name##_##fn __used \
27 __attribute__((__section__(".ksplice_call_" #name))) = fn
29 #define ksplice_pre_apply(fn) ksplice_call_int(pre_apply, fn)
30 #define ksplice_check_apply(fn) ksplice_call_int(check_apply, fn)
31 #define ksplice_apply(fn) ksplice_call_void(apply, fn)
32 #define ksplice_post_apply(fn) ksplice_call_void(post_apply, fn)
33 #define ksplice_fail_apply(fn) ksplice_call_void(fail_apply, fn)
35 #define ksplice_pre_reverse(fn) ksplice_call_int(pre_reverse, fn)
36 #define ksplice_check_reverse(fn) ksplice_call_int(check_reverse, fn)
37 #define ksplice_reverse(fn) ksplice_call_void(reverse, fn)
38 #define ksplice_post_reverse(fn) ksplice_call_void(post_reverse, fn)
39 #define ksplice_fail_reverse(fn) ksplice_call_void(fail_reverse, fn)
41 #define ksplice_assume_rodata(obj) \
42 const struct ksplice_option \
43 __used __attribute__((__section__(".ksplice_options"))) \
44 assume_rodata_##obj = { \
45 .type = KSPLICE_OPTION_ASSUME_RODATA, \
46 .target = (const void *)&obj, \
49 int init_shadow_field_type(int *shadow_key
, typeof(GFP_KERNEL
) gfp_flags
);
50 void *init_shadow_field(int *shadow_key
, void *obj
, int size
,
51 typeof(GFP_KERNEL
) gfp_flags
);
52 void cleanup_shadow_field(int *shadow_key
, void *obj
);
53 void *get_shadow_field(int *shadow_key
, void *obj
);
54 void cleanup_shadow_field_type(int *shadow_key
);
57 #define __DEFINE_SHADOW_FIELD(base_type, field_type, gfp_flags, \
58 init_field_type_fn, init_field_fn, get_field_fn, \
59 make_field_fn, cleanup_field_fn, \
60 cleanup_field_type_fn, shadow_key, init_field) \
61 static int shadow_key = 0; \
62 int init_field_type_fn(void) \
64 return init_shadow_field_type(&shadow_key, gfp_flags); \
66 field_type *init_field_fn(base_type *obj, typeof(GFP_KERNEL) flags) \
68 field_type *data = init_shadow_field(&shadow_key, (void *)obj, \
69 sizeof(*data), flags); \
74 void cleanup_field_fn(base_type *obj) \
76 cleanup_shadow_field(&shadow_key, obj); \
78 field_type *get_field_fn(base_type *obj) \
80 return get_shadow_field(&shadow_key, obj); \
82 field_type *make_field_fn(base_type *obj, typeof(GFP_KERNEL) flags) \
84 void *data = get_shadow_field(&shadow_key, (void *)obj); \
86 data = init_field_fn(obj, flags); \
89 void cleanup_field_type_fn(void) \
91 return cleanup_shadow_field_type(&shadow_key); \
93 struct eat_trailing_semicolon
95 #define DEFINE_SHADOW_FIELD(base_type, field_type, gfp_flags, name, init_field) \
96 __DEFINE_SHADOW_FIELD(base_type, field_type, gfp_flags, \
97 init_##name##_shadows, init_##name##_shadow, \
98 get_##name##_shadow, make_##name##_shadow, \
99 cleanup_##name##_shadow, cleanup_##name##_shadows,\
100 shadow_key_##name, init_field); \
101 ksplice_check_apply(init_##name##_shadows); \
102 ksplice_post_reverse(cleanup_##name##_shadows); \
103 ksplice_fail_apply(cleanup_##name##_shadows)
105 #define __DECLARE_SHADOW_FIELD(base_type, field_type, init_field_type_fn, \
106 init_field_fn, get_field_fn, make_field_fn, \
107 cleanup_field_fn, cleanup_field_type_fn) \
108 int init_field_type_fn(void); \
109 field_type *init_field_fn(base_type *obj, typeof(GFP_KERNEL) flags); \
110 void cleanup_field_fn(base_type *obj); \
111 field_type *get_field_fn(base_type *obj); \
112 field_type *make_field_fn(base_type *obj, typeof(GFP_KERNEL) flags); \
113 void cleanup_field_type_fn(void)
115 #define DECLARE_SHADOW_FIELD(base_type, field_type, name) \
116 __DECLARE_SHADOW_FIELD(base_type, field_type, init_##name##_shadows, \
117 init_##name##_shadow, get_##name##_shadow, \
118 make_##name##_shadow, cleanup_##name##_shadow, \
119 cleanup_##name##_shadows)
121 #endif /* __KERNEL__ */
123 #endif /* _KSPLICE_PATCH_H */