return found;
}
+TEEC_Result tempSharedMemAllocate(TEEC_SharedMemory** tmpSharedMem, uint32_t type,
+ TEEC_Context* context, TEEC_Parameter param)
+{
+ TEEC_Result result;
+ *tmpSharedMem = (TEEC_SharedMemory *)OsaMalloc(sizeof(TEEC_SharedMemory));
+ (*tmpSharedMem)->size = param.tmpref.size;
+ (*tmpSharedMem)->buffer = param.tmpref.buffer;
+
+ (*tmpSharedMem)->flags = type & (TEEC_MEM_INPUT | TEEC_MEM_OUTPUT);
+
+ result = TEEC_RegisterSharedMemory(context, *tmpSharedMem);
+
+ if (result != TEEC_SUCCESS) {
+ if (*tmpSharedMem) {
+ OsaFree(*tmpSharedMem);
+ *tmpSharedMem = NULL;
+ }
+ return result;
+ }
+
+ if (type & TEEC_MEMREF_TEMP_INPUT) {
+ memcpy(((TEEC_SharedMemoryImp *)(*tmpSharedMem)->imp)->allocPtr,
+ (*tmpSharedMem)->buffer, (*tmpSharedMem)->size);
+ }
+ return result;
+}
+
+void tempSharedMemoryDeallocate(TEEC_SharedMemory** tmpSharedMem)
+{
+ if (*tmpSharedMem) {
+ TEEC_ReleaseSharedMemory(*tmpSharedMem);
+ OsaFree(*tmpSharedMem);
+ *tmpSharedMem = NULL;
+ }
+}
+
/*
* === FUNCTION ======================================================================
* Name: preProcessOperation
op->paramTypes |= type << (8 * i);
if (!tmpSharedMem[i]) {
- tmpSharedMem[i] = (TEEC_SharedMemory *)OsaMalloc(
- sizeof(TEEC_SharedMemory));
- tmpSharedMem[i]->size = operation->params[i].tmpref.size;
- tmpSharedMem[i]->buffer = operation->params[i].tmpref.buffer;
-
- if (type == TEEC_MEMREF_TEMP_INPUT)
- tmpSharedMem[i]->flags = TEEC_MEM_INPUT;
-
- else if (type == TEEC_MEMREF_TEMP_OUTPUT)
- tmpSharedMem[i]->flags = TEEC_MEM_OUTPUT;
-
- else if (type == TEEC_MEMREF_TEMP_INOUT)
- tmpSharedMem[i]->flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
-
- result = TEEC_RegisterSharedMemory(
- ((TEEC_SessionImp *)session->imp)->context, tmpSharedMem[i]);
-
- if (result != TEEC_SUCCESS) {
- for (i = 0; i < 4; i++) {
- if (tmpSharedMem[i]) {
- OsaFree(tmpSharedMem[i]);
- tmpSharedMem[i] = NULL;
- }
- }
-
- return result;
- }
-
- if (type & TEEC_MEMREF_TEMP_INPUT) {
- memcpy(((TEEC_SharedMemoryImp *)tmpSharedMem[i]->imp)->allocPtr,
- tmpSharedMem[i]->buffer, tmpSharedMem[i]->size);
- }
+ result = tempSharedMemAllocate(&tmpSharedMem[i], type,
+ ((TEEC_SessionImp *)session->imp)->context, operation->params[i]);
+ if (result != TEEC_SUCCESS)
+ goto cleanup;
}
op->params[i].mem.size = tmpSharedMem[i]->size;
break;
case TEEC_MEMREF_WHOLE:
- op->paramTypes |= TEE_PARAM_TYPE_MEMREF_INOUT << (8 * i);
memref = &operation->params[i].memref;
if ((NULL == memref) || (NULL == memref->parent)
|| (((TEEC_SharedMemoryImp *)memref->parent->imp)->context->imp
!= context->imp)) {
- for (i = 0; i < 4; i++) {
- if (tmpSharedMem[i]) {
- TEEC_ReleaseSharedMemory(tmpSharedMem[i]);
- OsaFree(tmpSharedMem[i]);
- tmpSharedMem[i] = NULL;
- }
- }
-
LOGE(TEEC_LIB, "Bad parameters");
- return TEEC_ERROR_BAD_PARAMETERS;
+ result = TEEC_ERROR_BAD_PARAMETERS;
+ goto cleanup;
}
memref_imp = (TEEC_SharedMemoryImp *)memref->parent->imp;
+ op->paramTypes |= (operation->params[i].memref.parent->flags |
+ (TEE_PARAM_TYPE_MEMREF_INPUT & TEE_PARAM_TYPE_MEMREF_OUTPUT)) << (8 * i);
op->params[i].mem.offset = 0;
op->params[i].mem.size = memref->parent->size;
op->params[i].mem.shmKey = memref_imp->shmKey;
case TEEC_MEMREF_PARTIAL_INPUT:
case TEEC_MEMREF_PARTIAL_OUTPUT:
case TEEC_MEMREF_PARTIAL_INOUT:
- op->paramTypes |= (type + TEE_PARAM_TYPE_MEMREF_INPUT
- - TEEC_MEMREF_PARTIAL_INPUT) << (8 * i);
+ op->paramTypes |= ((operation->params[i].memref.parent->flags & type) |
+ (TEE_PARAM_TYPE_MEMREF_INPUT & TEE_PARAM_TYPE_MEMREF_OUTPUT)) << (8 * i);
memref = &operation->params[i].memref;
if ((NULL == memref) || (NULL == memref->parent)
|| (((TEEC_SharedMemoryImp *)memref->parent->imp)->context->imp
!= context->imp)) {
- for (i = 0; i < 4; i++) {
- if (tmpSharedMem[i]) {
- TEEC_ReleaseSharedMemory(tmpSharedMem[i]);
- OsaFree(tmpSharedMem[i]);
- tmpSharedMem[i] = NULL;
- }
- }
-
LOGE(TEEC_LIB, "Bad parameters");
- return TEEC_ERROR_BAD_PARAMETERS;
+ result = TEEC_ERROR_BAD_PARAMETERS;
+ goto cleanup;
}
memref_imp = (TEEC_SharedMemoryImp *)memref->parent->imp;
break;
default:
- for (i = 0; i < 4; i++) {
- if (tmpSharedMem[i]) {
- TEEC_ReleaseSharedMemory(tmpSharedMem[i]);
- OsaFree(tmpSharedMem[i]);
- tmpSharedMem[i] = NULL;
- }
- }
-
- return TEEC_ERROR_BAD_PARAMETERS;
+ result = TEEC_ERROR_BAD_PARAMETERS;
+ goto cleanup;
}
}
- return TEEC_SUCCESS;
+ return result;
+
+cleanup:
+ for (i = 0; i < 4; i++) {
+ tempSharedMemoryDeallocate(&tmpSharedMem[i]);
+ }
+ return result;
}
/*