jump_label.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #ifndef _LINUX_JUMP_LABEL_H
  2. #define _LINUX_JUMP_LABEL_H
  3. #include <linux/types.h>
  4. #include <linux/compiler.h>
  5. #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
  6. struct jump_label_key {
  7. atomic_t enabled;
  8. struct jump_entry *entries;
  9. #ifdef CONFIG_MODULES
  10. struct jump_label_mod *next;
  11. #endif
  12. };
  13. # include <asm/jump_label.h>
  14. # define HAVE_JUMP_LABEL
  15. #endif /* CC_HAVE_ASM_GOTO && CONFIG_JUMP_LABEL */
  16. enum jump_label_type {
  17. JUMP_LABEL_DISABLE = 0,
  18. JUMP_LABEL_ENABLE,
  19. };
  20. struct module;
  21. #ifdef HAVE_JUMP_LABEL
  22. #ifdef CONFIG_MODULES
  23. #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL, NULL}
  24. #else
  25. #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL}
  26. #endif
  27. static __always_inline bool static_branch(struct jump_label_key *key)
  28. {
  29. return arch_static_branch(key);
  30. }
  31. extern struct jump_entry __start___jump_table[];
  32. extern struct jump_entry __stop___jump_table[];
  33. extern void jump_label_init(void);
  34. extern void jump_label_lock(void);
  35. extern void jump_label_unlock(void);
  36. extern void arch_jump_label_transform(struct jump_entry *entry,
  37. enum jump_label_type type);
  38. extern void arch_jump_label_transform_static(struct jump_entry *entry,
  39. enum jump_label_type type);
  40. extern int jump_label_text_reserved(void *start, void *end);
  41. extern void jump_label_inc(struct jump_label_key *key);
  42. extern void jump_label_dec(struct jump_label_key *key);
  43. extern bool jump_label_enabled(struct jump_label_key *key);
  44. extern void jump_label_apply_nops(struct module *mod);
  45. #else /* !HAVE_JUMP_LABEL */
  46. #include <linux/atomic.h>
  47. #define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
  48. struct jump_label_key {
  49. atomic_t enabled;
  50. };
  51. static __always_inline void jump_label_init(void)
  52. {
  53. }
  54. static __always_inline bool static_branch(struct jump_label_key *key)
  55. {
  56. if (unlikely(atomic_read(&key->enabled)))
  57. return true;
  58. return false;
  59. }
  60. static inline void jump_label_inc(struct jump_label_key *key)
  61. {
  62. atomic_inc(&key->enabled);
  63. }
  64. static inline void jump_label_dec(struct jump_label_key *key)
  65. {
  66. atomic_dec(&key->enabled);
  67. }
  68. static inline int jump_label_text_reserved(void *start, void *end)
  69. {
  70. return 0;
  71. }
  72. static inline void jump_label_lock(void) {}
  73. static inline void jump_label_unlock(void) {}
  74. static inline bool jump_label_enabled(struct jump_label_key *key)
  75. {
  76. return !!atomic_read(&key->enabled);
  77. }
  78. static inline int jump_label_apply_nops(struct module *mod)
  79. {
  80. return 0;
  81. }
  82. #endif /* HAVE_JUMP_LABEL */
  83. #endif /* _LINUX_JUMP_LABEL_H */