jump_label.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * jump label x86 support
  3. *
  4. * Copyright (C) 2009 Jason Baron <jbaron@redhat.com>
  5. *
  6. */
  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>
  16. #ifdef HAVE_JUMP_LABEL
  17. union jump_code_union {
  18. char code[JUMP_LABEL_NOP_SIZE];
  19. struct {
  20. char jump;
  21. int offset;
  22. } __attribute__((packed));
  23. };
  24. void arch_jump_label_transform(struct jump_entry *entry,
  25. enum jump_label_type type)
  26. {
  27. union jump_code_union code;
  28. if (type == JUMP_LABEL_ENABLE) {
  29. code.jump = 0xe9;
  30. code.offset = entry->target -
  31. (entry->code + JUMP_LABEL_NOP_SIZE);
  32. } else
  33. memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
  34. get_online_cpus();
  35. mutex_lock(&text_mutex);
  36. text_poke_smp((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE);
  37. mutex_unlock(&text_mutex);
  38. put_online_cpus();
  39. }
  40. void arch_jump_label_text_poke_early(jump_label_t addr)
  41. {
  42. text_poke_early((void *)addr, ideal_nops[NOP_ATOMIC5],
  43. JUMP_LABEL_NOP_SIZE);
  44. }
  45. #endif