mirror of
https://github.com/openharmony/tee_tee_os_framework.git
synced 2026-07-01 07:22:28 -04:00
Use unmap_sharemem to unmap shared memory and replace malloc_coherent with malloc
Signed-off-by: suwanghw <wangsu14@huawei.com>
This commit is contained in:
@@ -45,7 +45,7 @@ static int32_t crypto_ioctl_alloc_ctx_buf(struct drv_data *drv, uint32_t cmd, un
|
||||
tloge("Get ctx size failed, ctx size=%d\n", ctx_size);
|
||||
return CRYPTO_BAD_PARAMETERS;
|
||||
}
|
||||
uint8_t *ctx_buffer = (uint8_t *)malloc_coherent((size_t)ctx_size);
|
||||
uint8_t *ctx_buffer = (uint8_t *)malloc((size_t)ctx_size);
|
||||
if (ctx_buffer == NULL) {
|
||||
tloge("Malloc ctx buffer failed, ctx size=%d\n", ctx_size);
|
||||
return CRYPTO_OVERFLOW;
|
||||
|
||||
@@ -455,7 +455,7 @@ static TEE_Result map_memref_for_gtask(bool ta2ta, const smc_cmd_t *cmd, tee_par
|
||||
p.memref.size, ta2ta);
|
||||
if (ret != TEE_SUCCESS) {
|
||||
tloge("failed to refcount the memory\n");
|
||||
if (munmap(*ree_addr, p.memref.size) != 0)
|
||||
if (unmap_sharemem(*ree_addr, p.memref.size) != 0)
|
||||
tloge("munmap ree_addr failed\n");
|
||||
return ret;
|
||||
}
|
||||
@@ -616,8 +616,13 @@ static TEE_Result map_cmd_to_operation(bool ta2ta, uint32_t *operation_size, con
|
||||
if (mapped) {
|
||||
ret = task_add_mem_region(cmd->event_nr, 0, (uint64_t)(uintptr_t)(*operation), *operation_size, ta2ta);
|
||||
if (ret != TEE_SUCCESS) {
|
||||
if (munmap(*operation, *operation_size) != 0)
|
||||
tloge("unmap operation failed\n");
|
||||
if (ta2ta) {
|
||||
if (unmap_sharemem(*operation, *operation_size) != 0)
|
||||
tloge("unmap sharemem operation failed\n");
|
||||
} else {
|
||||
if (task_unmap(0, (uint64_t)*operation, *operation_size) != 0)
|
||||
tloge("task unmap operation failed\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -804,7 +809,7 @@ TEE_Result map_secure_operation(uint64_t tacmd, smc_cmd_t *out_cmd, uint32_t tas
|
||||
ret = TEE_ERROR_GENERIC;
|
||||
}
|
||||
|
||||
if (munmap(cmd, sizeof(smc_cmd_t)) != 0)
|
||||
if (unmap_sharemem(cmd, sizeof(smc_cmd_t)) != 0)
|
||||
tloge("unmap cmd failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -479,15 +479,15 @@ static TEE_Result map_params(struct global_to_ta_msg *entry_msg, size_t *map_siz
|
||||
out:
|
||||
for (int i = 0; i < map_size_size; i++) {
|
||||
if (params_vaddrs[i] != 0) {
|
||||
if (free_sharemem((void *)(uintptr_t)params_vaddrs[i], map_size[i]) != 0)
|
||||
tloge("free sharemem param's vaddr failed\n");
|
||||
if (unmap_sharemem((void *)(uintptr_t)params_vaddrs[i], map_size[i]) != 0)
|
||||
tloge("unmap sharemem param's vaddr failed\n");
|
||||
map_addrs[i] = 0;
|
||||
}
|
||||
map_size[i] = 0;
|
||||
}
|
||||
|
||||
if ((vaddr != 0) && (free_sharemem((void *)(uintptr_t)vaddr, sizeof(TEE_Param) * map_addrs_size) != 0))
|
||||
tloge("free sharemem vaddr failed\n");
|
||||
if ((vaddr != 0) && (unmap_sharemem((void *)(uintptr_t)vaddr, sizeof(TEE_Param) * map_addrs_size) != 0))
|
||||
tloge("unmap sharemem vaddr failed\n");
|
||||
|
||||
return TEE_ERROR_GENERIC;
|
||||
}
|
||||
@@ -511,15 +511,15 @@ static void unmap_params(struct global_to_ta_msg *entry_msg, size_t *map_size, i
|
||||
* cannot use memref.size because it may be changed by TA
|
||||
* must use map_size[i]
|
||||
*/
|
||||
if (free_sharemem((void *)(uintptr_t)map_addrs[i], map_size[i]) != 0)
|
||||
tloge("free sharemem buffer failed\n");
|
||||
if (unmap_sharemem((void *)(uintptr_t)map_addrs[i], map_size[i]) != 0)
|
||||
tloge("unmap sharemem buffer failed\n");
|
||||
map_addrs[i] = 0;
|
||||
}
|
||||
map_size[i] = 0;
|
||||
}
|
||||
|
||||
if (free_sharemem(entry_msg->params, sizeof(TEE_Param) * map_addrs_size) != 0)
|
||||
tloge("free sharemem params failed\n");
|
||||
if (unmap_sharemem(entry_msg->params, sizeof(TEE_Param) * map_addrs_size) != 0)
|
||||
tloge("unmap sharemem params failed\n");
|
||||
entry_msg->params = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ void tee_srv_unmap_from_task(uint32_t va_addr, uint32_t size)
|
||||
(void)va_addr;
|
||||
(void)size;
|
||||
#else
|
||||
(void)munmap((void *)(uintptr_t)va_addr, size);
|
||||
(void)unmap_sharemem((void *)(uintptr_t)va_addr, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@ int32_t copy_from_sharemem(uint32_t src_task, uint64_t src, uint32_t src_size, u
|
||||
ret = memcpy_s((void *)dst, dst_size, (void *)(uintptr_t)temp_dst, src_size);
|
||||
if (ret != EOK) {
|
||||
tloge("copy buffer from sharemem failed\n");
|
||||
if (munmap((void *)(uintptr_t)temp_dst, src_size) != 0)
|
||||
if (unmap_sharemem((void *)(uintptr_t)temp_dst, src_size) != 0)
|
||||
tloge("unmap temp dst failed in from sharemem\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (munmap((void *)(uintptr_t)temp_dst, src_size) != 0) {
|
||||
if (unmap_sharemem((void *)(uintptr_t)temp_dst, src_size) != 0) {
|
||||
tloge("something wrong, unmap temp dst failed in from sharemem\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -88,12 +88,12 @@ int32_t copy_to_sharemem(uintptr_t src, uint32_t src_size, uint32_t dst_task, ui
|
||||
ret = memcpy_s((void *)(uintptr_t)temp_dst, dst_size, (void *)src, src_size);
|
||||
if (ret != EOK) {
|
||||
tloge("copy buffer to sharemem failed\n");
|
||||
if (munmap((void *)(uintptr_t)temp_dst, dst_size) != 0)
|
||||
if (unmap_sharemem((void *)(uintptr_t)temp_dst, dst_size) != 0)
|
||||
tloge("unmap temp dst failed in to sharemem\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (munmap((void *)(uintptr_t)temp_dst, dst_size) != 0) {
|
||||
if (unmap_sharemem((void *)(uintptr_t)temp_dst, dst_size) != 0) {
|
||||
tloge("something wrong, unmap temp dst failed in to sharemem\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ static void huk_srv_task_unmap(uint64_t virt_addr, uint32_t size)
|
||||
{
|
||||
if (virt_addr == 0)
|
||||
return;
|
||||
if (munmap((void *)(uintptr_t)virt_addr, size) != 0)
|
||||
if (unmap_sharemem((void *)(uintptr_t)virt_addr, size) != 0)
|
||||
tloge("huk srv unmap error\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ void perm_srv_unmap_from_task(uint64_t vaddr, uint32_t size)
|
||||
if (vaddr == 0)
|
||||
return;
|
||||
|
||||
if (munmap((void *)(uintptr_t)vaddr, size) != 0)
|
||||
if (unmap_sharemem((void *)(uintptr_t)vaddr, size) != 0)
|
||||
tloge("perm unmap error\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -678,7 +678,7 @@ void ssa_unmap_from_task(uint32_t task_id, uintptr_t va_addr, uint32_t size, boo
|
||||
return;
|
||||
}
|
||||
|
||||
(void)munmap((void *)va_addr, size);
|
||||
(void)unmap_sharemem((void *)va_addr, size);
|
||||
}
|
||||
|
||||
static void ssa_write_attributes(const uint8_t *attributes, uint32_t attributes_len, struct sfd_t *sfd,
|
||||
|
||||
@@ -527,7 +527,7 @@ static TEE_Result cal_construct_block(struct sfd_t *sfd, uint32_t data_size)
|
||||
struct block_info_t *last_block_pos = NULL;
|
||||
uint32_t block_size = CRYPT_BLOCK_SIZE_V3;
|
||||
uint8_t *buffer = NULL;
|
||||
buffer = malloc_coherent(CRYPT_BLOCK_SIZE_V3);
|
||||
buffer = malloc(CRYPT_BLOCK_SIZE_V3);
|
||||
if (buffer == NULL)
|
||||
return TEE_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user