Linux: GateMP_daemon: Fix incorrect mapping of IGateProvider_NULL
authorAngela Stegmaier <angelabaker@ti.com>
Thu, 23 Jun 2016 21:16:01 +0000 (16:16 -0500)
committerAngela Stegmaier <angelabaker@ti.com>
Wed, 29 Jun 2016 18:44:44 +0000 (13:44 -0500)
In the case that IGateProvider_NULL is used for one of the remoteCustom
gates, the code will anyway attempt to map it and throw and error trace.
The code continues as this is the last part of the attach and the error
is essentially ignored as part of the design of GateMP support in order
to allow the LAD daemon to continue even if the setup fails. So the error
trace doesn't cause any functionality failure.

Fix up the code so that mappings are only done when there is a valid
size, so that the valid case of IGateProvider_NULL is properly handled.

Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
linux/src/daemon/GateMP_daemon.c

index 56b2ad6dd741eddc75342b9d085e0d94570e9a40..56ab5802f7974909298917ebe5402cbc9482c3ce 100644 (file)
@@ -254,25 +254,31 @@ Int GateMP_attach(UInt16 procId)
             offset = nsValue[0] & ~(sysconf(_SC_PAGE_SIZE) - 1);
             offset -= baseaddr;
 
+            if (size > 0) {
 #if defined(IPC_BUILDOS_ANDROID)
-            GateMP_module->remoteSystemInUse = mmap64(NULL, size,
-                (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
-                (off64_t)offset);
+                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)offset);
+                GateMP_module->remoteSystemInUse = mmap(NULL, size,
+                    (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
+                    (off_t)offset);
 #endif
-            if (GateMP_module->remoteSystemInUse == MAP_FAILED) {
-                 LOG1("Failed to map remoteSystemInUse=0x%p to host address" \
-                      "  space!", GateMP_module->remoteSystemInUse);
-                 GateMP_module->remoteSystemInUse = NULL;
-                 status = GateMP_E_MEMORY;
+                if (GateMP_module->remoteSystemInUse == MAP_FAILED) {
+                     LOG1("Failed to map remoteSystemInUse=0x%p to host address" \
+                          "  space!", GateMP_module->remoteSystemInUse);
+                     GateMP_module->remoteSystemInUse = NULL;
+                     status = GateMP_E_MEMORY;
+                }
+                else {
+                    alignDiff = nsValue[0] - baseaddr - offset;
+                    GateMP_module->remoteSystemInUse =
+                        GateMP_module->remoteSystemInUse + alignDiff;
+                }
             }
             else {
-                alignDiff = nsValue[0] - baseaddr - offset;
-                GateMP_module->remoteSystemInUse =
-                    GateMP_module->remoteSystemInUse + alignDiff;
+                LOG0("Invalid configuration for remoteSystem gate");
+                status = GateMP_E_FAIL;
             }
 
             size = GateMP_module->numRemoteCustom1 * sizeof (UInt8) +
@@ -281,7 +287,7 @@ Int GateMP_attach(UInt16 procId)
             offset = nsValue[1] & ~(sysconf(_SC_PAGE_SIZE) - 1);
             offset -= baseaddr;
 
-            if (status == GateMP_S_SUCCESS) {
+            if ((status == GateMP_S_SUCCESS) && (size > 0)) {
 #if defined(IPC_BUILDOS_ANDROID)
                 GateMP_module->remoteCustom1InUse = mmap64(NULL, size,
                     (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,
@@ -310,7 +316,7 @@ Int GateMP_attach(UInt16 procId)
             offset = nsValue[2] & ~(sysconf(_SC_PAGE_SIZE) - 1);
             offset -= baseaddr;
 
-            if (status == GateMP_S_SUCCESS) {
+            if ((status == GateMP_S_SUCCESS) && (size > 0)) {
 #if defined(IPC_BUILDOS_ANDROID)
                 GateMP_module->remoteCustom2InUse = mmap64(NULL, size,
                     (PROT_READ|PROT_WRITE), (MAP_SHARED), fdMem,