blob: 48a83d4364cff3c6995025ac6459d04e868f169f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Kosina10517422017-03-08 14:27:05 +01002#ifndef _LIVEPATCH_CORE_H
3#define _LIVEPATCH_CORE_H
4
Joe Lawrence93862e32017-10-13 15:08:41 -04005#include <linux/livepatch.h>
6
Jiri Kosina10517422017-03-08 14:27:05 +01007extern struct mutex klp_mutex;
8
Joe Lawrence93862e32017-10-13 15:08:41 -04009static inline bool klp_is_object_loaded(struct klp_object *obj)
10{
11 return !obj->name || obj->mod;
12}
13
14static inline int klp_pre_patch_callback(struct klp_object *obj)
15{
Petr Mladek5aaf1ab2017-10-20 16:56:50 +020016 int ret = 0;
Joe Lawrence93862e32017-10-13 15:08:41 -040017
Petr Mladek5aaf1ab2017-10-20 16:56:50 +020018 if (obj->callbacks.pre_patch)
19 ret = (*obj->callbacks.pre_patch)(obj);
Joe Lawrence93862e32017-10-13 15:08:41 -040020
21 obj->callbacks.post_unpatch_enabled = !ret;
22
23 return ret;
24}
25
26static inline void klp_post_patch_callback(struct klp_object *obj)
27{
28 if (obj->callbacks.post_patch)
29 (*obj->callbacks.post_patch)(obj);
30}
31
32static inline void klp_pre_unpatch_callback(struct klp_object *obj)
33{
34 if (obj->callbacks.pre_unpatch)
35 (*obj->callbacks.pre_unpatch)(obj);
36}
37
38static inline void klp_post_unpatch_callback(struct klp_object *obj)
39{
40 if (obj->callbacks.post_unpatch_enabled &&
41 obj->callbacks.post_unpatch)
42 (*obj->callbacks.post_unpatch)(obj);
Petr Mladek5aaf1ab2017-10-20 16:56:50 +020043
44 obj->callbacks.post_unpatch_enabled = false;
Joe Lawrence93862e32017-10-13 15:08:41 -040045}
46
Jiri Kosina10517422017-03-08 14:27:05 +010047#endif /* _LIVEPATCH_CORE_H */