insn-eval.h (1668B)
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 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 18int pt_regs_offset(struct pt_regs *regs, int regno); 19 20bool insn_has_rep_prefix(struct insn *insn); 21void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs); 22int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs); 23int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs); 24unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs); 25unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx); 26int insn_get_code_seg_params(struct pt_regs *regs); 27int insn_get_effective_ip(struct pt_regs *regs, unsigned long *ip); 28int insn_fetch_from_user(struct pt_regs *regs, 29 unsigned char buf[MAX_INSN_SIZE]); 30int insn_fetch_from_user_inatomic(struct pt_regs *regs, 31 unsigned char buf[MAX_INSN_SIZE]); 32bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs, 33 unsigned char buf[MAX_INSN_SIZE], int buf_size); 34 35enum mmio_type { 36 MMIO_DECODE_FAILED, 37 MMIO_WRITE, 38 MMIO_WRITE_IMM, 39 MMIO_READ, 40 MMIO_READ_ZERO_EXTEND, 41 MMIO_READ_SIGN_EXTEND, 42 MMIO_MOVS, 43}; 44 45enum mmio_type insn_decode_mmio(struct insn *insn, int *bytes); 46 47#endif /* _ASM_X86_INSN_EVAL_H */