Xen Test Framework
Data Structures | Functions | Variables
main.c File Reference

Software Interrupt Emulation - Emulation of software interrupts. More...

#include <xtf.h>
#include "lowlevel.h"
+ Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  single
 Single stub's worth of information. More...
 
struct  sequence
 A collection of subs for an instruction. More...
 
struct  expectation
 

Functions

void expect (const void *prefix, const void *ip, unsigned int ev, unsigned int ec)
 Latch details of the stub under test. More...
 
void check (void)
 Check the exception long against the expected details. More...
 
bool do_unhandled_exception (struct cpu_regs *regs)
 Print expected information in the case of an unexpected exception. More...
 
void test_seq (struct sequence *seq, unsigned int vector, unsigned int error, bool fault)
 Test a single sequence of related instructions. More...
 
static void test_trap (struct sequence *seq, unsigned int vector)
 test_seq() wrapper, for caller clarity. More...
 
static void test_fault (struct sequence *seq, unsigned int vector, unsigned int error)
 test_seq() wrapper, for caller clarity. More...
 
static void set_idt_entries_present (bool present)
 Modify the present flag on the IDT entries under test. More...
 
static void set_idt_entries_dpl (unsigned int dpl)
 Modify the descriptor privilege level on the IDT entries under test. More...
 
void cpl3_tests (void)
 Tests run in user mode. More...
 
void cpl0_tests (void)
 Tests run in supervisor mode. More...
 
void test_main (void)
 To be implemented by each test, as its entry point. More...
 

Variables

const char test_title [] = "Software interrupt emulation"
 The title of the test. More...
 
bool test_wants_user_mappings = true
 Boolean indicating whether the test wants user mappings or not. More...
 
struct sequence int3
 Sequence for int3. More...
 
struct sequence int_0x3
 Sequence for int $3. More...
 
struct sequence icebp
 Sequence for icebp. More...
 
struct sequence int_0x1
 Sequence for int $1. More...
 
struct sequence into
 Sequence for into. More...
 
static bool user = false
 Whether to run the stub in user or supervisor mode. More...
 
struct expectation expectation
 Expected %eip, vector and error code from the stub under test. More...
 

Detailed Description

Software Interrupt Emulation - Emulation of software interrupts.

Definition in file main.c.

Function Documentation

◆ expect()

void expect ( const void *  prefix,
const void *  ip,
unsigned int  ev,
unsigned int  ec 
)

Latch details of the stub under test.

Definition at line 171 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check()

void check ( void  )

Check the exception long against the expected details.

Definition at line 179 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_unhandled_exception()

bool do_unhandled_exception ( struct cpu_regs *  regs)

Print expected information in the case of an unexpected exception.

May be implemented by a guest to provide custom exception handling.

Definition at line 215 of file main.c.

+ Here is the call graph for this function:

◆ test_seq()

void test_seq ( struct sequence seq,
unsigned int  vector,
unsigned int  error,
bool  fault 
)

Test a single sequence of related instructions.

Definition at line 224 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_trap()

static void test_trap ( struct sequence seq,
unsigned int  vector 
)
static

test_seq() wrapper, for caller clarity.

Definition at line 250 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_fault()

static void test_fault ( struct sequence seq,
unsigned int  vector,
unsigned int  error 
)
static

test_seq() wrapper, for caller clarity.

Definition at line 256 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_idt_entries_present()

static void set_idt_entries_present ( bool  present)
static

Modify the present flag on the IDT entries under test.

Definition at line 263 of file main.c.

+ Here is the caller graph for this function:

◆ set_idt_entries_dpl()

static void set_idt_entries_dpl ( unsigned int  dpl)
static

Modify the descriptor privilege level on the IDT entries under test.

Definition at line 271 of file main.c.

+ Here is the caller graph for this function:

◆ cpl3_tests()

void cpl3_tests ( void  )

Tests run in user mode.

Definition at line 279 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cpl0_tests()

void cpl0_tests ( void  )

Tests run in supervisor mode.

Definition at line 335 of file main.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ test_main()

void test_main ( void  )

To be implemented by each test, as its entry point.

Todo:
Implement better command line infrastructure, but this will do for now.

Definition at line 368 of file main.c.

+ Here is the call graph for this function:

Variable Documentation

◆ test_title

const char test_title[] = "Software interrupt emulation"

The title of the test.

Definition at line 51 of file main.c.

◆ test_wants_user_mappings

bool test_wants_user_mappings = true

Boolean indicating whether the test wants user mappings or not.

Some tests want an easy transition between supervisor and user modes. For such tests, this requires running on _PAGE_USER mappings, and they must opt-in.

