Functions | Variables
common.c File Reference

Go to the source code of this file.

Functions

struct module_tget_module (int64_t index)
 
uint64_t symbol_length (const char *sym)
 
int64_t resolve_symbol (const char *name, void **sym)
 
int64_t execute_symbol (const char *sym, uint64_t arg1, uint64_t arg2, uint64_t cpuid)
 
int64_t add_raw_md_to_memory_manager (uint64_t virt, uint64_t type)
 
int64_t add_md_to_memory_manager (struct module_t *module)
 
int64_t load_elf_file (struct module_t *module)
 
int64_t common_vmm_status (void)
 
int64_t common_reset (void)
 
int64_t common_init (void)
 
int64_t common_fini (void)
 
int64_t common_add_module (const char *file, uint64_t fsize)
 
int64_t common_load_vmm (void)
 
int64_t common_unload_vmm (void)
 
int64_t common_start_vmm (void)
 
int64_t common_stop_vmm (void)
 
int64_t common_dump_vmm (struct debug_ring_resources_t **drr, uint64_t vcpuid)
 
int64_t common_vmcall (struct vmcall_registers_t *regs, uint64_t cpuid)
 

Variables

int64_t g_vmm_status = VMM_UNLOADED
 
int64_t g_num_modules = 0
 
struct module_t g_modules [MAX_NUM_MODULES]
 
struct bfelf_loader_t g_loader
 
int64_t g_num_cpus_started = 0
 
void * g_tls = 0
 
void * g_stack = 0
 
uint64_t g_tls_size = 0
 
uint64_t g_stack_size = 0
 
uint64_t g_stack_top = 0
 
execute_entry_t execute_entry = 0
 

Function Documentation

◆ get_module()

struct module_t* get_module ( int64_t  index)

Definition at line 64 of file common.c.

◆ symbol_length()

uint64_t symbol_length ( const char *  sym)

Definition at line 73 of file common.c.

◆ resolve_symbol()

int64_t resolve_symbol ( const char *  name,
void **  sym 
)

Definition at line 87 of file common.c.

◆ execute_symbol()

int64_t execute_symbol ( const char *  sym,
uint64_t  arg1,
uint64_t  arg2,
uint64_t  cpuid 
)

Definition at line 108 of file common.c.

◆ add_raw_md_to_memory_manager()

int64_t add_raw_md_to_memory_manager ( uint64_t  virt,
uint64_t  type 
)

Definition at line 135 of file common.c.

◆ add_md_to_memory_manager()

int64_t add_md_to_memory_manager ( struct module_t module)

Definition at line 152 of file common.c.

◆ load_elf_file()

int64_t load_elf_file ( struct module_t module)

Definition at line 191 of file common.c.

◆ common_vmm_status()

int64_t common_vmm_status ( void  )

VMM Status

Returns
returns the current status of the VMM.

Definition at line 227 of file common.c.

◆ common_reset()

int64_t common_reset ( void  )

Reset

This function should not be called directly. Instead, use common_unload. This is only exposed publically for unit testing.

Returns
will always return BF_SUCCESS

Definition at line 233 of file common.c.

◆ common_init()

int64_t common_init ( void  )

Initialize Driver Entry

This code should be run as part of the driver entry's init code. This sets up some resources that are needed throughout the lifetime of the driver entry.

Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 267 of file common.c.

◆ common_fini()

int64_t common_fini ( void  )

Finalize Driver Entry

This code should be run as part of the driver entry's fini code. This cleans up some resources that were needed throughout the lifetime of the driver entry.

Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 273 of file common.c.

◆ common_add_module()

int64_t common_add_module ( const char *  file,
uint64_t  fsize 
)

Add Module

Add's a module into memory to be executed once start_vmm is run. This function uses the platform functions to allocate memory for the executable. The file that is provided should not be removed until after stop_vmm is run. Removing the file from memory could cause a crash, as the start_vmm function uses the file that is being added to search for symbols that are needed, as well as the stop_vmm function. Once stop_vmm is run, it's safe to remove the files. Also, this function cannot be run if the vmm has already been started.

Parameters
filethe file to add to memory
fsizethe size of the file in bytes
Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 305 of file common.c.

◆ common_load_vmm()

int64_t common_load_vmm ( void  )

Load VMM

This function loads the vmm (assuming that the modules that were loaded are actually a vmm). Once a VMM is loaded, it is placed in memory, and all of the modules are properly reloacted such that, code within each module is now capable of executing.

Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 357 of file common.c.

◆ common_unload_vmm()

int64_t common_unload_vmm ( void  )

Unload VMM

This function unloads the vmm. Once the VMM is unloaded, all of the symbols for the VMM are removed from memory, and are no longer accessible. The VMM cannot be unloaded unless the VMM is already loaded, but is not running.

Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 451 of file common.c.

◆ common_start_vmm()

int64_t common_start_vmm ( void  )

Start VMM

This function starts the vmm. Before the VMM can be started, it must first be loaded.

Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 490 of file common.c.

◆ common_stop_vmm()

int64_t common_stop_vmm ( void  )

Stop VMM

This function stops the vmm. Before a VMM can be stopped, it must first be loaded, and running.

Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 543 of file common.c.

◆ common_dump_vmm()

int64_t common_dump_vmm ( struct debug_ring_resources_t **  drr,
uint64_t  vcpuid 
)

Dump VMM

This grabs the conents of the debug ring, and dumps the contents to the driver entry's console. This is one of a couple of ways to get feedback from the VMM. Note that the VMM must at least be loaded for this function to work as it has to do a symbol lookup

Parameters
drra pointer to the drr provided by the user
vcpuidindicates which drr to get as each vcpu has its own drr
Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 592 of file common.c.

◆ common_vmcall()

int64_t common_vmcall ( struct vmcall_registers_t regs,
uint64_t  cpuid 
)

VMCall

This performs a vmcall on the requested CPU.

Parameters
regsthe vmcall registers used in the vmcall
cpuidindicates which cpu to vmcall
Returns
BF_SUCCESS on success, negative error code on failure

Definition at line 610 of file common.c.

Variable Documentation

◆ g_vmm_status

int64_t g_vmm_status = VMM_UNLOADED

Definition at line 37 of file common.c.

◆ g_num_modules

int64_t g_num_modules = 0

Definition at line 39 of file common.c.

◆ g_modules

struct module_t g_modules[MAX_NUM_MODULES]

Definition at line 40 of file common.c.

◆ g_loader

struct bfelf_loader_t g_loader

Definition at line 42 of file common.c.

◆ g_num_cpus_started

int64_t g_num_cpus_started = 0

Definition at line 44 of file common.c.

◆ g_tls

void* g_tls = 0

Definition at line 46 of file common.c.

◆ g_stack

void* g_stack = 0

Definition at line 47 of file common.c.

◆ g_tls_size

uint64_t g_tls_size = 0

Definition at line 49 of file common.c.

◆ g_stack_size

uint64_t g_stack_size = 0

Definition at line 50 of file common.c.

◆ g_stack_top

uint64_t g_stack_top = 0

Definition at line 51 of file common.c.

◆ execute_entry

execute_entry_t execute_entry = 0

Definition at line 57 of file common.c.