Main Page Modules Data Structures File List Data Fields Globals Related Pages

# jitter.h File Reference

Go to the source code of this file.

## Data Structures
struct | binary_stream
| A stream of X86 binary code. More...
struct | JIT_BPF_Filter
| Structure describing a x86 filtering program created by the jitter. More...
## Defines
#define | EAX 0
#define | ECX 1
#define | EDX 2
#define | EBX 3
#define | ESP 4
#define | EBP 5
#define | ESI 6
#define | EDI 7
#define | AX 0
#define | CX 1
#define | DX 2
#define | BX 3
#define | SP 4
#define | BP 5
#define | SI 6
#define | DI 7
#define | AL 0
#define | CL 1
#define | DL 2
#define | BL 3
#define | MOVid(r32, i32) emitm(&stream, 11 << 4 | 1 << 3 | r32 & 0x7, 1); emitm(&stream, i32, 4);
| mov r32,i32
#define | MOVrd(dr32, sr32) emitm(&stream, 8 << 4 | 3 | 1 << 3, 1); emitm(&stream, 3 << 6 | (dr32 & 0x7) << 3 | sr32 & 0x7, 1);
| mov dr32,sr32
#define | MOVodd(dr32, sr32, off)
| mov dr32,sr32[off]
#define | MOVobd(dr32, sr32, or32)
| mov dr32,sr32[or32]
#define | MOVobw(dr32, sr32, or32)
| mov dr16,sr32[or32]
#define | MOVobb(dr8, sr32, or32)
| mov dr8,sr32[or32]
#define | MOVomd(dr32, or32, sr32)
| mov [dr32][or32],sr32
#define | BSWAP(dr32)
| bswap dr32
#define | SWAP_AX()
| xchg al,ah
#define | PUSH(r32) emitm(&stream, 5 << 4 | 0 << 3 | r32 & 0x7, 1);
| push r32
#define | POP(r32) emitm(&stream, 5 << 4 | 1 << 3 | r32 & 0x7, 1);
| pop r32
#define | RET() emitm(&stream, 12 << 4 | 0 << 3 | 3, 1);
| ret
#define | ADDrd(dr32, sr32)
| add dr32,sr32
#define | ADD_EAXi(i32)
| add eax,i32
#define | ADDid(r32, i32)
| add r32,i32
#define | ADDib(r32, i8)
| add r32,i8
#define | SUBrd(dr32, sr32)
| sub dr32,sr32
#define | SUB_EAXi(i32)
| sub eax,i32
#define | MULrd(r32)
| mul r32
#define | DIVrd(r32)
| div r32
#define | ANDib(r8, i8)
| and r8,i8
#define | ANDid(r32, i32)
| and r32,i32
#define | ANDrd(dr32, sr32)
| and dr32,sr32
#define | ORrd(dr32, sr32)
| or dr32,sr32
#define | ORid(r32, i32)
| or r32,i32
#define | SHLib(r32, i8)
| shl r32,i8
#define | SHL_CLrb(dr32)
| shl dr32,cl
#define | SHRib(r32, i8)
| shr r32,i8
#define | SHR_CLrb(dr32)
| shr dr32,cl
#define | NEGd(r32)
| neg r32
#define | CMPodd(dr32, sr32, off)
| cmp dr32,sr32[off]
#define | CMPrd(dr32, sr32)
| cmp dr32,sr32
#define | CMPid(dr32, i32)
| cmp dr32,i32
#define | JNEb(off8)
| jne off32
#define | JE(off32)
| je off32
#define | JLE(off32)
| jle off32
#define | JLEb(off8)
| jle off8
#define | JA(off32)
| ja off32
#define | JAE(off32)
| jae off32
#define | JG(off32)
| jg off32
#define | JGE(off32)
| jge off32
#define | JMP(off32)
| jmp off32
## Typedefs
typedef binary_stream | binary_stream
| A stream of X86 binary code.
typedef UINT(* | BPF_filter_function )(binary_stream *, ULONG, UINT)
| Prototype of a filtering function created by the jitter.
typedef void(* | emit_func )(binary_stream *stream, ULONG value, UINT n)
| Prototype of the emit functions.
typedef JIT_BPF_Filter | JIT_BPF_Filter
| Structure describing a x86 filtering program created by the jitter.
## Functions
JIT_BPF_Filter * | BPF_jitter (struct bpf_insn *fp, INT nins)
| BPF jitter, builds an x86 function from a BPF program.
BPF_filter_function | BPFtoX86 (struct bpf_insn *ins, UINT nins, INT *mem)
| Translates a set of BPF instructions in a set of x86 ones.
void | BPF_Destroy_JIT_Filter (JIT_BPF_Filter *Filter)
| Deletes a filtering function that was previously created by BPF_jitter().

## Function Documentation

void BPF_Destroy_JIT_Filter | ( | JIT_BPF_Filter * | Filter | ) |

  | Deletes a filtering function that was previously created by BPF_jitter(). Parameters:
  Filter | The filter to destroy.
This function frees the variuos buffers (code, memory, etc.) associated with a filtering function. Definition at line 670 of file jitter.c. References JIT_BPF_Filter::Function, and JIT_BPF_Filter::mem. Referenced by NPF_Close(), NPF_CloseAdapterComplete(), and NPF_IoControl().

JIT_BPF_Filter* BPF_jitter | ( | struct bpf_insn * | fp,
|  | INT | nins
| ) |

  | BPF jitter, builds an x86 function from a BPF program. Parameters:
  fp | The BPF pseudo-assembly filter that will be translated into x86 code.
  nins | Number of instructions of the input filter.
Returns: The JIT_BPF_Filter structure containing the x86 filtering binary. BPF_jitter allocates the buffers for the new native filter and then translates the program pointed by fp calling BPFtoX86(). Definition at line 619 of file jitter.c. References BPFtoX86(), JIT_BPF_Filter, and JIT_BPF_Filter::mem. Referenced by NPF_IoControl().

BPF_filter_function BPFtoX86 | ( | struct bpf_insn * | ins,
|  | UINT | nins,
|  | INT * | mem
| ) |

  | Translates a set of BPF instructions in a set of x86 ones. Parameters:
  ins | Pointer to the BPF instructions that will be translated into x86 code.
  nins | Number of instructions to translate.
  mem | Memory used by the x86 function to emulate the RAM of the BPF pseudo processor.
Returns: The x86 filtering function. This function does the hard work for the JIT compilation. It takes a group of BPF pseudo instructions and through the instruction macros defined in jitter.h it is able to create an function directly executable by NPF. Definition at line 86 of file jitter.c. References ADD_EAXi, ADDib, ADDrd, ANDib, ANDid, ANDrd, BPF_filter_function, binary_stream::bpf_pc, BSWAP, CMPid, CMPodd, CMPrd, bpf_insn::code, binary_stream::cur_ip, DIVrd, emit_code(), emit_lenght(), emitm, binary_stream::ibuf, JA, JAE, JE, bpf_insn::jf, JG, JGE, JLEb, JMP, JNEb, bpf_insn::jt, bpf_insn::k, MOVid, MOVobb, MOVobd, MOVobw, MOVodd, MOVomd, MOVrd, MULrd, NEGd, ORid, ORrd, POP, PUSH, binary_stream::refs, RET, SHL_CLrb, SHLib, SHR_CLrb, SHRib, SUB_EAXi, SUBrd, and SWAP_AX. Referenced by BPF_jitter().

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.