#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;
* 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) {