1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

tools/uhyve: refactor syscalls definitions into new file

This commit is contained in:
daniel-k 2017-03-01 18:48:45 +01:00
parent 9285e1f96f
commit 3942d62fe8
2 changed files with 65 additions and 38 deletions

64
tools/uhyve-syscalls.h Normal file
View file

@ -0,0 +1,64 @@
/* Copyright (c) 2017, RWTH Aachen University
* Author(s): Daniel Krebs <github@daniel-krebs.net>
*
* 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 <unistd.h>
#include <stddef.h>
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

View file

@ -58,6 +58,7 @@
#include <asm/msr-index.h>
#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 */