blob: c1438f9239e46ce5f22f1792e24c1014647b99fc [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001#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
Olivier Deprez157378f2022-04-04 15:47:50 +020018bool insn_has_rep_prefix(struct insn *insn);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000019void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs);
20int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs);
Olivier Deprez157378f2022-04-04 15:47:50 +020021int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000022unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
23int insn_get_code_seg_params(struct pt_regs *regs);
Olivier Deprez157378f2022-04-04 15:47:50 +020024unsigned long insn_get_effective_ip(struct pt_regs *regs);
25int insn_fetch_from_user(struct pt_regs *regs,
26 unsigned char buf[MAX_INSN_SIZE]);
27int insn_fetch_from_user_inatomic(struct pt_regs *regs,
28 unsigned char buf[MAX_INSN_SIZE]);
29bool insn_decode(struct insn *insn, struct pt_regs *regs,
30 unsigned char buf[MAX_INSN_SIZE], int buf_size);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000031
32#endif /* _ASM_X86_INSN_EVAL_H */