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.


added extension for syscall interception
Kyle Hale [Thu, 23 Jun 2011 00:23:46 +0000 (19:23 -0500)]
palacios/include/interfaces/syscall_hijack.h [new file with mode: 0644]
palacios/src/extensions/ext_syscall_hijack.c

diff --git a/palacios/include/interfaces/syscall_hijack.h b/palacios/include/interfaces/syscall_hijack.h
new file mode 100644 (file)
index 0000000..389b8f0
--- /dev/null
@@ -0,0 +1,32 @@
+/* 
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National 
+ * Science Foundation and the Department of Energy.  
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico.  You can find out more at 
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2011, Kyle C. Hale <kh@u.northwestern.edu> 
+ * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Kyle C. Hale <kh@u.northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#ifndef __SYSCALL_HIJACK_H__
+#define __SYSCALL_HIJACK_H__
+
+
+int v3_hook_syscall (struct guest_info * core,
+    uint_t syscall_nr,
+    int (*handler)(struct guest_info * core, uint_t syscall_nr, void * priv_data), 
+    void * priv_data);
+
+int v3_hook_passthrough_syscall (struct guest_info * core, uint_t syscall_nr);
+
+
+#endif
index 31445df..59ea961 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 <interfaces/syscall_hijack.h>
+#include <interfaces/sw_intr.h>
 
-#ifndef CONFIG_DEBUG_SYSCALL_HIJACK
+#include "syscall_ref.h"
+
+#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_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 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 +136,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 +178,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 +206,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 +229,4 @@ int v3_sysexecve_handler (struct guest_info * core, uint_t syscall_nr, void * pr
     return 0;
 }
 
+*/