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