Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


bug fixes for VMX
[palacios.git] / palacios / src / extensions / ext_syscall_hijack.c
index 31445df..0bd0b08 100644 (file)
 #include <palacios/vmm_decoder.h>
 #include <palacios/vmm_string.h>
 #include <palacios/vmm_shadow_paging.h>
-#include <palacios/vmm_syscall_hijack.h>
-#include <palacios/vmm_linux_syscall_map.h>
-#include <palacios/vmm_process_environment.h>
-#include <palacios/vmm_execve_hook.h>
+#include <palacios/vmm_extensions.h>
+#include <palacios/vmm_intr.h>
+
+#include <interfaces/syscall_hijack.h>
+#include <interfaces/sw_intr.h>
 
+#include "syscall_ref.h"
 
-#ifndef CONFIG_DEBUG_SYSCALL_HIJACK
+#ifndef V3_CONFIG_DEBUG_EXT_SYSCALL_HIJACK
 #undef PrintDebug
 #define PrintDebug(fmt, args...)
 #endif
     #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;
 }
 
+*/