jump_label.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. static void __jump_label_transform(struct jump_entry *entry,
  25. enum jump_label_type type,
  26. void *(*poker)(void *, const void *, size_t))
  27. {
  28. union jump_code_union code;
  29. if (type == JUMP_LABEL_ENABLE) {
  30. code.jump = 0xe9;
  31. code.offset = entry->target -
  32. (entry->code + JUMP_LABEL_NOP_SIZE);
  33. } else
  34. memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
  35. (*poker)((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE);
  36. }
  37. void arch_jump_label_transform(struct jump_entry *entry,
  38. enum jump_label_type type)
  39. {
  40. get_online_cpus();
  41. mutex_lock(&text_mutex);
  42. __jump_label_transform(entry, type, text_poke_smp);
  43. mutex_unlock(&text_mutex);
  44. put_online_cpus();
  45. }
  46. __init_or_module void arch_jump_label_transform_static(struct jump_entry *entry,
  47. enum jump_label_type type)
  48. {
  49. __jump_label_transform(entry, type, text_poke_early);
  50. }
  51. #endif