blob: 7880f18e4b863b7d0ad6a84a0b55a06452ad0990 [file] [log] [blame]
Jason Baronbf5438fc2010-09-17 11:09:00 -04001#ifndef _LINUX_JUMP_LABEL_H
2#define _LINUX_JUMP_LABEL_H
3
Steven Rostedt45f81b12010-10-29 12:33:43 -04004#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
Jason Baronbf5438fc2010-09-17 11:09:00 -04005# include <asm/jump_label.h>
6# define HAVE_JUMP_LABEL
7#endif
8
9enum jump_label_type {
10 JUMP_LABEL_ENABLE,
11 JUMP_LABEL_DISABLE
12};
13
14struct module;
15
16#ifdef HAVE_JUMP_LABEL
17
18extern struct jump_entry __start___jump_table[];
19extern struct jump_entry __stop___jump_table[];
20
Jason Baron91bad2f82010-10-01 17:23:48 -040021extern void jump_label_lock(void);
22extern void jump_label_unlock(void);
Jason Baronbf5438fc2010-09-17 11:09:00 -040023extern void arch_jump_label_transform(struct jump_entry *entry,
24 enum jump_label_type type);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040025extern void arch_jump_label_text_poke_early(jump_label_t addr);
Jason Baronbf5438fc2010-09-17 11:09:00 -040026extern void jump_label_update(unsigned long key, enum jump_label_type type);
27extern void jump_label_apply_nops(struct module *mod);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040028extern int jump_label_text_reserved(void *start, void *end);
Jason Baronbf5438fc2010-09-17 11:09:00 -040029
Peter Zijlstra3b6e9012010-10-14 21:10:38 +020030#define jump_label_enable(key) \
Jason Baronbf5438fc2010-09-17 11:09:00 -040031 jump_label_update((unsigned long)key, JUMP_LABEL_ENABLE);
32
Peter Zijlstra3b6e9012010-10-14 21:10:38 +020033#define jump_label_disable(key) \
Jason Baronbf5438fc2010-09-17 11:09:00 -040034 jump_label_update((unsigned long)key, JUMP_LABEL_DISABLE);
35
36#else
37
38#define JUMP_LABEL(key, label) \
39do { \
40 if (unlikely(*key)) \
41 goto label; \
42} while (0)
43
Peter Zijlstra3b6e9012010-10-14 21:10:38 +020044#define jump_label_enable(cond_var) \
Jason Baronbf5438fc2010-09-17 11:09:00 -040045do { \
46 *(cond_var) = 1; \
47} while (0)
48
Peter Zijlstra3b6e9012010-10-14 21:10:38 +020049#define jump_label_disable(cond_var) \
Jason Baronbf5438fc2010-09-17 11:09:00 -040050do { \
51 *(cond_var) = 0; \
52} while (0)
53
54static inline int jump_label_apply_nops(struct module *mod)
55{
56 return 0;
57}
58
Jason Baron4c3ef6d2010-09-17 11:09:08 -040059static inline int jump_label_text_reserved(void *start, void *end)
60{
61 return 0;
62}
63
Jason Baron91bad2f82010-10-01 17:23:48 -040064static inline void jump_label_lock(void) {}
65static inline void jump_label_unlock(void) {}
66
Jason Baronbf5438fc2010-09-17 11:09:00 -040067#endif
68
Peter Zijlstraebf31f52010-10-17 12:15:00 +020069#define COND_STMT(key, stmt) \
70do { \
71 __label__ jl_enabled; \
72 JUMP_LABEL(key, jl_enabled); \
73 if (0) { \
74jl_enabled: \
75 stmt; \
76 } \
77} while (0)
78
Jason Baronbf5438fc2010-09-17 11:09:00 -040079#endif