#ifdef __V3VEE__
+typedef void * v3_file_t;
 
-#define V3_FileOpen(path, mode, host_data)                             \
-    ({                                                                 \
-       void * fd = NULL;                                               \
-       extern struct v3_file_hooks * file_hooks;                       \
-       if ((file_hooks) && (file_hooks)->file_open) {                  \
-           fd = (file_hooks)->file_open((path), (mode), (host_data));  \
-       }                                                               \
-       fd;                                                             \
-    })
-
-#define V3_FileClose(fd)                                               \
-    ({                                                                 \
-       int ret = 0;                                                    \
-       extern struct v3_file_hooks * file_hooks;                       \
-       if ((file_hooks) && (file_hooks)->file_close) {                 \
-           ret = (file_hooks)->file_close((fd));                       \
-       }                                                               \
-       ret;                                                            \
-    })
-
-#define V3_FileSize(fd)                                                        \
-    ({                                                                 \
-       long long size = -1;                                            \
-       extern struct v3_file_hooks * file_hooks;                       \
-       if ((file_hooks) && (file_hooks)->file_size) {                  \
-           size = (file_hooks)->file_size((fd));                       \
-       }                                                               \
-       size;                                                           \
-    })
-
-#define V3_FileRead(fd, start, buf, len)                               \
-    ({                                                                 \
-       long long ret = -1;                                             \
-       extern struct v3_file_hooks * file_hooks;                       \
-       if ((file_hooks) && (file_hooks)->file_read) {                  \
-           ret = (file_hooks)->file_read((fd), (buf), (len), (start)); \
-       }                                                               \
-       ret;                                                            \
-    })
-
-#define V3_FileWrite(fd,start,buf,len)                                 \
-    ({                                                                 \
-       long long ret = -1;                                             \
-       extern struct v3_file_hooks * file_hooks;                       \
-       if ((file_hooks) && (file_hooks)->file_write) {                 \
-           ret = (file_hooks)->file_write((fd), (buf), (len), (start)); \
-       }                                                               \
-       ret;                                                            \
-    })
 
+v3_file_t v3_file_open(struct v3_vm_info * vm, char * path, uint8_t mode);
+int v3_file_close(v3_file_t file);
+uint64_t v3_file_size(v3_file_t file);
+
+uint64_t v3_file_read(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off);
+uint64_t v3_file_write(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off);
 
 #endif
 
 
 struct v3_file_hooks {
 
-    void * (*file_open)(const char * path, int mode, void * host_data);
-    int (*file_close)(void * fd);
+    void * (*open)(const char * path, int mode, void * host_data);
+    int (*close)(void * fd);
 
-    long long (*file_size)(void * fd);
+    long long (*size)(void * fd);
 
     // blocking reads and writes
-    long long (*file_read)(void * fd, void * buffer, long long length, long long offset);
-    long long (*file_write)(void * fd, void * buffer, long long length, long long offset);
+    long long (*read)(void * fd, void * buffer, long long length, long long offset);
+    long long (*write)(void * fd, void * buffer, long long length, long long offset);
 
 };
 
 
 struct disk_state {
     uint64_t capacity; // in bytes
 
-    void * fd;
+    v3_file_t fd;
 };
 
 
 
