jump_label.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2013 Huawei Ltd.
  3. * Author: Jiang Liu <liuj97@gmail.com>
  4. *
  5. * Based on arch/arm/include/asm/jump_label.h
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_JUMP_LABEL_H
  20. #define __ASM_JUMP_LABEL_H
  21. #include <linux/types.h>
  22. #include <asm/insn.h>
  23. #ifdef __KERNEL__
  24. #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE
  25. static __always_inline bool arch_static_branch(struct static_key *key)
  26. {
  27. asm goto("1: nop\n\t"
  28. ".pushsection __jump_table, \"aw\"\n\t"
  29. ".align 3\n\t"
  30. ".quad 1b, %l[l_yes], %c0\n\t"
  31. ".popsection\n\t"
  32. : : "i"(key) : : l_yes);
  33. return false;
  34. l_yes:
  35. return true;
  36. }
  37. #endif /* __KERNEL__ */
  38. typedef u64 jump_label_t;
  39. struct jump_entry {
  40. jump_label_t code;
  41. jump_label_t target;
  42. jump_label_t key;
  43. };
  44. #endif /* __ASM_JUMP_LABEL_H */