core.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LIVEPATCH_CORE_H
  3. #define _LIVEPATCH_CORE_H
  4. #include <linux/livepatch.h>
  5. extern struct mutex klp_mutex;
  6. static inline bool klp_is_object_loaded(struct klp_object *obj)
  7. {
  8. return !obj->name || obj->mod;
  9. }
  10. static inline int klp_pre_patch_callback(struct klp_object *obj)
  11. {
  12. int ret = 0;
  13. if (obj->callbacks.pre_patch)
  14. ret = (*obj->callbacks.pre_patch)(obj);
  15. obj->callbacks.post_unpatch_enabled = !ret;
  16. return ret;
  17. }
  18. static inline void klp_post_patch_callback(struct klp_object *obj)
  19. {
  20. if (obj->callbacks.post_patch)
  21. (*obj->callbacks.post_patch)(obj);
  22. }
  23. static inline void klp_pre_unpatch_callback(struct klp_object *obj)
  24. {
  25. if (obj->callbacks.pre_unpatch)
  26. (*obj->callbacks.pre_unpatch)(obj);
  27. }
  28. static inline void klp_post_unpatch_callback(struct klp_object *obj)
  29. {
  30. if (obj->callbacks.post_unpatch_enabled &&
  31. obj->callbacks.post_unpatch)
  32. (*obj->callbacks.post_unpatch)(obj);
  33. obj->callbacks.post_unpatch_enabled = false;
  34. }
  35. #endif /* _LIVEPATCH_CORE_H */