Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jiri Kosina | 1051742 | 2017-03-08 14:27:05 +0100 | [diff] [blame] | 2 | #ifndef _LIVEPATCH_CORE_H |
| 3 | #define _LIVEPATCH_CORE_H |
| 4 | |
Joe Lawrence | 93862e3 | 2017-10-13 15:08:41 -0400 | [diff] [blame] | 5 | #include <linux/livepatch.h> |
| 6 | |
Jiri Kosina | 1051742 | 2017-03-08 14:27:05 +0100 | [diff] [blame] | 7 | extern struct mutex klp_mutex; |
| 8 | |
Joe Lawrence | 93862e3 | 2017-10-13 15:08:41 -0400 | [diff] [blame] | 9 | static inline bool klp_is_object_loaded(struct klp_object *obj) |
| 10 | { |
| 11 | return !obj->name || obj->mod; |
| 12 | } |
| 13 | |
| 14 | static inline int klp_pre_patch_callback(struct klp_object *obj) |
| 15 | { |
Petr Mladek | 5aaf1ab | 2017-10-20 16:56:50 +0200 | [diff] [blame] | 16 | int ret = 0; |
Joe Lawrence | 93862e3 | 2017-10-13 15:08:41 -0400 | [diff] [blame] | 17 | |
Petr Mladek | 5aaf1ab | 2017-10-20 16:56:50 +0200 | [diff] [blame] | 18 | if (obj->callbacks.pre_patch) |
| 19 | ret = (*obj->callbacks.pre_patch)(obj); |
Joe Lawrence | 93862e3 | 2017-10-13 15:08:41 -0400 | [diff] [blame] | 20 | |
| 21 | obj->callbacks.post_unpatch_enabled = !ret; |
| 22 | |
| 23 | return ret; |
| 24 | } |
| 25 | |
| 26 | static 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 | |
| 32 | static 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 | |
| 38 | static 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 Mladek | 5aaf1ab | 2017-10-20 16:56:50 +0200 | [diff] [blame] | 43 | |
| 44 | obj->callbacks.post_unpatch_enabled = false; |
Joe Lawrence | 93862e3 | 2017-10-13 15:08:41 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Jiri Kosina | 1051742 | 2017-03-08 14:27:05 +0100 | [diff] [blame] | 47 | #endif /* _LIVEPATCH_CORE_H */ |