check.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
  4. */
  5. #ifndef _CHECK_H
  6. #define _CHECK_H
  7. #include <stdbool.h>
  8. #include "cfi.h"
  9. #include "arch.h"
  10. struct insn_state {
  11. struct cfi_state cfi;
  12. unsigned int uaccess_stack;
  13. bool uaccess;
  14. bool df;
  15. bool noinstr;
  16. s8 instr;
  17. };
  18. struct instruction {
  19. struct list_head list;
  20. struct hlist_node hash;
  21. struct list_head static_call_node;
  22. struct list_head mcount_loc_node;
  23. struct section *sec;
  24. unsigned long offset;
  25. unsigned int len;
  26. enum insn_type type;
  27. unsigned long immediate;
  28. bool dead_end, ignore, ignore_alts;
  29. bool hint;
  30. bool retpoline_safe;
  31. s8 instr;
  32. u8 visited;
  33. u8 ret_offset;
  34. int alt_group;
  35. struct symbol *call_dest;
  36. struct instruction *jump_dest;
  37. struct instruction *first_jump_src;
  38. struct reloc *jump_table;
  39. struct list_head alts;
  40. struct symbol *func;
  41. struct list_head stack_ops;
  42. struct cfi_state cfi;
  43. #ifdef INSN_USE_ORC
  44. struct orc_entry orc;
  45. #endif
  46. };
  47. static inline bool is_static_jump(struct instruction *insn)
  48. {
  49. return insn->type == INSN_JUMP_CONDITIONAL ||
  50. insn->type == INSN_JUMP_UNCONDITIONAL;
  51. }
  52. static inline bool is_dynamic_jump(struct instruction *insn)
  53. {
  54. return insn->type == INSN_JUMP_DYNAMIC ||
  55. insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL;
  56. }
  57. static inline bool is_jump(struct instruction *insn)
  58. {
  59. return is_static_jump(insn) || is_dynamic_jump(insn);
  60. }
  61. struct instruction *find_insn(struct objtool_file *file,
  62. struct section *sec, unsigned long offset);
  63. #define for_each_insn(file, insn) \
  64. list_for_each_entry(insn, &file->insn_list, list)
  65. #define sec_for_each_insn(file, sec, insn) \
  66. for (insn = find_insn(file, sec, 0); \
  67. insn && &insn->list != &file->insn_list && \
  68. insn->sec == sec; \
  69. insn = list_next_entry(insn, list))
  70. #endif /* _CHECK_H */