Ricardo Neri | 32542ee | 2017-10-27 13:25:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_INSN_EVAL_H |
| 2 | #define _ASM_X86_INSN_EVAL_H |
| 3 | /* |
| 4 | * A collection of utility functions for x86 instruction analysis to be |
| 5 | * used in a kernel context. Useful when, for instance, making sense |
| 6 | * of the registers indicated by operands. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/compiler.h> |
| 10 | #include <linux/bug.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <asm/ptrace.h> |
| 13 | |
Ricardo Neri | 4efea85 | 2017-10-27 13:25:43 -0700 | [diff] [blame] | 14 | #define INSN_CODE_SEG_ADDR_SZ(params) ((params >> 4) & 0xf) |
| 15 | #define INSN_CODE_SEG_OPND_SZ(params) (params & 0xf) |
| 16 | #define INSN_CODE_SEG_PARAMS(oper_sz, addr_sz) (oper_sz | (addr_sz << 4)) |
| 17 | |
Joerg Roedel | 5901781 | 2020-09-07 15:15:12 +0200 | [diff] [blame] | 18 | bool insn_has_rep_prefix(struct insn *insn); |
Ricardo Neri | 32542ee | 2017-10-27 13:25:36 -0700 | [diff] [blame] | 19 | void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs); |
Ricardo Neri | e5e45f1 | 2017-10-27 13:25:38 -0700 | [diff] [blame] | 20 | int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs); |
Joerg Roedel | 7af1bd8 | 2020-09-07 15:15:11 +0200 | [diff] [blame] | 21 | int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs); |
Ricardo Neri | bd5a410 | 2017-10-27 13:25:42 -0700 | [diff] [blame] | 22 | unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx); |
Borislav Petkov | e2a5dca | 2017-11-23 10:19:51 +0100 | [diff] [blame] | 23 | int insn_get_code_seg_params(struct pt_regs *regs); |
Joerg Roedel | 172b75e | 2020-09-07 15:15:09 +0200 | [diff] [blame] | 24 | int insn_fetch_from_user(struct pt_regs *regs, |
| 25 | unsigned char buf[MAX_INSN_SIZE]); |
Joerg Roedel | bffe30d | 2021-03-03 15:17:16 +0100 | [diff] [blame] | 26 | int insn_fetch_from_user_inatomic(struct pt_regs *regs, |
| 27 | unsigned char buf[MAX_INSN_SIZE]); |
Borislav Petkov | 9e76129 | 2020-11-02 18:47:34 +0100 | [diff] [blame] | 28 | bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs, |
| 29 | unsigned char buf[MAX_INSN_SIZE], int buf_size); |
Ricardo Neri | 32542ee | 2017-10-27 13:25:36 -0700 | [diff] [blame] | 30 | |
| 31 | #endif /* _ASM_X86_INSN_EVAL_H */ |