See also
Errata

The framework variable is a weak reference, and may be overridden by a test wishing to change the default.

Definition at line 53 of file main.c.

◆ int3

struct sequence int3
Initial value:
=
{ "int3",
{
{"regular", stub_int3_reg,
{"redundant", stub_int3_red,
{"forced", stub_int3_force,
{"forced redundant", stub_int3_forcered,
},
}
unsigned long label_int3_red_trap[]
unsigned long label_int3_force_trap[]
unsigned long label_int3_reg_trap[]
unsigned long label_int3_forcered_fault[]
void stub_int3_red(void)
unsigned long label_int3_force_fault[]
void stub_int3_forcered(void)
unsigned long label_int3_red_fault[]
void stub_int3_force(void)
unsigned long label_int3_reg_fault[]
unsigned long label_int3_forcered_trap[]
void stub_int3_reg(void)

Sequence for int3.

Definition at line 71 of file main.c.

◆ int_0x3

struct sequence int_0x3
Initial value:
=
{ "int $3",
{
{"regular", stub_int_0x3_reg,
{"redundant", stub_int_0x3_red,
{"forced", stub_int_0x3_force,
{"forced redundant", stub_int_0x3_forcered,
},
}
void stub_int_0x3_reg(void)
unsigned long label_int_0x3_forcered_trap[]
unsigned long label_int_0x3_forcered_fault[]
unsigned long label_int_0x3_reg_fault[]
void stub_int_0x3_forcered(void)
void stub_int_0x3_red(void)
unsigned long label_int_0x3_force_trap[]
void stub_int_0x3_force(void)
unsigned long label_int_0x3_force_fault[]
unsigned long label_int_0x3_red_fault[]
unsigned long label_int_0x3_red_trap[]
unsigned long label_int_0x3_reg_trap[]

Sequence for int $3.

Definition at line 89 of file main.c.

◆ icebp

struct sequence icebp
Initial value:
=
{ "icebp",
{
{"regular", stub_icebp_reg,
{"redundant", stub_icebp_red,
{"forced", stub_icebp_force,
{"forced redundant", stub_icebp_forcered,
},
}
unsigned long label_icebp_reg_fault[]
unsigned long label_icebp_red_trap[]
unsigned long label_icebp_red_fault[]
void stub_icebp_reg(void)
unsigned long label_icebp_forcered_trap[]
unsigned long label_icebp_force_trap[]
unsigned long label_icebp_force_fault[]
void stub_icebp_force(void)
void stub_icebp_forcered(void)
unsigned long label_icebp_reg_trap[]
unsigned long label_icebp_forcered_fault[]
void stub_icebp_red(void)

Sequence for icebp.

Definition at line 107 of file main.c.

◆ int_0x1

struct sequence int_0x1
Initial value:
=
{ "int $1",
{
{"regular", stub_int_0x1_reg,
{"redundant", stub_int_0x1_red,
{"forced", stub_int_0x1_force,
{"forced redundant", stub_int_0x1_forcered,
},
}
unsigned long label_int_0x1_red_fault[]
void stub_int_0x1_red(void)
unsigned long label_int_0x1_force_trap[]
void stub_int_0x1_reg(void)
unsigned long label_int_0x1_force_fault[]
void stub_int_0x1_forcered(void)
void stub_int_0x1_force(void)
unsigned long label_int_0x1_forcered_trap[]
unsigned long label_int_0x1_red_trap[]
unsigned long label_int_0x1_reg_trap[]
unsigned long label_int_0x1_forcered_fault[]
unsigned long label_int_0x1_reg_fault[]

Sequence for int $1.

Definition at line 125 of file main.c.

◆ into

struct sequence into
Initial value:
=
{ "into",
{
{"regular", stub_into_reg,
{"redundant", stub_into_red,
{"forced", stub_into_force,
{"forced redundant", stub_into_forcered,
},
}
unsigned long label_into_forcered_fault[]
void stub_into_reg(void)
void stub_into_force(void)
unsigned long label_into_force_fault[]
unsigned long label_into_red_trap[]
unsigned long label_into_force_trap[]
unsigned long label_into_forcered_trap[]
unsigned long label_into_reg_trap[]
void stub_into_forcered(void)
void stub_into_red(void)
unsigned long label_into_reg_fault[]
unsigned long label_into_red_fault[]

Sequence for into.

Definition at line 143 of file main.c.

◆ user

bool user = false
static

Whether to run the stub in user or supervisor mode.

Definition at line 161 of file main.c.

◆ expectation

Expected %eip, vector and error code from the stub under test.