Android: GateMP uses mmap64 calls to map inUse array 3.30 ipc-3.30-next 3.30.03.14
authorArnie Reynoso <arnier@ti.com>
Tue, 27 Jan 2015 19:13:42 +0000 (11:13 -0800)
committerRobert Tivy <rtivy@ti.com>
Thu, 29 Jan 2015 00:41:20 +0000 (16:41 -0800)
Android's Lollipop filesystem (64-bit) has an issue with mmap() calls.
The offset (off_t type) is incorrectly casted and sign extended.
Using mmap64() and off64_t type explicitly on Android to avoid the issue.

linux/src/daemon/GateMP_daemon.c

index afb1bbd52688c333964efb1caaede7380c58b5c6..d2db25d3bed18809991fd4058ad5ef34ed658f03 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, Texas Instruments Incorporated
+ * Copyright (c) 2013-2015, Texas Instruments Incorporated
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -133,6 +133,7 @@ Int GateMP_setup(Void)
     UInt32            len;
     UInt32            size;
     UInt32            alignDiff;
+    UInt32            offset;
     Int32             fdMem;
 
     NameServer_Params_init(&params);
@@ -191,59 +192,77 @@ Int GateMP_setup(Void)
             size = GateMP_module->numRemoteSystem * sizeof (UInt8) +
                 (nsValue[0] & (sysconf(_SC_PAGE_SIZE) - 1));
             size = PAGE_ALIGN(size, sysconf(_SC_PAGE_SIZE));
+            offset = nsValue[0] & ~(sysconf(_SC_PAGE_SIZE) - 1);
+#if defined(IPC_BUILDOS_ANDROID)
+            GateMP_module->remoteSystemInUse = mmap64(NULL, size,
+                (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
+                (off64_t)offset);
+#else
             GateMP_module->remoteSystemInUse = mmap(NULL, size,
                 (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
-                (off_t)nsValue[0] & ~(sysconf(_SC_PAGE_SIZE) - 1));
+                (off_t)offset);
+#endif
             if (GateMP_module->remoteSystemInUse == MAP_FAILED) {
-                 GateMP_module->remoteSystemInUse = NULL;
-                 status = GateMP_E_MEMORY;
                  LOG1("Failed to map remoteSystemInUse=0x%p to host address" \
                       "  space!", GateMP_module->remoteSystemInUse);
+                 GateMP_module->remoteSystemInUse = NULL;
+                 status = GateMP_E_MEMORY;
             }
             else {
-                alignDiff = (off_t)nsValue[0] -
-                    ((off_t)nsValue[0] & ~(sysconf(_SC_PAGE_SIZE) - 1));
+                alignDiff = nsValue[0] - offset;
                 GateMP_module->remoteSystemInUse =
                     GateMP_module->remoteSystemInUse + alignDiff;
             }
 
             size = GateMP_module->numRemoteCustom1 * sizeof (UInt8) +
-                (nsValue[0] & (sysconf(_SC_PAGE_SIZE) - 1));
+                (nsValue[1] & (sysconf(_SC_PAGE_SIZE) - 1));
             size = PAGE_ALIGN(size, sysconf(_SC_PAGE_SIZE));
+            offset = nsValue[1] & ~(sysconf(_SC_PAGE_SIZE) - 1);
             if (status == GateMP_S_SUCCESS) {
+#if defined(IPC_BUILDOS_ANDROID)
+                GateMP_module->remoteCustom1InUse = mmap64(NULL, size,
+                    (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
+                    (off64_t)offset);
+#else
                 GateMP_module->remoteCustom1InUse = mmap(NULL, size,
                     (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
-                    (off_t)nsValue[1] & ~(sysconf(_SC_PAGE_SIZE) - 1));
+                    (off_t)offset);
+#endif
                 if (GateMP_module->remoteCustom1InUse == MAP_FAILED) {
-                    GateMP_module->remoteCustom1InUse = NULL;
-                    status = GateMP_E_MEMORY;
                     LOG1("Failed to map remoteCustom1InUse=%p to host address" \
                         " space!", GateMP_module->remoteCustom1InUse);
+                    GateMP_module->remoteCustom1InUse = NULL;
+                    status = GateMP_E_MEMORY;
                 }
                 else {
-                    alignDiff = (off_t)nsValue[1] -
-                        ((off_t)nsValue[1] & ~(sysconf(_SC_PAGE_SIZE) - 1));
+                    alignDiff = nsValue[1] - offset;
                     GateMP_module->remoteCustom1InUse =
                         GateMP_module->remoteCustom1InUse + alignDiff;
                 }
             }
 
             size = GateMP_module->numRemoteCustom2 * sizeof (UInt8) +
-                (nsValue[0] & (sysconf(_SC_PAGE_SIZE) - 1));
+                (nsValue[2] & (sysconf(_SC_PAGE_SIZE) - 1));
             size = PAGE_ALIGN(size, sysconf(_SC_PAGE_SIZE));
+            offset = nsValue[2] & ~(sysconf(_SC_PAGE_SIZE) - 1);
             if (status == GateMP_S_SUCCESS) {
+#if defined(IPC_BUILDOS_ANDROID)
+                GateMP_module->remoteCustom2InUse = mmap64(NULL, size,
+                    (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
+                    (off64_t)offset);
+#else
                 GateMP_module->remoteCustom2InUse = mmap(NULL, size,
                     (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
-                    (off_t)nsValue[2] & ~(sysconf(_SC_PAGE_SIZE) - 1));
+                    (off_t)offset);
+#endif
                 if (GateMP_module->remoteCustom2InUse == MAP_FAILED) {
-                    GateMP_module->remoteCustom2InUse = NULL;
-                    status = GateMP_E_MEMORY;
                     LOG1("Failed to map remoteCustom2InUse=%p to host address" \
                         " space!", GateMP_module->remoteCustom2InUse);
+                    GateMP_module->remoteCustom2InUse = NULL;
+                    status = GateMP_E_MEMORY;
                 }
                 else {
-                    alignDiff = (off_t)nsValue[2] -
-                        ((off_t)nsValue[2] & ~(sysconf(_SC_PAGE_SIZE) - 1));
+                    alignDiff = nsValue[2] - offset;
                     GateMP_module->remoteCustom2InUse =
                         GateMP_module->remoteCustom2InUse + alignDiff;
                 }