xref: /linux/kernel/livepatch/core.h (revision 93862e385ded7c60351e09fcd2a541d273650905)
110517429SJiri Kosina #ifndef _LIVEPATCH_CORE_H
210517429SJiri Kosina #define _LIVEPATCH_CORE_H
310517429SJiri Kosina 
4*93862e38SJoe Lawrence #include <linux/livepatch.h>
5*93862e38SJoe Lawrence 
610517429SJiri Kosina extern struct mutex klp_mutex;
710517429SJiri Kosina 
8*93862e38SJoe Lawrence static inline bool klp_is_object_loaded(struct klp_object *obj)
9*93862e38SJoe Lawrence {
10*93862e38SJoe Lawrence 	return !obj->name || obj->mod;
11*93862e38SJoe Lawrence }
12*93862e38SJoe Lawrence 
13*93862e38SJoe Lawrence static inline int klp_pre_patch_callback(struct klp_object *obj)
14*93862e38SJoe Lawrence {
15*93862e38SJoe Lawrence 	int ret;
16*93862e38SJoe Lawrence 
17*93862e38SJoe Lawrence 	ret = (obj->callbacks.pre_patch) ?
18*93862e38SJoe Lawrence 		(*obj->callbacks.pre_patch)(obj) : 0;
19*93862e38SJoe Lawrence 
20*93862e38SJoe Lawrence 	obj->callbacks.post_unpatch_enabled = !ret;
21*93862e38SJoe Lawrence 
22*93862e38SJoe Lawrence 	return ret;
23*93862e38SJoe Lawrence }
24*93862e38SJoe Lawrence 
25*93862e38SJoe Lawrence static inline void klp_post_patch_callback(struct klp_object *obj)
26*93862e38SJoe Lawrence {
27*93862e38SJoe Lawrence 	if (obj->callbacks.post_patch)
28*93862e38SJoe Lawrence 		(*obj->callbacks.post_patch)(obj);
29*93862e38SJoe Lawrence }
30*93862e38SJoe Lawrence 
31*93862e38SJoe Lawrence static inline void klp_pre_unpatch_callback(struct klp_object *obj)
32*93862e38SJoe Lawrence {
33*93862e38SJoe Lawrence 	if (obj->callbacks.pre_unpatch)
34*93862e38SJoe Lawrence 		(*obj->callbacks.pre_unpatch)(obj);
35*93862e38SJoe Lawrence }
36*93862e38SJoe Lawrence 
37*93862e38SJoe Lawrence static inline void klp_post_unpatch_callback(struct klp_object *obj)
38*93862e38SJoe Lawrence {
39*93862e38SJoe Lawrence 	if (obj->callbacks.post_unpatch_enabled &&
40*93862e38SJoe Lawrence 	    obj->callbacks.post_unpatch)
41*93862e38SJoe Lawrence 		(*obj->callbacks.post_unpatch)(obj);
42*93862e38SJoe Lawrence }
43*93862e38SJoe Lawrence 
4410517429SJiri Kosina #endif /* _LIVEPATCH_CORE_H */
45