2017-10-27 16:25:36 -04:00
|
|
|
#ifndef _ASM_X86_INSN_EVAL_H
|
|
|
|
#define _ASM_X86_INSN_EVAL_H
|
|
|
|
/*
|
|
|
|
* A collection of utility functions for x86 instruction analysis to be
|
|
|
|
* used in a kernel context. Useful when, for instance, making sense
|
|
|
|
* of the registers indicated by operands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/bug.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
|
2017-10-27 16:25:43 -04:00
|
|
|
#define INSN_CODE_SEG_ADDR_SZ(params) ((params >> 4) & 0xf)
|
|
|
|
#define INSN_CODE_SEG_OPND_SZ(params) (params & 0xf)
|
|
|
|
#define INSN_CODE_SEG_PARAMS(oper_sz, addr_sz) (oper_sz | (addr_sz << 4))
|
|
|
|
|
2021-11-10 05:01:09 -05:00
|
|
|
int pt_regs_offset(struct pt_regs *regs, int regno);
|
|
|
|
|
2020-09-07 09:15:12 -04:00
|
|
|
bool insn_has_rep_prefix(struct insn *insn);
|
2017-10-27 16:25:36 -04:00
|
|
|
void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
|
2017-10-27 16:25:38 -04:00
|
|
|
int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs);
|
2020-09-07 09:15:11 -04:00
|
|
|
int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
|
2021-11-30 13:49:31 -05:00
|
|
|
unsigned long *insn_get_modrm_reg_ptr(struct insn *insn, struct pt_regs *regs);
|
2017-10-27 16:25:42 -04:00
|
|
|
unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
|
2017-11-23 04:19:51 -05:00
|
|
|
int insn_get_code_seg_params(struct pt_regs *regs);
|
2021-09-17 05:20:04 -04:00
|
|
|
int insn_get_effective_ip(struct pt_regs *regs, unsigned long *ip);
|
2020-09-07 09:15:09 -04:00
|
|
|
int insn_fetch_from_user(struct pt_regs *regs,
|
|
|
|
unsigned char buf[MAX_INSN_SIZE]);
|
2021-03-03 09:17:16 -05:00
|
|
|
int insn_fetch_from_user_inatomic(struct pt_regs *regs,
|
|
|
|
unsigned char buf[MAX_INSN_SIZE]);
|
2020-11-02 12:47:34 -05:00
|
|
|
bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs,
|
|
|
|
unsigned char buf[MAX_INSN_SIZE], int buf_size);
|
2017-10-27 16:25:36 -04:00
|
|
|
|
2023-01-01 11:29:04 -05:00
|
|
|
enum insn_mmio_type {
|
|
|
|
INSN_MMIO_DECODE_FAILED,
|
|
|
|
INSN_MMIO_WRITE,
|
|
|
|
INSN_MMIO_WRITE_IMM,
|
|
|
|
INSN_MMIO_READ,
|
|
|
|
INSN_MMIO_READ_ZERO_EXTEND,
|
|
|
|
INSN_MMIO_READ_SIGN_EXTEND,
|
|
|
|
INSN_MMIO_MOVS,
|
2021-11-30 13:49:32 -05:00
|
|
|
};
|
|
|
|
|
2023-01-01 11:29:04 -05:00
|
|
|
enum insn_mmio_type insn_decode_mmio(struct insn *insn, int *bytes);
|
2021-11-30 13:49:32 -05:00
|
|
|
|
2017-10-27 16:25:36 -04:00
|
|
|
#endif /* _ASM_X86_INSN_EVAL_H */
|