diff --git a/tools/uhyve-syscalls.h b/tools/uhyve-syscalls.h new file mode 100644 index 000000000..7b7998e03 --- /dev/null +++ b/tools/uhyve-syscalls.h @@ -0,0 +1,64 @@ +/* Copyright (c) 2017, RWTH Aachen University + * Author(s): Daniel Krebs + * + * Permission to use, copy, modify, and/or distribute this software + * for any purpose with or without fee is hereby granted, provided + * that the above copyright notice and this permission notice appear + * in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef UHYVE_SYSCALLS_H +#define UHYVE_SYSCALLS_H + +#include +#include + +typedef enum { + UHYVE_PORT_WRITE = 0x499, + UHYVE_PORT_OPEN = 0x500, + UHYVE_PORT_CLOSE = 0x501, + UHYVE_PORT_READ = 0x502, + UHYVE_PORT_EXIT = 0x503, + UHYVE_PORT_LSEEK = 0x504 +} uhyve_syscall_t; + +typedef struct { + int fd; + const char* buf; + size_t len; +} __attribute__((packed)) uhyve_write_t; + +typedef struct { + const char* name; + int flags; + int mode; + int ret; +} __attribute__((packed)) uhyve_open_t; + +typedef struct { + int fd; + int ret; +} __attribute__((packed)) uhyve_close_t; + +typedef struct { + int fd; + char* buf; + size_t len; + ssize_t ret; +} __attribute__((packed)) uhyve_read_t; + +typedef struct { + int fd; + off_t offset; + int whence; +} __attribute__((packed)) uhyve_lseek_t; + +#endif // UHYVE_SYSCALLS_H diff --git a/tools/uhyve.c b/tools/uhyve.c index 791edfba2..fbb4ad041 100644 --- a/tools/uhyve.c +++ b/tools/uhyve.c @@ -58,6 +58,7 @@ #include #include "uhyve-cpu.h" +#include "uhyve-syscalls.h" #include "proxy.h" #define GUEST_OFFSET 0x0 @@ -79,13 +80,6 @@ #define KVM_32BIT_GAP_SIZE (768 << 20) #define KVM_32BIT_GAP_START (KVM_32BIT_MAX_MEM_SIZE - KVM_32BIT_GAP_SIZE) -#define UHYVE_PORT_WRITE 0x499 -#define UHYVE_PORT_OPEN 0x500 -#define UHYVE_PORT_CLOSE 0x501 -#define UHYVE_PORT_READ 0x502 -#define UHYVE_PORT_EXIT 0x503 -#define UHYVE_PORT_LSEEK 0x504 - #define kvm_ioctl(fd, cmd, arg) ({ \ int ret = ioctl(fd, cmd, arg); \ if(ret == -1) \ @@ -104,37 +98,6 @@ static int kvm = -1, vmfd = -1; static __thread struct kvm_run *run = NULL; static __thread int vcpufd = 1; -typedef struct { - int fd; - const char* buf; - size_t len; -} __attribute__((packed)) uhyve_write_t; - -typedef struct { - const char* name; - int flags; - int mode; - int ret; -} __attribute__((packed)) uhyve_open_t; - -typedef struct { - int fd; - int ret; -} __attribute__((packed)) uhyve_close_t; - -typedef struct { - int fd; - char* buf; - size_t len; - ssize_t ret; -} __attribute__((packed)) uhyve_read_t; - -typedef struct { - int fd; - off_t offset; - int whence; -} __attribute__((packed)) uhyve_lseek_t; - static size_t memparse(const char *ptr) { char *endptr; /* local pointer to end of parsed string */