commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r810898 - in /commons/sandbox/runtime/trunk/src/main/native: configure include/arch/unix/acr_arch.h os/unix/file.c os/unix/mmap.c test/testcase.c
Date Thu, 03 Sep 2009 11:48:03 GMT
Author: mturk
Date: Thu Sep  3 11:48:03 2009
New Revision: 810898

URL: http://svn.apache.org/viewvc?rev=810898&view=rev
Log:
Use mmap64 if present

Modified:
    commons/sandbox/runtime/trunk/src/main/native/configure
    commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=810898&r1=810897&r2=810898&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Thu Sep  3 11:48:03 2009
@@ -761,6 +761,7 @@
     have_uuid_uuid=0
     have_off64t=0
     have_strerror_r=0
+    have_mmap64=0
 else
     have_fileextd=0
     have_ktmw32=0
@@ -786,6 +787,7 @@
     else
         have_strerror_r=`have_function strerror_r`
     fi
+    have_mmap64=`have_function mmap64`
 fi
 
 if [ ".$host" = ".linux" ]; then
@@ -869,6 +871,7 @@
 #define HAVE_RESOLV_H         `have_include resolv`
 #define HAVE_SYS_UN_H         `have_include sys/un`
 #define HAVE_STRERROR_R       $have_strerror_r
+#define HAVE_MMAP64           $have_mmap64
 #define HAVE_ACCEPT4          `have_function accept4`
 #define HAVE_DUP3             `have_function dup3`
 #define HAVE_EPOLL_CREATE1    `have_function epoll_create1`

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=810898&r1=810897&r2=810898&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Thu Sep  3
11:48:03 2009
@@ -55,6 +55,19 @@
 #define IS_INVALID_MEMORY(h) (((h) == NULL || (h) == INVALID_MEMORY_VALUE))
 #define IS_VALID_MEMORY(h)   (((h) != NULL && (h) != INVALID_MEMORY_VALUE))
 
+/** Common large file replacement macros
+ */
+#if defined(_LARGEFILE64_SOURCE)
+#define stat(f,b)       stat64(f,b)
+#define lstat(f,b)      lstat64(f,b)
+#define fstat(f,b)      fstat64(f,b)
+#define lseek(f,o,w)    lseek64(f,o,w)
+#define ftruncate(f,l)  ftruncate64(f,l)
+typedef struct stat64   struct_stat_t;
+#else
+typedef struct stat     struct_stat_t;
+#endif
+
 typedef struct acr_ioh acr_ioh;
 typedef int (acr_ioh_cleanup_fn_t)(void *, int, unsigned int);
 

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=810898&r1=810897&r2=810898&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Thu Sep  3 11:48:03 2009
@@ -26,22 +26,12 @@
  * Posix file functions
  *
  */
-#if defined(_LARGEFILE64_SOURCE)
-#define stat(f,b) stat64(f,b)
-#define lstat(f,b) lstat64(f,b)
-#define fstat(f,b) fstat64(f,b)
-#define lseek(f,o,w) lseek64(f,o,w)
-#define ftruncate(f,l) ftruncate64(f,l)
-typedef struct stat64 struct_stat;
-#else
-typedef struct stat struct_stat;
-#endif
 extern mode_t acr_default_umask;
 extern mode_t acr_default_perms;
 
 ACR_DECLARE(int) ACR_FileTypeGet(JNIEnv *_E, const char *fname)
 {
-    struct_stat info;
+    struct_stat_t info;
 
     if (lstat(fname, &info) == 0) {
         int type;
@@ -127,7 +117,7 @@
 
     UNREFERENCED_O;
     WITH_CSTR(pathname) {
-        struct_stat info;
+        struct_stat_t info;
 
         if ((ex = stat(J2S(pathname), &info)) == 0) {
             rv = ((jlong)info.st_dev << 32) +  (jlong)info.st_ino;
@@ -303,7 +293,7 @@
 
 ACR_DECLARE(int) ACR_FileProtectionGet(JNIEnv *_E, char *fname)
 {
-    struct_stat info;
+    struct_stat_t info;
 
     /* Always use a real target */
     if (stat(fname, &info) == 0) {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c?rev=810898&r1=810897&r2=810898&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/mmap.c Thu Sep  3 11:48:03 2009
@@ -33,6 +33,9 @@
 
 #include <sys/mman.h>
 
+#if defined(_LARGEFILE64_SOURCE) && HAVE_MMAP64
+#define mmap(a, l, p, f, d, o) mmap64(a, l, p, f, d, o)
+#endif
 #define MMAP_OWNS_FILE 1
 
 struct acr_mmap_t {
@@ -248,6 +251,18 @@
         ACR_THROW_IO_IF_ERR(ACR_EEXIST);
         return NULL;
     }
+#if HAVE_MMAP64
+    if (offset + size > LONG_MAX) {
+        ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+        return NULL;
+    }
+#elif defined(_LARGEFILE64_SOURCE) && CC_SIZEOF_SIZE_T == 4
+    /* LFS but no mmap64: check for overflow */
+    if (offset + size > INT_MAX) {
+        ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+        return NULL;
+    }
+#endif
     m->base = mmap(NULL, size, m->flags, MAP_SHARED, m->fd, offset);
     if (IS_INVALID_MEMORY(m->base)) {
         ACR_THROW_IO_ERRNO();
@@ -396,6 +411,18 @@
         ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE);
         return NULL;
     }
+#if HAVE_MMAP64
+    if (offset + size > LONG_MAX) {
+        ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+        return NULL;
+    }
+#elif defined(_LARGEFILE64_SOURCE) && CC_SIZEOF_SIZE_T == 4
+    /* LFS but no mmap64: check for overflow */
+    if (offset + size > INT_MAX) {
+        ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+        return NULL;
+    }
+#endif
     base = mmap(NULL, (size_t)size, m->flags, MAP_SHARED, m->fd, (off_t)offset);
     if (IS_INVALID_MEMORY(base)) {
         ACR_THROW_IO_ERRNO();
@@ -415,7 +442,7 @@
 {
     void   *base  = NULL;
     jobject mptr  = NULL;
-    struct  stat  s;
+    struct_stat_t s;
     off_t   size;
     acr_mmap_t *m = (acr_mmap_t *)ACR_IOH_FDATA(map);
 
@@ -428,6 +455,18 @@
         return NULL;
     }
     size = s.st_size - offset;
+#if HAVE_MMAP64
+    if (size > LONG_MAX) {
+        ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+        return NULL;
+    }
+#elif defined(_LARGEFILE64_SOURCE) && CC_SIZEOF_SIZE_T == 4
+    /* LFS but no mmap64: check for overflow */
+    if (size > INT_MAX) {
+        ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+        return NULL;
+    }
+#endif
     base = mmap(NULL, (size_t)size, m->flags, MAP_SHARED, m->fd, (off_t)offset);
     if (IS_INVALID_MEMORY(base)) {
         ACR_THROW_IO_ERRNO();

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=810898&r1=810897&r2=810898&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Thu Sep  3 11:48:03 2009
@@ -364,7 +364,7 @@
         return -1;
     else {
         int rfd = test_desc_perf[i].f;
-        struct stat s;
+        struct_stat_t s;
         if (rfd > 0) {
             fstat(rfd, &s);
             return (jint)s.st_dev + v;
@@ -382,7 +382,7 @@
         return -1;
     else {
         int rfd = test_desc_perf[fd].f;
-        struct stat s;
+        struct_stat_t s;
         if (rfd > 0) {
             fstat(rfd, &s);
             return (jint)s.st_dev + v;



Mime
View raw message