Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_JUMP_LABEL_H |
| 2 | #define _LINUX_JUMP_LABEL_H |
| 3 | |
Steven Rostedt | 45f81b1 | 2010-10-29 12:33:43 -0400 | [diff] [blame] | 4 | #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL) |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 5 | # include <asm/jump_label.h> |
| 6 | # define HAVE_JUMP_LABEL |
| 7 | #endif |
| 8 | |
| 9 | enum jump_label_type { |
| 10 | JUMP_LABEL_ENABLE, |
| 11 | JUMP_LABEL_DISABLE |
| 12 | }; |
| 13 | |
| 14 | struct module; |
| 15 | |
| 16 | #ifdef HAVE_JUMP_LABEL |
| 17 | |
| 18 | extern struct jump_entry __start___jump_table[]; |
| 19 | extern struct jump_entry __stop___jump_table[]; |
| 20 | |
Jason Baron | 91bad2f8 | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 21 | extern void jump_label_lock(void); |
| 22 | extern void jump_label_unlock(void); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 23 | extern void arch_jump_label_transform(struct jump_entry *entry, |
| 24 | enum jump_label_type type); |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 25 | extern void arch_jump_label_text_poke_early(jump_label_t addr); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 26 | extern void jump_label_update(unsigned long key, enum jump_label_type type); |
| 27 | extern void jump_label_apply_nops(struct module *mod); |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 28 | extern int jump_label_text_reserved(void *start, void *end); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 29 | |
Peter Zijlstra | 3b6e901 | 2010-10-14 21:10:38 +0200 | [diff] [blame] | 30 | #define jump_label_enable(key) \ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 31 | jump_label_update((unsigned long)key, JUMP_LABEL_ENABLE); |
| 32 | |
Peter Zijlstra | 3b6e901 | 2010-10-14 21:10:38 +0200 | [diff] [blame] | 33 | #define jump_label_disable(key) \ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 34 | jump_label_update((unsigned long)key, JUMP_LABEL_DISABLE); |
| 35 | |
| 36 | #else |
| 37 | |
| 38 | #define JUMP_LABEL(key, label) \ |
| 39 | do { \ |
| 40 | if (unlikely(*key)) \ |
| 41 | goto label; \ |
| 42 | } while (0) |
| 43 | |
Peter Zijlstra | 3b6e901 | 2010-10-14 21:10:38 +0200 | [diff] [blame] | 44 | #define jump_label_enable(cond_var) \ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 45 | do { \ |
| 46 | *(cond_var) = 1; \ |
| 47 | } while (0) |
| 48 | |
Peter Zijlstra | 3b6e901 | 2010-10-14 21:10:38 +0200 | [diff] [blame] | 49 | #define jump_label_disable(cond_var) \ |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 50 | do { \ |
| 51 | *(cond_var) = 0; \ |
| 52 | } while (0) |
| 53 | |
| 54 | static inline int jump_label_apply_nops(struct module *mod) |
| 55 | { |
| 56 | return 0; |
| 57 | } |
| 58 | |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 59 | static inline int jump_label_text_reserved(void *start, void *end) |
| 60 | { |
| 61 | return 0; |
| 62 | } |
| 63 | |
Jason Baron | 91bad2f8 | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 64 | static inline void jump_label_lock(void) {} |
| 65 | static inline void jump_label_unlock(void) {} |
| 66 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 67 | #endif |
| 68 | |
Peter Zijlstra | ebf31f5 | 2010-10-17 12:15:00 +0200 | [diff] [blame] | 69 | #define COND_STMT(key, stmt) \ |
| 70 | do { \ |
| 71 | __label__ jl_enabled; \ |
| 72 | JUMP_LABEL(key, jl_enabled); \ |
| 73 | if (0) { \ |
| 74 | jl_enabled: \ |
| 75 | stmt; \ |
| 76 | } \ |
| 77 | } while (0) |
| 78 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 79 | #endif |