From: Akhil Guliani and William Gross Date: Tue, 23 Jun 2015 00:12:32 +0000 (-0500) Subject: Device File Virtualization Proof of Concept (Kernel+Preload) X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=de0aa03dbd9812a48cab6d899ab41b7f2cc593b5;p=palacios.git Device File Virtualization Proof of Concept (Kernel+Preload) This is an implementation of device file virtualization in Palacios for a Linux Host. Please consult palacios/gears/services/devfile/README for more information. --- diff --git a/gears/services/devfile/Makefile b/gears/services/devfile/Makefile new file mode 100644 index 0000000..45abbf6 --- /dev/null +++ b/gears/services/devfile/Makefile @@ -0,0 +1,35 @@ +.PHONY: clear +EXTRA = -m64 + +#TEST_CASES := $(wildcard test*.c) + +#TEST_TARGETS := $(wildcard (test*).c) + +all: devfile_hc.o test_preload devfile_host.ko libdevfile_hcall.a devfile_preload.so + +libdevfile_hcall.a: devfile_hc.o + ar ruv libdevfile_hcall.a devfile_hc.o + +devfile_hc.o: devfile_hc.c devfile_hc.h hcall.h + gcc $(EXTRA) -g -static -fPIC -S devfile_hc.c -o devfile_hc.s + gcc $(EXTRA) -g -static -fPIC -c devfile_hc.c -o devfile_hc.o + +devfile_preload.so: devfile_preload.c libdevfile_hcall.a + gcc $(EXTRA) -Wall -O2 -fPIC -shared -I/usr/include devfile_preload.c -L. -ldevfile_hcall -ldl -lc -o devfile_preload.so + +EXTRA_CFLAGS += -I$(PWD)/../../../palacios/include + +obj-m += devfile_host.o + +devfile_host.ko: devfile_host.c + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +test_preload: test_preload.c + gcc $(EXTRA) -Wall -g test_preload.c -o test_preload + +clean: + rm *.o *.so *.a *.ko test_preload *.out *.symvers *.mod.c *.s *.order + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean + +clear: + rm test_ld_lib *.o *.mod.o *.out *.symvers *.mod.c *.s *.order diff --git a/gears/services/devfile/README b/gears/services/devfile/README new file mode 100644 index 0000000..9e5cfaa --- /dev/null +++ b/gears/services/devfile/README @@ -0,0 +1,190 @@ +Device File Palacios Extension + +Akhil Guliani and William Gross +(Advised by Peter Dinda) +Northwestern University + +What Is This? + +This is a proof-of-concept implementation of device file +virtualization in the spirit of the Paradice system. Unlike Paradice, +it is implemented using only a preload library in the guest (no guest +modifications) and a kernel module in the host (no kernel +modifications). Also, there are no modifications to the Palacios +VMM either, as the core mechanisms used are the host hypercall +interface and the user-level guest memory access capabilities +implemented within Palacios. + +Note that it is a proof of concept. It does not do many of the things +that Paradice can do. For example, a hypercall currently involves a +hard stop of the guest core. Address space integration in the shadow +process is page granularity only. Pointer detection for system call +forwarding is done at a coarse granularity, meaning that ioctls would +need ot be hand coded. Select across guest and host fds is +completely ignored. + +Theory of Operation + +The basic idea is that we introduce a preload library into a guest +process. This library hijacks system calls. When you open a /dev +device that is in the list of devices we are proxying, the libraryio +handles the open by converting it to a hypercall, and binding the +result of the "open" hypercall and the fd returned. On subsequent +system calls involving the fd, the system calls are also converted to +hypercalls. The preload library merges fds/syscalls handled by the +guest and those handled by the host. The preload library also assures +that any data accessed is touched (page table entry exists), and could +pin it (currently does not). It also limits any pointer argument to +point to an block that fits within one page (e.g., read(1K offset, +4K length) turns into read(1K offset, 3K length). + +The hypercall is directed to the second component, a kernel module. +The kernel module swizzles pointers involved in the system call from +their GVAs to their GPAs. It then queues them for interaction with +host user space process called the shadow process. The kernel module +and the shadow share a page used to transfer the system call arguments +and the return value and errno. The kernel module signals the shadow +that a new swizzled system call is available by letting a poll/select +complete. The shadow signals the kernel module that it is finished +with the system call via an ioctl. + +The shadow process maps the guest's physical memory into its address +space using the guest memory access mechanisms. It then goes into a +select waiting for the kernel module. When it receives a system call +from the kernel module, it swizzles any pointer arguments in the +system call from their GPAs (provided by the kernel module) to their +corresponding HVAs (where the guest is mapped). It then issues the +system call, and writes back on the shared page both the return code +and the current errno value. It then signals completion via the +ioctl. + +The kernel module then returns from the hypercall to palacios, which +returns to the guest preload library, which copies out the relevant +results so that it appears that a system call has completed (on the +guest). + +Note that this model can be potentailly also be used as a general +system call forwarding mechanism. + +What's Here and There + +In this directory (palacios/gears/services/devfile) you will find the +prelaod library and the kernel module. There is also a simple test +program for the guest.. In the palacios user space directory +(palacios/linux_usr), you will find the shadow process code. The +latter is separate as it has dependencies on the guest memory access +library and build config. + +In palacios/gears/services/devfile/scripts, you will find scripts +which may help to evaluate the system. + + +General Setup + +[root@v-test-r415-3 linux_usr]# ./v3_devfile_shadow +v3_devfile_shadow + +Shadow process to support device file-level virtualization +in the spirit of Paradice. + +This operates with the devfile_host.ko kernel module +in the host and devfile_preload.so preload library in +the guest. These can be found, along with example scripts +in palacios/gears/services/devfile. + +The general steps are: + 1. insmod kernel module into host + 2. copy preload library into guest + 3. instantiate guest + 4. use v3_hypercall to bind the devfile hypercall (99993) + to the kernel module for your guest + 5. run v3_devfile_shadow + 6. run process in guest that uses preload library + + +****Scripts and More Detail Below**** + +Setup: + +Copy the patched_start_guest, patched_mem_script, +patched_insert_hypercall, and patched_view_console to the top of the +palacios directory then cd to the to top of the directory so that you +are at path/to/palacios/ and the scripts are at +path/to/palacios/patched_* + + + +Guest Requirements: + +For this system to work, the guest needs a couple things. It needs to +be configured with a CGA console (to get v3_console to work). It needs +to have sufficient memory (1024kb seems to work). It needs to accept +an LD_PRELOAD library. It needs to be an x86_64 architecture OS. It +needs to be running a Linux kernel. It needs a second drive set up as +a CD-ROM. Once that second drive is set up, replace the backing file +with a handmade loopback file system (perhaps using dd). For our +scripts to work exactly, this handmade file system should be called +littlefs.dat and an empty directory (for mounting) should be present +in the guest folder called tmp. The scripts are short and few, so the +relevant paths in them can be modified as necessary to fit your setup. + + + +Start Guest with Device File Forwarding: + +in that terminal source patched_mem_script in other terminal go to the +same position and source insert_hypercall if the terminal doesn't open +into the guest, resize your terminal appropriately and then source +patched_view_console and then from the guest do the following + +mkdir mnt +mount /dev/hdb mnt +cd /mnt/dev_file +source load_lib_in_guest +./test_preload +EXAMPLE: ./test_preload r 10 /dev/urandom + +This will attempt to read 10 bytes from /dev/urandom, where /dev/urandom +is a host device. + +If that last argument (/dev/urandom)is present in the +devfile_preload.c library, then the system will access the host +version of that device, if not it will just perform the regular system +calls on the guest's version of that device if it is present. + + +Close Running Guest with Device File Forwarding: + +To shut down smoothly kill the shadow process run from the first +terminal (patched_mem_script) make sure the second terminal has left +the guest by pressing \ then in either terminal source +patched_close_guest + + +Adding Host Devices in /dev to the list of Supported Devices: + +go to path/to/palacios/gears/services/devfile +edit guest_devices.txt +then run from the command line 'python guest_device_setup.py' + +this will update the dev_file_ld_lib.c file, which can be made from +that directory the object file is copied over to the guests /dev/hdb +drive within the patched_mem_script NOTE: Adding devices requires the +preload library (devfile_preload.c) to be made and copied to the guest +so, they cannot be added while a guest is running with this +feature. Close the guest first, add the new device changes, run the +python script, make the /gears/services/dev_file directory, start the +guest. + + + +Extending the System Call Interface: + +devfile_preload.c is the LD_PRELOAD library for the guest that hijacks +some basic system calls to see if they should be forwarded to the +host. To support a broader range of devices, this basic set can be +added to. Any addition should follow a similar structure to the read +or write system call in there. The things to make sure are that all +pointer arguments get pinned into memory and that the file descriptor +argument is checked against the set of active fds in the dtrack struct +(also in the library file). diff --git a/gears/services/devfile/devfile_guest_fd_tracker.h b/gears/services/devfile/devfile_guest_fd_tracker.h new file mode 100644 index 0000000..27ef088 --- /dev/null +++ b/gears/services/devfile/devfile_guest_fd_tracker.h @@ -0,0 +1,129 @@ +/* + Device File Virtualization Guest Preload Library Helpers + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + +*/ + +#define MAX_DEV_NAME_LENGTH 80 +#define MAX_DEVICES 100 + +//PYTHONSCRIPTBREAK1 +#define DEV_COUNT 9 +//PYTHONSCRIPTBREAK2 + +#include +#include +#include +#include + + + +#define MIN(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + + +char *strcpy(char *dest, const char *src) +{ + unsigned i; + for (i=0; src[i] != '\0'; ++i) + dest[i] = src[i]; + dest[i] = '\0'; + return dest; +} + +size_t strlen(const char * str) +{ + const char *s; + for (s = str; *s; ++s) {} + return(s - str); +} + + +//taken from: https://stuff.mit.edu/afs/sipb/project/tcl80/src/tcl8.0/compat/strstr.c +char* strstr(const char* string,char* substring) + // register char *string; /* String to search. */ + // char *substring; /* Substring to try to find in string. */ +{ + register char *a, *b; + + /* First scan quickly through the two strings looking for a + * * single-character match. When it's found, then compare the + * * rest of the substring. + * */ + + b = substring; + if (*b == 0) { + return (char*)string; + } + for ( ; *string != 0; string += 1) { + if (*string != *b) { + continue; + } + a = (char*)string; + while (1) { + if (*b == 0) { + return (char*)string; + } + if (*a++ != *b++) { + break; + } + } + b = substring; + } + return (char *) 0; +} + + +//Used to keep track of the active file descriptor for the supported devices +//Initially the fd is -1 to indicate that the device has not yet been opened +typedef struct dev_file_fd_tracker { + char devName[MAX_DEV_NAME_LENGTH]; + int devFD; +} dev_tracker; + + +dev_tracker dtrack[] = { +//PYTHONSCRIPTBREAK3 +{"/dev/urandom",-1}, +{"/dev/input/mouse0",-1}, +{"/dev/input/event0",-1}, +{"/dev/input/event1",-1}, +{"/dev/ttyS0",-1}, +{"/dev/ttyS1",-1}, +{"/dev/ttyS2",-1}, +{"/dev/ttyS3",-1}, +{"/dev/newDevice",-1} +//PYTHONSCRIPTBREAK4 + +}; + +//returns -1, means no match is found +//other than -1, is the index in the dtracker array of the match +int check_name(const char* path, dev_tracker tracker[]){ + int i; + for(i=0; i +#include "hcall.h" +#include "devfile_hc.h" + + +#include "sys_point_arr.h" + +int dev_file_syscall_hcall(long long sys_code, + long long a1, long long a2, long long a3, long long a4, + long long a5, long long a6, long long *sys_errno) +{ + long long rc; + long long cmd = DEV_FILE_HCALL; + long long bit_vec = sys_pointer_arr[sys_code]; + // Here, IOCTL needs to be handled specially because what + // arguments are pointes, etc, depends on the device + DEBUG_PRINT("Initiate syscall hypercall, code: %llu\n",sys_code); + HCALL(rc,cmd,sys_code,a1,a2,a3,a4,a5,a6,bit_vec); + *sys_errno = cmd; + DEBUG_PRINT("Syscall Hypercall done: rc = %llx errno = %llx\n",rc, *sys_errno); + return rc; +} diff --git a/gears/services/devfile/devfile_hc.h b/gears/services/devfile/devfile_hc.h new file mode 100644 index 0000000..65ce4d7 --- /dev/null +++ b/gears/services/devfile/devfile_hc.h @@ -0,0 +1,28 @@ +/* + Device File Virtualization Guest Preload Library Helpers + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + +*/ + +#define DEV_FILE_HCALL 99993 + +#include "syscall_ref.h" + +#ifndef __KERNEL__ + +#define DEBUG 1 +#if DEBUG +#define DEBUG_PRINT(fmt,args...) fprintf(stderr,(fmt),##args) +#else +#define DEBUG_PRINT(fmt,args...) +#endif + + +int dev_file_syscall_hcall(long long syscode, + long long a1, long long a2, long long a3, long long a4, + long long a5, long long a6, long long *sys_errno); + +#endif // KERNEL diff --git a/gears/services/devfile/devfile_host.c b/gears/services/devfile/devfile_host.c new file mode 100644 index 0000000..91a76c3 --- /dev/null +++ b/gears/services/devfile/devfile_host.c @@ -0,0 +1,546 @@ +/* + Device File Virtualization Host Module + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include +#include + + +#include "devfile_hc.h" + + +#define DEEP_DEBUG 1 +#define SHALLOW_DEBUG 1 + +#if DEEP_DEBUG +#define DEEP_DEBUG_PRINT(fmt, args...) printk(("devfile: " fmt), ##args) +#else +#define DEEP_DEBUG_PRINT(fmt, args...) +#endif + +#if SHALLOW_DEBUG +#define SHALLOW_DEBUG_PRINT(fmt, args...) printk(("devfile: " fmt), ##args) +#else +#define SHALLOW_DEBUG_PRINT(fmt, args...) +#endif + + +#define ERROR(fmt, args...) printk(("devfile: " fmt), ##args) +#define INFO(fmt, args...) printk(("devfile: " fmt), ##args) + +#define PRINT_CONSOLE(fmt,args...) printf(("devfile: " fmt),##args) + + + + +// Added to make unique id's for IOCTL +#define MY_MACIG 'G' +#define INIT_IOCTL _IOR(MY_MACIG, 0, int) +#define SHADOW_SYSCALL_DONE _IOW(MY_MACIG, 2, int) + +#define DEVFILE_NAME "v3-devfile" + +static int devfile_major_num = 0; +static struct class *devfile_class = 0; +static struct cdev devfile_dev; + + + +struct devfile_state { + void *shared_mem_va; + uint64_t shared_mem_uva; + uint64_t shared_mem_pa; + uint64_t returned_fd; + + wait_queue_head_t user_wait_queue; + wait_queue_head_t host_wait_queue; + + enum { WAIT_FOR_INIT, WAIT_ON_GUEST, WAIT_ON_SHADOW} state; +} ; + +// Currently this proof of concept supports a single userland/VM binding +// and is serially reusable +static struct devfile_state *state=0; + +static inline struct devfile_state *find_matching_state(palacios_core_t core) { return state; } + + +/* Hypercall helpers */ + +static void get_args_64(palacios_core_t core, + struct guest_accessors *acc, + uint64_t *a1, + uint64_t *a2, + uint64_t *a3, + uint64_t *a4, + uint64_t *a5, + uint64_t *a6, + uint64_t *a7, + uint64_t *a8) +{ + *a1 = acc->get_rcx(core); + *a2 = acc->get_rdx(core); + *a3 = acc->get_rsi(core); + *a4 = acc->get_rdi(core); + *a5 = acc->get_r8(core); + *a6 = acc->get_r9(core); + *a7 = acc->get_r10(core); + *a8 = acc->get_r11(core); +} + +static void get_args_32(palacios_core_t core, + struct guest_accessors *acc, + uint64_t *a1, + uint64_t *a2, + uint64_t *a3, + uint64_t *a4, + uint64_t *a5, + uint64_t *a6, + uint64_t *a7, + uint64_t *a8) +{ + uint64_t rsp; + uint32_t temp; + + + rsp = acc->get_rsp(core); + + acc->read_gva(core,rsp,4,&temp); *a1=temp; + acc->read_gva(core,rsp+4,4,&temp); *a2=temp; + acc->read_gva(core,rsp+8,4,&temp); *a3=temp; + acc->read_gva(core,rsp+12,4,&temp); *a4=temp; + acc->read_gva(core,rsp+16,4,&temp); *a5=temp; + acc->read_gva(core,rsp+20,4,&temp); *a6=temp; + acc->read_gva(core,rsp+24,4,&temp); *a7=temp; + acc->read_gva(core,rsp+28,4,&temp); *a8=temp; +} + +static void get_args(palacios_core_t core, + struct guest_accessors *acc, + uint64_t *a1, + uint64_t *a2, + uint64_t *a3, + uint64_t *a4, + uint64_t *a5, + uint64_t *a6, + uint64_t *a7, + uint64_t *a8) +{ + uint64_t rbx; + uint32_t ebx; + + rbx=acc->get_rbx(core); + ebx=rbx&0xffffffff; + + switch (ebx) { + case 0x64646464: + DEEP_DEBUG_PRINT("64 bit hcall\n"); + return get_args_64(core,acc,a1,a2,a3,a4,a5,a6,a7,a8); + break; + case 0x32323232: + DEEP_DEBUG_PRINT("32 bit hcall\n"); + return get_args_32(core,acc,a1,a2,a3,a4,a5,a6,a7,a8); + break; + default: + ERROR("UNKNOWN hcall calling convention\n"); + break; + } +} + +static void put_return(palacios_core_t core, + struct guest_accessors *acc, + uint64_t rc, + uint64_t errno) +{ + acc->set_rax(core,rc); + acc->set_rbx(core,rc); +} + +/* + Convert all hypercall pointer arguments from GVAs to GPAs + The host userland is responsible for converting from + GVAs to HVAs. + + The assumption here is that any pointer argument + points to a structure that does NOT span a page + boundary. The guest userland is responsible for + assuring that this is the case. +*/ +static int deref_args(palacios_core_t core, + struct guest_accessors *acc, + uint64_t* a1, uint64_t* a2, uint64_t* a3, uint64_t* a4, uint64_t* a5, + uint64_t* a6, uint64_t bvec) +{ + if (bvec & 1){ + uint64_t a1tmp = *a1; + acc->gva_to_gpa(core,a1tmp,a1); + } + if (bvec & 2){ + uint64_t a2tmp = *a2; + acc->gva_to_gpa(core,a2tmp,a2); + } + if (bvec & 4){ + uint64_t a3tmp = *a3; + acc->gva_to_gpa(core,a3tmp,a3); + } + if (bvec & 8){ + uint64_t a4tmp = *a4; + acc->gva_to_gpa(core,a4tmp,a4); + } + if (bvec & 16){ + uint64_t a5tmp = *a5; + acc->gva_to_gpa(core,a5tmp,a5); + } + if (bvec & 32){ + uint64_t a6tmp = *a6; + acc->gva_to_gpa(core,a6tmp,a6); + } + return 0; +} + + +#if 0 +/* Create /dev/v3-devfile in the host */ + +// User mode helper call to create module private chardev for ioctls +static int setup_mknod_call(int major_num) +{ + //www.ibm.com/developerworks/library/l-user-space-apps/ + struct subprocess_info *sub_info; + char buf[20]; + + snprintf(buf,20,"%d",major_num); + + const char *argv[] = { "/bin/mknod", "/dev/" DEVFILE_NAME,"c", buf, "0", NULL }; + static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL }; + + sub_info = call_usermodehelper_setup( (char*)argv[0], (char**)argv, envp, GFP_ATOMIC ); + + if (sub_info == NULL) { + ERROR("failed to create %s\n",DEVFILE_PATH); + return -ENOMEM; + } + + SHALLOW_DEBUG_PRINT("set up usermode call\n"); + + return call_usermodehelper_exec( sub_info, UMH_WAIT_PROC ); +} + +#endif + +static uint64_t devfile_syscall_return(struct devfile_state *s, uint64_t *errno) +{ + uint64_t rc; + uint64_t *shared_page = (uint64_t*)(s->shared_mem_va); + + s->state=WAIT_ON_SHADOW; + + // kick the the user if needed + //!! IDEA: We can add Usermode Helper to start shadow process instead + // and wait for it to send us an ioctl to wake up the module. + wake_up_interruptible(&(s->user_wait_queue)); + // goto sleep until we see a message received + // part of a separate ioctl + SHALLOW_DEBUG_PRINT("waiting For Shadow Process\n"); + while (wait_event_interruptible(s->host_wait_queue, (s->state==WAIT_ON_GUEST)) != 0) {} + SHALLOW_DEBUG_PRINT("waiting done\n"); + // Get the returned value and errno + rc = *(shared_page +8); + *errno = *(shared_page +9); + + SHALLOW_DEBUG_PRINT("waiting done %016llu (errno %016llu)\n",rc,*errno); + return rc; +} + + +static int devfile_syscall_hcall(struct devfile_state *s, + palacios_core_t core, + uint64_t sys_code, + uint64_t a1, uint64_t a2,uint64_t a3, + uint64_t a4, uint64_t a5, uint64_t a6, + uint64_t bit_vec, + uint64_t *errno) +{ + //Using shared memory page + uint64_t ret; + uint64_t *shared_page = (uint64_t*)(s->shared_mem_va); + + *(shared_page +0) = sys_code; + *(shared_page +1) = a1; + *(shared_page +2) = a2; + *(shared_page +3) = a3; + *(shared_page +4) = a4; + *(shared_page +5) = a5; + *(shared_page +6) = a6; + *(shared_page +7) = bit_vec; + + SHALLOW_DEBUG_PRINT("Host Module to wait on shadow\n"); + + //Now wait for rc and errno to be written to the shared page + ret = devfile_syscall_return(s, errno); + + SHALLOW_DEBUG_PRINT("SYSCALL HCALL %016llu (errno %016llu)\n",ret,*errno); + + return ret; +} + + + +// The main Interface for Hypercalls +int devfile_hypercall(palacios_core_t *core, + unsigned int hid, + struct guest_accessors *acc, + void *p) +{ + uint64_t a1,a2,a3,a4,a5,a6,bit_vec,sys_code; + uint64_t rc; + uint64_t errno; + + struct devfile_state *s = find_matching_state(core); + + if (s->state == WAIT_FOR_INIT){ + SHALLOW_DEBUG_PRINT("Shared Memory Not Yet Initialized, returning syscall hypercall\n"); + return -1; + } + + sys_code = 0; + bit_vec = 0; + + DEEP_DEBUG_PRINT("devfile_hypercall(%p,0x%x,%p,%p)\n", + core,hid,acc,p); + + get_args(core,acc,&sys_code,&a1,&a2,&a3,&a4,&a5,&a6,&bit_vec); + + DEEP_DEBUG_PRINT("original arguments: %016llu, %016llu, %016llu, %016llu, %016llu, %016llu, %016llu, %016llu\n", + sys_code,a1,a2,a3,a4,a5,a6,bit_vec); + + // Convert any pointer arguments from GVAs to GPAs + deref_args(core,acc,&a1,&a2,&a3,&a4,&a5,&a6,bit_vec); + + DEEP_DEBUG_PRINT("derefed arguments: %016llu, %016llu, %016llu, %016llu, %016llu, %016llu, %016llu, %016llu\n", + sys_code,a1,a2,a3,a4,a5,a6,bit_vec); + + rc = devfile_syscall_hcall(s,core,sys_code,a1,a2,a3,a4,a5,a6,bit_vec,&errno); + + SHALLOW_DEBUG_PRINT("Syscall rc: %016llu errno=%016llu\n",rc,errno); + + put_return(core,acc,rc,errno); + + return 0; + +} + + +static int devfile_open(struct inode * inode, struct file * filp) +{ + struct devfile_state *s = state; + + if (s) { + ERROR("attempting to open devfile that is already open\n"); + return -EINVAL; + } + + s=(struct devfile_state*)kmalloc(sizeof(struct devfile_state),GFP_KERNEL); + + if (!s) { + ERROR("Failed to allocate space for open\n"); + return -EINVAL; + } + + // This hideousness is here because in this POC we + // are simply allowing a single userland to be tied to + // a single VM. At the same time, we are making + // the rest of the code more flexible for the future + state = s; + + memset(s,0,sizeof(*s)); + + init_waitqueue_head(&s->user_wait_queue); + init_waitqueue_head(&s->host_wait_queue); + + s->state = WAIT_FOR_INIT; + + filp->private_data = (void*) s; + + return 0; +} + +static int devfile_close(struct inode * inode, struct file * filp) +{ + struct devfile_state *s = filp->private_data; + + if (s) { + if (s->state==WAIT_ON_SHADOW) { + ERROR("Odd, userland is closing devfile while we are waiting for it\n"); + } + kfree(s); + state=0; + } + + return 0; + +} + + +static long devfile_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct devfile_state *s = filp->private_data; + + switch(cmd) { + case INIT_IOCTL: + s->shared_mem_pa = (uint64_t)arg; + s->shared_mem_va = __va(s->shared_mem_pa); + SHALLOW_DEBUG_PRINT("Shared Memory Physical Address: %016llu\n",s->shared_mem_pa); + SHALLOW_DEBUG_PRINT("Shared Memory Kernel VA: %p\n",s->shared_mem_va); + //Change State to wait on guest + s->state = WAIT_ON_GUEST; + break; + + case SHADOW_SYSCALL_DONE: + s->state = WAIT_ON_GUEST; + wake_up_interruptible(&(s->host_wait_queue)); + break; + + default: + return -EINVAL; + } + + return 0; + +} + + +static unsigned int devfile_poll(struct file * filp, + struct poll_table_struct * poll_tb) +{ + struct devfile_state *s = filp->private_data; + + SHALLOW_DEBUG_PRINT("poll\n"); + + // register ourselves on the user wait queue + poll_wait(filp, &(s->user_wait_queue), poll_tb); + + if (s->state==WAIT_ON_SHADOW) { + // Yes, we have a request if you want it! + DEEP_DEBUG_PRINT("poll done immediate\n"); + return POLLIN | POLLRDNORM; + } + // No request yet, so we need to wait for one to show up. + DEEP_DEBUG_PRINT("poll delayed\n"); + // We will get called again when that queue is woken up + + return 0; +} + +static struct file_operations devfile_fops = { + .open = devfile_open, + .release = devfile_close, + .poll = devfile_poll, + .unlocked_ioctl = devfile_ioctl, + .compat_ioctl = devfile_ioctl +}; + +EXPORT_SYMBOL(devfile_hypercall); + +int init_module(void) +{ + dev_t dev; + + SHALLOW_DEBUG_PRINT("INIT\n"); + + devfile_class = class_create(THIS_MODULE,"devfile"); + if (!devfile_class || IS_ERR(devfile_class)) { + ERROR("Cannot register devfile device class\n"); + return PTR_ERR(devfile_class); + } + + dev = MKDEV(0,0); + + if (alloc_chrdev_region(&dev,0,1,"devfile")<0) { + ERROR("Failed to alloc chrdev region\n"); + return -1; + } + + devfile_major_num = MAJOR(dev); + + dev = MKDEV(devfile_major_num,1); + + cdev_init(&devfile_dev, &devfile_fops); + devfile_dev.owner = THIS_MODULE; + devfile_dev.ops = &devfile_fops; + cdev_add(&devfile_dev, dev, 1); + + device_create(devfile_class, NULL, dev, NULL, "v3-devfile"); + +#if 0 + // Setup chardev for IOCTL + major = register_chrdev(0,"dfvDev", &fops); + if(major < 0){ + SHALLOW_DEBUG_PRINT("registering dfvDev char device failed with %d\n", major); + return major; + } + SHALLOW_DEBUG_PRINT("assigned major: %d\n", major); + SHALLOW_DEBUG_PRINT("creating node with mknod %s c %d 0\n", DEVFILE_PATH, major); + + // Call Helper API function to setup chardev + rc = setup_mknod_call(major); + SHALLOW_DEBUG_PRINT("UMH api mknod %s c %d 0 -- ret: %d\n\n", DEVFILE_PATH, major,rc); + +#endif + + INFO("inited\n"); + + return 0; +} + +void cleanup_module(void) +{ + dev_t dev = MKDEV(devfile_major_num,1); + + unregister_chrdev_region(MKDEV(devfile_major_num,0),1); + cdev_del(&devfile_dev); + device_destroy(devfile_class,dev); + class_destroy(devfile_class); + +#if 0 + unregister_chrdev(major, "dfvDev"); +#endif + if (state) { + kfree(state); + } + + INFO("deinited\n"); +} diff --git a/gears/services/devfile/devfile_preload.c b/gears/services/devfile/devfile_preload.c new file mode 100644 index 0000000..fea7a6e --- /dev/null +++ b/gears/services/devfile/devfile_preload.c @@ -0,0 +1,165 @@ +/* + Device File Virtualization Guest Preload Library + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + +*/ + +#define _GNU_SOURCE + +#include +#include +#include +#include + + + +#include "devfile_hc.h" +#include "devfile_guest_fd_tracker.h" + +static int __LocalFD = 0; +static int __last_open_index = -1; + + +unsigned long long syscall(); + +int touch_ptr(volatile char* ptr, int size) +{ + int i; + for(i=0;i=0) { + DEBUG_PRINT("In our file, \n"); + __LocalFD = dtrack[__last_open_index].devFD; + if(__LocalFD >= 0) { + return __LocalFD; + } else { + // Execute open hypercall here + char buf[8192]; + char* my_path; + int path_length = strlen(path)+1; + //check if path is across a page boundary + //if so try to copy into a local buffer, that doesn't cross a page boundary + //if its greater than 4k, fail + if (path_length > 4096){ + DEBUG_PRINT("Path greater than 4k, failing open\n"); + return -1; + } + //forcing path to be in a single page + my_path = (char*)((((unsigned long long)buf+4096)/4096)*4096); + strcpy(my_path,path); // my_path is touched via this + long long sys_errno; + int rcFD = dev_file_syscall_hcall(SYS64_OPEN,(long long)my_path,flags,0 ,0,0,0,&sys_errno); + DEBUG_PRINT(" ReturnFD : %d; \n", rcFD); + __LocalFD = rcFD; + // set global errno so caller can see + errno=sys_errno; + return rcFD; + } + } else { + DEBUG_PRINT("performing original open\n"); + + return syscall(SYS64_OPEN, path, flags, mode); + } +} + +size_t read(int fd, void *buf, size_t count) +{ + //does buf+count extend pass page boundary? + //if so, only do up to page boundary + // if( (buf%4096)+count <= 4096) + // normal + + if (fd == __LocalFD || (check_fd(fd,dtrack)>=0)){ + long long sys_errno; + //Need to handle only up to a page boundary, can't handle contiguous pages right now + count = MIN(count,4096-((unsigned long long)buf%4096)); + touch_ptr(buf,count); + int ret = dev_file_syscall_hcall(SYS64_READ,fd,(long long)buf,count,0,0,0,&sys_errno); + DEBUG_PRINT("Read of %lu bytes returned %d (errno %lld)\n",count,ret,sys_errno); + errno = sys_errno; + return ret; + } else { + DEBUG_PRINT("performing original read\n"); + return syscall(SYS64_READ,fd, buf, count); + } +} + +ssize_t write(int fd, const void *buf, size_t count) +{ + if (fd == __LocalFD || (check_fd(fd,dtrack)>=0)) { + long long sys_errno; + //Need to handle only up to a page boundary, can't handle contiguous pages right now + count = MIN(count,4096-((unsigned long long)buf%4096)); + touch_ptr((char*)buf,count); + int ret = dev_file_syscall_hcall(SYS64_WRITE,fd, (long long)buf,count,0,0,0,&sys_errno); + DEBUG_PRINT("Write of %lu bytes returned %d (errno %lld)\n",count,ret,sys_errno); + errno=sys_errno; + return ret; + } else { + DEBUG_PRINT("performing original write\n"); + return syscall(SYS64_WRITE,fd, buf, count); + } +} + +int close(int fd) +{ + int index = check_fd(fd,dtrack); + if (fd == __LocalFD || (index>=0)) { + long long sys_errno; + int ret = dev_file_syscall_hcall(SYS64_CLOSE,fd,0,0,0,0,0,&sys_errno); + if (ret >=0) { + dtrack[index].devFD = -1; + __LocalFD = -1; + } + DEBUG_PRINT("Close returned %d (errno %lld)\n",ret, sys_errno); + errno=sys_errno; + return ret; + } else { + DEBUG_PRINT("performing original close\n"); + return syscall(SYS64_CLOSE,fd); + } +} + + +int ioctl(int fd, int request, void* data) { + //int sign_post; + int index = check_fd(fd,dtrack); + + // this is where a careful, device-specific decode is needed + // to figure out whether the argument or anything it points + // is a pointer. + if (fd == __LocalFD || (index>=0)) { + long long sys_errno=0; + int ret; + // First cut for just the data pointer: + // if (data > &sign_post){ + //probably on stack + // } + // if (data < brk() + ret = dev_file_syscall_hcall(SYS64_IOCTL,fd,request,(unsigned long long)data,0,0,0,&sys_errno); + + DEBUG_PRINT("ioctl(%d) returned %d (errno %lld)\n",request,ret, sys_errno); + errno=sys_errno; + return ret; + } + else{ + return syscall(SYS64_IOCTL,fd,request,data); + } + return -1; + +} + diff --git a/gears/services/devfile/guest_device_setup.py b/gears/services/devfile/guest_device_setup.py new file mode 100644 index 0000000..2108816 --- /dev/null +++ b/gears/services/devfile/guest_device_setup.py @@ -0,0 +1,45 @@ + + +def main(): + ff = open("guest_devices.txt",'r') + + count = 0 + out = '' + for line in ff: + count+=1 + this_line = '{\"'+line.strip('\n')+'\",-1},\n' + out += this_line + out = out.rstrip('\n,') + out+="\n" + top = "#define DEV_COUNT "+str(count)+"\n" + + ff.close() + + writeable = open("dev_file_guest_fd_tracker.h",'r'); + lst = writeable.readlines() + writeable.close() + count = 0 + for line in lst: + count+=1 + if 'PYTHONSCRIPTBREAK1' in line: + index1 = count + if 'PYTHONSCRIPTBREAK3' in line: + index2 = count + if 'PYTHONSCRIPTBREAK4' in line: + index3 = count + + lst.pop(index1) + lst.insert(index1,top) + subcount = index3-2 + while(subcount>= index2): + lst.pop(subcount) + subcount-=1 + lst.insert(index2,out) + writeable = open("dev_file_guest_fd_tracker.h",'w'); + writeable.write(''.join(lst)) + writeable.close() + return + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/gears/services/devfile/guest_devices.txt b/gears/services/devfile/guest_devices.txt new file mode 100644 index 0000000..c259bfd --- /dev/null +++ b/gears/services/devfile/guest_devices.txt @@ -0,0 +1,9 @@ +/dev/urandom +/dev/input/mouse0 +/dev/input/event0 +/dev/input/event1 +/dev/ttyS0 +/dev/ttyS1 +/dev/ttyS2 +/dev/ttyS3 +/dev/newDevice diff --git a/gears/services/devfile/hcall.h b/gears/services/devfile/hcall.h new file mode 100644 index 0000000..29c6be1 --- /dev/null +++ b/gears/services/devfile/hcall.h @@ -0,0 +1,97 @@ +/* + Device File Virtualization Guest Preload Library Helpers + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + + Note that the calling convention here is a bit different + since we need to return errno + + +*/ + +#ifndef __HCALL__ +#define __HCALL__ + +/* + Calling convention: + +64 bit: + rax = hcall number + rbx = 0x6464646464646464... + rcx = 1st arg + rdx = 2nd arg + rsi = 3rd arg + rdi = 4th arg + r8 = 5th arg + r9 = 6th arg + r10 = 7th arg + r11 = 8th arg + +32 bit: + eax = hcall number + ebx = 0x32323232 + arguments on stack in C order (first argument is TOS) + arguments are also 32 bit + +In this convention, + RAX is assumed to be the return code from the system call + RBX is assumed to be the errno set by the system call + + RAX comes back via rc + RBX comes back via overwrite of id +*/ +#define HCALL64(rc,id,a,b,c,d,e,f,g,h) \ + asm volatile ("movq %1, %%rax; " \ + "pushq %%rbx; " \ + "movq $0x6464646464646464, %%rbx; " \ + "movq %2, %%rcx; " \ + "movq %3, %%rdx; " \ + "movq %4, %%rsi; " \ + "movq %5, %%rdi; " \ + "movq %6, %%r8 ; " \ + "movq %7, %%r9 ; " \ + "movq %8, %%r10; " \ + "movq %9, %%r11; " \ + "vmmcall ; " \ + "movq %%rax, %0; " \ + "movq %%rbx, %1; " \ + "popq %%rbx; " \ + : "=m"(rc),"=m"(id) \ + : "m"(a), "m"(b), "m"(c), "m"(d), \ + "m"(e), "m"(f), "m"(g), "m"(h) \ + : "%rax","%rcx","%rdx","%rsi","%rdi", \ + "%r8","%r9","%r10","%r11" \ + ) + +#define HCALL32(rc,id,a,b,c,d,e,f,g,h) \ + asm volatile ("movl %1, %%eax; " \ + "pushl %%ebx; " \ + "movl $0x32323232, %%ebx; " \ + "pushl %9;" \ + "pushl %8;" \ + "pushl %7;" \ + "pushl %6;" \ + "pushl %5;" \ + "pushl %4;" \ + "pushl %3;" \ + "pushl %2;" \ + "vmmcall ; " \ + "movl %%eax, %0; " \ + "movl %%ebx, %1; " \ + "addl $32, %%esp; " \ + "popl %%ebx; " \ + : "=m"(rc), "=m"(id) \ + : "m"(a), "m"(b), "m"(c), "m"(d), \ + "m"(e), "m"(f), "m"(g), "m"(h) \ + : "%eax" \ + ) + +#ifdef __x86_64__ +#define HCALL(rc,id,a,b,c,d,e,f,g,h) HCALL64(rc,id,a,b,c,d,e,f,g,h) +#else +#define HCALL(rc,id,a,b,c,d,e,f,g,h) HCALL32(rc,id,a,b,c,d,e,f,g,h) +#endif + +#endif diff --git a/gears/services/devfile/scripts/close_guest b/gears/services/devfile/scripts/close_guest new file mode 100755 index 0000000..c6b6b62 --- /dev/null +++ b/gears/services/devfile/scripts/close_guest @@ -0,0 +1,5 @@ +#!/bin/sh +v3_hypercall /dev/v3-vm0 remove 99993 devfile_hypercall +v3_stop /dev/v3-vm0 +v3_free 0 +rmmod devfile_host.ko diff --git a/gears/services/devfile/scripts/copy_to_guest b/gears/services/devfile/scripts/copy_to_guest new file mode 100755 index 0000000..a28588d --- /dev/null +++ b/gears/services/devfile/scripts/copy_to_guest @@ -0,0 +1,8 @@ +cd ~/akbill/palacios/guest7/ +mount littlefs.dat tmp +cp -u ~/akbill/palacios/gears/services/devfile/test_preload tmp/dev_file/. +cp -u ~/akbill/palacios/gears/services/devfile/devfile_preload.so tmp/dev_file/. +cp -u ~/akbill/palacios/gears/services/devfile/scripts/load_lib_in_guest tmp/dev_file/. +echo "Copy done" +umount tmp +cd ~/akbill/palacios diff --git a/gears/services/devfile/scripts/insert_hypercall b/gears/services/devfile/scripts/insert_hypercall new file mode 100755 index 0000000..8491529 --- /dev/null +++ b/gears/services/devfile/scripts/insert_hypercall @@ -0,0 +1,6 @@ +#!/bin/sh +source ENV +cd ~/akbill/palacios/ +v3_hypercall /dev/v3-vm0 add 99993 devfile_hypercall +v3_launch /dev/v3-vm0 +v3_console /dev/v3-vm0 diff --git a/gears/services/devfile/scripts/load_lib_in_guest b/gears/services/devfile/scripts/load_lib_in_guest new file mode 100644 index 0000000..bc81b3d --- /dev/null +++ b/gears/services/devfile/scripts/load_lib_in_guest @@ -0,0 +1,17 @@ +#copy the missing library over to correct path +cd /lib64 +cp /mnt/libtest/libdl.so.2 . + +#set LD_PRELOAD correctly +export LD_PRELOAD=/mnt/dev_file/devfile_preload.so + + +#check if the loader is able to load the LD_library +./ld-linux-x86-64.so.2 --list /mnt/dev_file/devfile_preload.so + +#check if test program gets the ld preload loaded +./ld-linux-x86-64.so.2 --list /mnt/dev_file/test_preload + +# run test program +cd /mnt/dev_file/ +#./test_preload r 24 /dev/urandom diff --git a/gears/services/devfile/scripts/mem_script b/gears/services/devfile/scripts/mem_script new file mode 100755 index 0000000..b99f848 --- /dev/null +++ b/gears/services/devfile/scripts/mem_script @@ -0,0 +1,18 @@ +jobs -p | xargs kill -9 +./close_guest +./v3_deinit +cd ~/akbill/palacios/linux_usr +make clean +make +cd .. +make clean +make -j 8 +source ENV +source copy_to_guest +./v3_init +cd ~/akbill/palacios/gears/services/dev_file/ +make +insmod devfile_host.ko +cd scripts +source start_guest_persistent +jobs -l diff --git a/gears/services/devfile/scripts/patched_close_guest b/gears/services/devfile/scripts/patched_close_guest new file mode 100755 index 0000000..c6b6b62 --- /dev/null +++ b/gears/services/devfile/scripts/patched_close_guest @@ -0,0 +1,5 @@ +#!/bin/sh +v3_hypercall /dev/v3-vm0 remove 99993 devfile_hypercall +v3_stop /dev/v3-vm0 +v3_free 0 +rmmod devfile_host.ko diff --git a/gears/services/devfile/scripts/patched_copy_to_guest b/gears/services/devfile/scripts/patched_copy_to_guest new file mode 100755 index 0000000..7886ad2 --- /dev/null +++ b/gears/services/devfile/scripts/patched_copy_to_guest @@ -0,0 +1,8 @@ +cd dev_file_guest +mount littlefs.dat tmp +cp -u ../gears/services/devfile/scripts/load_lib_in_guest tmp/dev_file/. +cp -u ../gears/services/devfile/test_prelaod tmp/dev_file/. +cp -u ../gears/services/devfile/devfile_preload.so tmp/dev_file/. +echo "Copy done" +umount tmp +cd .. diff --git a/gears/services/devfile/scripts/patched_insert_hypercall b/gears/services/devfile/scripts/patched_insert_hypercall new file mode 100755 index 0000000..8a658c0 --- /dev/null +++ b/gears/services/devfile/scripts/patched_insert_hypercall @@ -0,0 +1,5 @@ +#!/bin/sh +source ENV +v3_hypercall /dev/v3-vm0 add 99993 devfile_hypercall +v3_launch /dev/v3-vm0 +v3_console /dev/v3-vm0 diff --git a/gears/services/devfile/scripts/patched_mem_script b/gears/services/devfile/scripts/patched_mem_script new file mode 100755 index 0000000..3b928dc --- /dev/null +++ b/gears/services/devfile/scripts/patched_mem_script @@ -0,0 +1,18 @@ +jobs -p | xargs kill -9 +source patched_close_guest +./v3_deinit +cd linux_usr +make clean +make +cd .. +make clean +make -j 8 +source ENV +source gears/services/devfile/scripts/patched_copy_to_guest +./v3_init +cd gears/services/devfile/ +make +insmod devfile_host.ko +cd ../../.. +source gears/services/dev_ile/patched_start_guest +jobs -l diff --git a/gears/services/devfile/scripts/patched_start_guest b/gears/services/devfile/scripts/patched_start_guest new file mode 100755 index 0000000..9479313 --- /dev/null +++ b/gears/services/devfile/scripts/patched_start_guest @@ -0,0 +1,4 @@ +cd dev_file_guest +v3_create -b guest.pal gg +dev_file_shadow /dev/v3-vm0 +cd .. diff --git a/gears/services/devfile/scripts/start_guest b/gears/services/devfile/scripts/start_guest new file mode 100755 index 0000000..501dd42 --- /dev/null +++ b/gears/services/devfile/scripts/start_guest @@ -0,0 +1,9 @@ +#!/bin/sh +cd guest7 +v3_create -b -u guest7.pal gg +cd ../dev_file/ +insmod devfile_host.ko +v3_hypercall /dev/v3-vm0 add 99993 devfile_hypercall +v3_launch /dev/v3-vm0 +v3_console /dev/v3-vm0 +cd .. diff --git a/gears/services/devfile/scripts/start_guest_persistent b/gears/services/devfile/scripts/start_guest_persistent new file mode 100755 index 0000000..8a08d43 --- /dev/null +++ b/gears/services/devfile/scripts/start_guest_persistent @@ -0,0 +1,4 @@ +cd guest7 +v3_create -b guest7.pal gg +v3_devfile_shadow /dev/v3-vm0 +cd .. diff --git a/gears/services/devfile/scripts/sys_fd_arr.h b/gears/services/devfile/scripts/sys_fd_arr.h new file mode 100644 index 0000000..ab887a0 --- /dev/null +++ b/gears/services/devfile/scripts/sys_fd_arr.h @@ -0,0 +1,325 @@ +int sys_pointer_arr[323] = { +0, +0, +-1, +0, +-1, +0, +-1, +1, +0, +4, +-1, +-1, +-1, +-1, +-1, +-1, +0, +0, +0, +0, +0, +-1, +-1, +3, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +1, +-1, +-1, +-1, +-1, +-1, +-1, +1, +-1, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +-1, +0, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +0, +0, +0, +-1, +0, +0, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +-1, +-1, +-1, +0, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +2, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +-1, +0, +0, +-1, +0, +0, +0, +0, +0, +0, +0, +2, +2, +1, +0, +0, +0, +3, +1, +-1, +-1, +-1, +2, +1, +0, +0, +-1, +0, +0, +0, +-1, +-1, +0, +0, +0, +0, +0, +-1, +-1, +1, +-1, +-1, +0, +0, +-1, +3, +0, +-1, +3, +-1, +0, +0, +-1, +0, +0, +0, +-1, +-1, +-1, +-1, +0, +-1, +-1, +2, +-1, +-1, +-1, +1, +-1, +0 +}; diff --git a/gears/services/devfile/scripts/syscall_arr.py b/gears/services/devfile/scripts/syscall_arr.py new file mode 100644 index 0000000..5e699a1 --- /dev/null +++ b/gears/services/devfile/scripts/syscall_arr.py @@ -0,0 +1,66 @@ +import bs4 + +#http://blog.rchapman.org/post/36801038863/linux-system-call-table-for-x86-64 + +def fd_arr(): + ff = open('syscalltable.txt','r') + soup = bs4.BeautifulSoup(ff.read()) + ff.close() + ff = open('sys_fd_arr.h','w') + + len_list = len(list(soup.find_all('tr'))) + ff.write('int sys_pointer_arr[323] = {\n') + for (i,row) in enumerate(list(soup.find_all('tr'))): + print str(row.find('td'))[4:len(str(row.find('td')))-5] + + if len(list(row.find_all('td')))>0: + candidate = -1 + for (j,ele) in enumerate(list(row.find_all('td'))[2::]): + inner = str(ele)[4:len(str(ele))-5] + inner_split = inner.split() + for inn in inner_split: + if 'fd' in inn: + print inner + candidate = j + if i>=len_list-1: + ff.write(str(candidate)+'\n') + else: + ff.write(str(candidate)+',\n') + ff.write('};\n') + ff.close() + return + +def main(): + ff = open('syscalltable.txt','r') + soup = bs4.BeautifulSoup(ff.read()) + ff.close() + ff = open('sys_point_arr.h','w') + + len_list = len(list(soup.find_all('tr'))) + ff.write('int sys_pointer_arr[323] = {\n') + for (i,row) in enumerate(list(soup.find_all('tr'))): + print str(row.find('td'))[4:len(str(row.find('td')))-5] + bit_vec = '' + if len(list(row.find_all('td')))>0: + for ele in list(row.find_all('td'))[2::]: + inner = str(ele)[4:len(str(ele))-5] + if '*' in inner: + bit_vec+= '1' + elif '' == inner: + bit_vec+= '0' + else: + bit_vec+= '0' + bit_vec+='00' + print bit_vec[::-1] + print int(bit_vec[::-1],2) + if i>=len_list-1: + ff.write(str(int(bit_vec[::-1],2))+'\n') + else: + ff.write(str(int(bit_vec[::-1],2))+',\n') + ff.write('};\n') + ff.close() + return + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/gears/services/devfile/scripts/syscalltable.txt b/gears/services/devfile/scripts/syscalltable.txt new file mode 100644 index 0000000..b9d497f --- /dev/null +++ b/gears/services/devfile/scripts/syscalltable.txt @@ -0,0 +1,2 @@ +
%raxSystem call%rdi%rsi%rdx%r10%r8%r9
0sys_readunsigned int fdchar *bufsize_t count
1sys_writeunsigned int fdconst char *bufsize_t count
2sys_openconst char *filenameint flagsint mode
3sys_closeunsigned int fd
4sys_statconst char *filenamestruct stat *statbuf
5sys_fstatunsigned int fdstruct stat *statbuf
6sys_lstatfconst char *filenamestruct stat *statbuf
7sys_pollstruct poll_fd *ufdsunsigned int nfdslong timeout_msecs
8sys_lseekunsigned int fdoff_t offsetunsigned int origin
9sys_mmapunsigned long addrunsigned long lenunsigned long protunsigned long flagsunsigned long fdunsigned long off
10sys_mprotectunsigned long startsize_t lenunsigned long prot
11sys_munmapunsigned long addrsize_t len
12sys_brkunsigned long brk
13sys_rt_sigactionint sigconst struct sigaction *actstruct sigaction *oactsize_t sigsetsize
14sys_rt_sigprocmaskint howsigset_t *nsetsigset_t *osetsize_t sigsetsize
15sys_rt_sigreturnunsigned long __unused
16sys_ioctlunsigned int fdunsigned int cmdunsigned long arg
17sys_pread64unsigned long fdchar *bufsize_t countloff_t pos
18sys_pwrite64unsigned int fdconst char *bufsize_t countloff_t pos
19sys_readvunsigned long fdconst struct iovec *vecunsigned long vlen
20sys_writevunsigned long fdconst struct iovec *vecunsigned long vlen
21sys_accessconst char *filenameint mode
22sys_pipeint *filedes
23sys_selectint nfd_set *inpfd_set *outpfd_set*expstruct timeval *tvp
24sys_sched_yield
25sys_mremapunsigned long addrunsigned long old_lenunsigned long new_lenunsigned long flagsunsigned long new_addr
26sys_msyncunsigned long startsize_t lenint flags
27sys_mincoreunsigned long startsize_t lenunsigned char *vec
28sys_madviseunsigned long startsize_t len_inint behavior
29sys_shmgetkey_t keysize_t sizeint shmflg
30sys_shmatint shmidchar *shmaddrint shmflg
31sys_shmctlint shmidint cmdstruct shmid_ds *buf
32sys_dupunsigned int fildes
33sys_dup2unsigned int oldfdunsigned int newfd
34sys_pause
35sys_nanosleepstruct timespec *rqtpstruct timespec *rmtp
36sys_getitimerint whichstruct itimerval *value
37sys_alarmunsigned int seconds
38sys_setitimerint whichstruct itimerval *valuestruct itimerval *ovalue
39sys_getpid
40sys_sendfileint out_fdint in_fdoff_t *offsetsize_t count
41sys_socketint familyint typeint protocol
42sys_connectint fdstruct sockaddr *uservaddrint addrlen
43sys_acceptint fdstruct sockaddr *upeer_sockaddrint *upeer_addrlen
44sys_sendtoint fdvoid *buffsize_t lenunsigned flagsstruct sockaddr *addrint addr_len
45sys_recvfromint fdvoid *ubufsize_t sizeunsigned flagsstruct sockaddr *addrint *addr_len
46sys_sendmsgint fdstruct msghdr *msgunsigned flags
47sys_recvmsgint fdstruct msghdr *msgunsigned int flags
48sys_shutdownint fdint how
49sys_bindint fdstruct sokaddr *umyaddrint addrlen
50sys_listenint fdint backlog
51sys_getsocknameint fdstruct sockaddr *usockaddrint *usockaddr_len
52sys_getpeernameint fdstruct sockaddr *usockaddrint *usockaddr_len
53sys_socketpairint familyint typeint protocolint *usockvec
54sys_setsockoptint fdint levelint optnamechar *optvalint optlen
55sys_getsockoptint fdint levelint optnamechar *optvalint *optlen
56sys_cloneunsigned long clone_flagsunsigned long newspvoid *parent_tidvoid *child_tid
57sys_fork
58sys_vfork
59sys_execveconst char *filenameconst char *const argv[]const char *const envp[]
60sys_exitint error_code
61sys_wait4pid_t upidint *stat_addrint optionsstruct rusage *ru
62sys_killpid_t pidint sig
63sys_unamestruct old_utsname *name
64sys_semgetkey_t keyint nsemsint semflg
65sys_semopint semidstruct sembuf *tsopsunsigned nsops
66sys_semctlint semidint semnumint cmdunion semun arg
67sys_shmdtchar *shmaddr
68sys_msggetkey_t keyint msgflg
69sys_msgsndint msqidstruct msgbuf *msgpsize_t msgszint msgflg
70sys_msgrcvint msqidstruct msgbuf *msgpsize_t msgszlong msgtypint msgflg
71sys_msgctlint msqidint cmdstruct msqid_ds *buf
72sys_fcntlunsigned int fdunsigned int cmdunsigned long arg
73sys_flockunsigned int fdunsigned int cmd
74sys_fsyncunsigned int fd
75sys_fdatasyncunsigned int fd
76sys_truncateconst char *pathlong length
77sys_ftruncateunsigned int fdunsigned long length
78sys_getdentsunsigned int fdstruct linux_dirent *direntunsigned int count
79sys_getcwdchar *bufunsigned long size
80sys_chdirconst char *filename
81sys_fchdirunsigned int fd
82sys_renameconst char *oldnameconst char *newname
83sys_mkdirconst char *pathnameint mode
84sys_rmdirconst char *pathname
85sys_creatconst char *pathnameint mode
86sys_linkconst char *oldnameconst char *newname
87sys_unlinkconst char *pathname
88sys_symlinkconst char *oldnameconst char *newname
89sys_readlinkconst char *pathchar *bufint bufsiz
90sys_chmodconst char *filenamemode_t mode
91sys_fchmodunsigned int fdmode_t mode
92sys_chownconst char *filenameuid_t usergit_t group
93sys_fchownunsigned int fduid_t usergit_t group
94sys_lchownconst char *filenameuid_t usergit_t group
95sys_umaskint mask
96sys_gettimeofdaystruct timeval *tvstruct timezone *tz
97sys_getrlimitunsigned int resourcestruct rlimit *rlim
98sys_getrusageint whostruct rusage *ru
99sys_sysinfostruct sysinfo *info
100sys_timesstruct sysinfo *info
101sys_ptracelong requestlong pidunsigned long addrunsigned long data
102sys_getuid
103sys_syslogint typechar *bufint len
104sys_getgid
105sys_setuiduid_t uid
106sys_setgidgit_t gid
107sys_geteuid
108sys_getegid
109sys_setpgidpid_t pidpid_t pgid
110sys_getppid
111sys_getpgrp
112sys_setsid
113sys_setreuiduid_t ruiduid_t euid
114sys_setregidgit_t rgidgid_t egid
115sys_getgroupsint gidsetsizegid_t *grouplist
116sys_setgroupsint gidsetsizegid_t *grouplist
117sys_setresuiduid_t *ruiduid_t *euiduid_t *suid
118sys_getresuiduid_t *ruiduid_t *euiduid_t *suid
119sys_setresgidgid_t rgidgid_t egidgid_t sgid
120sys_getresgidgit_t *rgidgit_t *egidgit_t *sgid
121sys_getpgidpid_t pid
122sys_setfsuiduid_t uid
123sys_setfsgidgid_t gid
124sys_getsidpid_t pid
125sys_capgetcap_user_header_t headercap_user_data_t dataptr
126sys_capsetcap_user_header_t headerconst cap_user_data_t data
127sys_rt_sigpendingsigset_t *setsize_t sigsetsize
128sys_rt_sigtimedwaitconst sigset_t *uthesesiginfo_t *uinfoconst struct timespec *utssize_t sigsetsize
129sys_rt_sigqueueinfopid_t pidint sigsiginfo_t *uinfo
130sys_rt_sigsuspendsigset_t *unewsetsize_t sigsetsize
131sys_sigaltstackconst stack_t *ussstack_t *uoss
132sys_utimechar *filenamestruct utimbuf *times
133sys_mknodconst char *filenameint modeunsigned dev
134sys_uselibNOT IMPLEMENTED
135sys_personalityunsigned int personality
136sys_ustatunsigned devstruct ustat *ubuf
137sys_statfsconst char *pathnamestruct statfs *buf
138sys_fstatfsunsigned int fdstruct statfs *buf
139sys_sysfsint optionunsigned long arg1unsigned long arg2
140sys_getpriorityint whichint who
141sys_setpriorityint whichint whoint niceval
142sys_sched_setparampid_t pidstruct sched_param *param
143sys_sched_getparampid_t pidstruct sched_param *param
144sys_sched_setschedulerpid_t pidint policystruct sched_param *param
145sys_sched_getschedulerpid_t pid
146sys_sched_get_priority_maxint policy
147sys_sched_get_priority_minint policy
148sys_sched_rr_get_intervalpid_t pidstruct timespec *interval
149sys_mlockunsigned long startsize_t len
150sys_munlockunsigned long startsize_t len
151sys_mlockallint flags
152sys_munlockall
153sys_vhangup
154sys_modify_ldtint funcvoid *ptrunsigned long bytecount
155sys_pivot_rootconst char *new_rootconst char *put_old
156sys__sysctlstruct __sysctl_args *args
157sys_prctlint optionunsigned long arg2unsigned long arg3unsigned long arg4unsigned long arg5
158sys_arch_prctlstruct task_struct *taskint codeunsigned long *addr
159sys_adjtimexstruct timex *txc_p
160sys_setrlimitunsigned int resourcestruct rlimit *rlim
161sys_chrootconst char *filename
162sys_sync
163sys_acctconst char *name
164sys_settimeofdaystruct timeval *tvstruct timezone *tz
165sys_mountchar *dev_namechar *dir_namechar *typeunsigned long flagsvoid *data
166sys_umount2const char *targetint flags
167sys_swaponconst char *specialfileint swap_flags
168sys_swapoffconst char *specialfile
169sys_rebootint magic1int magic2unsigned int cmdvoid *arg
170sys_sethostnamechar *nameint len
171sys_setdomainnamechar *nameint len
172sys_ioplunsigned int levelstruct pt_regs *regs
173sys_iopermunsigned long fromunsigned long numint turn_on
174sys_create_moduleREMOVED IN Linux 2.6
175sys_init_modulevoid *umodunsigned long lenconst char *uargs
176sys_delete_moduleconst chat *name_userunsigned int flags
177sys_get_kernel_symsREMOVED IN Linux 2.6
178sys_query_moduleREMOVED IN Linux 2.6
179sys_quotactlunsigned int cmdconst char *specialqid_t idvoid *addr
180sys_nfsservctlNOT IMPLEMENTED
181sys_getpmsgNOT IMPLEMENTED
182sys_putpmsgNOT IMPLEMENTED
183sys_afs_syscallNOT IMPLEMENTED
184sys_tuxcallNOT IMPLEMENTED
185sys_securityNOT IMPLEMENTED
186sys_gettid
187sys_readaheadint fdloff_t offsetsize_t count
188sys_setxattrconst char *pathnameconst char *nameconst void *valuesize_t sizeint flags
189sys_lsetxattrconst char *pathnameconst char *nameconst void *valuesize_t sizeint flags
190sys_fsetxattrint fdconst char *nameconst void *valuesize_t sizeint flags
191sys_getxattrconst char *pathnameconst char *namevoid *valuesize_t size
192sys_lgetxattrconst char *pathnameconst char *namevoid *valuesize_t size
193sys_fgetxattrint fdconst har *namevoid *valuesize_t size
194sys_listxattrconst char *pathnamechar *listsize_t size
195sys_llistxattrconst char *pathnamechar *listsize_t size
196sys_flistxattrint fdchar *listsize_t size
197sys_removexattrconst char *pathnameconst char *name
198sys_lremovexattrconst char *pathnameconst char *name
199sys_fremovexattrint fdconst char *name
200sys_tkillpid_t piding sig
201sys_timetime_t *tloc
202sys_futexu32 *uaddrint opu32 valstruct timespec *utimeu32 *uaddr2u32 val3
203sys_sched_setaffinitypid_t pidunsigned int lenunsigned long *user_mask_ptr
204sys_sched_getaffinitypid_t pidunsigned int lenunsigned long *user_mask_ptr
205sys_set_thread_areaNOT IMPLEMENTED. Use arch_prctl
206sys_io_setupunsigned nr_eventsaio_context_t *ctxp
207sys_io_destroyaio_context_t ctx
208sys_io_geteventsaio_context_t ctx_idlong min_nrlong nrstruct io_event *events
209sys_io_submitaio_context_t ctx_idlong nrstruct iocb **iocbpp
210sys_io_cancelaio_context_t ctx_idstruct iocb *iocbstruct io_event *result
211sys_get_thread_areaNOT IMPLEMENTED. Use arch_prctl
212sys_lookup_dcookieu64 cookie64long buflong len
213sys_epoll_createint size
214sys_epoll_ctl_oldNOT IMPLEMENTED
215sys_epoll_wait_oldNOT IMPLEMENTED
216sys_remap_file_pagesunsigned long startunsigned long sizeunsigned long protunsigned long pgoffunsigned long flags
217sys_getdents64unsigned int fdstruct linux_dirent64 *direntunsigned int count
218sys_set_tid_addressint *tidptr
219sys_restart_syscall
220sys_semtimedopint semidstruct sembuf *tsopsunsigned nsopsconst struct timespec *timeout
221sys_fadvise64int fdloff_t offsetsize_t lenint advice
222sys_timer_createconst clockid_t which_clockstruct sigevent *timer_event_spectimer_t *created_timer_id
223sys_timer_settimetimer_t timer_idint flagsconst struct itimerspec *new_settingstruct itimerspec *old_setting
224sys_timer_gettimetimer_t timer_idstruct itimerspec *setting
225sys_timer_getoverruntimer_t timer_id
226sys_timer_deletetimer_t timer_id
227sys_clock_settimeconst clockid_t which_clockconst struct timespec *tp
228sys_clock_gettimeconst clockid_t which_clockstruct timespec *tp
229sys_clock_getresconst clockid_t which_clockstruct timespec *tp
230sys_clock_nanosleepconst clockid_t which_clockint flagsconst struct timespec *rqtpstruct timespec *rmtp
231sys_exit_groupint error_code
232sys_epoll_waitint epfdstruct epoll_event *eventsint maxeventsint timeout
233sys_epoll_ctlint epfdint opint fdstruct epoll_event *event
234sys_tgkillpid_t tgidpid_t pidint sig
235sys_utimeschar *filenamestruct timeval *utimes
236sys_vserverNOT IMPLEMENTED
237sys_mbindunsigned long startunsigned long lenunsigned long modeunsigned long *nmaskunsigned long maxnodeunsigned flags
238sys_set_mempolicyint modeunsigned long *nmaskunsigned long maxnode
239sys_get_mempolicyint *policyunsigned long *nmaskunsigned long maxnodeunsigned long addrunsigned long flags
240sys_mq_openconst char *u_nameint oflagmode_t modestruct mq_attr *u_attr
241sys_mq_unlinkconst char *u_name
242sys_mq_timedsendmqd_t mqdesconst char *u_msg_ptrsize_t msg_lenunsigned int msg_prioconst stuct timespec *u_abs_timeout
243sys_mq_timedreceivemqd_t mqdeschar *u_msg_ptrsize_t msg_lenunsigned int *u_msg_prioconst struct timespec *u_abs_timeout
244sys_mq_notifymqd_t mqdesconst struct sigevent *u_notification
245sys_mq_getsetattrmqd_t mqdesconst struct mq_attr *u_mqstatstruct mq_attr *u_omqstat
246sys_kexec_loadunsigned long entryunsigned long nr_segmentsstruct kexec_segment *segmentsunsigned long flags
247sys_waitidint whichpid_t upidstruct siginfo *infopint optionsstruct rusage *ru
248sys_add_keyconst char *_typeconst char *_descriptionconst void *_payloadsize_t plen
249sys_request_keyconst char *_typeconst char *_descriptionconst char *_callout_infokey_serial_t destringid
250sys_keyctlint optionunsigned long arg2unsigned long arg3unsigned long arg4unsigned long arg5
251sys_ioprio_setint whichint whoint ioprio
252sys_ioprio_getint whichint who
253sys_inotify_init
254sys_inotify_add_watchint fdconst char *pathnameu32 mask
255sys_inotify_rm_watchint fd__s32 wd
256sys_migrate_pagespid_t pidunsigned long maxnodeconst unsigned long *old_nodesconst unsigned long *new_nodes
257sys_openatint dfdconst char *filenameint flagsint mode
258sys_mkdiratint dfdconst char *pathnameint mode
259sys_mknodatint dfdconst char *filenameint modeunsigned dev
260sys_fchownatint dfdconst char *filenameuid_t usergid_t groupint flag
261sys_futimesatint dfdconst char *filenamestruct timeval *utimes
262sys_newfstatatint dfdconst char *filenamestruct stat *statbufint flag
263sys_unlinkatint dfdconst char *pathnameint flag
264sys_renameatint oldfdconst char *oldnameint newfdconst char *newname
265sys_linkatint oldfdconst char *oldnameint newfdconst char *newnameint flags
266sys_symlinkatconst char *oldnameint newfdconst char *newname
267sys_readlinkatint dfdconst char *pathnamechar *bufint bufsiz
268sys_fchmodatint dfdconst char *filenamemode_t mode
269sys_faccessatint dfdconst char *filenameint mode
270sys_pselect6int nfd_set *inpfd_set *outpfd_set *expstruct timespec *tspvoid *sig
271sys_ppollstruct pollfd *ufdsunsigned int nfdsstruct timespec *tspconst sigset_t *sigmasksize_t sigsetsize
272sys_unshareunsigned long unshare_flags
273sys_set_robust_liststruct robust_list_head *headsize_t len
274sys_get_robust_listint pidstruct robust_list_head **head_ptrsize_t *len_ptr
275sys_spliceint fd_inloff_t *off_inint fd_outloff_t *off_outsize_t lenunsigned int flags
276sys_teeint fdinint fdoutsize_t lenunsigned int flags
277sys_sync_file_rangelong fdloff_t offsetloff_t byteslong flags
278sys_vmspliceint fdconst struct iovec *iovunsigned long nr_segsunsigned int flags
279sys_move_pagespid_t pidunsigned long nr_pagesconst void **pagesconst int *nodesint *statusint flags
280sys_utimensatint dfdconst char *filenamestruct timespec *utimesint flags
281sys_epoll_pwaitint epfdstruct epoll_event *eventsint maxeventsint timeoutconst sigset_t *sigmasksize_t sigsetsize
282sys_signalfdint ufdsigset_t *user_masksize_t sizemask
283sys_timerfd_createint clockidint flags
284sys_eventfdunsigned int count
285sys_fallocatelong fdlong modeloff_t offsetloff_t len
286sys_timerfd_settimeint ufdint flagsconst struct itimerspec *utmrstruct itimerspec *otmr
287sys_timerfd_gettimeint ufdstruct itimerspec *otmr
288sys_accept4int fdstruct sockaddr *upeer_sockaddrint *upeer_addrlenint flags
289sys_signalfd4int ufdsigset_t *user_masksize_t sizemaskint flags
290sys_eventfd2unsigned int countint flags
291sys_epoll_create1int flags
292sys_dup3unsigned int oldfdunsigned int newfdint flags
293sys_pipe2int *filedesint flags
294sys_inotify_init1int flags
295sys_preadvunsigned long fdconst struct iovec *vecunsigned long vlenunsigned long pos_lunsigned long pos_h
296sys_pwritevunsigned long fdconst struct iovec *vecunsigned long vlenunsigned long pos_lunsigned long pos_h
297sys_rt_tgsigqueueinfopid_t tgidpid_t pidint sigsiginfo_t *uinfo
298sys_perf_event_openstruct perf_event_attr *attr_uptrpid_t pidint cpuint group_fdunsigned long flags
299sys_recvmmsgint fdstruct msghdr *mmsgunsigned int vlenunsigned int flagsstruct timespec *timeout
300sys_fanotify_initunsigned int flagsunsigned int event_f_flags
301sys_fanotify_marklong fanotify_fdlong flags__u64 masklong dfdlong pathname
302sys_prlimit64pid_t pidunsigned int resourceconst struct rlimit64 *new_rlimstruct rlimit64 *old_rlim
303sys_name_to_handle_atint dfdconst char *namestruct file_handle *handleint *mnt_idint flag
304sys_open_by_handle_atint dfdconst char *namestruct file_handle *handleint *mnt_idint flags
305sys_clock_adjtimeclockid_t which_clockstruct timex *tx
306sys_syncfsint fd
307sys_sendmmsgint fdstruct mmsghdr *mmsgunsigned int vlenunsigned int flags
308sys_setnsint fdint nstype
309sys_getcpuunsigned *cpupunsigned *nodepstruct getcpu_cache *unused
310sys_process_vm_readvpid_t pidconst struct iovec *lvecunsigned long liovcntconst struct iovec *rvecunsigned long riovcntunsigned long flags
311sys_process_vm_writevpid_t pidconst struct iovec *lvecunsigned long liovcntconst struct iovcc *rvecunsigned long riovcntunsigned long flags
312sys_kcmppid_t pid1pid_t pid2int typeunsigned long idx1unsigned long idx2
313sys_finit_moduleint fdconst char __user *uargsint flags
314sys_sched_setattrpid_t pidstruct sched_attr __user *attrunsigned int flags
315sys_sched_getattrpid_t pidstruct sched_attr __user *attrunsigned int sizeunsigned int flags
316sys_renameat2int olddfdconst char __user *oldnameint newdfd, const char __user *newnameunsigned int flags
317sys_seccompunsigned int opunsigned int flagsconst char __user *uargs
318sys_getrandomchar __user *bufsize_t countunsigned int flags
319sys_memfd_createconst char __user *uname_ptrunsigned +int flags
320sys_kexec_file_loadint kernel_fdint initrd_fdunsigned long cmdline_lenconst char __user *cmdline_ptrunsigned long flags
321sys_bpfint cmdunion bpf_attr *attrunsigned int size
322stub_execveatint dfdconst char __user *filenameconst char __user *const __user *argvconst char __user *const __user *envpint flags
\ No newline at end of file diff --git a/gears/services/devfile/sys_point_arr.h b/gears/services/devfile/sys_point_arr.h new file mode 100644 index 0000000..736a868 --- /dev/null +++ b/gears/services/devfile/sys_point_arr.h @@ -0,0 +1,343 @@ +/* + Device File Virtualization Guest Preload Library Helpers + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + +*/ + +/* + This is a mapping between system call number (64 bit Linux) + and a bit vector whose set bits indicate which of the arguments + to the givien system call are pointer arguments, and thus need + to be swizzled by the devfile implementation. + +*/ + +long long sys_pointer_arr[323] = { +2, +2, +1, +0, +3, +2, +3, +1, +0, +0, +0, +0, +0, +6, +6, +0, +4, +2, +2, +2, +2, +1, +1, +30, +0, +0, +0, +4, +0, +0, +2, +4, +0, +0, +0, +3, +2, +0, +6, +0, +4, +0, +2, +6, +18, +50, +2, +2, +0, +2, +0, +6, +6, +8, +8, +24, +12, +0, +0, +7, +0, +10, +0, +1, +0, +2, +0, +1, +0, +2, +2, +4, +0, +0, +0, +0, +1, +0, +2, +1, +1, +0, +3, +1, +1, +1, +3, +1, +3, +3, +1, +0, +1, +0, +1, +0, +3, +2, +2, +1, +1, +0, +0, +2, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +0, +2, +2, +7, +7, +0, +7, +0, +0, +0, +0, +0, +0, +1, +7, +4, +1, +3, +3, +1, +0, +0, +2, +3, +2, +0, +0, +0, +2, +2, +4, +0, +0, +0, +2, +0, +0, +0, +0, +0, +2, +3, +1, +0, +5, +1, +2, +1, +0, +1, +3, +23, +1, +1, +1, +8, +1, +1, +2, +0, +0, +5, +1, +0, +0, +10, +0, +0, +0, +0, +0, +0, +0, +0, +7, +7, +6, +7, +7, +6, +3, +3, +2, +3, +3, +2, +0, +1, +25, +4, +4, +0, +2, +0, +8, +4, +6, +0, +0, +0, +0, +0, +0, +2, +1, +0, +10, +0, +6, +12, +2, +0, +0, +2, +2, +2, +12, +0, +2, +8, +0, +3, +0, +8, +2, +3, +9, +1, +18, +26, +2, +6, +4, +20, +7, +7, +0, +0, +0, +0, +2, +0, +12, +2, +2, +2, +2, +6, +6, +2, +10, +10, +5, +6, +2, +2, +62, +13, +0, +1, +6, +10, +0, +0, +2, +28, +6, +18, +2, +0, +0, +0, +12, +2, +6, +2, +0, +0, +0, +1, +0, +2, +2, +8, +1, +18, +0, +0, +12, +14, +14, +2, +0, +2, +0, +7, +10, +10, +0, +2, +2, +2, +6, +4, +1, +1, +8, +2, +14 +}; + diff --git a/gears/services/devfile/syscall_ref.h b/gears/services/devfile/syscall_ref.h new file mode 100644 index 0000000..ff96801 --- /dev/null +++ b/gears/services/devfile/syscall_ref.h @@ -0,0 +1,663 @@ +/* + * 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 + * Copyright (c) 2011, The V3VEE Project + * All rights reserved. + * + * Author: Kyle C. Hale + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __SYSCALL_REF_H__ +#define __SYSCALL_REF_H__ + + + +/* 32bit syscalls */ +#define SYS32_RESTART_SYSCALL 0 +#define SYS32_EXIT 1 +#define SYS32_FORK 2 +#define SYS32_READ 3 +#define SYS32_WRITE 4 +#define SYS32_OPEN 5 +#define SYS32_CLOSE 6 +#define SYS32_WAITPID 7 +#define SYS32_CREAT 8 +#define SYS32_LINK 9 +#define SYS32_UNLINK 10 +#define SYS32_EXECVE 11 +#define SYS32_CHDIR 12 +#define SYS32_TIME 13 +#define SYS32_MKNOD 14 +#define SYS32_CHMOD 15 +#define SYS32_LCHOWN 16 +#define SYS32_BREAK 17 +#define SYS32_OLDSTAT 18 +#define SYS32_LSEEK 19 +#define SYS32_GETPID 20 +#define SYS32_MOUNT 21 +#define SYS32_UMOUNT 22 +#define SYS32_SETUID 23 +#define SYS32_GETUID 24 +#define SYS32_STIME 25 +#define SYS32_PTRACE 26 +#define SYS32_ALARM 27 +#define SYS32_OLDFSTAT 28 +#define SYS32_PAUSE 29 +#define SYS32_UTIME 30 +#define SYS32_STTY 31 +#define SYS32_GTTY 32 +#define SYS32_ACCESS 33 +#define SYS32_NICE 34 +#define SYS32_FTIME 35 +#define SYS32_SYNC 36 +#define SYS32_KILL 37 +#define SYS32_RENAME 38 +#define SYS32_MKDIR 39 +#define SYS32_RMDIR 40 +#define SYS32_DUP 41 +#define SYS32_PIPE 42 +#define SYS32_TIMES 43 +#define SYS32_PROF 44 +#define SYS32_BRK 45 +#define SYS32_SETGID 46 +#define SYS32_GETGID 47 +#define SYS32_SIGNAL 48 +#define SYS32_GETEUID 49 +#define SYS32_GETEGID 50 +#define SYS32_ACCT 51 +#define SYS32_UMOUNT2 52 +#define SYS32_LOCK 53 +#define SYS32_IOCTL 54 +#define SYS32_FCNTL 55 +#define SYS32_MPX 56 +#define SYS32_SETPGID 57 +#define SYS32_ULIMIT 58 +#define SYS32_OLDOLDUNAME 59 +#define SYS32_UMASK 60 +#define SYS32_CHROOT 61 +#define SYS32_USTAT 62 +#define SYS32_DUP2 63 +#define SYS32_GETPPID 64 +#define SYS32_GETPGRP 65 +#define SYS32_SETSID 66 +#define SYS32_SIGACTION 67 +#define SYS32_SGETMASK 68 +#define SYS32_SSETMASK 69 +#define SYS32_SETREUID 70 +#define SYS32_SETREGID 71 +#define SYS32_SIGSUSPEND 72 +#define SYS32_SIGPENDING 73 +#define SYS32_SETHOSTNAME 74 +#define SYS32_SETRLIMIT 75 +#define SYS32_GETRLIMIT 76 +#define SYS32_GETRUSAGE 77 +#define SYS32_GETTIMEOFDAY 78 +#define SYS32_SETTIMEOFDAY 79 +#define SYS32_GETGROUPS 80 +#define SYS32_SETGROUPS 81 +#define SYS32_SELECT 82 +#define SYS32_SYMLINK 83 +#define SYS32_OLDLSTAT 84 +#define SYS32_READLINK 85 +#define SYS32_USELIB 86 +#define SYS32_SWAPON 87 +#define SYS32_REBOOT 88 +#define SYS32_READDIR 89 +#define SYS32_MMAP 90 +#define SYS32_MUNMAP 91 +#define SYS32_TRUNCATE 92 +#define SYS32_FTRUNCATE 93 +#define SYS32_FCHMOD 94 +#define SYS32_FCHOWN 95 +#define SYS32_GETPRIORITY 96 +#define SYS32_SETPRIORITY 97 +#define SYS32_PROFIL 98 +#define SYS32_STATFS 99 +#define SYS32_FSTATFS 100 +#define SYS32_IOPERM 101 +#define SYS32_SOCKETCALL 102 +#define SYS32_SYSLOG 103 +#define SYS32_SETITIMER 104 +#define SYS32_GETITIMER 105 +#define SYS32_STAT 106 +#define SYS32_LSTAT 107 +#define SYS32_FSTAT 108 +#define SYS32_OLDUNAME 109 +#define SYS32_IOPL 110 +#define SYS32_VHANGUP 111 +#define SYS32_IDLE 112 +#define SYS32_VM86OLD 113 +#define SYS32_WAIT4 114 +#define SYS32_SWAPOFF 115 +#define SYS32_SYSINFO 116 +#define SYS32_IPC 117 +#define SYS32_FSYNC 118 +#define SYS32_SIGRETURN 119 +#define SYS32_CLONE 120 +#define SYS32_SETDOMAINNAME 121 +#define SYS32_UNAME 122 +#define SYS32_MODIFY_LDT 123 +#define SYS32_ADJTIMEX 124 +#define SYS32_MPROTECT 125 +#define SYS32_SIGPROCMASK 126 +#define SYS32_CREATE_MODULE 127 +#define SYS32_INIT_MODULE 128 +#define SYS32_DELETE_MODULE 129 +#define SYS32_GET_KERNEL_SYMS 130 +#define SYS32_QUOTACTL 131 +#define SYS32_GETPGID 132 +#define SYS32_FCHDIR 133 +#define SYS32_BDFLUSH 134 +#define SYS32_SYSFS 135 +#define SYS32_PERSONALITY 136 +#define SYS32_AFS_SYSCALL 137 +#define SYS32_SETFSUID 138 +#define SYS32_SETFSGID 139 +#define SYS32__LLSEEK 140 +#define SYS32_GETDENTS 141 +#define SYS32__NEWSELECT 142 +#define SYS32_FLOCK 143 +#define SYS32_MSYNC 144 +#define SYS32_READV 145 +#define SYS32_WRITEV 146 +#define SYS32_GETSID 147 +#define SYS32_FDATASYNC 148 +#define SYS32__SYSCTL 149 +#define SYS32_MLOCK 150 +#define SYS32_MUNLOCK 151 +#define SYS32_MLOCKALL 152 +#define SYS32_MUNLOCKALL 153 +#define SYS32_SCHED_SETPARAM 154 +#define SYS32_SCHED_GETPARAM 155 +#define SYS32_SCHED_SETSCHEDULER 156 +#define SYS32_SCHED_GETSCHEDULER 157 +#define SYS32_SCHED_YIELD 158 +#define SYS32_SCHED_GET_PRIORITY_MAX 159 +#define SYS32_SCHED_GET_PRIORITY_MIN 160 +#define SYS32_SCHED_RR_GET_INTERVAL 161 +#define SYS32_NANOSLEEP 162 +#define SYS32_MREMAP 163 +#define SYS32_SETRESUID 164 +#define SYS32_GETRESUID 165 +#define SYS32_VM86 166 +#define SYS32_QUERY_MODULE 167 +#define SYS32_POLL 168 +#define SYS32_NFSSERVCTL 169 +#define SYS32_SETRESGID 170 +#define SYS32_GETRESGID 171 +#define SYS32_PRCTL 172 +#define SYS32_RT_SIGRETURN 173 +#define SYS32_RT_SIGACTION 174 +#define SYS32_RT_SIGPROCMASK 175 +#define SYS32_RT_SIGPENDING 176 +#define SYS32_RT_SIGTIMEDWAIT 177 +#define SYS32_RT_SIGQUEUEINFO 178 +#define SYS32_RT_SIGSUSPEND 179 +#define SYS32_PREAD64 180 +#define SYS32_PWRITE64 181 +#define SYS32_CHOWN 182 +#define SYS32_GETCWD 183 +#define SYS32_CAPGET 184 +#define SYS32_CAPSET 185 +#define SYS32_SIGALTSTACK 186 +#define SYS32_SENDFILE 187 +#define SYS32_GETPMSG 188 +#define SYS32_PUTPMSG 189 +#define SYS32_VFORK 190 +#define SYS32_UGETRLIMIT 191 +#define SYS32_MMAP2 192 +#define SYS32_TRUNCATE64 193 +#define SYS32_FTRUNCATE64 194 +#define SYS32_STAT64 195 +#define SYS32_LSTAT64 196 +#define SYS32_FSTAT64 197 +#define SYS32_LCHOWN32 198 +#define SYS32_GETUID32 199 +#define SYS32_GETGID32 200 +#define SYS32_GETEUID32 201 +#define SYS32_GETEGID32 202 +#define SYS32_SETREUID32 203 +#define SYS32_SETREGID32 204 +#define SYS32_GETGROUPS32 205 +#define SYS32_SETGROUPS32 206 +#define SYS32_FCHOWN32 207 +#define SYS32_SETRESUID32 208 +#define SYS32_GETRESUID32 209 +#define SYS32_SETRESGID32 210 +#define SYS32_GETRESGID32 211 +#define SYS32_CHOWN32 212 +#define SYS32_SETUID32 213 +#define SYS32_SETGID32 214 +#define SYS32_SETFSUID32 215 +#define SYS32_SETFSGID32 216 +#define SYS32_PIVOT_ROOT 217 +#define SYS32_MINCORE 218 +#define SYS32_MADVISE1 219 +#define SYS32_GETDENTS64 220 +#define SYS32_FCNTL64 221 +#define SYS32_GETTID 224 +#define SYS32_READAHEAD 225 +#define SYS32_SETXATTR 226 +#define SYS32_LSETXATTR 227 +#define SYS32_FSETXATTR 228 +#define SYS32_GETXATTR 229 +#define SYS32_LGETXATTR 230 +#define SYS32_FGETXATTR 231 +#define SYS32_LISTXATTR 232 +#define SYS32_LLISTXATTR 233 +#define SYS32_FLISTXATTR 234 +#define SYS32_REMOVEXATTR 235 +#define SYS32_LREMOVEXATTR 236 +#define SYS32_FREMOVEXATTR 237 +#define SYS32_TKILL 238 +#define SYS32_SENDFILE64 239 +#define SYS32_FUTEX 240 +#define SYS32_SCHED_SETAFFINITY 241 +#define SYS32_SCHED_GETAFFINITY 242 +#define SYS32_SET_THREAD_AREA 243 +#define SYS32_GET_THREAD_AREA 244 +#define SYS32_IO_SETUP 245 +#define SYS32_IO_DESTROY 246 +#define SYS32_IO_GETEVENTS 247 +#define SYS32_IO_SUBMIT 248 +#define SYS32_IO_CANCEL 249 +#define SYS32_FADVISE64 250 +#define SYS32_EXIT_GROUP 252 +#define SYS32_LOOKUP_DCOOKIE 253 +#define SYS32_EPOLL_CREATE 254 +#define SYS32_EPOLL_CTL 255 +#define SYS32_EPOLL_WAIT 256 +#define SYS32_REMAP_FILE_PAGES 257 +#define SYS32_SET_TID_ADDRESS 258 +#define SYS32_TIMER_CREATE 259 +#define SYS32_TIMER_SETTIME 260 +#define SYS32_TIMER_GETTIME 261 +#define SYS32_TIMER_GETOVERRUN 262 +#define SYS32_TIMER_DELETE 263 +#define SYS32_CLOCK_SETTIME 264 +#define SYS32_CLOCK_GETTIME 265 +#define SYS32_CLOCK_GETRES 266 +#define SYS32_CLOCK_NANOSLEEP 267 +#define SYS32_STATFS64 268 +#define SYS32_FSTATFS64 269 +#define SYS32_TGKILL 270 +#define SYS32_UTIMES 271 +#define SYS32_FADVISE64_64 272 +#define SYS32_VSERVER 273 +#define SYS32_MBIND 274 +#define SYS32_GET_MEMPOLICY 275 +#define SYS32_SET_MEMPOLICY 276 +#define SYS32_MQ_OPEN 277 +#define SYS32_MQ_UNLINK 278 +#define SYS32_MQ_TIMEDSEND 279 +#define SYS32_MQ_TIMEDRECEIVE 280 +#define SYS32_MQ_NOTIFY 281 +#define SYS32_MQ_GETSETATTR 282 +#define SYS32_KEXEC_LOAD 283 +#define SYS32_WAITID 284 +#define SYS32_SYS32_SETALTROOT 285 +#define SYS32_ADD_KEY 286 +#define SYS32_REQUEST_KEY 287 +#define SYS32_KEYCTL 288 +#define SYS32_IOPRIO_SET 289 +#define SYS32_IOPRIO_GET 290 +#define SYS32_INOTIFY_INIT 291 +#define SYS32_INOTIFY_ADD_WATCH 292 +#define SYS32_INOTIFY_RM_WATCH 293 +#define SYS32_MIGRATE_PAGES 294 +#define SYS32_OPENAT 295 +#define SYS32_MKDIRAT 296 +#define SYS32_MKNODAT 297 +#define SYS32_FCHOWNAT 298 +#define SYS32_FUTIMESAT 299 +#define SYS32_FSTATAT64 300 +#define SYS32_UNLINKAT 301 +#define SYS32_RENAMEAT 302 +#define SYS32_LINKAT 303 +#define SYS32_SYMLINKAT 304 +#define SYS32_READLINKAT 305 +#define SYS32_FCHMODAT 306 +#define SYS32_FACCESSAT 307 +#define SYS32_PSELECT6 308 +#define SYS32_PPOLL 309 +#define SYS32_UNSHARE 310 +#define SYS32_SET_ROBUST_LIST 311 +#define SYS32_GET_ROBUST_LIST 312 +#define SYS32_SPLICE 313 +#define SYS32_SYNC_FILE_RANGE 314 +#define SYS32_TEE 315 +#define SYS32_VMSPLICE 316 +#define SYS32_MOVE_PAGES 317 +#define SYS32_GETCPU 318 +#define SYS32_EPOLL_PWAIT 319 +#define SYS32_UTIMENSAT 320 +#define SYS32_SIGNALFD 321 +#define SYS32_TIMERFD_CREATE 322 +#define SYS32_EVENTFD 323 +#define SYS32_FALLOCATE 324 +#define SYS32_TIMERFD_SETTIME 325 +#define SYS32_TIMERFD_GETTIME 326 +#define SYS32_SIGNALFD4 327 +#define SYS32_EVENTFD2 328 +#define SYS32_EPOLL_CREATE1 329 +#define SYS32_DUP3 330 +#define SYS32_PIPE2 331 +#define SYS32_INOTIFY_INIT1 332 +#define SYS32_PREADV 333 +#define SYS32_PWRITEV 334 +#define SYS32_RT_TGSIGQUEUEINFO 335 +#define SYS32_PERF_EVENT_OPEN 336 + +/* 64bit syscalls */ +#define SYS64_READ 0 +#define SYS64_WRITE 1 +#define SYS64_OPEN 2 +#define SYS64_CLOSE 3 +#define SYS64_STAT 4 +#define SYS64_FSTAT 5 +#define SYS64_LSTAT 6 +#define SYS64_POLL 7 +#define SYS64_LSEEK 8 +#define SYS64_MMAP 9 +#define SYS64_MPROTECT 10 +#define SYS64_MUNMAP 11 +#define SYS64_BRK 12 +#define SYS64_RT_SIGACTION 13 +#define SYS64_RT_SIGPROCMASK 14 +#define SYS64_RT_SIGRETURN 15 +#define SYS64_IOCTL 16 +#define SYS64_PREAD64 17 +#define SYS64_PWRITE64 18 +#define SYS64_READV 19 +#define SYS64_WRITEV 20 +#define SYS64_ACCESS 21 +#define SYS64_PIPE 22 +#define SYS64_SELECT 23 +#define SYS64_SCHED_YIELD 24 +#define SYS64_MREMAP 25 +#define SYS64_MSYNC 26 +#define SYS64_MINCORE 27 +#define SYS64_MADVISE 28 +#define SYS64_SHMGET 29 +#define SYS64_SHMAT 30 +#define SYS64_SHMCTL 31 +#define SYS64_DUP 32 +#define SYS64_DUP2 33 +#define SYS64_PAUSE 34 +#define SYS64_NANOSLEEP 35 +#define SYS64_GETITIMER 36 +#define SYS64_ALARM 37 +#define SYS64_SETITIMER 38 +#define SYS64_GETPID 39 +#define SYS64_SENDFILE 40 +#define SYS64_SOCKET 41 +#define SYS64_CONNECT 42 +#define SYS64_ACCEPT 43 +#define SYS64_SENDTO 44 +#define SYS64_RECVFROM 45 +#define SYS64_SENDMSG 46 +#define SYS64_RECVMSG 47 +#define SYS64_SHUTDOWN 48 +#define SYS64_BIND 49 +#define SYS64_LISTEN 50 +#define SYS64_GETSOCKNAME 51 +#define SYS64_GETPEERNAME 52 +#define SYS64_SOCKETPAIR 53 +#define SYS64_SETSOCKOPT 54 +#define SYS64_GETSOCKOPT 55 +#define SYS64_CLONE 56 +#define SYS64_FORK 57 +#define SYS64_VFORK 58 +#define SYS64_EXECVE 59 +#define SYS64_EXIT 60 +#define SYS64_WAIT4 61 +#define SYS64_KILL 62 +#define SYS64_UNAME 63 +#define SYS64_SEMGET 64 +#define SYS64_SEMOP 65 +#define SYS64_SEMCTL 66 +#define SYS64_SHMDT 67 +#define SYS64_MSGGET 68 +#define SYS64_MSGSND 69 +#define SYS64_MSGRCV 70 +#define SYS64_MSGCTL 71 +#define SYS64_FCNTL 72 +#define SYS64_FLOCK 73 +#define SYS64_FSYNC 74 +#define SYS64_FDATASYNC 75 +#define SYS64_TRUNCATE 76 +#define SYS64_FTRUNCATE 77 +#define SYS64_GETDENTS 78 +#define SYS64_GETCWD 79 +#define SYS64_CHDIR 80 +#define SYS64_FCHDIR 81 +#define SYS64_RENAME 82 +#define SYS64_MKDIR 83 +#define SYS64_RMDIR 84 +#define SYS64_CREAT 85 +#define SYS64_LINK 86 +#define SYS64_UNLINK 87 +#define SYS64_SYMLINK 88 +#define SYS64_READLINK 89 +#define SYS64_CHMOD 90 +#define SYS64_FCHMOD 91 +#define SYS64_CHOWN 92 +#define SYS64_FCHOWN 93 +#define SYS64_LCHOWN 94 +#define SYS64_UMASK 95 +#define SYS64_GETTIMEOFDAY 96 +#define SYS64_GETRLIMIT 97 +#define SYS64_GETRUSAGE 98 +#define SYS64_SYSINFO 99 +#define SYS64_TIMES 100 +#define SYS64_PTRACE 101 +#define SYS64_GETUID 102 +#define SYS64_SYSLOG 103 +#define SYS64_GETGID 104 +#define SYS64_SETUID 105 +#define SYS64_SETGID 106 +#define SYS64_GETEUID 107 +#define SYS64_GETEGID 108 +#define SYS64_SETPGID 109 +#define SYS64_GETPPID 110 +#define SYS64_GETPGRP 111 +#define SYS64_SETSID 112 +#define SYS64_SETREUID 113 +#define SYS64_SETREGID 114 +#define SYS64_GETGROUPS 115 +#define SYS64_SETGROUPS 116 +#define SYS64_SETRESUID 117 +#define SYS64_GETRESUID 118 +#define SYS64_SETRESGID 119 +#define SYS64_GETRESGID 120 +#define SYS64_GETPGID 121 +#define SYS64_SETFSUID 122 +#define SYS64_SETFSGID 123 +#define SYS64_GETSID 124 +#define SYS64_CAPGET 125 +#define SYS64_CAPSET 126 +#define SYS64_RT_SIGPENDING 127 +#define SYS64_RT_SIGTIMEDWAIT 128 +#define SYS64_RT_SIGQUEUEINFO 129 +#define SYS64_RT_SIGSUSPEND 130 +#define SYS64_SIGALTSTACK 131 +#define SYS64_UTIME 132 +#define SYS64_MKNOD 133 +#define SYS64_USELIB 134 +#define SYS64_PERSONALITY 135 +#define SYS64_USTAT 136 +#define SYS64_STATFS 137 +#define SYS64_FSTATFS 138 +#define SYS64_SYSFS 139 +#define SYS64_GETPRIORITY 140 +#define SYS64_SETPRIORITY 141 +#define SYS64_SCHED_SETPARAM 142 +#define SYS64_SCHED_GETPARAM 143 +#define SYS64_SCHED_SETSCHEDULER 144 +#define SYS64_SCHED_GETSCHEDULER 145 +#define SYS64_SCHED_GET_PRIORITY_MAX 146 +#define SYS64_SCHED_GET_PRIORITY_MIN 147 +#define SYS64_SCHED_RR_GET_INTERVAL 148 +#define SYS64_MLOCK 149 +#define SYS64_MUNLOCK 150 +#define SYS64_MLOCKALL 151 +#define SYS64_MUNLOCKALL 152 +#define SYS64_VHANGUP 153 +#define SYS64_MODIFY_LDT 154 +#define SYS64_PIVOT_ROOT 155 +#define SYS64__SYSCTL 156 +#define SYS64_PRCTL 157 +#define SYS64_ARCH_PRCTL 158 +#define SYS64_ADJTIMEX 159 +#define SYS64_SETRLIMIT 160 +#define SYS64_CHROOT 161 +#define SYS64_SYNC 162 +#define SYS64_ACCT 163 +#define SYS64_SETTIMEOFDAY 164 +#define SYS64_MOUNT 165 +#define SYS64_UMOUNT2 166 +#define SYS64_SWAPON 167 +#define SYS64_SWAPOFF 168 +#define SYS64_REBOOT 169 +#define SYS64_SETHOSTNAME 170 +#define SYS64_SETDOMAINNAME 171 +#define SYS64_IOPL 172 +#define SYS64_IOPERM 173 +#define SYS64_CREATE_MODULE 174 +#define SYS64_INIT_MODULE 175 +#define SYS64_DELETE_MODULE 176 +#define SYS64_GET_KERNEL_SYMS 177 +#define SYS64_QUERY_MODULE 178 +#define SYS64_QUOTACTL 179 +#define SYS64_NFSSERVCTL 180 +#define SYS64_GETPMSG 181 +#define SYS64_PUTPMSG 182 +#define SYS64_AFS_SYSCALL 183 +#define SYS64_TUXCALL 184 +#define SYS64_SECURITY 185 +#define SYS64_GETTID 186 +#define SYS64_READAHEAD 187 +#define SYS64_SETXATTR 188 +#define SYS64_LSETXATTR 189 +#define SYS64_FSETXATTR 190 +#define SYS64_GETXATTR 191 +#define SYS64_LGETXATTR 192 +#define SYS64_FGETXATTR 193 +#define SYS64_LISTXATTR 194 +#define SYS64_LLISTXATTR 195 +#define SYS64_FLISTXATTR 196 +#define SYS64_REMOVEXATTR 197 +#define SYS64_LREMOVEXATTR 198 +#define SYS64_FREMOVEXATTR 199 +#define SYS64_TKILL 200 +#define SYS64_TIME 201 +#define SYS64_FUTEX 202 +#define SYS64_SCHED_SETAFFINITY 203 +#define SYS64_SCHED_GETAFFINITY 204 +#define SYS64_SET_THREAD_AREA 205 +#define SYS64_IO_SETUP 206 +#define SYS64_IO_DESTROY 207 +#define SYS64_IO_GETEVENTS 208 +#define SYS64_IO_SUBMIT 209 +#define SYS64_IO_CANCEL 210 +#define SYS64_GET_THREAD_AREA 211 +#define SYS64_LOOKUP_DCOOKIE 212 +#define SYS64_EPOLL_CREATE 213 +#define SYS64_EPOLL_CTL_OLD 214 +#define SYS64_EPOLL_WAIT_OLD 215 +#define SYS64_REMAP_FILE_PAGES 216 +#define SYS64_GETDENTS64 217 +#define SYS64_SET_TID_ADDRESS 218 +#define SYS64_RESTART_SYSCALL 219 +#define SYS64_SEMTIMEDOP 220 +#define SYS64_FADVISE64 221 +#define SYS64_TIMER_CREATE 222 +#define SYS64_TIMER_SETTIME 223 +#define SYS64_TIMER_GETTIME 224 +#define SYS64_TIMER_GETOVERRUN 225 +#define SYS64_TIMER_DELETE 226 +#define SYS64_CLOCK_SETTIME 227 +#define SYS64_CLOCK_GETTIME 228 +#define SYS64_CLOCK_GETRES 229 +#define SYS64_CLOCK_NANOSLEEP 230 +#define SYS64_EXIT_GROUP 231 +#define SYS64_EPOLL_WAIT 232 +#define SYS64_EPOLL_CTL 233 +#define SYS64_TGKILL 234 +#define SYS64_UTIMES 235 +#define SYS64_VSERVER 236 +#define SYS64_MBIND 237 +#define SYS64_SET_MEMPOLICY 238 +#define SYS64_GET_MEMPOLICY 239 +#define SYS64_MQ_OPEN 240 +#define SYS64_MQ_UNLINK 241 +#define SYS64_MQ_TIMEDSEND 242 +#define SYS64_MQ_TIMEDRECEIVE 243 +#define SYS64_MQ_NOTIFY 244 +#define SYS64_MQ_GETSETATTR 245 +#define SYS64_KEXEC_LOAD 246 +#define SYS64_WAITID 247 +#define SYS64_ADD_KEY 248 +#define SYS64_REQUEST_KEY 249 +#define SYS64_KEYCTL 250 +#define SYS64_IOPRIO_SET 251 +#define SYS64_IOPRIO_GET 252 +#define SYS64_INOTIFY_INIT 253 +#define SYS64_INOTIFY_ADD_WATCH 254 +#define SYS64_INOTIFY_RM_WATCH 255 +#define SYS64_MIGRATE_PAGES 256 +#define SYS64_OPENAT 257 +#define SYS64_MKDIRAT 258 +#define SYS64_MKNODAT 259 +#define SYS64_FCHOWNAT 260 +#define SYS64_FUTIMESAT 261 +#define SYS64_NEWFSTATAT 262 +#define SYS64_UNLINKAT 263 +#define SYS64_RENAMEAT 264 +#define SYS64_LINKAT 265 +#define SYS64_SYMLINKAT 266 +#define SYS64_READLINKAT 267 +#define SYS64_FCHMODAT 268 +#define SYS64_FACCESSAT 269 +#define SYS64_PSELECT6 270 +#define SYS64_PPOLL 271 +#define SYS64_UNSHARE 272 +#define SYS64_SET_ROBUST_LIST 273 +#define SYS64_GET_ROBUST_LIST 274 +#define SYS64_SPLICE 275 +#define SYS64_TEE 276 +#define SYS64_SYNC_FILE_RANGE 277 +#define SYS64_VMSPLICE 278 +#define SYS64_MOVE_PAGES 279 +#define SYS64_UTIMENSAT 280 +#define SYS64_EPOLL_PWAIT 281 +#define SYS64_SIGNALFD 282 +#define SYS64_TIMERFD_CREATE 283 +#define SYS64_EVENTFD 284 +#define SYS64_FALLOCATE 285 +#define SYS64_TIMERFD_SETTIME 286 +#define SYS64_TIMERFD_GETTIME 287 +#define SYS64_ACCEPT4 288 +#define SYS64_SIGNALFD4 289 +#define SYS64_EVENTFD2 290 +#define SYS64_EPOLL_CREATE1 291 +#define SYS64_DUP3 292 +#define SYS64_PIPE2 293 +#define SYS64_INOTIFY_INIT1 294 +#define SYS64_PREADV 295 +#define SYS64_PWRITEV 296 +#define SYS64_RT_TGSIGQUEUEINFO 297 +#define SYS64_PERF_EVENT_OPEN 298 + + +#endif diff --git a/gears/services/devfile/test_preload.c b/gears/services/devfile/test_preload.c new file mode 100644 index 0000000..ebeaac9 --- /dev/null +++ b/gears/services/devfile/test_preload.c @@ -0,0 +1,158 @@ +/* + Device File Virtualization Guest Preload Library + Test Program + + (c) Akhil Guliani and William Gross, 2015 + + Adapted from MPI module (c) 2012 Peter Dinda + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "devfile_hc.h" + + +int read_all(int fd, char *data, int numbytes) +{ + int i; + int rc; + + for (i=0;i > output\n"); + fprintf(stderr,"test_preload w < input\n"); + return -1; + } + + what = argv[1]; + count = atoi(argv[2]); + path = argv[3]; + + fprintf(stderr,"what: %s\n",what); + fprintf(stderr,"path: %s\n",path); + fprintf(stderr,"count: %d\n",count); + + if (*what=='w') { + flags = O_RDWR; + mode = 0; // we are not doing a file creation + } else if (*what=='r') { + flags = O_RDONLY; + mode = 0; // we are not doing a file creation + } else { + fprintf(stderr,"Don't know how to %s\n",what); + return -1; + } + + fprintf(stderr,"flags: %d, mode: %d\n",flags,mode); + + if ((fd = open(path, flags, mode)) < 0) { + fprintf(stderr,"Failed to open file %s\n",argv[3]); + return -1; + } + + fprintf(stderr,"Open Done, fd : %d\n",fd); + + buff = (char*)malloc(count); + + if (!buff) { + perror("Can't allocate\n"); + return -1; + } + + if (*what=='r') { + fprintf(stderr,"READ: fd: %d, buff: %p, bytes: %d \n", fd, buff, count); + + bytes = read_all(fd,buff,count); + + if (bytes < 0) { + fprintf(stderr,"Failed to read file %s\n",path); + free(buff); + close(fd); + return -1; + } + + fprintf(stderr,"WRITE: fd: %d, buff: %p, bytes: %d \n", 1, buff, count); + + bytes = write_all(1,buff,count); + + if (bytes<0) { + fprintf(stderr,"Failed to write stdout\n"); + free(buff); + close(fd); + return -1; + } + + } else if (*what=='w') { + + fprintf(stderr,"READ: fd: %d, buff: %p, bytes: %d \n", 0, buff, count); + + bytes = read_all(0,buff,count); + + if (bytes < 0) { + fprintf(stderr,"Failed to read stdin\n"); + free(buff); + close(fd); + return -1; + } + + fprintf(stderr,"WRITE: fd: %d, buff: %p, bytes: %d \n", fd, buff, count); + + bytes = write_all(fd,buff,count); + + if (bytes<0) { + fprintf(stderr,"Failed to write stdout\n"); + free(buff); + close(fd); + return -1; + } + + } + + free(buff); + close(fd); + fprintf(stderr,"Close done\n"); + return 0; +}