Linux Perf
insn.c File Reference
#include <string.h>
#include "inat.h"
#include "insn.h"
Include dependency graph for insn.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define validate_next(t, insn, n)   ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
 
#define __get_next(t, insn)   ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
 
#define __peek_nbyte_next(t, insn, n)   ({ t r = *(t*)((insn)->next_byte + n); r; })
 
#define get_next(t, insn)   ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
 
#define peek_nbyte_next(t, insn, n)   ({ if (unlikely(!validate_next(t, insn, n))) goto err_out; __peek_nbyte_next(t, insn, n); })
 
#define peek_next(t, insn)   peek_nbyte_next(t, insn, 0)
 

Functions

void insn_init (struct insn *insn, const void *kaddr, int buf_len, int x86_64)
 
void insn_get_prefixes (struct insn *insn)
 
void insn_get_opcode (struct insn *insn)
 
void insn_get_modrm (struct insn *insn)
 
int insn_rip_relative (struct insn *insn)
 
void insn_get_sib (struct insn *insn)
 
void insn_get_displacement (struct insn *insn)
 
static int __get_moffset (struct insn *insn)
 
static int __get_immv32 (struct insn *insn)
 
static int __get_immv (struct insn *insn)
 
static int __get_immptr (struct insn *insn)
 
void insn_get_immediate (struct insn *insn)
 
void insn_get_length (struct insn *insn)
 

Macro Definition Documentation

◆ __get_next

#define __get_next (   t,
  insn 
)    ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })

Definition at line 33 of file insn.c.

◆ __peek_nbyte_next

#define __peek_nbyte_next (   t,
  insn,
 
)    ({ t r = *(t*)((insn)->next_byte + n); r; })

Definition at line 36 of file insn.c.

◆ get_next

#define get_next (   t,
  insn 
)    ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })

Definition at line 39 of file insn.c.

◆ peek_nbyte_next

#define peek_nbyte_next (   t,
  insn,
 
)    ({ if (unlikely(!validate_next(t, insn, n))) goto err_out; __peek_nbyte_next(t, insn, n); })

Definition at line 42 of file insn.c.

◆ peek_next

#define peek_next (   t,
  insn 
)    peek_nbyte_next(t, insn, 0)

Definition at line 45 of file insn.c.

◆ validate_next

#define validate_next (   t,
  insn,
 
)    ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)

Definition at line 30 of file insn.c.

Function Documentation

◆ __get_immptr()

static int __get_immptr ( struct insn insn)
static

Definition at line 493 of file insn.c.

◆ __get_immv()

static int __get_immv ( struct insn insn)
static

Definition at line 465 of file insn.c.

◆ __get_immv32()

static int __get_immv32 ( struct insn insn)
static

Definition at line 442 of file insn.c.

◆ __get_moffset()

static int __get_moffset ( struct insn insn)
static

Definition at line 413 of file insn.c.

◆ insn_get_displacement()

void insn_get_displacement ( struct insn insn)

insn_get_displacement() - Get the displacement of instruction : &struct insn containing instruction

If necessary, first collects the instruction up to and including the SIB byte. Displacement value is sign-expanded.

Definition at line 357 of file insn.c.

Here is the call graph for this function:

◆ insn_get_immediate()

void insn_get_immediate ( struct insn insn)

insn_get_immediate() - Get the immediates of instruction : &struct insn containing instruction

If necessary, first collects the instruction up to and including the displacement bytes. Basically, most of immediates are sign-expanded. Unsigned-value can be get by bit masking with ((1 << (nbytes * 8)) - 1)

Definition at line 528 of file insn.c.

Here is the call graph for this function:

◆ insn_get_length()

void insn_get_length ( struct insn insn)

insn_get_length() - Get the length of instruction : &struct insn containing instruction

If necessary, first collects the instruction up to and including the immediates bytes.

Definition at line 598 of file insn.c.

Here is the call graph for this function:

◆ insn_get_modrm()

void insn_get_modrm ( struct insn insn)

insn_get_modrm - collect ModRM byte, if any : &struct insn containing instruction

Populates ->modrm and updates ->next_byte to point past the ModRM byte, if any. If necessary, first collects the preceding bytes (prefixes and opcode(s)). No effect if ->modrm.got is already 1.

Definition at line 266 of file insn.c.

Here is the call graph for this function:

◆ insn_get_opcode()

void insn_get_opcode ( struct insn insn)

insn_get_opcode - collect opcode(s) : &struct insn containing instruction

Populates ->opcode, updates ->next_byte to point past the opcode byte(s), and set ->attr (except for groups). If necessary, first collects any preceding (prefix) bytes. Sets ->opcode.value = opcode1. No effect if ->opcode.got is already 1.

Definition at line 213 of file insn.c.

Here is the call graph for this function:

◆ insn_get_prefixes()

void insn_get_prefixes ( struct insn insn)

insn_get_prefixes - scan x86 instruction prefix bytes : &struct insn containing instruction

Populates the ->prefixes bitmap, and updates ->next_byte to point to the (first) opcode. No effect if ->prefixes.got is already set.

Definition at line 82 of file insn.c.

Here is the call graph for this function:

◆ insn_get_sib()

void insn_get_sib ( struct insn insn)

insn_get_sib() - Get the SIB byte of instruction : &struct insn containing instruction

If necessary, first collects the instruction up to and including the ModRM byte.

Definition at line 326 of file insn.c.

Here is the call graph for this function:

◆ insn_init()

void insn_init ( struct insn insn,
const void *  kaddr,
int  buf_len,
int  x86_64 
)

insn_init() - initialize struct insn : &struct insn to be initialized : address (in kernel memory) of instruction (or copy thereof) : !0 for 64-bit kernel or 64-bit app

Definition at line 53 of file insn.c.

Here is the call graph for this function:

◆ insn_rip_relative()

int insn_rip_relative ( struct insn insn)

insn_rip_relative() - Does instruction use RIP-relative addressing mode? : &struct insn containing instruction

If necessary, first collects the instruction up to and including the ModRM byte. No effect if ->x86_64 is 0.

Definition at line 304 of file insn.c.

Here is the call graph for this function: