Browse Source

fix for large files within an SGX enclave (#136)

Replacing some "int" in the code base as "int64_t" or "uint64_t".
Chia-Che Tsai 6 years ago
parent
commit
849859809c

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

@@ -86,12 +86,12 @@ struct shim_file_handle {
     struct shim_file_data * data;
     struct shim_file_data * data;
 
 
     enum shim_file_type type;
     enum shim_file_type type;
-    unsigned long       size;
-    unsigned long       marker;
+    uint64_t		size;
+    uint64_t 		marker;
 
 
     enum { FILEBUF_MAP, FILEBUF_NONE } buf_type;
     enum { FILEBUF_MAP, FILEBUF_NONE } buf_type;
-    unsigned long       mapsize;
-    unsigned long       mapoffset;
+    uint64_t 		mapsize;
+    uint64_t 		mapoffset;
     void *              mapbuf;
     void *              mapbuf;
 };
 };
 
 

+ 11 - 9
LibOS/shim/src/fs/chroot/fs.c

@@ -649,10 +649,10 @@ static inline int __map_buffer (struct shim_handle * hdl, int size)
     }
     }
 
 
     /* second, reallocate the buffer */
     /* second, reallocate the buffer */
-    int bufsize = file->mapsize ? : FILE_BUFMAP_SIZE;
+    uint64_t bufsize = file->mapsize ? : FILE_BUFMAP_SIZE;
     int prot = PAL_PROT_READ;
     int prot = PAL_PROT_READ;
-    unsigned long mapoff = file->marker & ~(bufsize - 1);
-    unsigned long maplen = bufsize;
+    uint64_t mapoff = file->marker & ~(bufsize - 1);
+    uint64_t maplen = bufsize;	
 
 
     if (hdl->acc_mode & MAY_WRITE)
     if (hdl->acc_mode & MAY_WRITE)
         prot |= PAL_PROT_WRITE;
         prot |= PAL_PROT_WRITE;
@@ -682,13 +682,13 @@ static int map_read (struct shim_handle * hdl, void * buf, size_t count)
     lock(hdl->lock);
     lock(hdl->lock);
 
 
     struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
     struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
-    unsigned int size = atomic_read(&data->size);
+    uint64_t size = atomic_read(&data->size);
 
 
     if (check_version(hdl) &&
     if (check_version(hdl) &&
         file->size < size)
         file->size < size)
         file->size = size;
         file->size = size;
 
 
-    int marker = file->marker;
+    uint64_t marker = file->marker;
 
 
     if (marker >= file->size) {
     if (marker >= file->size) {
         count = 0;
         count = 0;
@@ -722,7 +722,7 @@ static int map_write (struct shim_handle * hdl, const void * buf,
     lock(hdl->lock);
     lock(hdl->lock);
 
 
     struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
     struct shim_file_data * data = FILE_HANDLE_DATA(hdl);
-    int marker = file->marker;
+    uint64_t marker = file->marker;
 
 
     if (file->marker + count > file->size) {
     if (file->marker + count > file->size) {
         file->size = file->marker + count;
         file->size = file->marker + count;
@@ -734,11 +734,12 @@ static int map_write (struct shim_handle * hdl, const void * buf,
             goto out;
             goto out;
         }
         }
 
 
-        if (ret < count)
-            file->size -= count - ret;
+        if (ret < count) {
+           file->size -= count - ret;
+        }
 
 
         if (check_version(hdl)) {
         if (check_version(hdl)) {
-            int size;
+            uint64_t size;
             do {
             do {
                 if ((size = atomic_read(&data->size)) >= file->size) {
                 if ((size = atomic_read(&data->size)) >= file->size) {
                     file->size = size;
                     file->size = size;
@@ -754,6 +755,7 @@ static int map_write (struct shim_handle * hdl, const void * buf,
     if ((ret = __map_buffer(hdl, count)) < 0)
     if ((ret = __map_buffer(hdl, count)) < 0)
         goto out;
         goto out;
 
 
+
     if (count) {
     if (count) {
         memcpy(file->mapbuf + (marker - file->mapoffset), buf, count);
         memcpy(file->mapbuf + (marker - file->mapoffset), buf, count);
         file->marker = marker + count;
         file->marker = marker + count;

+ 2 - 2
LibOS/shim/test/apps/apache/Makefile

@@ -39,10 +39,10 @@ APXS_FLAGS = -S CC="gcc -g"
 endif
 endif
 
 
 %: %.tar.gz
 %: %.tar.gz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 %: %.tar.bz2
 %: %.tar.bz2
-	tar -xjf $<
+	tar -xmjf $<
 
 
 $(INSTALL_DIR)/lib/libapr-1.so.0: $(APR_DIR)
 $(INSTALL_DIR)/lib/libapr-1.so.0: $(APR_DIR)
 	#cd $< && patch -p1 < ../disable-epoll.patch
 	#cd $< && patch -p1 < ../disable-epoll.patch

+ 1 - 1
LibOS/shim/test/apps/bash/Makefile

@@ -7,7 +7,7 @@ level = ../../
 include ../../Makefile
 include ../../Makefile
 
 
 $(bash_src): $(BASH_DIR).tar.gz
 $(bash_src): $(BASH_DIR).tar.gz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 $(bash_src)/bash: $(BASH_DIR)
 $(bash_src)/bash: $(BASH_DIR)
 	cd $(BASH_DIR) && ./configure --without-gnu-malloc
 	cd $(BASH_DIR) && ./configure --without-gnu-malloc

+ 5 - 5
LibOS/shim/test/apps/gcc/Makefile

@@ -52,7 +52,7 @@ obj/bin/ld: src/binutils-$(BINUTILS_VER)
 	$(MAKE) -C $< install
 	$(MAKE) -C $< install
 
 
 src/binutils-$(BINUTILS_VER): binutils-$(BINUTILS_VER).tar.bz2 src
 src/binutils-$(BINUTILS_VER): binutils-$(BINUTILS_VER).tar.bz2 src
-	cd src && tar -xjf ../$<
+	cd src && tar -xmjf ../$<
 
 
 obj/lib/$(GMP_OBJ) obj/lib/$(GMPXX_OBJ): src/$(GMP_SRC)
 obj/lib/$(GMP_OBJ) obj/lib/$(GMPXX_OBJ): src/$(GMP_SRC)
 	cd $< && ./configure --prefix=$(PWD)/obj --enable-cxx --enable-shared \
 	cd $< && ./configure --prefix=$(PWD)/obj --enable-cxx --enable-shared \
@@ -61,7 +61,7 @@ obj/lib/$(GMP_OBJ) obj/lib/$(GMPXX_OBJ): src/$(GMP_SRC)
 	$(MAKE) -C $< install
 	$(MAKE) -C $< install
 
 
 src/$(GMP_SRC): $(GMP_SRC).tar.bz2 src
 src/$(GMP_SRC): $(GMP_SRC).tar.bz2 src
-	cd src && tar -xjf ../$<
+	cd src && tar -xmjf ../$<
 
 
 obj/lib/$(PPL_OBJ): src/$(PPL_SRC) obj/lib/$(GMP_OBJ)
 obj/lib/$(PPL_OBJ): src/$(PPL_SRC) obj/lib/$(GMP_OBJ)
 	cd $< && ./configure --prefix=$(PWD)/obj --with-libgmp-prefix=$(PWD)/obj --enable-shared \
 	cd $< && ./configure --prefix=$(PWD)/obj --with-libgmp-prefix=$(PWD)/obj --enable-shared \
@@ -70,7 +70,7 @@ obj/lib/$(PPL_OBJ): src/$(PPL_SRC) obj/lib/$(GMP_OBJ)
 	$(MAKE) -C $< install
 	$(MAKE) -C $< install
 
 
 src/$(PPL_SRC): $(PPL_SRC).tar.gz src
 src/$(PPL_SRC): $(PPL_SRC).tar.gz src
-	cd src && tar -xzf ../$<
+	cd src && tar -xmzf ../$<
 
 
 obj/lib/$(MPFR_OBJ): src/$(MPFR_SRC) obj/lib/$(GMP_OBJ)
 obj/lib/$(MPFR_OBJ): src/$(MPFR_SRC) obj/lib/$(GMP_OBJ)
 	cd $< && ./configure --prefix=$(PWD)/obj --enable-shared \
 	cd $< && ./configure --prefix=$(PWD)/obj --enable-shared \
@@ -79,7 +79,7 @@ obj/lib/$(MPFR_OBJ): src/$(MPFR_SRC) obj/lib/$(GMP_OBJ)
 	$(MAKE) -C $< install
 	$(MAKE) -C $< install
 
 
 src/$(MPFR_SRC): $(MPFR_SRC).tar.bz2 src
 src/$(MPFR_SRC): $(MPFR_SRC).tar.bz2 src
-	cd src && tar -xjf ../$<
+	cd src && tar -xmjf ../$<
 
 
 obj/lib/$(MPC_OBJ): src/$(MPC_SRC)
 obj/lib/$(MPC_OBJ): src/$(MPC_SRC)
 	cd $< && ./configure --prefix=$(PWD)/obj --with-gmp=$(PWD)/obj --enable-shared \
 	cd $< && ./configure --prefix=$(PWD)/obj --with-gmp=$(PWD)/obj --enable-shared \
@@ -88,7 +88,7 @@ obj/lib/$(MPC_OBJ): src/$(MPC_SRC)
 	$(MAKE) -C $< install
 	$(MAKE) -C $< install
 
 
 src/$(MPC_SRC): $(MPC_SRC).tar.gz src
 src/$(MPC_SRC): $(MPC_SRC).tar.gz src
-	cd src && tar -xzf ../$<
+	cd src && tar -xmzf ../$<
 
 
 regression:
 regression:
 	@echo "\n\nBuilding GCC..."
 	@echo "\n\nBuilding GCC..."

+ 1 - 1
LibOS/shim/test/apps/lighttpd/Makefile

@@ -25,7 +25,7 @@ build/sbin/lighttpd: $(SRCDIR)
 	$(MAKE) -C $(SRCDIR) install
 	$(MAKE) -C $(SRCDIR) install
 
 
 $(SRCDIR): %: %.tar.gz
 $(SRCDIR): %: %.tar.gz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 lighttpd-server.conf:
 lighttpd-server.conf:
 	rm -rf $@
 	rm -rf $@

+ 1 - 1
LibOS/shim/test/apps/ltp/Makefile

@@ -16,7 +16,7 @@ $(SRCDIR).tar.xz:
 	wget $(SRCURL)/$(SRCVERSION)/$@
 	wget $(SRCURL)/$(SRCVERSION)/$@
 
 
 $(SRCDIR)/configure: $(SRCDIR).tar.xz
 $(SRCDIR)/configure: $(SRCDIR).tar.xz
-	tar -xJf $<
+	tar -xmJf $<
 	cd $(SRCDIR) && make autotools
 	cd $(SRCDIR) && make autotools
 
 
 $(BUILDDIR)/runltp: $(SRCDIR)/configure
 $(BUILDDIR)/runltp: $(SRCDIR)/configure

+ 6 - 0
LibOS/shim/test/apps/ltp/PASSED

@@ -362,6 +362,9 @@ pread01,1
 pread01_64,1
 pread01_64,1
 pread02,1
 pread02,1
 pread02_64,1
 pread02_64,1
+preadv01,2
+preadv01,3
+preadv01,4
 preadv01_64,2
 preadv01_64,2
 preadv01_64,3
 preadv01_64,3
 preadv01_64,4
 preadv01_64,4
@@ -976,6 +979,9 @@ wait401,1
 wait401,2
 wait401,2
 waitpid01,1
 waitpid01,1
 waitpid01,2
 waitpid01,2
+waitpid02,1
+waitpid02,2
+waitpid02,3
 waitpid05,1
 waitpid05,1
 waitpid05,2
 waitpid05,2
 waitpid05,3
 waitpid05,3

+ 1 - 1
LibOS/shim/test/apps/make/Makefile

@@ -25,7 +25,7 @@ test_targets = $(test_tarballs) helloworld graphene
 make_src = make-3.82
 make_src = make-3.82
 
 
 $(make_src) $(test_tarballs): %: %.tar.gz
 $(make_src) $(test_tarballs): %: %.tar.gz
-	[ -d $@ ] || tar -zxf $<
+	[ -d $@ ] || tar -zmxf $<
 
 
 $(make_src)/make:
 $(make_src)/make:
 	cd $(make_src) && ./configure
 	cd $(make_src) && ./configure

+ 2 - 2
LibOS/shim/test/apps/nginx/Makefile

@@ -24,7 +24,7 @@ build/sbin/nginx: $(SRCDIR)
 	$(MAKE) -C $(SRCDIR) install
 	$(MAKE) -C $(SRCDIR) install
 
 
 $(SRCDIR): %: %.tar.gz
 $(SRCDIR): %: %.tar.gz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 $(conf_files): %.t: %.t.template
 $(conf_files): %.t: %.t.template
 	sed $(extra_rules) $< > $@
 	sed $(extra_rules) $< > $@
@@ -46,7 +46,7 @@ test-data = build/html/oscar-web build/html/oscar-web-static build/html/random \
 	    $(addprefix build/html/random/,$(random-data))
 	    $(addprefix build/html/random/,$(random-data))
 
 
 build/html/%: ../web-data/%.tar.gz
 build/html/%: ../web-data/%.tar.gz
-	[ -d "$@" ] || (cd $(dir $@) && tar -xzf ../../$^)
+	[ -d "$@" ] || (cd $(dir $@) && tar -xmzf ../../$^)
 
 
 build/html/random:
 build/html/random:
 	mkdir -p $@
 	mkdir -p $@

+ 3 - 3
LibOS/shim/test/apps/openjdk/Makefile

@@ -33,17 +33,17 @@ JAVA_SRC = $(JAVA_DIR) $(JAVA_DIR)/hotspot $(JAVA_DIR)/jdk $(JAVA_DIR)/jdk/src/s
 JAVA_HOME = openjdk-7-jre
 JAVA_HOME = openjdk-7-jre
 
 
 $(JAVA_DIR): openjdk.tar.bz2
 $(JAVA_DIR): openjdk.tar.bz2
-	tar -xjf $<
+	tar -xmjf $<
 	rm -rf $@
 	rm -rf $@
 	mv $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) $@
 	mv $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) $@
 
 
 $(JAVA_DIR)/hotspot: hotspot.tar.bz2 | $(JAVA_DIR)
 $(JAVA_DIR)/hotspot: hotspot.tar.bz2 | $(JAVA_DIR)
-	tar -xjf $<
+	tar -xmjf $<
 	rm -rf $@
 	rm -rf $@
 	mv $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) $@
 	mv $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) $@
 
 
 $(JAVA_DIR)/jdk: jdk.tar.bz2 | $(JAVA_DIR)
 $(JAVA_DIR)/jdk: jdk.tar.bz2 | $(JAVA_DIR)
-	tar -xjf $<
+	tar -xmjf $<
 	rm -rf $@
 	rm -rf $@
 	cd $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) && patch -p1 < ../JDK-8015880.patch
 	cd $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) && patch -p1 < ../JDK-8015880.patch
 	mv $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) $@
 	mv $(shell tar -tjf $< | sed -e 's@/.*@@' | head -n 1) $@

+ 2 - 2
LibOS/shim/test/apps/python/Makefile

@@ -21,10 +21,10 @@ $(PYTHON_SRC)/Makefile: $(PYTHON_SRC)/configure
 		./configure --prefix=$(shell readlink -f $(PYTHON_INSTALL))
 		./configure --prefix=$(shell readlink -f $(PYTHON_INSTALL))
 
 
 $(PYTHON_SRC)/configure: $(PYTHON_SRC).tgz
 $(PYTHON_SRC)/configure: $(PYTHON_SRC).tgz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 benchmarks: benchmarks.tar.gz
 benchmarks: benchmarks.tar.gz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 regression: 
 regression: 
 	@echo "\n\nBuilding Python..."
 	@echo "\n\nBuilding Python..."

+ 1 - 1
LibOS/shim/test/apps/r/Makefile

@@ -20,7 +20,7 @@ $(R_SRC)/Makefile: $(R_SRC)/configure
 		./configure --prefix=$(shell readlink -f $(R_INSTALL))
 		./configure --prefix=$(shell readlink -f $(R_INSTALL))
 
 
 $(R_SRC)/configure: $(R_SRC).tar.gz
 $(R_SRC)/configure: $(R_SRC).tar.gz
-	tar -xzf $<
+	tar -xmzf $<
 
 
 distclean: clean
 distclean: clean
 	rm -rf $(R_SRC)
 	rm -rf $(R_SRC)

+ 1 - 0
Pal/lib/slabmgr.h

@@ -27,6 +27,7 @@
 #define SLABMGR_H
 #define SLABMGR_H
 
 
 #include "list.h"
 #include "list.h"
+#include <pal_debug.h>
 #include <assert.h>
 #include <assert.h>
 #include <sys/mman.h>
 #include <sys/mman.h>
 
 

+ 11 - 11
Pal/src/db_streams.c

@@ -250,8 +250,8 @@ void DkStreamDelete (PAL_HANDLE handle, PAL_FLG access)
 
 
 /* _DkStreamRead for internal use. Read from stream as absolute offset.
 /* _DkStreamRead for internal use. Read from stream as absolute offset.
    The actual behavior of stream read is defined by handler */
    The actual behavior of stream read is defined by handler */
-int _DkStreamRead (PAL_HANDLE handle, int offset, int count, void * buf,
-                   char * addr, int addrlen)
+int64_t _DkStreamRead (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                       void * buf, char * addr, int addrlen)
 {
 {
     if (UNKNOWN_HANDLE(handle))
     if (UNKNOWN_HANDLE(handle))
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
@@ -266,7 +266,7 @@ int _DkStreamRead (PAL_HANDLE handle, int offset, int count, void * buf,
     if (!count)
     if (!count)
         return -PAL_ERROR_ZEROSIZE;
         return -PAL_ERROR_ZEROSIZE;
 
 
-    int ret;
+    int64_t ret;
 
 
     if (addr) {
     if (addr) {
         if (!ops->readbyaddr)
         if (!ops->readbyaddr)
@@ -296,9 +296,9 @@ DkStreamRead (PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count,
         LEAVE_PAL_CALL_RETURN(0);
         LEAVE_PAL_CALL_RETURN(0);
     }
     }
 
 
-    int ret = _DkStreamRead(handle, offset, count, (void *) buffer,
-                            size ? (char *) source : NULL,
-                            source ? size : 0);
+    int64_t ret = _DkStreamRead(handle, offset, count, (void *) buffer,
+                                size ? (char *) source : NULL,
+                                source ? size : 0);
 
 
     if (ret < 0) {
     if (ret < 0) {
         _DkRaiseFailure(-ret);
         _DkRaiseFailure(-ret);
@@ -310,8 +310,8 @@ DkStreamRead (PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count,
 
 
 /* _DkStreamWrite for internal use, write to stream at absolute offset.
 /* _DkStreamWrite for internal use, write to stream at absolute offset.
    The actual behavior of stream write is defined by handler */
    The actual behavior of stream write is defined by handler */
-int _DkStreamWrite (PAL_HANDLE handle, int offset, int count, const void * buf,
-                    const char * addr, int addrlen)
+int64_t _DkStreamWrite (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                        const void * buf, const char * addr, int addrlen)
 {
 {
     if (UNKNOWN_HANDLE(handle))
     if (UNKNOWN_HANDLE(handle))
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
@@ -324,7 +324,7 @@ int _DkStreamWrite (PAL_HANDLE handle, int offset, int count, const void * buf,
     if (!count)
     if (!count)
         return -PAL_ERROR_ZEROSIZE;
         return -PAL_ERROR_ZEROSIZE;
 
 
-    int ret;
+    int64_t ret;
 
 
     if (addr) {
     if (addr) {
         if (!ops->writebyaddr)
         if (!ops->writebyaddr)
@@ -354,8 +354,8 @@ DkStreamWrite (PAL_HANDLE handle, PAL_NUM offset, PAL_NUM count,
         LEAVE_PAL_CALL_RETURN(0);
         LEAVE_PAL_CALL_RETURN(0);
     }
     }
 
 
-    int ret = _DkStreamWrite(handle, offset, count, (void *) buffer, dest,
-                             dest ? strlen(dest) : 0);
+    int64_t ret = _DkStreamWrite(handle, offset, count, (void *) buffer, dest,
+                                 dest ? strlen(dest) : 0);
 
 
     if (ret < 0) {
     if (ret < 0) {
         _DkRaiseFailure(-ret);
         _DkRaiseFailure(-ret);

+ 17 - 8
Pal/src/host/Linux-SGX/db_devices.c

@@ -85,8 +85,9 @@ static int parse_device_uri (const char ** uri, const char ** type,
 static inline void
 static inline void
 dev_attrcopy (PAL_STREAM_ATTR * attr, struct stat * stat);
 dev_attrcopy (PAL_STREAM_ATTR * attr, struct stat * stat);
 
 
-static int char_read (PAL_HANDLE handle, int offset, int count, void * buffer);
-static int char_write (PAL_HANDLE handle, int offset, int count,
+static int64_t char_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                          void * buffer);
+static int64_t char_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
                        const void * buffer);
                        const void * buffer);
 static int term_attrquery (const char * type, const char * uri,
 static int term_attrquery (const char * type, const char * uri,
                            PAL_STREAM_ATTR * attr);
                            PAL_STREAM_ATTR * attr);
@@ -181,25 +182,32 @@ static struct handle_ops term_ops = {
     };
     };
 
 
 /* 'read' operation for character streams. */
 /* 'read' operation for character streams. */
-static int char_read (PAL_HANDLE handle, int offset, int size, void * buffer)
+static int64_t char_read (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                          void * buffer)
 {
 {
     int fd = handle->dev.fd_in;
     int fd = handle->dev.fd_in;
 
 
     if (fd == PAL_IDX_POISON)
     if (fd == PAL_IDX_POISON)
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;
 
 
+    if (size >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     return ocall_read(fd, buffer, size);
     return ocall_read(fd, buffer, size);
 }
 }
 
 
 /* 'write' operation for character streams. */
 /* 'write' operation for character streams. */
-static int char_write (PAL_HANDLE handle, int offset, int size,
-                      const void * buffer)
+static int64_t char_write (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                           const void * buffer)
 {
 {
     int fd = handle->dev.fd_out;
     int fd = handle->dev.fd_out;
 
 
     if (fd == PAL_IDX_POISON)
     if (fd == PAL_IDX_POISON)
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;
 
 
+    if (size >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     return ocall_write(fd, buffer, size);
     return ocall_write(fd, buffer, size);
 }
 }
 
 
@@ -230,7 +238,8 @@ static int dev_open (PAL_HANDLE * handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation for device stream */
 /* 'read' operation for device stream */
-static int dev_read (PAL_HANDLE handle, int offset, int size, void * buffer)
+static int64_t dev_read (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                         void * buffer)
 {
 {
     const struct handle_ops * ops = DEVICE_OPS(handle);
     const struct handle_ops * ops = DEVICE_OPS(handle);
 
 
@@ -241,8 +250,8 @@ static int dev_read (PAL_HANDLE handle, int offset, int size, void * buffer)
 }
 }
 
 
 /* 'write' operation for device stream */
 /* 'write' operation for device stream */
-static int dev_write (PAL_HANDLE handle, int offset, int size,
-                      const void * buffer)
+static int64_t dev_write (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                          const void * buffer)
 {
 {
     const struct handle_ops * ops = DEVICE_OPS(handle);
     const struct handle_ops * ops = DEVICE_OPS(handle);
 
 

+ 14 - 13
Pal/src/host/Linux-SGX/db_files.c

@@ -83,7 +83,7 @@ static int file_open (PAL_HANDLE * handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation for file streams. */
 /* 'read' operation for file streams. */
-static int file_read (PAL_HANDLE handle, int offset, int count,
+static int64_t file_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
                       void * buffer)
                       void * buffer)
 {
 {
     sgx_stub_t * stubs = (sgx_stub_t *) handle->file.stubs;
     sgx_stub_t * stubs = (sgx_stub_t *) handle->file.stubs;
@@ -93,8 +93,8 @@ static int file_read (PAL_HANDLE handle, int offset, int count,
     if (offset >= total)
     if (offset >= total)
         return 0;
         return 0;
 
 
-    unsigned long end = (offset + count > total) ? total : offset + count;
-    unsigned long map_start, map_end;
+    uint64_t end = (offset + count > total) ? total : offset + count;
+    uint64_t map_start, map_end;
 
 
     if (stubs) {
     if (stubs) {
         map_start = offset & ~(TRUSTED_STUB_SIZE - 1);
         map_start = offset & ~(TRUSTED_STUB_SIZE - 1);
@@ -127,18 +127,19 @@ static int file_read (PAL_HANDLE handle, int offset, int count,
 }
 }
 
 
 /* 'write' operation for file streams. */
 /* 'write' operation for file streams. */
-static int file_write (PAL_HANDLE handle, int offset, int count,
-                       const void * buffer)
+static int64_t file_write(PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                          const void * buffer)
 {
 {
-    unsigned long map_start = ALLOC_ALIGNDOWN(offset);
-    unsigned long map_end = ALLOC_ALIGNUP(offset + count);
+    uint64_t map_start = ALLOC_ALIGNDOWN(offset);
+    uint64_t map_end = ALLOC_ALIGNUP(offset + count);
     void * umem;
     void * umem;
     int ret;
     int ret;
 
 
     ret = ocall_map_untrusted(handle->file.fd, map_start,
     ret = ocall_map_untrusted(handle->file.fd, map_start,
                               map_end - map_start, PROT_WRITE, &umem);
                               map_end - map_start, PROT_WRITE, &umem);
-    if (ret < 0)
+    if (ret < 0) {
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;
+    }
 
 
     if (offset + count > handle->file.total) {
     if (offset + count > handle->file.total) {
         ocall_ftruncate(handle->file.fd, offset + count);
         ocall_ftruncate(handle->file.fd, offset + count);
@@ -180,13 +181,12 @@ static int file_map (PAL_HANDLE handle, void ** addr, int prot,
                      uint64_t offset, uint64_t size)
                      uint64_t offset, uint64_t size)
 {
 {
     sgx_stub_t * stubs = (sgx_stub_t *) handle->file.stubs;
     sgx_stub_t * stubs = (sgx_stub_t *) handle->file.stubs;
-    unsigned int total = handle->file.total;
+    uint64_t total = handle->file.total;
     void * mem = *addr;
     void * mem = *addr;
     void * umem;
     void * umem;
     int ret;
     int ret;
 
 
     if (!stubs && !(prot & PAL_PROT_WRITECOPY)) {
     if (!stubs && !(prot & PAL_PROT_WRITECOPY)) {
-map_untrusted:
         ret = ocall_map_untrusted(handle->file.fd, offset, size,
         ret = ocall_map_untrusted(handle->file.fd, offset, size,
                                   HOST_PROT(prot), &mem);
                                   HOST_PROT(prot), &mem);
         if (!ret)
         if (!ret)
@@ -199,8 +199,8 @@ map_untrusted:
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;
     }
     }
 
 
-    unsigned long end = (offset + size > total) ? total : offset + size;
-    unsigned long map_start, map_end;
+    uint64_t end = (offset + size > total) ? total : offset + size;
+    uint64_t map_start, map_end;
 
 
     if (stubs) {
     if (stubs) {
         map_start = offset & ~(TRUSTED_STUB_SIZE - 1);
         map_start = offset & ~(TRUSTED_STUB_SIZE - 1);
@@ -426,7 +426,8 @@ static int dir_open (PAL_HANDLE * handle, const char * type, const char * uri,
 
 
 /* 'read' operation for directory stream. Directory stream will not
 /* 'read' operation for directory stream. Directory stream will not
    need a 'write' operat4on. */
    need a 'write' operat4on. */
-int dir_read (PAL_HANDLE handle, int offset, int count, void * buf)
+static int64_t dir_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                         void * buf)
 {
 {
     void * dent_buf = (void *) handle->dir.buf ? : __alloca(DIRBUF_SIZE);
     void * dent_buf = (void *) handle->dir.buf ? : __alloca(DIRBUF_SIZE);
     void * ptr = (void *) handle->dir.ptr;
     void * ptr = (void *) handle->dir.ptr;

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

@@ -153,7 +153,7 @@ static int mutex_wait (PAL_HANDLE handle, uint64_t timeout)
 
 
 static int mutex_close (PAL_HANDLE handle)
 static int mutex_close (PAL_HANDLE handle)
 {
 {
-    free_untrusted(handle->mutex.mut.locked);
+    free_untrusted((int64_t *) handle->mutex.mut.locked);
     return 0;
     return 0;
 }
 }
 
 

+ 10 - 4
Pal/src/host/Linux-SGX/db_pipes.c

@@ -187,14 +187,17 @@ static int pipe_open (PAL_HANDLE *handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation of pipe stream. offset does not apply here. */
 /* 'read' operation of pipe stream. offset does not apply here. */
-static int pipe_read (PAL_HANDLE handle, int offset, int len,
-                      void * buffer)
+static int64_t pipe_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                          void * buffer)
 {
 {
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
         !IS_HANDLE_TYPE(handle, pipe))
         !IS_HANDLE_TYPE(handle, pipe))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[0] :
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[0] :
              handle->pipe.fd;
              handle->pipe.fd;
     int bytes = ocall_sock_recv(fd, buffer, len, NULL, NULL);
     int bytes = ocall_sock_recv(fd, buffer, len, NULL, NULL);
@@ -209,14 +212,17 @@ static int pipe_read (PAL_HANDLE handle, int offset, int len,
 }
 }
 
 
 /* 'write' operation of pipe stream. offset does not apply here. */
 /* 'write' operation of pipe stream. offset does not apply here. */
-static int pipe_write (PAL_HANDLE handle, int offset, int len,
-                       const void * buffer)
+static int64_t pipe_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                           const void * buffer)
 {
 {
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
         !IS_HANDLE_TYPE(handle, pipe))
         !IS_HANDLE_TYPE(handle, pipe))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[1] :
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[1] :
              handle->pipe.fd;
              handle->pipe.fd;
     int bytes = ocall_sock_send(fd, buffer, len, NULL, 0);
     int bytes = ocall_sock_send(fd, buffer, len, NULL, 0);

+ 9 - 3
Pal/src/host/Linux-SGX/db_process.c

@@ -332,15 +332,21 @@ int _DkProcessSandboxCreate (const char * manifest, int flags)
     return -PAL_ERROR_NOTIMPLEMENTED;
     return -PAL_ERROR_NOTIMPLEMENTED;
 }
 }
 
 
-static int proc_read (PAL_HANDLE handle, int offset, int count,
+static int64_t proc_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
                           void * buffer)
                           void * buffer)
 {
 {
+    if (count >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     return ocall_read(handle->process.stream_in, buffer, count);
     return ocall_read(handle->process.stream_in, buffer, count);
 }
 }
 
 
-static int proc_write (PAL_HANDLE handle, int offset, int count,
-                       const void * buffer)
+static int64_t proc_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                           const void * buffer)
 {
 {
+    if (count >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int bytes = ocall_write(handle->process.stream_out, buffer, count);
     int bytes = ocall_write(handle->process.stream_out, buffer, count);
 
 
     if (bytes == -PAL_ERROR_TRYAGAIN)
     if (bytes == -PAL_ERROR_TRYAGAIN)

+ 40 - 11
Pal/src/host/Linux-SGX/db_sockets.c

@@ -474,7 +474,8 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation of tcp stream */
 /* 'read' operation of tcp stream */
-static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
+static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                         void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -482,6 +483,9 @@ static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
     if (handle->sock.fd == PAL_IDX_POISON)
     if (handle->sock.fd == PAL_IDX_POISON)
         return -PAL_ERROR_ENDOFSTREAM;
         return -PAL_ERROR_ENDOFSTREAM;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int bytes = ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
     int bytes = ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
 
 
     if (bytes < 0)
     if (bytes < 0)
@@ -494,7 +498,8 @@ static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
 }
 }
 
 
 /* write' operation of tcp stream */
 /* write' operation of tcp stream */
-static int tcp_write (PAL_HANDLE handle, int offset, int len, const void * buf)
+static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                          const void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -502,6 +507,9 @@ static int tcp_write (PAL_HANDLE handle, int offset, int len, const void * buf)
     if (handle->sock.fd == PAL_IDX_POISON)
     if (handle->sock.fd == PAL_IDX_POISON)
         return -PAL_ERROR_CONNFAILED;
         return -PAL_ERROR_CONNFAILED;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
     int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
 
 
     if (bytes == -PAL_ERROR_TRYAGAIN)
     if (bytes == -PAL_ERROR_TRYAGAIN)
@@ -621,7 +629,8 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
     return -PAL_ERROR_NOTSUPPORT;
     return -PAL_ERROR_NOTSUPPORT;
 }
 }
 
 
-static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
+static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                            void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udp))
     if (!IS_HANDLE_TYPE(handle, udp))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -629,11 +638,14 @@ static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
     if (handle->sock.fd == PAL_IDX_POISON)
     if (handle->sock.fd == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     return ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
     return ocall_sock_recv(handle->sock.fd, buf, len, NULL, NULL);
 }
 }
 
 
-static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
-                              void * buf, char * addr, int addrlen)
+static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                                  void * buf, char * addr, int addrlen)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udpsrv))
     if (!IS_HANDLE_TYPE(handle, udpsrv))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -641,6 +653,9 @@ static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
     if (handle->sock.fd == PAL_IDX_POISON)
     if (handle->sock.fd == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     struct sockaddr conn_addr;
     struct sockaddr conn_addr;
     socklen_t conn_addrlen = sizeof(struct sockaddr);
     socklen_t conn_addrlen = sizeof(struct sockaddr);
 
 
@@ -662,7 +677,8 @@ static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
     return bytes;
     return bytes;
 }
 }
 
 
-static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
+static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                         const void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udp))
     if (!IS_HANDLE_TYPE(handle, udp))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -670,6 +686,9 @@ static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
     if (handle->sock.fd == PAL_IDX_POISON)
     if (handle->sock.fd == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
     int bytes = ocall_sock_send(handle->sock.fd, buf, len, NULL, 0);
 
 
     if (bytes == -PAL_ERROR_TRYAGAIN)
     if (bytes == -PAL_ERROR_TRYAGAIN)
@@ -686,8 +705,8 @@ static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
     return bytes;
     return bytes;
 }
 }
 
 
-static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
-                           const void * buf, const char * addr, int addrlen)
+static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                               const void * buf, const char * addr, int addrlen)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udpsrv))
     if (!IS_HANDLE_TYPE(handle, udpsrv))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -698,6 +717,9 @@ static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
     if (!strpartcmp_static(addr, "udp:"))
     if (!strpartcmp_static(addr, "udp:"))
         return -PAL_ERROR_INVAL;
         return -PAL_ERROR_INVAL;
 
 
+    if (len >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     addr    += static_strlen("udp:");
     addr    += static_strlen("udp:");
     addrlen -= static_strlen("udp:");
     addrlen -= static_strlen("udp:");
 
 
@@ -1036,12 +1058,15 @@ PAL_HANDLE _DkBroadcastStreamOpen (void)
     return hdl;
     return hdl;
 }
 }
 
 
-static int mcast_send (PAL_HANDLE handle, int offset, int size,
-                       const void * buf)
+static int64_t mcast_send (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                           const void * buf)
 {
 {
     if (handle->mcast.srv == PAL_IDX_POISON)
     if (handle->mcast.srv == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
 
 
+    if (size >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int bytes = ocall_sock_send(handle->mcast.srv, buf, size,
     int bytes = ocall_sock_send(handle->mcast.srv, buf, size,
                                 NULL, 0);
                                 NULL, 0);
 
 
@@ -1059,11 +1084,15 @@ static int mcast_send (PAL_HANDLE handle, int offset, int size,
     return bytes;
     return bytes;
 }
 }
 
 
-static int mcast_receive (PAL_HANDLE handle, int offset, int size, void * buf)
+static int64_t mcast_receive (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                              void * buf)
 {
 {
     if (handle->mcast.cli == PAL_IDX_POISON)
     if (handle->mcast.cli == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
 
 
+    if (size >= (1ULL << (sizeof(unsigned int) * 8)))
+        return -PAL_ERROR_INVAL;
+
     int bytes = ocall_sock_recv(handle->mcast.cli, buf, size, NULL,
     int bytes = ocall_sock_recv(handle->mcast.cli, buf, size, NULL,
                                 NULL);
                                 NULL);
 
 

+ 4 - 5
Pal/src/host/Linux-SGX/enclave_framework.c

@@ -280,16 +280,15 @@ failed:
 }
 }
 
 
 int verify_trusted_file (const char * uri, void * mem,
 int verify_trusted_file (const char * uri, void * mem,
-                         unsigned int offset, unsigned int size,
+                         uint64_t offset, uint64_t size,
                          sgx_stub_t * stubs,
                          sgx_stub_t * stubs,
-                         unsigned int total_size)
+                         uint64_t total_size)
 {
 {
-    unsigned long checking = offset;
+    uint64_t checking = offset;
     sgx_stub_t * s = stubs + checking / TRUSTED_STUB_SIZE;
     sgx_stub_t * s = stubs + checking / TRUSTED_STUB_SIZE;
-    int ret;
 
 
     for (; checking < offset + size ; checking += TRUSTED_STUB_SIZE, s++) {
     for (; checking < offset + size ; checking += TRUSTED_STUB_SIZE, s++) {
-        unsigned long checking_size = TRUSTED_STUB_SIZE;
+        uint64_t checking_size = TRUSTED_STUB_SIZE;
         if (checking_size > total_size - checking)
         if (checking_size > total_size - checking)
             checking_size = total_size - checking;
             checking_size = total_size - checking;
 
 

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

@@ -91,7 +91,7 @@ int ocall_print_string (const char * str, unsigned int length)
     return retval;
     return retval;
 }
 }
 
 
-int ocall_alloc_untrusted (unsigned int size, void ** mem)
+int ocall_alloc_untrusted (uint64_t size, void ** mem)
 {
 {
     int retval = 0;
     int retval = 0;
     ms_ocall_alloc_untrusted_t * ms;
     ms_ocall_alloc_untrusted_t * ms;
@@ -343,7 +343,7 @@ int ocall_fsync (int fd)
     return retval;
     return retval;
 }
 }
 
 
-int ocall_ftruncate (int fd, unsigned int length)
+int ocall_ftruncate (int fd, uint64_t length)
 {
 {
     int retval = 0;
     int retval = 0;
     ms_ocall_ftruncate_t * ms;
     ms_ocall_ftruncate_t * ms;

+ 2 - 2
Pal/src/host/Linux-SGX/enclave_ocalls.h

@@ -15,7 +15,7 @@ int ocall_exit (void);
 
 
 int ocall_print_string (const char * str, unsigned int length);
 int ocall_print_string (const char * str, unsigned int length);
 
 
-int ocall_alloc_untrusted (unsigned int size, void ** mem);
+int ocall_alloc_untrusted (uint64_t size, void ** mem);
 
 
 int ocall_map_untrusted (int fd, uint64_t offset,
 int ocall_map_untrusted (int fd, uint64_t offset,
                          uint64_t size, unsigned short prot,
                          uint64_t size, unsigned short prot,
@@ -46,7 +46,7 @@ int ocall_fchmod (int fd, unsigned short mode);
 
 
 int ocall_fsync (int fd);
 int ocall_fsync (int fd);
 
 
-int ocall_ftruncate (int fd, unsigned int length);
+int ocall_ftruncate (int fd, uint64_t length);
 
 
 int ocall_mkdir (const char *pathname, unsigned short mode);
 int ocall_mkdir (const char *pathname, unsigned short mode);
 
 

+ 13 - 8
Pal/src/host/Linux-SGX/ocall_types.h

@@ -7,6 +7,14 @@
 
 
 #include "linux_types.h"
 #include "linux_types.h"
 
 
+/*
+ * GCC's structure padding may cause leaking from uninialized
+ * regions (https://arxiv.org/abs/1710.09061).
+ * A simple contermeasure is to enable packing for all ocall
+ * argument structures.
+ */
+#pragma pack(push, 1)
+
 enum {
 enum {
     OCALL_EXIT = 0,
     OCALL_EXIT = 0,
     OCALL_PRINT_STRING,
     OCALL_PRINT_STRING,
@@ -52,11 +60,11 @@ enum {
 
 
 typedef struct {
 typedef struct {
     const char * ms_str;
     const char * ms_str;
-    int ms_length;
+    unsigned int ms_length;
 } ms_ocall_print_string_t;
 } ms_ocall_print_string_t;
 
 
 typedef struct {
 typedef struct {
-    unsigned int ms_size;
+    uint64_t ms_size;
     void * ms_mem;
     void * ms_mem;
 } ms_ocall_alloc_untrusted_t;
 } ms_ocall_alloc_untrusted_t;
 
 
@@ -106,11 +114,6 @@ typedef struct {
     struct stat ms_stat;
     struct stat ms_stat;
 } ms_ocall_fstat_t;
 } ms_ocall_fstat_t;
 
 
-typedef struct {
-    const char * ms_path;
-    struct stat * ms_stat;
-} ms_ocall_stat_t;
-
 typedef struct {
 typedef struct {
     int ms_fd;
     int ms_fd;
 } ms_ocall_fionread_t;
 } ms_ocall_fionread_t;
@@ -131,7 +134,7 @@ typedef struct {
 
 
 typedef struct {
 typedef struct {
     int ms_fd;
     int ms_fd;
-    unsigned int ms_length;
+    uint64_t ms_length;
 } ms_ocall_ftruncate_t;
 } ms_ocall_ftruncate_t;
 
 
 typedef struct {
 typedef struct {
@@ -258,3 +261,5 @@ typedef struct {
 typedef struct {
 typedef struct {
     unsigned int ms_tid;
     unsigned int ms_tid;
 } ms_ocall_schedule_t;
 } ms_ocall_schedule_t;
+
+#pragma pack(pop)

+ 2 - 2
Pal/src/host/Linux-SGX/pal_linux.h

@@ -107,8 +107,8 @@ int init_trusted_files (void);
 int load_trusted_file
 int load_trusted_file
     (PAL_HANDLE file, sgx_stub_t ** stubptr, uint64_t * sizeptr);
     (PAL_HANDLE file, sgx_stub_t ** stubptr, uint64_t * sizeptr);
 int verify_trusted_file
 int verify_trusted_file
-    (const char * uri, void * mem, unsigned int offset, unsigned int size,
-     sgx_stub_t * stubs, unsigned int total_size);
+    (const char * uri, void * mem, uint64_t offset, uint64_t size,
+     sgx_stub_t * stubs, uint64_t total_size);
 
 
 int init_trusted_children (void);
 int init_trusted_children (void);
 int register_trusted_child (const char * uri, const char * mrenclave_str);
 int register_trusted_child (const char * uri, const char * mrenclave_str);

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

@@ -843,8 +843,8 @@ static int load_enclave (struct pal_enclave * enclave,
     /* start running trusted PAL */
     /* start running trusted PAL */
     ecall_enclave_start(arguments, environments);
     ecall_enclave_start(arguments, environments);
 
 
-    PAL_NUM exit_time = 0;
 #if PRINT_ENCLAVE_STAT == 1
 #if PRINT_ENCLAVE_STAT == 1
+    PAL_NUM exit_time = 0;
     INLINE_SYSCALL(gettimeofday, 2, &tv, NULL);
     INLINE_SYSCALL(gettimeofday, 2, &tv, NULL);
     exit_time = tv.tv_sec * 1000000UL + tv.tv_usec;
     exit_time = tv.tv_sec * 1000000UL + tv.tv_usec;
 #endif
 #endif

+ 14 - 11
Pal/src/host/Linux/db_devices.c

@@ -86,9 +86,10 @@ static int parse_device_uri (const char ** uri, const char ** type,
 static inline void
 static inline void
 dev_attrcopy (PAL_STREAM_ATTR * attr, struct stat * stat);
 dev_attrcopy (PAL_STREAM_ATTR * attr, struct stat * stat);
 
 
-static int char_read (PAL_HANDLE handle, int offset, int count, void * buffer);
-static int char_write (PAL_HANDLE handle, int offset, int count,
-                       const void * buffer);
+static int64_t char_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                          void * buffer);
+static int64_t char_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                           const void * buffer);
 static int term_attrquery (const char * type, const char * uri,
 static int term_attrquery (const char * type, const char * uri,
                            PAL_STREAM_ATTR * attr);
                            PAL_STREAM_ATTR * attr);
 static int term_attrquerybyhdl (PAL_HANDLE hdl,
 static int term_attrquerybyhdl (PAL_HANDLE hdl,
@@ -182,14 +183,15 @@ static struct handle_ops term_ops = {
     };
     };
 
 
 /* 'read' operation for character streams. */
 /* 'read' operation for character streams. */
-static int char_read (PAL_HANDLE handle, int offset, int size, void * buffer)
+static int64_t char_read (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                          void * buffer)
 {
 {
     int fd = handle->dev.fd_in;
     int fd = handle->dev.fd_in;
 
 
     if (fd == PAL_IDX_POISON)
     if (fd == PAL_IDX_POISON)
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;
 
 
-    int bytes = INLINE_SYSCALL(read, 3, fd, buffer, size);
+    int64_t bytes = INLINE_SYSCALL(read, 3, fd, buffer, size);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         return unix_to_pal_error(ERRNO(bytes));
         return unix_to_pal_error(ERRNO(bytes));
@@ -198,15 +200,15 @@ static int char_read (PAL_HANDLE handle, int offset, int size, void * buffer)
 }
 }
 
 
 /* 'write' operation for character streams. */
 /* 'write' operation for character streams. */
-static int char_write (PAL_HANDLE handle, int offset, int size,
-                      const void * buffer)
+static int64_t char_write (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                           const void * buffer)
 {
 {
     int fd = handle->dev.fd_out;
     int fd = handle->dev.fd_out;
 
 
     if (fd == PAL_IDX_POISON)
     if (fd == PAL_IDX_POISON)
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;
 
 
-    int bytes = INLINE_SYSCALL(write, 3, fd, buffer, size);
+    int64_t bytes = INLINE_SYSCALL(write, 3, fd, buffer, size);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         return unix_to_pal_error(ERRNO(bytes));
         return unix_to_pal_error(ERRNO(bytes));
@@ -241,7 +243,8 @@ static int dev_open (PAL_HANDLE * handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation for device stream */
 /* 'read' operation for device stream */
-static int dev_read (PAL_HANDLE handle, int offset, int size, void * buffer)
+static int64_t dev_read (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                         void * buffer)
 {
 {
     const struct handle_ops * ops = DEVICE_OPS(handle);
     const struct handle_ops * ops = DEVICE_OPS(handle);
 
 
@@ -252,8 +255,8 @@ static int dev_read (PAL_HANDLE handle, int offset, int size, void * buffer)
 }
 }
 
 
 /* 'write' operation for device stream */
 /* 'write' operation for device stream */
-static int dev_write (PAL_HANDLE handle, int offset, int size,
-                      const void * buffer)
+static int64_t dev_write (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                          const void * buffer)
 {
 {
     const struct handle_ops * ops = DEVICE_OPS(handle);
     const struct handle_ops * ops = DEVICE_OPS(handle);
 
 

+ 7 - 7
Pal/src/host/Linux/db_files.c

@@ -74,11 +74,11 @@ static int file_open (PAL_HANDLE * handle, const char * type, const char * uri,
 #endif
 #endif
 
 
 /* 'read' operation for file streams. */
 /* 'read' operation for file streams. */
-static int file_read (PAL_HANDLE handle, int offset, int count,
-                      void * buffer)
+static int64_t file_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                          void * buffer)
 {
 {
     int fd = handle->file.fd;
     int fd = handle->file.fd;
-    int ret;
+    int64_t ret;
 
 
     if (handle->file.offset != offset) {
     if (handle->file.offset != offset) {
         ret = INLINE_SYSCALL(lseek, 3, fd, offset, SEEK_SET);
         ret = INLINE_SYSCALL(lseek, 3, fd, offset, SEEK_SET);
@@ -98,11 +98,11 @@ static int file_read (PAL_HANDLE handle, int offset, int count,
 }
 }
 
 
 /* 'write' operation for file streams. */
 /* 'write' operation for file streams. */
-static int file_write (PAL_HANDLE handle, int offset, int count,
-                       const void * buffer)
+static int64_t file_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                           const void * buffer)
 {
 {
     int fd = handle->file.fd;
     int fd = handle->file.fd;
-    int ret;
+    int64_t ret;
 
 
     if (handle->file.offset != offset) {
     if (handle->file.offset != offset) {
         ret = INLINE_SYSCALL(lseek, 3, fd, offset, SEEK_SET);
         ret = INLINE_SYSCALL(lseek, 3, fd, offset, SEEK_SET);
@@ -373,7 +373,7 @@ struct linux_dirent64 {
 
 
 /* 'read' operation for directory stream. Directory stream will not
 /* 'read' operation for directory stream. Directory stream will not
    need a 'write' operat4on. */
    need a 'write' operat4on. */
-int dir_read (PAL_HANDLE handle, int offset, int count, void * buf)
+int64_t dir_read (PAL_HANDLE handle, uint64_t offset, uint64_t count, void * buf)
 {
 {
     void * dent_buf = (void *) handle->dir.buf ? : __alloca(DIRBUF_SIZE);
     void * dent_buf = (void *) handle->dir.buf ? : __alloca(DIRBUF_SIZE);
     void * ptr = (void *) handle->dir.ptr;
     void * ptr = (void *) handle->dir.ptr;

+ 6 - 6
Pal/src/host/Linux/db_pipes.c

@@ -321,8 +321,8 @@ static int pipe_open (PAL_HANDLE *handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation of pipe stream. offset does not apply here. */
 /* 'read' operation of pipe stream. offset does not apply here. */
-static int pipe_read (PAL_HANDLE handle, int offset, int len,
-                      void * buffer)
+static int64_t pipe_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                          void * buffer)
 {
 {
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
@@ -331,7 +331,7 @@ static int pipe_read (PAL_HANDLE handle, int offset, int len,
 
 
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[0] :
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[0] :
              handle->pipe.fd;
              handle->pipe.fd;
-    int bytes = 0;
+    int64_t bytes = 0;
 
 
 #if USE_PIPE_SYSCALL == 1
 #if USE_PIPE_SYSCALL == 1
     if (IS_HANDLE_TYPE(handle, pipeprv)) {
     if (IS_HANDLE_TYPE(handle, pipeprv)) {
@@ -377,8 +377,8 @@ static int pipe_read (PAL_HANDLE handle, int offset, int len,
 }
 }
 
 
 /* 'write' operation of pipe stream. offset does not apply here. */
 /* 'write' operation of pipe stream. offset does not apply here. */
-static int pipe_write (PAL_HANDLE handle, int offset, int len,
-                       const void * buffer)
+static int64_t pipe_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                           const void * buffer)
 {
 {
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
     if (!IS_HANDLE_TYPE(handle, pipecli) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
         !IS_HANDLE_TYPE(handle, pipeprv) &&
@@ -387,7 +387,7 @@ static int pipe_write (PAL_HANDLE handle, int offset, int len,
 
 
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[1] :
     int fd = IS_HANDLE_TYPE(handle, pipeprv) ? handle->pipeprv.fds[1] :
              handle->pipe.fd;
              handle->pipe.fd;
-    int bytes = 0;
+    int64_t bytes = 0;
 
 
 #if USE_PIPE_SYSCALL == 1
 #if USE_PIPE_SYSCALL == 1
     if (IS_HANDLE_TYPE(handle, pipeprv)) {
     if (IS_HANDLE_TYPE(handle, pipeprv)) {

+ 9 - 9
Pal/src/host/Linux/db_process.c

@@ -494,16 +494,16 @@ int _DkProcessSandboxCreate (const char * manifest, int flags)
     return set_graphene_task(manifest, flags);
     return set_graphene_task(manifest, flags);
 }
 }
 
 
-static int proc_read (PAL_HANDLE handle, int offset, int count,
-                          void * buffer)
+static int64_t proc_read (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                      void * buffer)
 {
 {
-    int bytes = INLINE_SYSCALL(read, 3, handle->process.stream_in, buffer,
-                               count);
+    int64_t bytes = INLINE_SYSCALL(read, 3, handle->process.stream_in, buffer,
+                                   count);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
             case EWOULDBLOCK:
             case EWOULDBLOCK:
-                return-PAL_ERROR_TRYAGAIN;
+                return -PAL_ERROR_TRYAGAIN;
             case EINTR:
             case EINTR:
                 return -PAL_ERROR_INTERRUPTED;
                 return -PAL_ERROR_INTERRUPTED;
             default:
             default:
@@ -513,17 +513,17 @@ static int proc_read (PAL_HANDLE handle, int offset, int count,
     return bytes;
     return bytes;
 }
 }
 
 
-static int proc_write (PAL_HANDLE handle, int offset, int count,
+static int64_t proc_write (PAL_HANDLE handle, uint64_t offset, uint64_t count,
                        const void * buffer)
                        const void * buffer)
 {
 {
-    int bytes = INLINE_SYSCALL(write, 3, handle->process.stream_out, buffer,
-                               count);
+    int64_t bytes = INLINE_SYSCALL(write, 3, handle->process.stream_out, buffer,
+                                   count);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
             case EWOULDBLOCK:
             case EWOULDBLOCK:
                 HANDLE_HDR(handle)->flags &= ~WRITEABLE(1);
                 HANDLE_HDR(handle)->flags &= ~WRITEABLE(1);
-                return-PAL_ERROR_TRYAGAIN;
+                return -PAL_ERROR_TRYAGAIN;
             case EINTR:
             case EINTR:
                 return -PAL_ERROR_INTERRUPTED;
                 return -PAL_ERROR_INTERRUPTED;
             default:
             default:

+ 25 - 20
Pal/src/host/Linux/db_sockets.c

@@ -570,7 +570,8 @@ static int tcp_open (PAL_HANDLE *handle, const char * type, const char * uri,
 }
 }
 
 
 /* 'read' operation of tcp stream */
 /* 'read' operation of tcp stream */
-static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
+static int64_t tcp_read (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                         void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -590,7 +591,7 @@ static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(recvmsg, 3, handle->sock.fd, &hdr, 0);
+    int64_t bytes = INLINE_SYSCALL(recvmsg, 3, handle->sock.fd, &hdr, 0);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch (ERRNO(bytes)) {
         switch (ERRNO(bytes)) {
@@ -607,7 +608,8 @@ static int tcp_read (PAL_HANDLE handle, int offset, int len, void * buf)
 }
 }
 
 
 /* write' operation of tcp stream */
 /* write' operation of tcp stream */
-static int tcp_write (PAL_HANDLE handle, int offset, int len, const void * buf)
+static int64_t tcp_write (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                          const void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
     if (!IS_HANDLE_TYPE(handle, tcp) || !handle->sock.conn)
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -627,7 +629,7 @@ static int tcp_write (PAL_HANDLE handle, int offset, int len, const void * buf)
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
+    int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
@@ -800,7 +802,8 @@ static int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri,
     return -PAL_ERROR_NOTSUPPORT;
     return -PAL_ERROR_NOTSUPPORT;
 }
 }
 
 
-static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
+static int64_t udp_receive (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                            void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udp))
     if (!IS_HANDLE_TYPE(handle, udp))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -820,7 +823,7 @@ static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(recvmsg, 3, handle->sock.fd, &hdr, 0);
+    int64_t bytes = INLINE_SYSCALL(recvmsg, 3, handle->sock.fd, &hdr, 0);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
@@ -835,8 +838,8 @@ static int udp_receive (PAL_HANDLE handle, int offset, int len, void * buf)
     return bytes;
     return bytes;
 }
 }
 
 
-static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
-                              void * buf, char * addr, int addrlen)
+static int64_t udp_receivebyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                                  void * buf, char * addr, int addrlen)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udpsrv))
     if (!IS_HANDLE_TYPE(handle, udpsrv))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -859,7 +862,7 @@ static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(recvmsg, 3, handle->sock.fd, &hdr, 0);
+    int64_t bytes = INLINE_SYSCALL(recvmsg, 3, handle->sock.fd, &hdr, 0);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
@@ -885,7 +888,8 @@ static int udp_receivebyaddr (PAL_HANDLE handle, int offset, int len,
     return bytes;
     return bytes;
 }
 }
 
 
-static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
+static int64_t udp_send (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                         const void * buf)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udp))
     if (!IS_HANDLE_TYPE(handle, udp))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -905,7 +909,7 @@ static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
+    int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
@@ -927,8 +931,8 @@ static int udp_send (PAL_HANDLE handle, int offset, int len, const void * buf)
     return bytes;
     return bytes;
 }
 }
 
 
-static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
-                           const void * buf, const char * addr, int addrlen)
+static int64_t udp_sendbyaddr (PAL_HANDLE handle, uint64_t offset, uint64_t len,
+                               const void * buf, const char * addr, int addrlen)
 {
 {
     if (!IS_HANDLE_TYPE(handle, udpsrv))
     if (!IS_HANDLE_TYPE(handle, udpsrv))
         return -PAL_ERROR_NOTCONNECTION;
         return -PAL_ERROR_NOTCONNECTION;
@@ -964,7 +968,7 @@ static int udp_sendbyaddr (PAL_HANDLE handle, int offset, int len,
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
+    int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->sock.fd, &hdr, MSG_NOSIGNAL);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
@@ -1372,8 +1376,8 @@ err:
     return NULL;
     return NULL;
 }
 }
 
 
-static int mcast_send (PAL_HANDLE handle, int offset, int size,
-                       const void * buf)
+static int64_t mcast_send (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                           const void * buf)
 {
 {
     if (handle->mcast.srv == PAL_IDX_POISON)
     if (handle->mcast.srv == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
@@ -1390,8 +1394,8 @@ static int mcast_send (PAL_HANDLE handle, int offset, int size,
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(sendmsg, 3, handle->mcast.srv, &hdr,
-                               MSG_NOSIGNAL);
+    int64_t bytes = INLINE_SYSCALL(sendmsg, 3, handle->mcast.srv, &hdr,
+                                   MSG_NOSIGNAL);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         switch(ERRNO(bytes)) {
         switch(ERRNO(bytes)) {
@@ -1412,7 +1416,8 @@ static int mcast_send (PAL_HANDLE handle, int offset, int size,
     return bytes;
     return bytes;
 }
 }
 
 
-static int mcast_receive (PAL_HANDLE handle, int offset, int size, void * buf)
+static int64_t mcast_receive (PAL_HANDLE handle, uint64_t offset, uint64_t size,
+                              void * buf)
 {
 {
     if (handle->mcast.cli == PAL_IDX_POISON)
     if (handle->mcast.cli == PAL_IDX_POISON)
         return -PAL_ERROR_BADHANDLE;
         return -PAL_ERROR_BADHANDLE;
@@ -1429,7 +1434,7 @@ static int mcast_receive (PAL_HANDLE handle, int offset, int size, void * buf)
     hdr.msg_controllen = 0;
     hdr.msg_controllen = 0;
     hdr.msg_flags = 0;
     hdr.msg_flags = 0;
 
 
-    int bytes = INLINE_SYSCALL(recvmsg, 3, handle->mcast.cli, &hdr, 0);
+    int64_t bytes = INLINE_SYSCALL(recvmsg, 3, handle->mcast.cli, &hdr, 0);
 
 
     if (IS_ERR(bytes))
     if (IS_ERR(bytes))
         return -PAL_ERROR_DENIED;
         return -PAL_ERROR_DENIED;

+ 1 - 1
Pal/src/pal.h

@@ -30,7 +30,7 @@
 #include <stddef.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdint.h>
 
 
-typedef unsigned long PAL_NUM;
+typedef uint64_t PAL_NUM;
 typedef const char *  PAL_STR;
 typedef const char *  PAL_STR;
 typedef void *        PAL_PTR;
 typedef void *        PAL_PTR;
 typedef uint32_t      PAL_FLG;
 typedef uint32_t      PAL_FLG;

+ 14 - 13
Pal/src/pal_internal.h

@@ -56,16 +56,17 @@ struct handle_ops {
 
 
     /* 'read' and 'write' is used by DkStreamRead and DkStreamWrite, so
     /* 'read' and 'write' is used by DkStreamRead and DkStreamWrite, so
        they have exactly same prototype as them.  */
        they have exactly same prototype as them.  */
-    int (*read) (PAL_HANDLE handle, int offset, int count, void * buffer);
-    int (*write) (PAL_HANDLE handle, int offset, int count,
-                  const void * buffer);
+    int64_t (*read) (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                     void * buffer);
+    int64_t (*write) (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                      const void * buffer);
 
 
     /* 'readbyaddr' and 'writebyaddr' are the same as read and write,
     /* 'readbyaddr' and 'writebyaddr' are the same as read and write,
        but with extra field to specify address */
        but with extra field to specify address */
-    int (*readbyaddr) (PAL_HANDLE handle, int offset, int count, void * buffer,
-                       char * addr, int addrlen);
-    int (*writebyaddr) (PAL_HANDLE handle, int offset, int count,
-                        const void * buffer, const char * addr, int addrlen);
+    int64_t (*readbyaddr) (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                           void * buffer, char * addr, int addrlen);
+    int64_t (*writebyaddr) (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                            const void * buffer, const char * addr, int addrlen);
 
 
     /* 'close' and 'delete' is used by DkObjectClose and DkStreamDelete,
     /* 'close' and 'delete' is used by DkObjectClose and DkStreamDelete,
        'close' will close the stream, while 'delete' actually destroy
        'close' will close the stream, while 'delete' actually destroy
@@ -129,7 +130,7 @@ static inline const struct handle_ops * HANDLE_OPS (PAL_HANDLE handle)
 /* interger hash functions defined inline. The algorithm we used here
 /* interger hash functions defined inline. The algorithm we used here
   is based on Robert Jenkins developed in 96', the algorithm has two
   is based on Robert Jenkins developed in 96', the algorithm has two
   version, 32-bit one and 64-bit one. */
   version, 32-bit one and 64-bit one. */
-static inline unsigned int hash32 (unsigned int key)
+static inline uint32_t hash32 (uint32_t key)
 {
 {
     key = ~key + (key << 15);
     key = ~key + (key << 15);
     key = key ^ (key >> 12);
     key = key ^ (key >> 12);
@@ -140,7 +141,7 @@ static inline unsigned int hash32 (unsigned int key)
     return key;
     return key;
 }
 }
 
 
-static inline unsigned int hash64 (unsigned long key)
+static inline uint64_t hash64 (uint64_t key)
 {
 {
     key = (~key) + (key << 21);
     key = (~key) + (key << 21);
     key = key ^ (key >> 24);
     key = key ^ (key >> 24);
@@ -270,10 +271,10 @@ void _DkGetCPUInfo (PAL_CPU_INFO * info);
 int _DkStreamOpen (PAL_HANDLE * handle, const char * uri,
 int _DkStreamOpen (PAL_HANDLE * handle, const char * uri,
                    int access, int share, int create, int options);
                    int access, int share, int create, int options);
 int _DkStreamDelete (PAL_HANDLE handle, int access);
 int _DkStreamDelete (PAL_HANDLE handle, int access);
-int _DkStreamRead (PAL_HANDLE handle, int offset, int count, void * buf,
-                   char * addr, int addrlen);
-int _DkStreamWrite (PAL_HANDLE handle, int offset, int count,
-                    const void * buf, const char * addr, int addrlen);
+int64_t _DkStreamRead (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                       void * buf, char * addr, int addrlen);
+int64_t _DkStreamWrite (PAL_HANDLE handle, uint64_t offset, uint64_t count,
+                        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, uint64_t offset,
 int _DkStreamMap (PAL_HANDLE handle, void ** addr, int prot, uint64_t offset,