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