Browse Source

Address bug report #11, by using 64-bit offsets and lengths internally. Create a regression test to capture this case

Don Porter 7 years ago
parent
commit
760446deac

+ 2 - 0
LibOS/buildglibc.py

@@ -126,6 +126,8 @@ if not do_install:
 
 
 link_binaries     = [ ( 'elf',    'ld-linux-x86-64.so.2' ),
 link_binaries     = [ ( 'elf',    'ld-linux-x86-64.so.2' ),
                       ( 'nptl',   'libpthread.so.0' ),
                       ( 'nptl',   'libpthread.so.0' ),
+                      ( '',   'libc.so' ),
+                      ( '',   'libc.so.6' ),
                       ( 'nptl_db','libthread_db.so.1' ),
                       ( 'nptl_db','libthread_db.so.1' ),
                       ( 'math',   'libm.so.6' ),
                       ( 'math',   'libm.so.6' ),
                       ( 'dlfcn',  'libdl.so.2' ),
                       ( 'dlfcn',  'libdl.so.2' ),

+ 1 - 1
LibOS/shim/include/shim_fs.h

@@ -69,7 +69,7 @@ struct shim_fs_ops {
     int (*move) (const char * trim_old_name, const char * trim_new_name);
     int (*move) (const char * trim_old_name, const char * trim_new_name);
     int (*copy) (const char * trim_old_name, const char * trim_new_name);
     int (*copy) (const char * trim_old_name, const char * trim_new_name);
 
 
-    int (*truncate) (struct shim_handle * hdl, int len);
+    int (*truncate) (struct shim_handle * hdl, uint64_t len);
 
 
     /* hstat: get status of the file */
     /* hstat: get status of the file */
     int (*hstat) (struct shim_handle * hdl, struct stat * buf);
     int (*hstat) (struct shim_handle * hdl, struct stat * buf);

+ 1 - 1
LibOS/shim/include/shim_handle.h

@@ -117,7 +117,7 @@ struct shim_dev_ops {
     /* seek: the content from the file opened as handle */
     /* seek: the content from the file opened as handle */
     int (*seek) (struct shim_handle * hdl, off_t offset, int wence);
     int (*seek) (struct shim_handle * hdl, off_t offset, int wence);
 
 
-    int (*truncate) (struct shim_handle * hdl, int len);
+    int (*truncate) (struct shim_handle * hdl, uint64_t len);
 
 
     int (*mode) (const char * name, mode_t * mode);
     int (*mode) (const char * name, mode_t * mode);
 
 

+ 12 - 12
LibOS/shim/include/shim_vma.h

@@ -42,10 +42,10 @@ struct shim_handle;
 struct shim_vma {
 struct shim_vma {
     REFTYPE                 ref_count;
     REFTYPE                 ref_count;
     void *                  addr;
     void *                  addr;
-    int                     length;
+    uint64_t                length;
     int                     prot;
     int                     prot;
     int                     flags;
     int                     flags;
-    int                     offset;
+    uint64_t                offset;
     struct shim_handle *    file;
     struct shim_handle *    file;
     struct list_head        list;
     struct list_head        list;
     char                    comment[VMA_COMMENT_LEN];
     char                    comment[VMA_COMMENT_LEN];
@@ -89,35 +89,35 @@ static inline PAL_FLG PAL_PROT (int prot, int flags)
 int init_vma (void);
 int init_vma (void);
 
 
 /* Bookkeeping mmap() system call */
 /* Bookkeeping mmap() system call */
-int bkeep_mmap (void * addr, int length, int prot, int flags,
-                struct shim_handle * file, int offset, const char * comment);
+int bkeep_mmap (void * addr, uint64_t length, int prot, int flags,
+                struct shim_handle * file, uint64_t offset, const char * comment);
 
 
 /* Bookkeeping munmap() system call */
 /* Bookkeeping munmap() system call */
-int bkeep_munmap (void * addr, int length, const int * flags);
+int bkeep_munmap (void * addr, uint64_t length, const int * flags);
 
 
 /* Bookkeeping mprotect() system call */
 /* Bookkeeping mprotect() system call */
-int bkeep_mprotect (void * addr, int length, int prot, const int * flags);
+int bkeep_mprotect (void * addr, uint64_t length, int prot, const int * flags);
 
 
 /* Get vma bookkeeping handle */
 /* Get vma bookkeeping handle */
 void get_vma (struct shim_vma * vma);
 void get_vma (struct shim_vma * vma);
 void put_vma (struct shim_vma * vma);
 void put_vma (struct shim_vma * vma);
 
 
-int lookup_supervma (const void * addr, int len, struct shim_vma ** vma);
-int lookup_overlap_vma (const void * addr, int len, struct shim_vma ** vma);
+int lookup_supervma (const void * addr, uint64_t len, struct shim_vma ** vma);
+int lookup_overlap_vma (const void * addr, uint64_t len, struct shim_vma ** vma);
 
 
 struct shim_vma * next_vma (struct shim_vma * vma);
 struct shim_vma * next_vma (struct shim_vma * vma);
 
 
-void * get_unmapped_vma (int len, int flags);
-void * get_unmapped_vma_for_cp (int len);
+void * get_unmapped_vma (uint64_t len, int flags);
+void * get_unmapped_vma_for_cp (uint64_t len);
 
 
-int dump_all_vmas (struct shim_thread * thread, char * buf, int size);
+int dump_all_vmas (struct shim_thread * thread, char * buf, uint64_t size);
 
 
 void unmap_all_vmas (void);
 void unmap_all_vmas (void);
 
 
 /* Debugging */
 /* Debugging */
 void debug_print_vma_list (void);
 void debug_print_vma_list (void);
 
 
-void print_vma_hash (struct shim_vma * vma, void * addr, int len,
+void print_vma_hash (struct shim_vma * vma, void * addr, uint64_t len,
                      bool force_protect);
                      bool force_protect);
 
 
 /* Constants */
 /* Constants */

+ 42 - 42
LibOS/shim/src/bookkeep/shim_vma.c

@@ -57,35 +57,35 @@ static LIST_HEAD(vma_list);
 static LOCKTYPE vma_list_lock;
 static LOCKTYPE vma_list_lock;
 
 
 static inline int test_vma_equal (struct shim_vma * tmp,
 static inline int test_vma_equal (struct shim_vma * tmp,
-                                  const void * addr, int length)
+                                  const void * addr, uint64_t length)
 {
 {
     return tmp->addr == addr &&
     return tmp->addr == addr &&
            tmp->addr + tmp->length == addr + length;
            tmp->addr + tmp->length == addr + length;
 }
 }
 
 
 static inline int test_vma_contain (struct shim_vma * tmp,
 static inline int test_vma_contain (struct shim_vma * tmp,
-                                    const void * addr, int length)
+                                    const void * addr, uint64_t length)
 {
 {
     return tmp->addr <= addr &&
     return tmp->addr <= addr &&
            tmp->addr + tmp->length >= addr + length;
            tmp->addr + tmp->length >= addr + length;
 }
 }
 
 
 static inline int test_vma_startin (struct shim_vma * tmp,
 static inline int test_vma_startin (struct shim_vma * tmp,
-                                    const void * addr, int length)
+                                    const void * addr, uint64_t length)
 {
 {
     return tmp->addr >= addr &&
     return tmp->addr >= addr &&
            tmp->addr < addr + length;
            tmp->addr < addr + length;
 }
 }
 
 
 static inline int test_vma_endin (struct shim_vma * tmp,
 static inline int test_vma_endin (struct shim_vma * tmp,
-                                  const void * addr, int length)
+                                  const void * addr, uint64_t length)
 {
 {
     return tmp->addr + tmp->length > addr &&
     return tmp->addr + tmp->length > addr &&
            tmp->addr + tmp->length <= addr + length;
            tmp->addr + tmp->length <= addr + length;
 }
 }
 
 
 static inline int test_vma_overlap (struct shim_vma * tmp,
 static inline int test_vma_overlap (struct shim_vma * tmp,
-                                    const void * addr, int length)
+                                    const void * addr, uint64_t length)
 {
 {
     return test_vma_contain (tmp, addr + 1, 0) ||
     return test_vma_contain (tmp, addr + 1, 0) ||
            test_vma_contain (tmp, addr + length - 1, 0) ||
            test_vma_contain (tmp, addr + length - 1, 0) ||
@@ -130,10 +130,10 @@ static inline void assert_vma (void)
     }
     }
 }
 }
 
 
-static struct shim_vma * __lookup_vma (const void * addr, int len);
-static struct shim_vma * __lookup_supervma (const void * addr, int length,
+static struct shim_vma * __lookup_vma (const void * addr, uint64_t len);
+static struct shim_vma * __lookup_supervma (const void * addr, uint64_t length,
                                             struct shim_vma ** prev);
                                             struct shim_vma ** prev);
-static struct shim_vma * __lookup_overlap_vma (const void * addr, int length,
+static struct shim_vma * __lookup_overlap_vma (const void * addr, uint64_t length,
                                                struct shim_vma ** prev);
                                                struct shim_vma ** prev);
 
 
 void get_vma (struct shim_vma * vma)
 void get_vma (struct shim_vma * vma)
@@ -174,11 +174,11 @@ static void __remove_vma (struct shim_vma * vma)
     put_vma(vma);
     put_vma(vma);
 }
 }
 
 
-static int __bkeep_mmap (void * addr, int length, int prot, int flags,
-                         struct shim_handle * file, int offset,
+static int __bkeep_mmap (void * addr, uint64_t length, int prot, int flags,
+                         struct shim_handle * file, uint64_t offset,
                          const char * comment);
                          const char * comment);
 
 
-static int __bkeep_mprotect (void * addr, int length, int prot,
+static int __bkeep_mprotect (void * addr, uint64_t length, int prot,
                              const int * flags);
                              const int * flags);
 
 
 static struct shim_vma * get_new_vma (void)
 static struct shim_vma * get_new_vma (void)
@@ -217,7 +217,7 @@ static inline void __set_comment (struct shim_vma * vma, const char * comment)
         return;
         return;
     }
     }
 
 
