2 * jump label x86 support
4 * Copyright (C) 2009 Jason Baron <jbaron@redhat.com>
7 #include <linux/jump_label.h>
8 #include <linux/memory.h>
9 #include <linux/uaccess.h>
10 #include <linux/module.h>
11 #include <linux/list.h>
12 #include <linux/jhash.h>
13 #include <linux/cpu.h>
14 #include <asm/kprobes.h>
15 #include <asm/alternative.h>
17 #ifdef HAVE_JUMP_LABEL
19 union jump_code_union {
20 char code[JUMP_LABEL_NOP_SIZE];
24 } __attribute__((packed));
27 static void __jump_label_transform(struct jump_entry *entry,
28 enum jump_label_type type,
29 void *(*poker)(void *, const void *, size_t))
31 union jump_code_union code;
33 if (type == JUMP_LABEL_ENABLE) {
35 code.offset = entry->target -
36 (entry->code + JUMP_LABEL_NOP_SIZE);
38 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
41 * Make text_poke_bp() a default fallback poker.
43 * At the time the change is being done, just ignore whether we
44 * are doing nop -> jump or jump -> nop transition, and assume
45 * always nop being the 'currently valid' instruction
49 (*poker)((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE);
51 text_poke_bp((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE,
52 (void *)entry->code + JUMP_LABEL_NOP_SIZE);
55 void arch_jump_label_transform(struct jump_entry *entry,
56 enum jump_label_type type)
59 mutex_lock(&text_mutex);
60 __jump_label_transform(entry, type, NULL);
61 mutex_unlock(&text_mutex);
65 __init_or_module void arch_jump_label_transform_static(struct jump_entry *entry,
66 enum jump_label_type type)
68 __jump_label_transform(entry, type, text_poke_early);