jump_label.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef _LINUX_JUMP_LABEL_H
  2. #define _LINUX_JUMP_LABEL_H
  3. #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
  4. # include <asm/jump_label.h>
  5. # define HAVE_JUMP_LABEL
  6. #endif
  7. enum jump_label_type {
  8. JUMP_LABEL_ENABLE,
  9. JUMP_LABEL_DISABLE
  10. };
  11. struct module;
  12. #ifdef HAVE_JUMP_LABEL
  13. extern struct jump_entry __start___jump_table[];
  14. extern struct jump_entry __stop___jump_table[];
  15. extern void jump_label_lock(void);
  16. extern void jump_label_unlock(void);
  17. extern void arch_jump_label_transform(struct jump_entry *entry,
  18. enum jump_label_type type);
  19. extern void arch_jump_label_text_poke_early(jump_label_t addr);
  20. extern void jump_label_update(unsigned long key, enum jump_label_type type);
  21. extern void jump_label_apply_nops(struct module *mod);
  22. extern int jump_label_text_reserved(void *start, void *end);
  23. #define jump_label_enable(key) \
  24. jump_label_update((unsigned long)key, JUMP_LABEL_ENABLE);
  25. #define jump_label_disable(key) \
  26. jump_label_update((unsigned long)key, JUMP_LABEL_DISABLE);
  27. #else
  28. #define JUMP_LABEL(key, label) \
  29. do { \
  30. if (unlikely(*key)) \
  31. goto label; \
  32. } while (0)
  33. #define jump_label_enable(cond_var) \
  34. do { \
  35. *(cond_var) = 1; \
  36. } while (0)
  37. #define jump_label_disable(cond_var) \
  38. do { \
  39. *(cond_var) = 0; \
  40. } while (0)
  41. static inline int jump_label_apply_nops(struct module *mod)
  42. {
  43. return 0;
  44. }
  45. static inline int jump_label_text_reserved(void *start, void *end)
  46. {
  47. return 0;
  48. }
  49. static inline void jump_label_lock(void) {}
  50. static inline void jump_label_unlock(void) {}
  51. #endif
  52. #define COND_STMT(key, stmt) \
  53. do { \
  54. __label__ jl_enabled; \
  55. JUMP_LABEL(key, jl_enabled); \
  56. if (0) { \
  57. jl_enabled: \
  58. stmt; \
  59. } \
  60. } while (0)
  61. #endif