-    int len = strlen(comment);
+    uint64_t len = strlen(comment);
 
 
     if (len > VMA_COMMENT_LEN - 1)
     if (len > VMA_COMMENT_LEN - 1)
         len = VMA_COMMENT_LEN - 1;
         len = VMA_COMMENT_LEN - 1;
@@ -225,9 +225,9 @@ static inline void __set_comment (struct shim_vma * vma, const char * comment)
     memcpy(vma->comment, comment, len + 1);
     memcpy(vma->comment, comment, len + 1);
 }
 }
 
 
-static int __bkeep_mmap (void * addr, int length,
+static int __bkeep_mmap (void * addr, uint64_t length,
                          int prot, int flags,
                          int prot, int flags,
-                         struct shim_handle * file, int offset,
+                         struct shim_handle * file, uint64_t offset,
                          const char * comment)
                          const char * comment)
 {
 {
     struct shim_vma * prev = NULL;
     struct shim_vma * prev = NULL;
@@ -331,8 +331,8 @@ err:
     return ret;
     return ret;
 }
 }
 
 
-int bkeep_mmap (void * addr, int length, int prot, int flags,
-                struct shim_handle * file, int offset, const char * comment)
+int bkeep_mmap (void * addr, uint64_t length, int prot, int flags,
+                struct shim_handle * file, uint64_t offset, const char * comment)
 {
 {
     if (!addr || !length)
     if (!addr || !length)
         return -EINVAL;
         return -EINVAL;
@@ -351,7 +351,7 @@ int bkeep_mmap (void * addr, int length, int prot, int flags,
  * We need to split the area aur reduce the size
  * We need to split the area aur reduce the size
  * Check the address falls between alread allocated area or not
  * Check the address falls between alread allocated area or not
  */
  */
-static int __bkeep_munmap (void * addr, int length, const int * flags)
+static int __bkeep_munmap (void * addr, uint64_t length, const int * flags)
 {
 {
     struct shim_vma * tmp, * n;
     struct shim_vma * tmp, * n;
 
 
@@ -423,7 +423,7 @@ static int __bkeep_munmap (void * addr, int length, const int * flags)
     return 0;
     return 0;
 }
 }
 
 
-int bkeep_munmap (void * addr, int length, const int * flags)
+int bkeep_munmap (void * addr, uint64_t length, const int * flags)
 {
 {
     if (!addr || !length)
     if (!addr || !length)
         return -EINVAL;
         return -EINVAL;
@@ -436,7 +436,7 @@ int bkeep_munmap (void * addr, int length, const int * flags)
     return ret;
     return ret;
 }
 }
 
 
-static int __bkeep_mprotect (void * addr, int length, int prot,
+static int __bkeep_mprotect (void * addr, uint64_t length, int prot,
                              const int * flags)
                              const int * flags)
 {
 {
     struct shim_vma * tmp = __lookup_vma(addr, length);
     struct shim_vma * tmp = __lookup_vma(addr, length);
@@ -469,11 +469,11 @@ static int __bkeep_mprotect (void * addr, int length, int prot,
         if (!check_vma_flags(tmp, flags))
         if (!check_vma_flags(tmp, flags))
             return -EACCES;
             return -EACCES;
 
 
-        int before_length = addr - tmp->addr;
-        int after_length  = tmp->addr + tmp->length - addr - length;
-        int after_offset  = tmp->file ? tmp->offset + tmp->length -
+        uint64_t before_length = addr - tmp->addr;
+        uint64_t after_length  = tmp->addr + tmp->length - addr - length;
+        uint64_t after_offset  = tmp->file ? tmp->offset + tmp->length -
                             after_length : 0;
                             after_length : 0;
-        int inside_offset = tmp->file ? tmp->offset + before_length : 0;
+        uint64_t inside_offset = tmp->file ? tmp->offset + before_length : 0;
 
 
         /* split the handler first, because we might call bkeep_mmap */
         /* split the handler first, because we might call bkeep_mmap */
         tmp->addr = (void *) addr;
         tmp->addr = (void *) addr;
@@ -519,7 +519,7 @@ static int __bkeep_mprotect (void * addr, int length, int prot,
      * the mapping if it fails
      * the mapping if it fails
      */
      */
 
 
-    int o_length = length;
+    uint64_t o_length = length;
 
 
     while (length) {
     while (length) {
         struct shim_vma * candidate = NULL;
         struct shim_vma * candidate = NULL;
@@ -529,15 +529,15 @@ static int __bkeep_mprotect (void * addr, int length, int prot,
                 if (!check_vma_flags(tmp, flags))
                 if (!check_vma_flags(tmp, flags))
                     return -EACCES;
                     return -EACCES;
 
 
-                int before_length = addr - tmp->addr;
-                int after_length  = tmp->addr + tmp->length > addr + length ?
+                uint64_t before_length = addr - tmp->addr;
+                uint64_t after_length  = tmp->addr + tmp->length > addr + length ?
                                     tmp->addr + tmp->length - addr - length : 0;
                                     tmp->addr + tmp->length - addr - length : 0;
-                int after_offset  = tmp->file ? tmp->offset + tmp->length -
+                uint64_t after_offset  = tmp->file ? tmp->offset + tmp->length -
                                     after_length : 0;
                                     after_length : 0;
-                int inside_length = tmp->addr + tmp->length > addr + length ?
+                uint64_t inside_length = tmp->addr + tmp->length > addr + length ?
                                     length :
                                     length :
                                     addr + length - tmp->addr - tmp->length;
                                     addr + length - tmp->addr - tmp->length;
-                int inside_offset = tmp->file ? tmp->offset + before_length : 0;
+                uint64_t inside_offset = tmp->file ? tmp->offset + before_length : 0;
 
 
                 /* split the handler first, because we might call bkeep_mmap */
                 /* split the handler first, because we might call bkeep_mmap */
                 tmp->addr = (void *) addr;
                 tmp->addr = (void *) addr;
@@ -600,7 +600,7 @@ static int __bkeep_mprotect (void * addr, int length, int prot,
     return 0;
     return 0;
 }
 }
 
 
-int bkeep_mprotect (void * addr, int length, int prot, const int * flags)
+int bkeep_mprotect (void * addr, uint64_t length, int prot, const int * flags)
 {
 {
     if (!addr || !length)
     if (!addr || !length)
         return -EINVAL;
         return -EINVAL;
@@ -630,7 +630,7 @@ static void __set_heap_top (void * bottom, void * top)
     debug("heap top adjusted to %p\n", heap_top);
     debug("heap top adjusted to %p\n", heap_top);
 }
 }
 
 
-void * get_unmapped_vma (int length, int flags)
+void * get_unmapped_vma (uint64_t length, int flags)
 {
 {
     struct shim_vma * new = get_new_vma(), * prev = NULL;
     struct shim_vma * new = get_new_vma(), * prev = NULL;
     if (!new)
     if (!new)
@@ -694,7 +694,7 @@ void * get_unmapped_vma (int length, int flags)
 
 
 #define NTRIES  4
 #define NTRIES  4
 
 
-void * get_unmapped_vma_for_cp (int length)
+void * get_unmapped_vma_for_cp (uint64_t length)
 {
 {
     struct shim_vma * new = get_new_vma(), * prev = NULL;
     struct shim_vma * new = get_new_vma(), * prev = NULL;
     if (!new)
     if (!new)
@@ -742,7 +742,7 @@ void * get_unmapped_vma_for_cp (int length)
 
 
 /* This might not give the same vma but we might need to
 /* This might not give the same vma but we might need to
    split after we find something */
    split after we find something */
-static struct shim_vma * __lookup_overlap_vma (const void * addr, int length,
+static struct shim_vma * __lookup_overlap_vma (const void * addr, uint64_t length,
                                                struct shim_vma ** pprev)
                                                struct shim_vma ** pprev)
 {
 {
     struct shim_vma * tmp, * prev = NULL;
     struct shim_vma * tmp, * prev = NULL;
@@ -767,12 +767,12 @@ static struct shim_vma * __lookup_overlap_vma (const void * addr, int length,
     return NULL;
     return NULL;
 }
 }
 
 
-int lookup_overlap_vma (const void * addr, int length,
+int lookup_overlap_vma (const void * addr, uint64_t length,
                         struct shim_vma ** vma)
                         struct shim_vma ** vma)
 {
 {
     struct shim_vma * tmp = NULL;
     struct shim_vma * tmp = NULL;
     void * tmp_addr = NULL;
     void * tmp_addr = NULL;
-    int tmp_length;
+    uint64_t tmp_length;
     lock(vma_list_lock);
     lock(vma_list_lock);
 
 
     if ((tmp = __lookup_overlap_vma(addr, length, NULL)) && vma)
     if ((tmp = __lookup_overlap_vma(addr, length, NULL)) && vma)
@@ -793,7 +793,7 @@ int lookup_overlap_vma (const void * addr, int length,
     return tmp ? 0: -ENOENT;
     return tmp ? 0: -ENOENT;
 }
 }
 
 
-static struct shim_vma * __lookup_vma (const void * addr, int length)
+static struct shim_vma * __lookup_vma (const void * addr, uint64_t length)
 {
 {
     struct shim_vma * tmp;
     struct shim_vma * tmp;
     struct shim_vma * prev __attribute__((unused)) = NULL;
     struct shim_vma * prev __attribute__((unused)) = NULL;
@@ -810,7 +810,7 @@ static struct shim_vma * __lookup_vma (const void * addr, int length)
     return NULL;
     return NULL;
 }
 }
 
 
-static struct shim_vma * __lookup_supervma (const void * addr, int length,
+static struct shim_vma * __lookup_supervma (const void * addr, uint64_t length,
                                             struct shim_vma ** pprev)
                                             struct shim_vma ** pprev)
 {
 {
     struct shim_vma * tmp, * prev = NULL;
     struct shim_vma * tmp, * prev = NULL;
@@ -835,7 +835,7 @@ static struct shim_vma * __lookup_supervma (const void * addr, int length,
     return NULL;
     return NULL;
 }
 }
 
 
-int lookup_supervma (const void * addr, int length, struct shim_vma ** vma)
+int lookup_supervma (const void * addr, uint64_t length, struct shim_vma ** vma)
 {
 {
     struct shim_vma * tmp = NULL;
     struct shim_vma * tmp = NULL;
 
 
@@ -922,7 +922,7 @@ unmap:
     }
     }
 }
 }
 
 
-int dump_all_vmas (struct shim_thread * thread, char * buf, int size)
+int dump_all_vmas (struct shim_thread * thread, char * buf, uint64_t size)
 {
 {
     struct shim_vma * vma;
     struct shim_vma * vma;
     int cnt = 0;
     int cnt = 0;
@@ -1074,11 +1074,11 @@ BEGIN_CP_FUNC(vma)
 #endif
 #endif
 
 
         void * send_addr = vma->addr;
         void * send_addr = vma->addr;
-        int    send_size = vma->length;
+        uint64_t    send_size = vma->length;
         bool protected = false;
         bool protected = false;
 
 
         if (vma->file) {
         if (vma->file) {
-            int file_len = get_file_size(vma->file);
+            uint64_t file_len = get_file_size(vma->file);
             if (file_len >= 0 &&
             if (file_len >= 0 &&
                 vma->offset + vma->length > file_len)
                 vma->offset + vma->length > file_len)
                 send_size = file_len > vma->offset ?
                 send_size = file_len > vma->offset ?
@@ -1299,7 +1299,7 @@ void debug_print_vma_list (void)
     }
     }
 }
 }
 
 
-void print_vma_hash (struct shim_vma * vma, void * addr, int len,
+void print_vma_hash (struct shim_vma * vma, void * addr, uint64_t len,
                      bool force_protect)
                      bool force_protect)
 {
 {
     if (!addr)
     if (!addr)

+ 7 - 3
LibOS/shim/src/fs/chroot/fs.c

@@ -848,9 +848,9 @@ out:
     return ret;
     return ret;
 }
 }
 
 
-static int chroot_truncate (struct shim_handle * hdl, int len)
+static int chroot_truncate (struct shim_handle * hdl, uint64_t len)
 {
 {
-    int ret = 0;
+    uint64_t ret = 0;
 
 
     if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
     if (NEED_RECREATE(hdl) && (ret = chroot_recreate(hdl)) < 0)
         return ret;
         return ret;
@@ -865,8 +865,12 @@ static int chroot_truncate (struct shim_handle * hdl, int len)
         atomic_set(&data->size, len);
         atomic_set(&data->size, len);
     }
     }
 
 
-    if ((ret = DkStreamSetLength(hdl->pal_handle, len)) != len)
+    if ((ret = DkStreamSetLength(hdl->pal_handle, len)) != len) {
         goto out;
         goto out;
+    }
+
+    // DEP 10/25/16: Truncate returns 0 on success, not the length
+    ret = 0;
 
 
     if (file->marker > len)
     if (file->marker > len)
         file->marker = len;
         file->marker = len;

+ 2 - 2
LibOS/shim/src/fs/dev/fs.c

@@ -103,7 +103,7 @@ static int dev_null_hstat (struct shim_handle * hdl, struct stat * stat)
     return 0;
     return 0;
 }
 }
 
 
-static int dev_null_truncate (struct shim_handle * hdl, int size)
+static int dev_null_truncate (struct shim_handle * hdl, uint64_t size)
 {
 {
     return 0;
     return 0;
 }
 }
@@ -308,7 +308,7 @@ static int dev_seek (struct shim_handle * hdl, off_t offset, int wence)
     return hdl->info.dev.dev_ops.seek(hdl, offset, wence);
     return hdl->info.dev.dev_ops.seek(hdl, offset, wence);
 }
 }
 
 
-static int dev_truncate (struct shim_handle * hdl, int len)
+static int dev_truncate (struct shim_handle * hdl, uint64_t len)
 {
 {
     if (!hdl->info.dev.dev_ops.truncate)
     if (!hdl->info.dev.dev_ops.truncate)
         return -EACCES;
         return -EACCES;

+ 1 - 1
LibOS/shim/src/shim_parser.c

@@ -435,7 +435,7 @@ static inline void parse_pointer_arg (va_list * ap)
 
 
 static inline void parse_integer_arg (va_list * ap)
 static inline void parse_integer_arg (va_list * ap)
 {
 {
-    VPRINTF("%d", ap);
+    VPRINTF("%ld", ap);
 }
 }
 
 
 static inline void parse_syscall_args (va_list * ap)
 static inline void parse_syscall_args (va_list * ap)

+ 1 - 1
LibOS/shim/src/sys/shim_mmap.c

@@ -97,7 +97,7 @@ void * shim_do_mmap (void * addr, size_t length, int prot, int flags, int fd,
             goto free_reserved;
             goto free_reserved;
         }
         }
 
 
-        if ((ret = hdl->fs->fs_ops->mmap(hdl, &addr, length, prot,
+        if ((ret = hdl->fs->fs_ops->mmap(hdl, &addr, length, PAL_PROT(prot, flags),
                                          flags, offset)) < 0) {
                                          flags, offset)) < 0) {
             put_handle(hdl);
             put_handle(hdl);
             goto free_reserved;
             goto free_reserved;

+ 1 - 0
LibOS/shim/test/regression/.gitignore

@@ -3,3 +3,4 @@
 !*.cpp
 !*.cpp
 !*.template
 !*.template
 !Makefile*
 !Makefile*
+!*.py

+ 2 - 0
LibOS/shim/test/regression/Makefile

@@ -47,6 +47,8 @@ PYTHONENV="PYTHONPATH=../../../../Scripts"
 regression: $(target)
 regression: $(target)
 	@echo "\n\nBasic Bootstrapping:"
 	@echo "\n\nBasic Bootstrapping:"
 	@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python $$f; done
 	@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python $$f; done
+	@echo "\n\nLarge File Support:"
+	@for f in $(wildcard 90_*.py); do env $(PYTHONENV) python $$f; done
 	@echo "\n\n"
 	@echo "\n\n"
 
 
 clean-tmp:
 clean-tmp:

+ 1 - 1
LibOS/shim/test/regression/manifest.template

@@ -5,7 +5,7 @@ loader.syscall_symbol = syscalldb
 
 
 fs.mount.lib.type = chroot
 fs.mount.lib.type = chroot
 fs.mount.lib.path = /lib
 fs.mount.lib.path = /lib
-fs.mount.lib.uri = file:../../../build
+fs.mount.lib.uri = file:../../../../Runtime
 
 
 fs.mount.bin.type = chroot
 fs.mount.bin.type = chroot
 fs.mount.bin.path = /bin
 fs.mount.bin.path = /bin

+ 4 - 4
Pal/src/db_streams.c

@@ -534,8 +534,8 @@ PAL_NUM DkStreamGetName (PAL_HANDLE handle, PAL_PTR buffer, PAL_NUM size)
 
 
 /* _DkStreamMap for internal use. Map specific handle to certain memory,
 /* _DkStreamMap for internal use. Map specific handle to certain memory,
    with given protection, offset and size */
    with given protection, offset and size */
-int _DkStreamMap (PAL_HANDLE handle, void ** paddr, int prot, int offset,
-                  int size)
+int _DkStreamMap (PAL_HANDLE handle, void ** paddr, int prot, uint64_t offset,
+                  uint64_t size)
 {
 {
     void * addr = *paddr;
     void * addr = *paddr;
     int ret;
     int ret;
@@ -618,7 +618,7 @@ void DkStreamUnmap (PAL_PTR addr, PAL_NUM size)
 
 
 /* _DkStreamSetLength for internal use. This function truncate the stream
 /* _DkStreamSetLength for internal use. This function truncate the stream
    to certain length. This call might not be support for certain streams */
    to certain length. This call might not be support for certain streams */
-int _DkStreamSetLength (PAL_HANDLE handle, int length)
+uint64_t _DkStreamSetLength (PAL_HANDLE handle, uint64_t length)
 {
 {
     if (UNKNOWN_HANDLE(handle))
     if (UNKNOWN_HANDLE(handle))
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
@@ -643,7 +643,7 @@ DkStreamSetLength (PAL_HANDLE handle, PAL_NUM length)
         LEAVE_PAL_CALL_RETURN(0);
         LEAVE_PAL_CALL_RETURN(0);
     }
     }
 
 
-    int ret = _DkStreamSetLength(handle, length);
+    uint64_t ret = _DkStreamSetLength(handle, length);
 
 
     if (ret < 0) {
     if (ret < 0) {
         _DkRaiseFailure(-ret);
         _DkRaiseFailure(-ret);

+ 2 - 2
Pal/src/host/Linux-SGX/db_files.c

@@ -176,7 +176,7 @@ static int file_delete (PAL_HANDLE handle, int access)
 
 
 /* 'map' operation for file stream. */
 /* 'map' operation for file stream. */
 static int file_map (PAL_HANDLE handle, void ** addr, int prot,
 static int file_map (PAL_HANDLE handle, void ** addr, int prot,
-                     int offset, int size)
+                     uint64_t offset, uint64_t size)
 {
 {
     sgx_checksum_t * stubs = (sgx_checksum_t *) handle->file.stubs;
     sgx_checksum_t * stubs = (sgx_checksum_t *) handle->file.stubs;
     unsigned int total = handle->file.total;
     unsigned int total = handle->file.total;
@@ -229,7 +229,7 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot,
 }
 }
 
 
 /* 'setlength' operation for file stream. */
 /* 'setlength' operation for file stream. */
-static int file_setlength (PAL_HANDLE handle, int length)
+static uint64_t file_setlength (PAL_HANDLE handle, uint64_t length)
 {
 {
     int ret = ocall_ftruncate(handle->file.fd, length);
     int ret = ocall_ftruncate(handle->file.fd, length);
     if (ret < 0)
     if (ret < 0)

+ 3 - 3
Pal/src/host/Linux-SGX/db_memory.c

@@ -66,7 +66,7 @@ bool _DkCheckMemoryMappable (const void * addr, int size)
     return false;
     return false;
 }
 }
 
 
-int _DkVirtualMemoryAlloc (void ** paddr, int size, int alloc_type, int prot)
+int _DkVirtualMemoryAlloc (void ** paddr, uint64_t size, int alloc_type, int prot)
 {
 {
     void * addr = *paddr, * mem;
     void * addr = *paddr, * mem;
 
 
@@ -102,13 +102,13 @@ int _DkVirtualMemoryAlloc (void ** paddr, int size, int alloc_type, int prot)
     return 0;
     return 0;
 }
 }
 
 
-int _DkVirtualMemoryFree (void * addr, int size)
+int _DkVirtualMemoryFree (void * addr, uint64_t size)
 {
 {
     free_pages(addr, size);
     free_pages(addr, size);
     return 0;
     return 0;
 }
 }
 
 
-int _DkVirtualMemoryProtect (void * addr, int size, int prot)
+int _DkVirtualMemoryProtect (void * addr, uint64_t size, int prot)
 {
 {
     return 0;
     return 0;
 }
 }

+ 1 - 1
Pal/src/host/Linux-SGX/db_streams.c

@@ -93,7 +93,7 @@ int handle_set_cloexec (PAL_HANDLE handle, bool enable)
 
 
 /* _DkStreamUnmap for internal use. Unmap stream at certain memory address.
 /* _DkStreamUnmap for internal use. Unmap stream at certain memory address.
    The memory is unmapped as a whole.*/
    The memory is unmapped as a whole.*/
-int _DkStreamUnmap (void * addr, int size)
+int _DkStreamUnmap (void * addr, uint64_t size)
 {
 {
     /* Just let the kernel tell us if the mapping isn't good. */
     /* Just let the kernel tell us if the mapping isn't good. */
     free_pages(addr, size);
     free_pages(addr, size);

+ 2 - 3
Pal/src/host/Linux/db_files.c

@@ -149,7 +149,7 @@ static int file_delete (PAL_HANDLE handle, int access)
 
 
 /* 'map' operation for file stream. */
 /* 'map' operation for file stream. */
 static int file_map (PAL_HANDLE handle, void ** addr, int prot,
 static int file_map (PAL_HANDLE handle, void ** addr, int prot,
-                     int offset, int size)
+                     uint64_t offset, uint64_t size)
 {
 {
     int fd = handle->file.fd;
     int fd = handle->file.fd;
     void * mem = *addr;
     void * mem = *addr;
@@ -158,7 +158,6 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot,
 
 
     /* The memory will always allocated with flag MAP_PRIVATE
     /* The memory will always allocated with flag MAP_PRIVATE
        and MAP_FILE */
        and MAP_FILE */
-
     mem = (void *) ARCH_MMAP(mem, size, prot, flags, fd, offset);
     mem = (void *) ARCH_MMAP(mem, size, prot, flags, fd, offset);
 
 
     if (IS_ERR_P(mem))
     if (IS_ERR_P(mem))
@@ -169,7 +168,7 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot,
 }
 }
 
 
 /* 'setlength' operation for file stream. */
 /* 'setlength' operation for file stream. */
-static int file_setlength (PAL_HANDLE handle, int length)
+static uint64_t file_setlength (PAL_HANDLE handle, uint64_t length)
 {
 {
     int ret = INLINE_SYSCALL(ftruncate, 2, handle->file.fd, length);
     int ret = INLINE_SYSCALL(ftruncate, 2, handle->file.fd, length);
 
 

+ 3 - 3
Pal/src/host/Linux/db_memory.c

@@ -40,7 +40,7 @@ bool _DkCheckMemoryMappable (const void * addr, int size)
     return (addr < DATA_END && addr + size > TEXT_START);
     return (addr < DATA_END && addr + size > TEXT_START);
 }
 }
 
 
-int _DkVirtualMemoryAlloc (void ** paddr, int size, int alloc_type,
+int _DkVirtualMemoryAlloc (void ** paddr, uint64_t size, int alloc_type,
                            int prot)
                            int prot)
 {
 {
     void * addr = *paddr, * mem = addr;
     void * addr = *paddr, * mem = addr;
@@ -59,14 +59,14 @@ int _DkVirtualMemoryAlloc (void ** paddr, int size, int alloc_type,
     return 0;
     return 0;
 }
 }
 
 
-int _DkVirtualMemoryFree (void * addr, int size)
+int _DkVirtualMemoryFree (void * addr, uint64_t size)
 {
 {
     int ret = INLINE_SYSCALL(munmap, 2, addr, size);
     int ret = INLINE_SYSCALL(munmap, 2, addr, size);
 
 
     return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : 0;
     return IS_ERR(ret) ? unix_to_pal_error(ERRNO(ret)) : 0;
 }
 }
 
 
-int _DkVirtualMemoryProtect (void * addr, int size, int prot)
+int _DkVirtualMemoryProtect (void * addr, uint64_t size, int prot)
 {
 {
     int ret = INLINE_SYSCALL(mprotect, 3, addr, size, HOST_PROT(prot));
     int ret = INLINE_SYSCALL(mprotect, 3, addr, size, HOST_PROT(prot));
 
 

+ 1 - 1
Pal/src/host/Linux/db_streams.c

@@ -103,7 +103,7 @@ int handle_set_cloexec (PAL_HANDLE handle, bool enable)
 
 
 /* _DkStreamUnmap for internal use. Unmap stream at certain memory address.
 /* _DkStreamUnmap for internal use. Unmap stream at certain memory address.
    The memory is unmapped as a whole.*/
    The memory is unmapped as a whole.*/
-int _DkStreamUnmap (void * addr, int size)
+int _DkStreamUnmap (void * addr, uint64_t size)
 {
 {
     /* Just let the kernel tell us if the mapping isn't good. */
     /* Just let the kernel tell us if the mapping isn't good. */
     int ret = INLINE_SYSCALL(munmap, 2, addr, size);
     int ret = INLINE_SYSCALL(munmap, 2, addr, size);

+ 1 - 0
Pal/src/pal.h

@@ -28,6 +28,7 @@
 
 
 #include <stdbool.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stddef.h>
+#include <stdint.h>
 
 
 typedef unsigned long PAL_NUM;
 typedef unsigned long PAL_NUM;
 typedef const char *  PAL_STR;
 typedef const char *  PAL_STR;

+ 10 - 10
Pal/src/pal_internal.h

@@ -75,12 +75,12 @@ struct handle_ops {
     /* 'map' and 'unmap' will map or unmap the handle into memory space,
     /* 'map' and 'unmap' will map or unmap the handle into memory space,
        it's not necessary mapped by mmap, so unmap also needs 'handle'
        it's not necessary mapped by mmap, so unmap also needs 'handle'
        to deal with special cases */
        to deal with special cases */
-    int (*map) (PAL_HANDLE handle, void ** address, int prot, int offset,
-                int size);
+    int (*map) (PAL_HANDLE handle, void ** address, int prot, uint64_t offset,
+                uint64_t size);
 
 
     /* 'setlength' is used by DkStreamFlush. It truncate the stream
     /* 'setlength' is used by DkStreamFlush. It truncate the stream
        to certain size. */
        to certain size. */
-    int (*setlength) (PAL_HANDLE handle, int length);
+    uint64_t (*setlength) (PAL_HANDLE handle, uint64_t length);
 
 
     /* 'flush' is used by DkStreamFlush. It syncs the stream to the device */
     /* 'flush' is used by DkStreamFlush. It syncs the stream to the device */
     int (*flush) (PAL_HANDLE handle);
     int (*flush) (PAL_HANDLE handle);
@@ -298,10 +298,10 @@ int _DkStreamWrite (PAL_HANDLE handle, int offset, int count,
                     const void * buf, const char * addr, int addrlen);
                     const void * buf, const char * addr, int addrlen);
 int _DkStreamAttributesQuery (const char * uri, PAL_STREAM_ATTR * attr);
 int _DkStreamAttributesQuery (const char * uri, PAL_STREAM_ATTR * attr);
 int _DkStreamAttributesQuerybyHandle (PAL_HANDLE hdl, PAL_STREAM_ATTR * attr);
 int _DkStreamAttributesQuerybyHandle (PAL_HANDLE hdl, PAL_STREAM_ATTR * attr);
-int _DkStreamMap (PAL_HANDLE handle, void ** addr, int prot, int offset,
-                  int size);
-int _DkStreamUnmap (void * addr, int size);
-int _DkStreamSetLength (PAL_HANDLE handle, int length);
+int _DkStreamMap (PAL_HANDLE handle, void ** addr, int prot, uint64_t offset,
+                  uint64_t size);
+int _DkStreamUnmap (void * addr, uint64_t size);
+uint64_t _DkStreamSetLength (PAL_HANDLE handle, uint64_t length);
 int _DkStreamFlush (PAL_HANDLE handle);
 int _DkStreamFlush (PAL_HANDLE handle);
 int _DkStreamGetName (PAL_HANDLE handle, char * buf, int size);
 int _DkStreamGetName (PAL_HANDLE handle, char * buf, int size);
 const char * _DkStreamRealpath (PAL_HANDLE hdl);
 const char * _DkStreamRealpath (PAL_HANDLE hdl);
@@ -340,9 +340,9 @@ int _DkEventWait (PAL_HANDLE event);
 int _DkEventClear (PAL_HANDLE event);
 int _DkEventClear (PAL_HANDLE event);
 
 
 /* DkVirtualMemory calls */
 /* DkVirtualMemory calls */
-int _DkVirtualMemoryAlloc (void ** paddr, int size, int alloc_type, int prot);
-int _DkVirtualMemoryFree (void * addr, int size);
-int _DkVirtualMemoryProtect (void * addr, int size, int prot);
+int _DkVirtualMemoryAlloc (void ** paddr, uint64_t size, int alloc_type, int prot);
+int _DkVirtualMemoryFree (void * addr, uint64_t size);
+int _DkVirtualMemoryProtect (void * addr, uint64_t size, int prot);
 
 
 /* DkObject calls */
 /* DkObject calls */
 int _DkObjectReference (PAL_HANDLE objectHandle);
 int _DkObjectReference (PAL_HANDLE objectHandle);