1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
4 */
5
6 #ifndef _CHECK_H
7 #define _CHECK_H
8
9 #include <stdbool.h>
10 #include "cfi.h"
11 #include "arch.h"
12
13 struct insn_state {
14 struct cfi_state cfi;
15 unsigned int uaccess_stack;
16 bool uaccess;
17 bool df;
18 bool noinstr;
19 s8 instr;
20 };
21
22 struct alt_group {
23 /*
24 * Pointer from a replacement group to the original group. NULL if it
25 * *is* the original group.
26 */
27 struct alt_group *orig_group;
28
29 /* First and last instructions in the group */
30 struct instruction *first_insn, *last_insn;
31
32 /*
33 * Byte-offset-addressed len-sized array of pointers to CFI structs.
34 * This is shared with the other alt_groups in the same alternative.
35 */
36 struct cfi_state **cfi;
37 };
38
39 struct instruction {
40 struct list_head list;
41 struct hlist_node hash;
42 struct list_head mcount_loc_node;
43 struct list_head call_node;
44 struct section *sec;
45 unsigned long offset;
46 unsigned int len;
47 enum insn_type type;
48 unsigned long immediate;
49 bool dead_end, ignore, ignore_alts;
50 bool hint;
51 bool save, restore;
52 bool retpoline_safe;
53 bool entry;
54 s8 instr;
55 u8 visited;
56 struct alt_group *alt_group;
57 struct symbol *call_dest;
58 struct instruction *jump_dest;
59 struct instruction *first_jump_src;
60 struct reloc *jump_table;
61 struct reloc *reloc;
62 struct list_head alts;
63 struct symbol *func;
64 struct list_head stack_ops;
65 struct cfi_state *cfi;
66 };
67
68 #define VISITED_BRANCH 0x01
69 #define VISITED_BRANCH_UACCESS 0x02
70 #define VISITED_BRANCH_MASK 0x03
71 #define VISITED_ENTRY 0x04
72
is_static_jump(struct instruction * insn)73 static inline bool is_static_jump(struct instruction *insn)
74 {
75 return insn->type == INSN_JUMP_CONDITIONAL ||
76 insn->type == INSN_JUMP_UNCONDITIONAL;
77 }
78
is_dynamic_jump(struct instruction * insn)79 static inline bool is_dynamic_jump(struct instruction *insn)
80 {
81 return insn->type == INSN_JUMP_DYNAMIC ||
82 insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL;
83 }
84
is_jump(struct instruction * insn)85 static inline bool is_jump(struct instruction *insn)
86 {
87 return is_static_jump(insn) || is_dynamic_jump(insn);
88 }
89
90 struct instruction *find_insn(struct objtool_file *file,
91 struct section *sec, unsigned long offset);
92
93 #define for_each_insn(file, insn) \
94 list_for_each_entry(insn, &file->insn_list, list)
95
96 #define sec_for_each_insn(file, sec, insn) \
97 for (insn = find_insn(file, sec, 0); \
98 insn && &insn->list != &file->insn_list && \
99 insn->sec == sec; \
100 insn = list_next_entry(insn, list))
101
102 #endif /* _CHECK_H */
103