-static int write_all(void * fd, char * buf, int offset, int length) {
+static int write_all(v3_file_t fd, char * buf, int offset, int length) {
     int bytes_written = 0;
     
     PrintDebug("Writing %d bytes\n", length - bytes_written);
     while (bytes_written < length) {
-       int tmp_bytes = V3_FileWrite(fd, offset+bytes_written, buf + bytes_written, length - bytes_written);
+       int tmp_bytes = v3_file_write(fd, buf + bytes_written, offset + bytes_written, length - bytes_written);
        PrintDebug("Wrote %d bytes\n", tmp_bytes);
        
        if (tmp_bytes <= 0 ) {
 }
 
 
-static int read_all(void * fd, char * buf, int offset, int length) {
+static int read_all(v3_file_t fd, char * buf, int offset, int length) {
     int bytes_read = 0;
     
     PrintDebug("Reading %d bytes\n", length - bytes_read);
     while (bytes_read < length) {
-       int tmp_bytes = V3_FileRead(fd, offset+bytes_read, buf + bytes_read, length - bytes_read);
+       int tmp_bytes = v3_file_read(fd, buf + bytes_read, offset + bytes_read, length - bytes_read);
        PrintDebug("Read %d bytes\n", tmp_bytes);
        
        if (tmp_bytes <= 0) {
     }
     
     if ( (allowRead == 1) && (allowWrite == 1) ) {
-       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE, vm->host_priv_data );
+       disk->fd = v3_file_open(vm, path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE );
     } else if ( (allowRead == 1) && (allowWrite == 0) ) {
-       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ, vm->host_priv_data );
+       disk->fd = v3_file_open(vm, path, FILE_OPEN_MODE_READ);
     } else if ( (allowRead == 0) && (allowWrite == 1) ) {
-       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_WRITE, vm->host_priv_data );
+       disk->fd = v3_file_open(vm, path, FILE_OPEN_MODE_WRITE);
     } else {
        PrintError("Error on %s: No file mode specified\n", dev_id );
        return -1;
 
     }
     
-    disk->capacity = V3_FileSize(disk->fd);
+    disk->capacity = v3_file_size(disk->fd);
 
     PrintDebug("Registering FILEDISK %s (path=%s, fd=%lu, size=%lu)\n",
               dev_id, path, file->fd, file->capacity);
 
 #include <palacios/vmm.h>
 #include <palacios/vmm_debug.h>
 #include <palacios/vmm_types.h>
+#include <palacios/vm_guest.h>
 
-
-struct v3_file_hooks * file_hooks = 0;
+static struct v3_file_hooks * file_hooks = NULL;
 
 void V3_Init_File(struct v3_file_hooks * hooks) {
     file_hooks = hooks;
 
     return;
 }
+
+
+v3_file_t v3_file_open(struct v3_vm_info * vm, char * path, uint8_t mode) {
+    V3_ASSERT(file_hooks);
+    V3_ASSERT(file_hooks->open);
+    void * priv_data = NULL;
+    
+    if (vm) {
+       priv_data = vm->host_priv_data;
+    }
+
+    return file_hooks->open(path, mode, priv_data);
+}
+
+int v3_file_close(v3_file_t file) {
+    V3_ASSERT(file_hooks);
+    V3_ASSERT(file_hooks->open);
+    
+    return file_hooks->close(file);
+}
+
+uint64_t v3_file_size(v3_file_t file) {
+    V3_ASSERT(file_hooks);
+    V3_ASSERT(file_hooks->size);
+    
+    return file_hooks->size(file);
+}
+
+uint64_t v3_file_read(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off) {
+    V3_ASSERT(file_hooks);
+    V3_ASSERT(file_hooks->read);
+    
+    return file_hooks->read(file, buf, len, off);
+}
+
+
+uint64_t v3_file_write(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off) {
+    V3_ASSERT(file_hooks);
+    V3_ASSERT(file_hooks->write);
+    
+    return file_hooks->write(file, buf, len, off);
+}
 
 v3_sock_t v3_create_udp_socket(struct v3_vm_info * vm) {
     V3_ASSERT(sock_hooks);
     V3_ASSERT(sock_hooks->udp_socket);
+    void * priv_data = NULL;
+
+    if (vm) {
+       priv_data = vm->host_priv_data;
+    }
     
-    return sock_hooks->udp_socket(0, 0, vm->host_priv_data);
+    return sock_hooks->udp_socket(0, 0, priv_data);
 }
 
 v3_sock_t v3_create_tcp_socket(struct v3_vm_info * vm) {
     V3_ASSERT(sock_hooks);
     V3_ASSERT(sock_hooks->tcp_socket);
-    
-    return sock_hooks->tcp_socket(0, 1, 0, vm->host_priv_data);
+    void * priv_data = NULL;
+
+    if (vm) {
+       priv_data = vm->host_priv_data;
+    }
+
+    return sock_hooks->tcp_socket(0, 1, 0, priv_data);
 }
 
 void v3_socket_close(v3_sock_t sock) {