X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fextensions%2Fext_syscall_hijack.c;h=0bd0b08b237092c33a1381409664f08603854cdd;hb=51e81a720ed4c05dba61e9475a310d88f4f32e40;hp=31445df7848af32b62e943c64b751e50f1c5ef3e;hpb=98c9bb5e5f3df156ec40abda7d765974a99c1e0e;p=palacios-OLD.git diff --git a/palacios/src/extensions/ext_syscall_hijack.c b/palacios/src/extensions/ext_syscall_hijack.c index 31445df..0bd0b08 100644 --- a/palacios/src/extensions/ext_syscall_hijack.c +++ b/palacios/src/extensions/ext_syscall_hijack.c @@ -24,13 +24,15 @@ #include #include #include -#include -#include -#include -#include +#include +#include + +#include +#include +#include "syscall_ref.h" -#ifndef CONFIG_DEBUG_SYSCALL_HIJACK +#ifndef V3_CONFIG_DEBUG_EXT_SYSCALL_HIJACK #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -40,6 +42,56 @@ #define max(a, b) ( ((a) > (b)) ? (a) : (b) ) #endif +#define SYSCALL_INT_VECTOR 0x80 + + +struct v3_syscall_hook { + int (*handler)(struct guest_info * core, uint_t syscall_nr, void * priv_data); + void * priv_data; +}; + +static struct v3_syscall_hook * syscall_hooks[512]; + + +static int v3_syscall_handler (struct guest_info * core, uint8_t vector, void * priv_data) { + + uint_t syscall_nr = (uint_t) core->vm_regs.rax; + int err = 0; + + struct v3_syscall_hook * hook = syscall_hooks[syscall_nr]; + if (hook == NULL) { +#ifdef V3_CONFIG_EXT_SYSCALL_PASSTHROUGH + if (v3_hook_passthrough_syscall(core, syscall_nr) == -1) { + PrintDebug("Error hooking passthrough syscall\n"); + return -1; + } + hook = syscall_hooks[syscall_nr]; +#else + return v3_raise_swintr(core, vector); +#endif + } + + err = hook->handler(core, syscall_nr, hook->priv_data); + if (err == -1) { + PrintDebug("V3 Syscall Handler: Error in syscall hook\n"); + return -1; + } + + return 0; +} + + +static int init_syscall_hijack (struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_data) { + + return 0; +} + + +static int init_syscall_hijack_core (struct guest_info * core, void * priv_data) { + + v3_hook_swintr(core, SYSCALL_INT_VECTOR, v3_syscall_handler, NULL); + return 0; +} static void print_arg (struct guest_info * core, v3_reg_t reg, uint8_t argnum) { @@ -85,36 +137,25 @@ static void print_syscall (uint8_t is64, struct guest_info * core) { } -int v3_syscall_handler (struct guest_info * core, uint8_t vector, void * priv_data) { - - uint_t syscall_nr = (uint_t) core->vm_regs.rax; - int err = 0; - struct v3_syscall_hook * hook = core->sc_hook_map.syscall_hooks[syscall_nr]; - if (hook == NULL) { -#ifdef CONFIG_SYSCALL_PASSTHROUGH - if (v3_hook_passthrough_syscall(core, syscall_nr) == -1) { - PrintDebug("Error hooking passthrough syscall\n"); - return -1; - } - hook = core->sc_hook_map.syscall_hooks[syscall_nr]; -#else - return v3_signal_swintr(core, vector); -#endif - } - - err = hook->handler(core, syscall_nr, hook->priv_data); - if (err == -1) { - PrintDebug("V3 Syscall Handler: Error in syscall hook\n"); - return -1; - } - return 0; -} +static struct v3_extension_impl syscall_impl = { + .name = "syscall_intercept", + .init = init_syscall_hijack, + .deinit = NULL, + .core_init = init_syscall_hijack_core, + .core_deinit = NULL, + .on_entry = NULL, + .on_exit = NULL +}; + +register_extension(&syscall_impl); + + static inline struct v3_syscall_hook * get_syscall_hook (struct guest_info * core, uint_t syscall_nr) { - return core->sc_hook_map.syscall_hooks[syscall_nr]; + return syscall_hooks[syscall_nr]; } @@ -138,7 +179,7 @@ int v3_hook_syscall (struct guest_info * core, hook->handler = handler; hook->priv_data = priv_data; - core->sc_hook_map.syscall_hooks[syscall_nr] = hook; + syscall_hooks[syscall_nr] = hook; return 0; } @@ -166,7 +207,7 @@ int v3_hook_passthrough_syscall (struct guest_info * core, uint_t syscall_nr) { return 0; } - +/* int v3_sysexecve_handler (struct guest_info * core, uint_t syscall_nr, void * priv_data) { addr_t hva, key; struct exec_hook * hook; @@ -189,3 +230,4 @@ int v3_sysexecve_handler (struct guest_info * core, uint_t syscall_nr, void * pr return 0; } +*/