jump_label.h 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef _LINUX_JUMP_LABEL_H
#define _LINUX_JUMP_LABEL_H

#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_HAVE_ARCH_JUMP_LABEL)
# include <asm/jump_label.h>
# define HAVE_JUMP_LABEL
#endif

enum jump_label_type {
	JUMP_LABEL_ENABLE,
	JUMP_LABEL_DISABLE
};

struct module;

#ifdef HAVE_JUMP_LABEL

extern struct jump_entry __start___jump_table[];
extern struct jump_entry __stop___jump_table[];

extern void arch_jump_label_transform(struct jump_entry *entry,
				 enum jump_label_type type);
23
extern void arch_jump_label_text_poke_early(jump_label_t addr);
24 25
extern void jump_label_update(unsigned long key, enum jump_label_type type);
extern void jump_label_apply_nops(struct module *mod);
26
extern int jump_label_text_reserved(void *start, void *end);
27

28
#define jump_label_enable(key) \
29 30
	jump_label_update((unsigned long)key, JUMP_LABEL_ENABLE);

31
#define jump_label_disable(key) \
32 33 34 35 36 37 38 39 40 41
	jump_label_update((unsigned long)key, JUMP_LABEL_DISABLE);

#else

#define JUMP_LABEL(key, label)			\
do {						\
	if (unlikely(*key))			\
		goto label;			\
} while (0)

42
#define jump_label_enable(cond_var)	\
43 44 45 46
do {					\
       *(cond_var) = 1;			\
} while (0)

47
#define jump_label_disable(cond_var)	\
48 49 50 51 52 53 54 55 56
do {					\
       *(cond_var) = 0;			\
} while (0)

static inline int jump_label_apply_nops(struct module *mod)
{
	return 0;
}

57 58 59 60 61
static inline int jump_label_text_reserved(void *start, void *end)
{
	return 0;
}

62 63
#endif

64 65 66 67 68 69 70 71 72 73
#define COND_STMT(key, stmt)					\
do {								\
	__label__ jl_enabled;					\
	JUMP_LABEL(key, jl_enabled);				\
	if (0) {						\
jl_enabled:							\
		stmt;						\
	}							\
} while (0)

74
#endif