dune: working test with emulated syscalls
authorRonald G. Minnich <rminnich@gmail.com>
Mon, 21 Nov 2016 22:09:46 +0000 (14:09 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sat, 1 Jul 2017 21:22:30 +0000 (17:22 -0400)
Dune is working with dune_test as a vm to test vmcall functionality

Change-Id: Iead546ccfb405519db525f4e5b81a1bb1e647517
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Signed-off-by: Zach Zimmerman <zpzim@google.com>
[minor formatting, removed redundant #defines for MiB and MinMemory]
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tests/dune/Makefrag
tests/dune/dune.c
user/iplib/include/iplib/iplib.h
user/vmm/include/vmm/linux_syscalls.h [new file with mode: 0644]
user/vmm/linuxemu.c [new file with mode: 0644]

index 3014ec3..5cce02c 100644 (file)
@@ -4,7 +4,7 @@ DUNE_TESTS_CFLAGS += $(CFLAGS_TESTS) -Wunused -Werror
 
 ALL_DUNE_TEST_FILES := $(wildcard $(DUNE_TESTS_DIR)/*.c)
 
-DUNE_TESTS_LDLIBS := $(TESTS_LDLIBS) -lelf
+DUNE_TESTS_LDLIBS := $(TESTS_LDLIBS) -lelf -liplib
 
 DUNE_TESTS_SRCS := $(ALL_DUNE_TEST_FILES)
 
index 379266c..e7470cc 100644 (file)
 #include <parlib/uthread.h>
 #include <vmm/linux_bootparam.h>
 #include <getopt.h>
-
+#include <iplib/iplib.h>
 #include <vmm/sched.h>
 #include <sys/eventfd.h>
 #include <sys/uio.h>
+#include <err.h>
 
-static struct virtual_machine local_vm, *vm = &local_vm;
 struct vmm_gpcore_init gpci;
-static void *ram;
+bool linuxemu(struct guest_thread *gth, struct vm_trapframe *tf);
+
+/* ah, elf. */
+struct elf_aux {
+       unsigned long v[2];
+};
+
+extern char **environ;
+
+static struct virtual_machine vm = {.halt_exit = true,};
+
 static unsigned long long memsize = GiB;
 static uintptr_t memstart = MinMemory;
-static uintptr_t stack;
-static unsigned long long *p512, *p1, *p2m;
 
-static int debug = 0;
+static int debug;
+
+static void hlt(void)
+{
+       __asm__ __volatile__("\thlt\n\t");
+}
+
+static int pc(uint16_t c)
+{
+       __asm__ __volatile__("movw $0, %%rax\nmovw %0, %%di\n\tvmcall\n" ::
+                            "m"(c) : "rdi", "rax");
+       return 0;
+}
+
+static void xnum(uint64_t x)
+{
+       static char *hex = "0123456789abcdef";
+
+       for (int i = 0; i < 8; i++) {
+               uint8_t v = ((uint8_t*)&x)[7 - i];
+
+               pc(hex[v >> 4]);
+               pc(hex[v & 0xf]);
+       }
+}
+
+static void show(char *s)
+{
+       static char *showedoff = "NULL POINTER: That's bad.\n";
+
+       if (!s) {
+               show(showedoff);
+               return;
+       }
+       while (*s) {
+       //      xnum((uint64_t)s);pc(';');
+               pc(*s);
+               s++;
+       }
+}
+
+/* This is a small test that runs in gr0 and tests our argument setup.
+ * This test can grow in capability as we find more broken bits in our
+ * dune-like environment. */
+void dune_test(void *stack)
+{
+       int argc;
+       char **argv;
+       struct elf_aux *auxv;
+
+       show("dune_test: dumping argv, env, and aux\n");
+
+       argc = *((uint64_t*)stack);
+       argv = &((char**)stack)[1];
+       show("argc: "); xnum(argc); show("\n");
+       show("argv: "); xnum((uint64_t)argv); show("\n");
+
+       for (int i = 0; i < argc; i++, argv++) {
+               show("arg["); xnum(i); show("]:");
+               show(argv[0]);
+               show("\n");
+       }
+       // skip the null and move on to envp.
+       argv++;
+       for (int i = 0; argv[0]; i++, argv++) {
+               show("env["); xnum(i); show("]:");
+               show(argv[0]);
+               show("\n");
+       }
+       // skip the null and move on to auxv.
+       argv++;
+       auxv = (void *)argv;
+       for (int i = 0; auxv[i].v[0]; i++) {
+               show("auxv["); xnum(i); show("]:");
+               xnum(auxv[i].v[0]); show(":");
+               xnum(auxv[i].v[1]); show("\n");
+       }
+       show("Done dumping [argv, env, auxv]\n");
+       __asm__ __volatile__("movl $0xdeadbeef, %eax\nmovq $1, %rdi\nmov $2,"
+                            "%rsi\nmovq $3, %rdx\n"
+                            "movq $4,%rcx\nmovq $5, %r8\nmovq $6,%r9\nvmcall\n");
+       hlt();
+}
+
+/* populate_stack fills the stack with an argv, envp, and auxv.
+ * We assume the stack pointer is backed by real memory.
+ * It will go hard with you if it does not. For your own health,
+ * stack should be 16-byte aligned. */
+void *populate_stack(uintptr_t *stack, int argc, char *argv[],
+                         int envc, char *envp[],
+                         int auxc, struct elf_aux auxv[])
+{
+       /* Function to get the lengths of the argument and environment strings. */
+       int get_lens(int argc, char *argv[], int arg_lens[])
+       {
+               int total = 0;
+
+               if (!argc)
+                       return 0;
+               for (int i = 0; i < argc; i++) {
+                       arg_lens[i] = strlen(argv[i]) + 1;
+                       total += arg_lens[i];
+               }
+               return total;
+       }
+
+       /* Function to help map the argument and environment strings, to their
+        * final location. */
+       int remap(int argc, char *argv[], char *new_argv[],
+              char new_argbuf[], int arg_lens[])
+       {
+               int offset = 0;
+
+               if (!argc)
+                       return 0;
+               for (int i = 0; i < argc; i++) {
+                       memcpy(new_argbuf + offset, argv[i], arg_lens[i]);
+                       if (debug) {
+                               fprintf(stderr, "data: memcpy(%p, %p, %ld)\n",
+                                       new_argbuf + offset, argv[i], arg_lens[i]);
+                               fprintf(stderr, "arg: set arg %d, @%p, to %p\n", i,
+                                       &new_argv[i], new_argbuf + offset);
+                       }
+                       new_argv[i] = new_argbuf + offset;
+                       offset += arg_lens[i];
+               }
+               new_argv[argc] = NULL;
+               return offset;
+       }
+
+       /* Start tracking the size of the buffer necessary to hold all of our data
+        * on the stack. Preallocate space for argc, argv, envp, and auxv in this
+        * buffer. */
+       int bufsize = 0;
+
+       bufsize += 1 * sizeof(size_t);
+       bufsize += (auxc + 1) * sizeof(struct elf_aux);
+       bufsize += (envc + 1) * sizeof(char**);
+       bufsize += (argc + 1) * sizeof(char**);
+       if (debug)
+               fprintf(stderr, "Bufsize for pointers and argc is %d\n", bufsize);
+
+       /* Add in the size of the env and arg strings. */
+       int arg_lens[argc];
+       int env_lens[envc];
+
+       bufsize += get_lens(argc, argv, arg_lens);
+       bufsize += get_lens(envc, envp, env_lens);
+       if (debug)
+               fprintf(stderr, "Bufsize for pointers, argc, and strings is %d\n",
+                       bufsize);
+
+       /* Adjust bufsize so that our buffer will ultimately be 16 byte aligned. */
+       bufsize = (bufsize + 15) & ~0xf;
+       if (debug)
+               fprintf(stderr,
+                       "Bufsize for pointers, argc, and strings is rounded is %d\n",
+                       bufsize);
+
+       /* Set up pointers to all of the appropriate data regions we map to. */
+       size_t *new_argc = (size_t*)((uint8_t*)stack - bufsize);
+       char **new_argv = (char**)(new_argc + 1);
+       char **new_envp = new_argv + argc + 1;
+       struct elf_aux *new_auxv = (struct elf_aux*)(new_envp + envc + 1);
+       char *new_argbuf = (char*)(new_auxv + auxc + 1);
+
+       if (debug) {
+               fprintf(stderr, "There are %d args, %d env, and %d aux\n", new_argc,
+                       envc, auxc);
+               fprintf(stderr, "Locations: argc: %p, argv: %p, envp: %p, auxv: %p\n",
+                               new_argc, new_argv, new_envp, new_auxv);
+               fprintf(stderr, "Locations: argbuf: %p, ", new_argbuf);
+               fprintf(stderr, "Sizeof argc is %d\n", sizeof(size_t));
+       }
+       /* Map argc into its final location. */
+       *new_argc = argc;
+
+       /* Map all data for argv and envp into its final location. */
+       int offset = 0;
+
+       offset = remap(argc, argv, new_argv, new_argbuf, arg_lens);
+       if (offset == -1)
+               return 0;
+       if (debug) {
+               fprintf(stderr, "Locations: argbuf: %p, envbuf: %p, ", new_argbuf,
+                       new_argbuf + offset);
+
+       }
+       offset = remap(envc, envp, new_envp, new_argbuf + offset, env_lens);
+       if (offset == -1)
+               return 0;
+
+       /* Map auxv into its final location. */
+       struct elf_aux null_aux = {0, 0};
+
+       memcpy(new_auxv, auxv, auxc * sizeof(struct elf_aux));
+       memcpy(new_auxv + auxc, &null_aux, sizeof(struct elf_aux));
+       if (debug) {
+               fprintf(stderr, "auxbuf: %p\n", new_auxv);
+               hexdump(stdout, new_auxv, auxc * sizeof(struct elf_aux));
+       }
+       return (uint8_t*)stack - bufsize;
+}
+
+static struct option long_options[] = {
+       {"aux",           required_argument, 0, 'a'},
+       {"debug",         no_argument,       0, 'd'},
+       {"vmmflags",      required_argument, 0, 'v'},
+       {"memsize",       required_argument, 0, 'm'},
+       {"memstart",      required_argument, 0, 'M'},
+       {"cmdline_extra", required_argument, 0, 'c'},
+       {"greedy",        no_argument,       0, 'g'},
+       {"scp",           no_argument,       0, 's'},
+       {"test",          no_argument,       0, 't'},
+       {"help",          no_argument,       0, 'h'},
+       {0, 0, 0, 0}
+};
+
+static void
+usage(void)
+{
+       // Sadly, the getopt_long struct does
+       // not have a pointer to help text.
+       fprintf(stderr,
+             "Usage: dune [options] <ELF file] [<ELF file>...]\n");
+       fprintf(stderr,
+             "Or for testing: dune -t [options]\nOptions are:\n");
+       for (int i = 0;
+            i < COUNT_OF(long_options) - 1;
+            i++) {
+               struct option *l = &long_options[i];
+
+               fprintf(stderr, "%s or %c%s\n", l->name, l->val,
+                       l->has_arg ? " <arg>" : "");
+       }
+       exit(0);
+}
+
+static struct elf_aux *
+getextra(int *auxc, char *_s)
+{
+       struct elf_aux *auxv;
+       char *s = strdup(_s);
+       // icky hardcode, but realistic.
+       char *auxpairs[32];
+
+       *auxc = gettokens(s, auxpairs, 32, ",");
+       if (debug)
+               fprintf(stderr, "Found %d extra aux pairs\n", *auxc);
+       if (*auxc < 1)
+               return NULL;
+       auxv = malloc(sizeof(*auxv) * *auxc);
+       if (!auxv)
+               errx(1, "auxv malloc: %r");
+       for (int i = 0; i < *auxc; i++) {
+               char *aux[2];
+               int j;
+               uint32_t t, v;
+
+               j = gettokens(auxpairs[i], aux, 2, "=");
+               if (j < 2) {
+                       fprintf(stderr, "%s: should be in the form type=val\n",
+                               auxpairs[i]);
+                       free(auxv);
+                       return NULL;
+               }
+               t = strtoul(aux[0], 0, 0);
+               v = strtoul(aux[1], 0, 0);
+               auxv[i].v[0] = t;
+               auxv[i].v[1] = v;
+               if (debug)
+                       fprintf(stderr, "Adding aux pair 0x%x:0x%x\n", auxv[i].v[0],
+                               auxv[i].v[1]);
+       }
+       return auxv;
+
+}
+
+static struct elf_aux *
+buildaux(struct elf_aux *base, int basec, struct elf_aux *extra, int extrac)
+{
+       int total = basec + extrac;
+       struct elf_aux *ret;
+
+       ret = realloc(extra, total * sizeof(*ret));
+       if (!ret)
+               return NULL;
+
+       if (debug)
+               fprintf(stderr, "buildaux: consolidating %d aux and %d extra\n",
+                       basec, extrac);
+       /* TOOD: check for dups. */
+       if (basec)
+               memmove(&ret[extrac], base, sizeof(*base)*basec);
+       return ret;
+}
+
+static bool
+testvmcall(struct guest_thread *gth, struct vm_trapframe *tf)
+{
+       uintptr_t rax = tf->tf_rax;
+
+       switch (rax) {
+       default:
+               fprintf(stderr, "testvmcall: gth %p tf %p\n", gth, tf);
+               fprintf(stderr, "args should be 1, 2, 3, 4, 5, 6:\n");
+               fprintf(stderr, "%p %p %p %p %p %p\n",
+                       tf->tf_rdi, tf->tf_rsi, tf->tf_rdx,
+                       tf->tf_rcx, tf->tf_r8, tf->tf_r9);
+               fprintf(stderr, "RAX should be deadbeef: 0x%x\n", rax);
+               break;
+       case 0:
+               write(1, &tf->tf_rdi, 1);
+               break;
+       }
+       tf->tf_rip += 3;
+       return true;
+}
 
 int main(int argc, char **argv)
 {
-       int vmmflags = VMM_VMCALL_PRINTF;
+       void *tos;
+       int envc, auxc, extrac = 0;
+       struct elf_aux *auxv, *extra = NULL;
+       int vmmflags = 0;
        uint64_t entry = 0;
        int ret;
        struct vm_trapframe *vm_tf;
        int c;
+       int test = 0;
        int option_index;
-       static struct option long_options[] = {
-               {"debug",         no_argument,       0, 'd'},
-               {"vmmflags",      required_argument, 0, 'v'},
-               {"memsize",       required_argument, 0, 'm'},
-               {"memstart",      required_argument, 0, 'M'},
-               {"stack",         required_argument, 0, 'S'},
-               {"cmdline_extra", required_argument, 0, 'c'},
-               {"greedy",        no_argument,       0, 'g'},
-               {"scp",           no_argument,       0, 's'},
-               {"help",          no_argument,       0, 'h'},
-               {0, 0, 0, 0}
-       };
+       int ac = argc;
+       char **av = argv;
 
        fprintf(stderr, "%p %p %p %p\n", PGSIZE, PGSHIFT, PML1_SHIFT,
-                       PML1_PTE_REACH);
+               PML1_PTE_REACH);
 
        if ((uintptr_t)__procinfo.program_end >= MinMemory) {
                fprintf(stderr,
@@ -68,50 +387,46 @@ int main(int argc, char **argv)
                exit(1);
        }
 
-       while ((c = getopt_long(argc, argv, "dv:m:M:S:gsh", long_options,
+       while ((c = getopt_long(argc, argv, "a:dv:m:M:gsth", long_options,
                                &option_index)) != -1) {
                switch (c) {
-                       case 'd':
-                               debug++;
-                               break;
-                       case 'v':
-                               vmmflags = strtoull(optarg, 0, 0);
-                               break;
-                       case 'm':
-                               memsize = strtoull(optarg, 0, 0);
-                               break;
-                       case 'M':
-                               memstart = strtoull(optarg, 0, 0);
-                               break;
-                       case 'S':
-                               stack = strtoull(optarg, 0, 0);
-                               break;
-                       case 'g':       /* greedy */
-                               parlib_never_yield = TRUE;
-                               break;
-                       case 's':       /* scp */
-                               parlib_wants_to_be_mcp = FALSE;
-                               break;
-                       case 'h':
-                       default:
-                               // Sadly, the getopt_long struct does
-                               // not have a pointer to help text.
-                               for (int i = 0;
-                                   i < sizeof(long_options)/sizeof(long_options[0]) - 1;
-                                   i++) {
-                                       struct option *l = &long_options[i];
-
-                                       fprintf(stderr, "%s or %c%s\n", l->name, l->val,
-                                               l->has_arg ? " <arg>" : "");
-                               }
-                               exit(0);
+               case 'a':
+                       extra = getextra(&extrac, optarg);
+                       if (debug)
+                               fprintf(stderr, "Added %d aux items\n", extrac);
+                       break;
+               case 'd':
+                       fprintf(stderr, "SET DEBUG\n");
+                       debug++;
+                       break;
+               case 'v':
+                       vmmflags = strtoull(optarg, 0, 0);
+                       break;
+               case 'm':
+                       memsize = strtoull(optarg, 0, 0);
+                       break;
+               case 'M':
+                       memstart = strtoull(optarg, 0, 0);
+                       break;
+               case 'g':       /* greedy */
+                       parlib_never_yield = TRUE;
+                       break;
+               case 's':       /* scp */
+                       parlib_wants_to_be_mcp = FALSE;
+                       break;
+               case 't':
+                       test = 1;
+                       break;
+               case 'h':
+               default:
+                       usage();
+                       break;
                }
        }
        argc -= optind;
        argv += optind;
-       if (argc < 1) {
-               fprintf(stderr, "Usage: %s vmimage [-n (no vmcall printf)]\n", argv[0]);
-               exit(1);
+       if ((!test) && (argc < 1)) {
+               usage();
        }
 
        if ((uintptr_t)(memstart + memsize) >= (uintptr_t)BRK_START) {
@@ -121,77 +436,60 @@ int main(int argc, char **argv)
                exit(1);
        }
 
-       ram = mmap((void *)memstart, memsize,
-                  PROT_READ | PROT_WRITE | PROT_EXEC,
-                  MAP_POPULATE | MAP_ANONYMOUS, -1, 0);
-       if (ram != (void *)memstart) {
-               fprintf(stderr, "Could not mmap 0x%lx bytes at 0x%lx\n",
-                       memsize, memstart);
-               exit(1);
-       }
+       mmap_memory(memstart, memsize);
+
+       if (debug)
+               fprintf(stderr, "mmap guest physical memory at %p for 0x%lx bytes\n",
+                       memstart, memsize);
 
-       entry = load_elf(argv[0]);
-       if (entry == 0) {
-               fprintf(stderr, "Unable to load kernel %s\n", argv[0]);
+       // TODO: find out why we can't use memstart + memsize as TOS.
+       tos = (void *)(memstart + 0x800000);
+
+       for (envc = 0; environ[envc]; envc++)
+               ;
+       auxv = (struct elf_aux *)&environ[envc+1];
+       for (auxc = 0; auxv[auxc].v[0]; auxc++)
+               ;
+       auxv = buildaux(auxv, auxc, extra, extrac);
+       if (!auxv) {
+               fprintf(stderr, "Can't build auxv: %r");
                exit(1);
        }
+       auxc = auxc + extrac;
 
-       vm->nr_gpcs = 1;
-       vm->gpcis = &gpci;
-       ret = vmm_init(vm, vmmflags);
-       if (ret) {
-               fprintf(stderr, "vmm_init failed: %r\n");
-               exit(1);
+       if (!test) {
+               entry = load_elf(argv[0]);
+               if (entry == 0) {
+                       fprintf(stderr, "Unable to load kernel %s\n", argv[0]);
+                       exit(1);
+               }
+       } else {
+               fprintf(stderr, "Running dune test\n");
+               entry = (uintptr_t) dune_test;
        }
+       if (debug)
+               fprintf(stderr, "Test: Populate stack at %p\n", tos);
+       tos = populate_stack(tos, ac, av, envc, environ, auxc, auxv);
+       if (debug)
+               fprintf(stderr, "populated stack at %p; argc %d, envc %d, auxc %d\n",
+                       tos, ac, envc, auxc);
 
-       /* Allocate 3 pages for page table pages: a page of 512 GiB
-        * PTEs with only one entry filled to point to a page of 1 GiB
-        * PTEs; a page of 1 GiB PTEs with only one entry filled to
-        * point to a page of 2 MiB PTEs; and a page of 2 MiB PTEs,
-        * all of which may be filled. For now, we don't handle
-        * starting addresses not aligned on 512 GiB boundaries or
-        * sizes > GiB */
-       ret = posix_memalign((void **)&p512, PGSIZE, 3 * PGSIZE);
+       ret = vthread_attr_init(&vm, vmmflags);
        if (ret) {
-               perror("ptp alloc");
+               fprintf(stderr, "vmm_init failed: %r\n");
                exit(1);
        }
 
-       /* Set up a 1:1 ("identity") page mapping from guest virtual
-        * to guest physical using the (host virtual)
-        * `kerneladdress`. This mapping may be used for only a short
-        * time, until the guest sets up its own page tables. Be aware
-        * that the values stored in the table are physical addresses.
-        * This is subtle and mistakes are easily disguised due to the
-        * identity mapping, so take care when manipulating these
-        * mappings. */
-       p1 = &p512[NPTENTRIES];
-       p2m = &p512[2 * NPTENTRIES];
-
-       fprintf(stderr, "Map %p for %zu bytes\n", memstart, memsize);
-       /* TODO: fix this nested loop so it's correct for more than
-        * one GiB. */
-       for(uintptr_t p4 = memstart; p4 < memstart + memsize;
-           p4 += PML4_PTE_REACH) {
-               p512[PML4(p4)] = (uint64_t)p1 | PTE_KERN_RW;
-               for (uintptr_t p3 = p4; p3 < memstart + memsize;
-                    p3 += PML3_PTE_REACH) {
-                       p1[PML3(p3)] = (uint64_t)p2m | PTE_KERN_RW;
-                       for (uintptr_t p2 = p3; p2 < memstart + memsize; p2 += PML2_PTE_REACH) {
-                               p2m[PML2(p2)] =
-                                       (uint64_t)(p2) | PTE_KERN_RW | PTE_PS;
-                       }
-               }
-       }
+       vm.gths[0]->vmcall = test ? testvmcall : linuxemu;
+       vm_tf = gth_to_vmtf(vm.gths[0]);
 
-       fprintf(stderr, "p512 %p p512[0] is 0x%lx p1 %p p1[0] is 0x%x\n", p512, p512[0], p1, p1[0]);
+       /* we can't use the default stack since we set one up
+        * ourselves. */
+       vm_tf->tf_rsp = (uint64_t)tos;
+       if (debug)
+               fprintf(stderr, "stack is %p\n", tos);
 
-       vm_tf = gth_to_vmtf(vm->gths[0]);
-       vm_tf->tf_cr3 = (uint64_t) p512;
-       vm_tf->tf_rip = entry;
-       vm_tf->tf_rsp = stack;
-       vm_tf->tf_rsi = (uint64_t) 0;
-       start_guest_thread(vm->gths[0]);
+       vthread_create(&vm, 0, (void *)entry, tos);
 
        uthread_sleep_forever();
        return 0;
index 6af6815..3d28dba 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -12,7 +12,7 @@
 
 __BEGIN_DECLS
 
-enum 
+enum
 {
        ETH_HDR_LEN                     = 14,
        ETH_OFF_DST                     = 0,
@@ -111,7 +111,7 @@ struct ipv6rp
        int     reachtime;
        int     rxmitra;
        int     ttl;
-       int     routerlt;       
+       int     routerlt;
 };
 
 /* actual interface */
@@ -224,7 +224,7 @@ struct icmp6hdr {
 /*
  *  user level udp headers with control message "headers"
  */
-enum 
+enum
 {
        Udphdrsize=     52,     /* size of a Udphdr */
 };
@@ -295,5 +295,6 @@ int accept9(int ctl, char *dir);
 int reject9(int ctl, char *dir, char *cause);
 int open_data_fd9(char *conv_dir, int flags);
 bool get_port9(char *conv_dir, char *which, uint16_t *port);
+int gettokens(char *s, char **args, int maxargs, char *sep);
 
 __END_DECLS
diff --git a/user/vmm/include/vmm/linux_syscalls.h b/user/vmm/include/vmm/linux_syscalls.h
new file mode 100644 (file)
index 0000000..045c756
--- /dev/null
@@ -0,0 +1,629 @@
+char *syscalls[] = {
+[0]    "DUNE_SYS_READ",
+[1]    "DUNE_SYS_WRITE",
+[2]    "DUNE_SYS_OPEN",
+[3]    "DUNE_SYS_CLOSE",
+[4]    "DUNE_SYS_STAT",
+[5]    "DUNE_SYS_FSTAT",
+[6]    "DUNE_SYS_LSTAT",
+[7]    "DUNE_SYS_POLL",
+[8]    "DUNE_SYS_LSEEK",
+[9]    "DUNE_SYS_MMAP",
+[10]   "DUNE_SYS_MPROTECT",
+[11]   "DUNE_SYS_MUNMAP",
+[12]   "DUNE_SYS_BRK",
+[13]   "DUNE_SYS_RT_SIGACTION",
+[14]   "DUNE_SYS_RT_SIGPROCMASK",
+[15]   "DUNE_SYS_RT_SIGRETURN",
+[16]   "DUNE_SYS_IOCTL",
+[17]   "DUNE_SYS_PREAD64",
+[18]   "DUNE_SYS_PWRITE64",
+[19]   "DUNE_SYS_READV",
+[20]   "DUNE_SYS_WRITEV",
+[21]   "DUNE_SYS_ACCESS",
+[22]   "DUNE_SYS_PIPE",
+[23]   "DUNE_SYS_SELECT",
+[24]   "DUNE_SYS_SCHED_YIELD",
+[25]   "DUNE_SYS_MREMAP",
+[26]   "DUNE_SYS_MSYNC",
+[27]   "DUNE_SYS_MINCORE",
+[28]   "DUNE_SYS_MADVISE",
+[29]   "DUNE_SYS_SHMGET",
+[30]   "DUNE_SYS_SHMAT",
+[31]   "DUNE_SYS_SHMCTL",
+[32]   "DUNE_SYS_DUP",
+[33]   "DUNE_SYS_DUP2",
+[34]   "DUNE_SYS_PAUSE",
+[35]   "DUNE_SYS_NANOSLEEP",
+[36]   "DUNE_SYS_GETITIMER",
+[37]   "DUNE_SYS_ALARM",
+[38]   "DUNE_SYS_SETITIMER",
+[39]   "DUNE_SYS_GETPID",
+[40]   "DUNE_SYS_SENDFILE",
+[41]   "DUNE_SYS_SOCKET",
+[42]   "DUNE_SYS_CONNECT",
+[43]   "DUNE_SYS_ACCEPT",
+[44]   "DUNE_SYS_SENDTO",
+[45]   "DUNE_SYS_RECVFROM",
+[46]   "DUNE_SYS_SENDMSG",
+[47]   "DUNE_SYS_RECVMSG",
+[48]   "DUNE_SYS_SHUTDOWN",
+[49]   "DUNE_SYS_BIND",
+[50]   "DUNE_SYS_LISTEN",
+[51]   "DUNE_SYS_GETSOCKNAME",
+[52]   "DUNE_SYS_GETPEERNAME",
+[53]   "DUNE_SYS_SOCKETPAIR",
+[54]   "DUNE_SYS_SETSOCKOPT",
+[55]   "DUNE_SYS_GETSOCKOPT",
+[56]   "DUNE_SYS_CLONE",
+[57]   "DUNE_SYS_FORK",
+[58]   "DUNE_SYS_VFORK",
+[59]   "DUNE_SYS_EXECVE",
+[60]   "DUNE_SYS_EXIT",
+[61]   "DUNE_SYS_WAIT4",
+[62]   "DUNE_SYS_KILL",
+[63]   "DUNE_SYS_UNAME",
+[64]   "DUNE_SYS_SEMGET",
+[65]   "DUNE_SYS_SEMOP",
+[66]   "DUNE_SYS_SEMCTL",
+[67]   "DUNE_SYS_SHMDT",
+[68]   "DUNE_SYS_MSGGET",
+[69]   "DUNE_SYS_MSGSND",
+[70]   "DUNE_SYS_MSGRCV",
+[71]   "DUNE_SYS_MSGCTL",
+[72]   "DUNE_SYS_FCNTL",
+[73]   "DUNE_SYS_FLOCK",
+[74]   "DUNE_SYS_FSYNC",
+[75]   "DUNE_SYS_FDATASYNC",
+[76]   "DUNE_SYS_TRUNCATE",
+[77]   "DUNE_SYS_FTRUNCATE",
+[78]   "DUNE_SYS_GETDENTS",
+[79]   "DUNE_SYS_GETCWD",
+[80]   "DUNE_SYS_CHDIR",
+[81]   "DUNE_SYS_FCHDIR",
+[82]   "DUNE_SYS_RENAME",
+[83]   "DUNE_SYS_MKDIR",
+[84]   "DUNE_SYS_RMDIR",
+[85]   "DUNE_SYS_CREAT",
+[86]   "DUNE_SYS_LINK",
+[87]   "DUNE_SYS_UNLINK",
+[88]   "DUNE_SYS_SYMLINK",
+[89]   "DUNE_SYS_READLINK",
+[90]   "DUNE_SYS_CHMOD",
+[91]   "DUNE_SYS_FCHMOD",
+[92]   "DUNE_SYS_CHOWN",
+[93]   "DUNE_SYS_FCHOWN",
+[94]   "DUNE_SYS_LCHOWN",
+[95]   "DUNE_SYS_UMASK",
+[96]   "DUNE_SYS_GETTIMEOFDAY",
+[97]   "DUNE_SYS_GETRLIMIT",
+[98]   "DUNE_SYS_GETRUSAGE",
+[99]   "DUNE_SYS_SYSINFO",
+[100]  "DUNE_SYS_TIMES",
+[101]  "DUNE_SYS_PTRACE",
+[102]  "DUNE_SYS_GETUID",
+[103]  "DUNE_SYS_SYSLOG",
+[104]  "DUNE_SYS_GETGID",
+[105]  "DUNE_SYS_SETUID",
+[106]  "DUNE_SYS_SETGID",
+[107]  "DUNE_SYS_GETEUID",
+[108]  "DUNE_SYS_GETEGID",
+[109]  "DUNE_SYS_SETPGID",
+[110]  "DUNE_SYS_GETPPID",
+[111]  "DUNE_SYS_GETPGRP",
+[112]  "DUNE_SYS_SETSID",
+[113]  "DUNE_SYS_SETREUID",
+[114]  "DUNE_SYS_SETREGID",
+[115]  "DUNE_SYS_GETGROUPS",
+[116]  "DUNE_SYS_SETGROUPS",
+[117]  "DUNE_SYS_SETRESUID",
+[118]  "DUNE_SYS_GETRESUID",
+[119]  "DUNE_SYS_SETRESGID",
+[120]  "DUNE_SYS_GETRESGID",
+[121]  "DUNE_SYS_GETPGID",
+[122]  "DUNE_SYS_SETFSUID",
+[123]  "DUNE_SYS_SETFSGID",
+[124]  "DUNE_SYS_GETSID",
+[125]  "DUNE_SYS_CAPGET",
+[126]  "DUNE_SYS_CAPSET",
+[127]  "DUNE_SYS_RT_SIGPENDING",
+[128]  "DUNE_SYS_RT_SIGTIMEDWAIT",
+[129]  "DUNE_SYS_RT_SIGQUEUEINFO",
+[130]  "DUNE_SYS_RT_SIGSUSPEND",
+[131]  "DUNE_SYS_SIGALTSTACK",
+[132]  "DUNE_SYS_UTIME",
+[133]  "DUNE_SYS_MKNOD",
+[134]  "DUNE_SYS_USELIB",
+[135]  "DUNE_SYS_PERSONALITY",
+[136]  "DUNE_SYS_USTAT",
+[137]  "DUNE_SYS_STATFS",
+[138]  "DUNE_SYS_FSTATFS",
+[139]  "DUNE_SYS_SYSFS",
+[140]  "DUNE_SYS_GETPRIORITY",
+[141]  "DUNE_SYS_SETPRIORITY",
+[142]  "DUNE_SYS_SCHED_SETPARAM",
+[143]  "DUNE_SYS_SCHED_GETPARAM",
+[144]  "DUNE_SYS_SCHED_SETSCHEDULER",
+[145]  "DUNE_SYS_SCHED_GETSCHEDULER",
+[146]  "DUNE_SYS_SCHED_GET_PRIORITY_MAX",
+[147]  "DUNE_SYS_SCHED_GET_PRIORITY_MIN",
+[148]  "DUNE_SYS_SCHED_RR_GET_INTERVAL",
+[149]  "DUNE_SYS_MLOCK",
+[150]  "DUNE_SYS_MUNLOCK",
+[151]  "DUNE_SYS_MLOCKALL",
+[152]  "DUNE_SYS_MUNLOCKALL",
+[153]  "DUNE_SYS_VHANGUP",
+[154]  "DUNE_SYS_MODIFY_LDT",
+[155]  "DUNE_SYS_PIVOT_ROOT",
+[156]  "DUNE_SYS__SYSCTL",
+[157]  "DUNE_SYS_PRCTL",
+[158]  "DUNE_SYS_ARCH_PRCTL",
+[159]  "DUNE_SYS_ADJTIMEX",
+[160]  "DUNE_SYS_SETRLIMIT",
+[161]  "DUNE_SYS_CHROOT",
+[162]  "DUNE_SYS_SYNC",
+[163]  "DUNE_SYS_ACCT",
+[164]  "DUNE_SYS_SETTIMEOFDAY",
+[165]  "DUNE_SYS_MOUNT",
+[166]  "DUNE_SYS_UMOUNT2",
+[167]  "DUNE_SYS_SWAPON",
+[168]  "DUNE_SYS_SWAPOFF",
+[169]  "DUNE_SYS_REBOOT",
+[170]  "DUNE_SYS_SETHOSTNAME",
+[171]  "DUNE_SYS_SETDOMAINNAME",
+[172]  "DUNE_SYS_IOPL",
+[173]  "DUNE_SYS_IOPERM",
+[174]  "DUNE_SYS_CREATE_MODULE",
+[175]  "DUNE_SYS_INIT_MODULE",
+[176]  "DUNE_SYS_DELETE_MODULE",
+[177]  "DUNE_SYS_GET_KERNEL_SYMS",
+[178]  "DUNE_SYS_QUERY_MODULE",
+[179]  "DUNE_SYS_QUOTACTL",
+[180]  "DUNE_SYS_NFSSERVCTL",
+[181]  "DUNE_SYS_GETPMSG",
+[182]  "DUNE_SYS_PUTPMSG",
+[183]  "DUNE_SYS_AFS_SYSCALL",
+[184]  "DUNE_SYS_TUXCALL",
+[185]  "DUNE_SYS_SECURITY",
+[186]  "DUNE_SYS_GETTID",
+[187]  "DUNE_SYS_READAHEAD",
+[188]  "DUNE_SYS_SETXATTR",
+[189]  "DUNE_SYS_LSETXATTR",
+[190]  "DUNE_SYS_FSETXATTR",
+[191]  "DUNE_SYS_GETXATTR",
+[192]  "DUNE_SYS_LGETXATTR",
+[193]  "DUNE_SYS_FGETXATTR",
+[194]  "DUNE_SYS_LISTXATTR",
+[195]  "DUNE_SYS_LLISTXATTR",
+[196]  "DUNE_SYS_FLISTXATTR",
+[197]  "DUNE_SYS_REMOVEXATTR",
+[198]  "DUNE_SYS_LREMOVEXATTR",
+[199]  "DUNE_SYS_FREMOVEXATTR",
+[200]  "DUNE_SYS_TKILL",
+[201]  "DUNE_SYS_TIME",
+[202]  "DUNE_SYS_FUTEX",
+[203]  "DUNE_SYS_SCHED_SETAFFINITY",
+[204]  "DUNE_SYS_SCHED_GETAFFINITY",
+[205]  "DUNE_SYS_SET_THREAD_AREA",
+[206]  "DUNE_SYS_IO_SETUP",
+[207]  "DUNE_SYS_IO_DESTROY",
+[208]  "DUNE_SYS_IO_GETEVENTS",
+[209]  "DUNE_SYS_IO_SUBMIT",
+[210]  "DUNE_SYS_IO_CANCEL",
+[211]  "DUNE_SYS_GET_THREAD_AREA",
+[212]  "DUNE_SYS_LOOKUP_DCOOKIE",
+[213]  "DUNE_SYS_EPOLL_CREATE",
+[214]  "DUNE_SYS_EPOLL_CTL_OLD",
+[215]  "DUNE_SYS_EPOLL_WAIT_OLD",
+[216]  "DUNE_SYS_REMAP_FILE_PAGES",
+[217]  "DUNE_SYS_GETDENTS64",
+[218]  "DUNE_SYS_SET_TID_ADDRESS",
+[219]  "DUNE_SYS_RESTART_SYSCALL",
+[220]  "DUNE_SYS_SEMTIMEDOP",
+[221]  "DUNE_SYS_FADVISE64",
+[222]  "DUNE_SYS_TIMER_CREATE",
+[223]  "DUNE_SYS_TIMER_SETTIME",
+[224]  "DUNE_SYS_TIMER_GETTIME",
+[225]  "DUNE_SYS_TIMER_GETOVERRUN",
+[226]  "DUNE_SYS_TIMER_DELETE",
+[227]  "DUNE_SYS_CLOCK_SETTIME",
+[228]  "DUNE_SYS_CLOCK_GETTIME",
+[229]  "DUNE_SYS_CLOCK_GETRES",
+[230]  "DUNE_SYS_CLOCK_NANOSLEEP",
+[231]  "DUNE_SYS_EXIT_GROUP",
+[232]  "DUNE_SYS_EPOLL_WAIT",
+[233]  "DUNE_SYS_EPOLL_CTL",
+[234]  "DUNE_SYS_TGKILL",
+[235]  "DUNE_SYS_UTIMES",
+[236]  "DUNE_SYS_VSERVER",
+[237]  "DUNE_SYS_MBIND",
+[238]  "DUNE_SYS_SET_MEMPOLICY",
+[239]  "DUNE_SYS_GET_MEMPOLICY",
+[240]  "DUNE_SYS_MQ_OPEN",
+[241]  "DUNE_SYS_MQ_UNLINK",
+[242]  "DUNE_SYS_MQ_TIMEDSEND",
+[243]  "DUNE_SYS_MQ_TIMEDRECEIVE",
+[244]  "DUNE_SYS_MQ_NOTIFY",
+[245]  "DUNE_SYS_MQ_GETSETATTR",
+[246]  "DUNE_SYS_KEXEC_LOAD",
+[247]  "DUNE_SYS_WAITID",
+[248]  "DUNE_SYS_ADD_KEY",
+[249]  "DUNE_SYS_REQUEST_KEY",
+[250]  "DUNE_SYS_KEYCTL",
+[251]  "DUNE_SYS_IOPRIO_SET",
+[252]  "DUNE_SYS_IOPRIO_GET",
+[253]  "DUNE_SYS_INOTIFY_INIT",
+[254]  "DUNE_SYS_INOTIFY_ADD_WATCH",
+[255]  "DUNE_SYS_INOTIFY_RM_WATCH",
+[256]  "DUNE_SYS_MIGRATE_PAGES",
+[257]  "DUNE_SYS_OPENAT",
+[258]  "DUNE_SYS_MKDIRAT",
+[259]  "DUNE_SYS_MKNODAT",
+[260]  "DUNE_SYS_FCHOWNAT",
+[261]  "DUNE_SYS_FUTIMESAT",
+[262]  "DUNE_SYS_NEWFSTATAT",
+[263]  "DUNE_SYS_UNLINKAT",
+[264]  "DUNE_SYS_RENAMEAT",
+[265]  "DUNE_SYS_LINKAT",
+[266]  "DUNE_SYS_SYMLINKAT",
+[267]  "DUNE_SYS_READLINKAT",
+[268]  "DUNE_SYS_FCHMODAT",
+[269]  "DUNE_SYS_FACCESSAT",
+[270]  "DUNE_SYS_PSELECT6",
+[271]  "DUNE_SYS_PPOLL",
+[272]  "DUNE_SYS_UNSHARE",
+[273]  "DUNE_SYS_SET_ROBUST_LIST",
+[274]  "DUNE_SYS_GET_ROBUST_LIST",
+[275]  "DUNE_SYS_SPLICE",
+[276]  "DUNE_SYS_TEE",
+[277]  "DUNE_SYS_SYNC_FILE_RANGE",
+[278]  "DUNE_SYS_VMSPLICE",
+[279]  "DUNE_SYS_MOVE_PAGES",
+[280]  "DUNE_SYS_UTIMENSAT",
+[281]  "DUNE_SYS_EPOLL_PWAIT",
+[282]  "DUNE_SYS_SIGNALFD",
+[283]  "DUNE_SYS_TIMERFD_CREATE",
+[284]  "DUNE_SYS_EVENTFD",
+[285]  "DUNE_SYS_FALLOCATE",
+[286]  "DUNE_SYS_TIMERFD_SETTIME",
+[287]  "DUNE_SYS_TIMERFD_GETTIME",
+[288]  "DUNE_SYS_ACCEPT4",
+[289]  "DUNE_SYS_SIGNALFD4",
+[290]  "DUNE_SYS_EVENTFD2",
+[291]  "DUNE_SYS_EPOLL_CREATE1",
+[292]  "DUNE_SYS_DUP3",
+[293]  "DUNE_SYS_PIPE2",
+[294]  "DUNE_SYS_INOTIFY_INIT1",
+[295]  "DUNE_SYS_PREADV",
+[296]  "DUNE_SYS_PWRITEV",
+[297]  "DUNE_SYS_RT_TGSIGQUEUEINFO",
+[298]  "DUNE_SYS_PERF_EVENT_OPEN",
+[299]  "DUNE_SYS_RECVMMSG",
+[300]  "DUNE_SYS_FANOTIFY_INIT",
+[301]  "DUNE_SYS_FANOTIFY_MARK",
+[302]  "DUNE_SYS_PRLIMIT64",
+[303]  "DUNE_SYS_NAME_TO_HANDLE_AT",
+[304]  "DUNE_SYS_OPEN_BY_HANDLE_AT",
+[305]  "DUNE_SYS_CLOCK_ADJTIME",
+[306]  "DUNE_SYS_SYNCFS",
+[307]  "DUNE_SYS_SENDMMSG",
+[308]  "DUNE_SYS_SETNS",
+[309]  "DUNE_SYS_GETCPU",
+[310]  "DUNE_SYS_PROCESS_VM_READV",
+[311]  "DUNE_SYS_PROCESS_VM_WRITEV",
+};
+
+enum syscall_names {
+DUNE_SYS_READ,
+DUNE_SYS_WRITE,
+DUNE_SYS_OPEN,
+DUNE_SYS_CLOSE,
+DUNE_SYS_STAT,
+DUNE_SYS_FSTAT,
+DUNE_SYS_LSTAT,
+DUNE_SYS_POLL,
+DUNE_SYS_LSEEK,
+DUNE_SYS_MMAP,
+DUNE_SYS_MPROTECT,
+DUNE_SYS_MUNMAP,
+DUNE_SYS_BRK,
+DUNE_SYS_RT_SIGACTION,
+DUNE_SYS_RT_SIGPROCMASK,
+DUNE_SYS_RT_SIGRETURN,
+DUNE_SYS_IOCTL,
+DUNE_SYS_PREAD64,
+DUNE_SYS_PWRITE64,
+DUNE_SYS_READV,
+DUNE_SYS_WRITEV,
+DUNE_SYS_ACCESS,
+DUNE_SYS_PIPE,
+DUNE_SYS_SELECT,
+DUNE_SYS_SCHED_YIELD,
+DUNE_SYS_MREMAP,
+DUNE_SYS_MSYNC,
+DUNE_SYS_MINCORE,
+DUNE_SYS_MADVISE,
+DUNE_SYS_SHMGET,
+DUNE_SYS_SHMAT,
+DUNE_SYS_SHMCTL,
+DUNE_SYS_DUP,
+DUNE_S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DUNE_SYS_RT_TGSIGQUEUEINFO,
+DUNE_SYS_PERF_EVENT_OPEN,
+DUNE_SYS_RECVMMSG,
+DUNE_SYS_FANOTIFY_INIT,
+DUNE_SYS_FANOTIFY_MARK,
+DUNE_SYS_PRLIMIT64,
+DUNE_SYS_NAME_TO_HANDLE_AT,
+DUNE_SYS_OPEN_BY_HANDLE_AT,
+DUNE_SYS_CLOCK_ADJTIME,
+DUNE_SYS_SYNCFS,
+DUNE_SYS_SENDMMSG,
+DUNE_SYS_SETNS,
+DUNE_SYS_GETCPU,
+DUNE_SYS_PROCESS_VM_READV,
+DUNE_SYS_PROCESS_VM_WRITEV,
+};
diff --git a/user/vmm/linuxemu.c b/user/vmm/linuxemu.c
new file mode 100644 (file)
index 0000000..a70bfcd
--- /dev/null
@@ -0,0 +1,58 @@
+/* Copyright (c) 2016 Google Inc.
+ * See LICENSE for details.
+ *
+ * Linux emulation for virtual machines. */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <vmm/vmm.h>
+#include <errno.h>
+#include <sys/syscall.h>
+#include <vmm/linux_syscalls.h>
+
+/* TODO: have an array which classifies syscall args
+ * and "special" system calls (ones with weird return
+ * values etc.). For some cases, we don't even do a system
+ * call, and in many cases we have to rearrange arguments
+ * since Linux and Akaros don't share signatures, so this
+ * gets tricky. */
+bool
+linuxemu(struct guest_thread *gth, struct vm_trapframe *tf)
+{
+       bool ret = false;
+
+       fprintf(stderr, "vmcall(%s(%d), %p, %p, %p, %p, %p, %p);\n",
+               tf->tf_rax < 311 ? syscalls[tf->tf_rax] : "",
+               tf->tf_rax, tf->tf_rdi, tf->tf_rsi, tf->tf_rdx,
+               tf->tf_rcx, tf->tf_r8, tf->tf_r9);
+
+       tf->tf_rip += 3;
+       /* we don't do tic/tou checking here yet. */
+       switch (tf->tf_rax) {
+       default:
+               /* TODO: just return the error to the guest once we are done
+                * debugging this. */
+               fprintf(stderr, "System call %d is not implemented\n", tf->tf_rax);
+               //tf->tf_rax = -ENOSYS;
+               break;
+       case DUNE_SYS_GETTIMEOFDAY:
+               tf->tf_rax = 0;
+               ret = true;
+               break;
+       case DUNE_SYS_GETTID:
+               tf->tf_rax = 1;
+               ret = true;
+               break;
+       case DUNE_SYS_WRITE:
+               /* debug: write to stdout too for now. */
+               write(2, (void *)tf->tf_rsi, (size_t)tf->tf_rdx);
+               tf->tf_rax = write(tf->tf_rdi, (void *)tf->tf_rsi, (size_t)tf->tf_rdx);
+               ret = true;
+               break;
+       }
+       return ret;
+}