Fix shared memory implementation 56/153856/2 submit/tizen/20171006.123809 submit/tizen_4.0/20171006.123936
authorPiotr Sawicki <p.sawicki2@partner.samsung.com>
Mon, 2 Oct 2017 06:01:52 +0000 (08:01 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Fri, 6 Oct 2017 12:09:46 +0000 (14:09 +0200)
* remove unused structure
* Adapt deleteAllSharedMemory() to POSIX API

Change-Id: Ia0e58cfbf35ef57b495d8bf64dacc83fc8fec61d

TEECLib/src/teec_api.c
TEEStub/TACommands/SharedMemoryMap.cpp

index 5cf6a74..172912b 100644 (file)
  *  Globals
  *-----------------------------------------------------------------------------*/
 
-typedef struct smem_info {
-       int32_t memKey;
-} mem_info;
-
 typedef struct sTEEC_ContextList {
        LIST_ENTRY(sTEEC_ContextList) list;
        TEEC_Context *context;
index 2093932..0c299b3 100644 (file)
@@ -47,8 +47,8 @@ using namespace std;
 #define PAGE_SIZE               0x1000
 #define PAGE_MASK               (~(PAGE_SIZE - 1))
 
-#define SHM_MAX_ID                             INT32_MAX
-#define SHM_NAME_PREFIX                        "/teec_shm"
+#define SHM_MAX_ID                     INT32_MAX
+#define SHM_NAME_PREFIX                "/teec_shm"
 
 map<uint32_t, registerItem> SharedMemoryMap::shmMap;
 
@@ -307,17 +307,29 @@ bool SharedMemoryMap::deleteSharedMemory(Operation &op) {
  * deleted, else false.
  */
 bool SharedMemoryMap::deleteAllSharedMemory() {
-       bool sharedResult = true;
-       for (map<uint32_t, registerItem>::iterator it = shmMap.begin(); it != shmMap.end();
-           it++) {
+       for (map<uint32_t, registerItem>::iterator it = shmMap.begin(); it != shmMap.end();) {
                registerItem item = it->second;
-               LOGE(TEE_STUB, "item will be free(%p(%u))",item.pBuffer, item.size);
-               if (-1 == shmdt(item.pBuffer)) {
-                       sharedResult = false;
+
+               LOGE(TEE_STUB, "item will be freed (%p (%u))", item.pBuffer, item.size);
+
+               std::string shm_name(SHM_NAME_PREFIX + std::to_string(it->first));
+
+               if (munmap(item.pBuffer, item.size) == -1) {
+                       LOGE(TEE_STUB, "cannot munmap buffer %p, error: %s",
+                            item.pBuffer, strerror(errno));
+                       return false;
                }
-               LOGE(TEE_STUB, "item will be free end(%p(%u))",item.pBuffer, item.size);
+
+               if (shm_unlink(shm_name.c_str()) == -1) {
+                       LOGE(TEE_STUB, "cannot shm_unlink %s, error: %s",
+                            shm_name.c_str(), strerror(errno));
+                       return false;
+               }
+
+               shmMap.erase(it++);
        }
-       return sharedResult;
+
+       return true;
 }
 
 char* SharedMemoryMap::getSharedMemoryAddress(uint32_t shmID) {