check.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _CHECK_H
  18. #define _CHECK_H
  19. #include <stdbool.h>
  20. #include "elf.h"
  21. #include "cfi.h"
  22. #include "arch.h"
  23. #include "orc.h"
  24. #include <linux/hashtable.h>
  25. struct insn_state {
  26. struct cfi_reg cfa;
  27. struct cfi_reg regs[CFI_NUM_REGS];
  28. int stack_size;
  29. unsigned char type;
  30. bool bp_scratch;
  31. bool drap, end;
  32. int drap_reg, drap_offset;
  33. struct cfi_reg vals[CFI_NUM_REGS];
  34. };
  35. struct instruction {
  36. struct list_head list;
  37. struct hlist_node hash;
  38. struct section *sec;
  39. unsigned long offset;
  40. unsigned int len;
  41. unsigned char type;
  42. unsigned long immediate;
  43. bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;
  44. bool retpoline_safe;
  45. struct symbol *call_dest;
  46. struct instruction *jump_dest;
  47. struct instruction *first_jump_src;
  48. struct list_head alts;
  49. struct symbol *func;
  50. struct stack_op stack_op;
  51. struct insn_state state;
  52. struct orc_entry orc;
  53. };
  54. struct objtool_file {
  55. struct elf *elf;
  56. struct list_head insn_list;
  57. DECLARE_HASHTABLE(insn_hash, 16);
  58. struct section *whitelist;
  59. bool ignore_unreachables, c_file, hints, rodata;
  60. };
  61. int check(const char *objname, bool orc);
  62. struct instruction *find_insn(struct objtool_file *file,
  63. struct section *sec, unsigned long offset);
  64. #define for_each_insn(file, insn) \
  65. list_for_each_entry(insn, &file->insn_list, list)
  66. #define sec_for_each_insn(file, sec, insn) \
  67. for (insn = find_insn(file, sec, 0); \
  68. insn && &insn->list != &file->insn_list && \
  69. insn->sec == sec; \
  70. insn = list_next_entry(insn, list))
  71. #endif /* _CHECK_H */