11bb92983SJerome Forissier // SPDX-License-Identifier: BSD-2-Clause 2b0104773SPascal Brand /* 3b0104773SPascal Brand * Copyright (c) 2014, STMicroelectronics International N.V. 4b0104773SPascal Brand */ 5b0104773SPascal Brand #include <stdlib.h> 6b0104773SPascal Brand #include <string.h> 765551e69SJerome Forissier #include <string_ext.h> 8b0104773SPascal Brand #include <tee_api.h> 996c1d8c5SJens Wiklander #include <tee_internal_api_extensions.h> 10ef305e54SJens Wiklander #include <types_ext.h> 11b0104773SPascal Brand #include <user_ta_header.h> 1296c1d8c5SJens Wiklander #include <utee_syscalls.h> 13e86f1266SJens Wiklander #include "tee_api_private.h" 14b0104773SPascal Brand 158f07fe6fSJerome Forissier static const void *tee_api_instance_data; 16b0104773SPascal Brand 17b0104773SPascal Brand /* System API - Internal Client API */ 18b0104773SPascal Brand 19ef305e54SJens Wiklander static TEE_Result copy_param(struct utee_params *up, uint32_t param_types, 20ef305e54SJens Wiklander const TEE_Param params[TEE_NUM_PARAMS], 21ef305e54SJens Wiklander void **tmp_buf, size_t *tmp_len, 22ef305e54SJens Wiklander void *tmp_va[TEE_NUM_PARAMS]) 23e86f1266SJens Wiklander { 24ef305e54SJens Wiklander size_t n = 0; 25ef305e54SJens Wiklander uint8_t *tb = NULL; 26ef305e54SJens Wiklander size_t tbl = 0; 27ef305e54SJens Wiklander size_t tmp_align = sizeof(vaddr_t) * 2; 28ef305e54SJens Wiklander bool is_tmp_mem[TEE_NUM_PARAMS] = { false }; 29ef305e54SJens Wiklander void *b = NULL; 30ef305e54SJens Wiklander size_t s = 0; 31ef305e54SJens Wiklander const uint32_t flags = TEE_MEMORY_ACCESS_READ; 32ef305e54SJens Wiklander 33ef305e54SJens Wiklander /* 34ef305e54SJens Wiklander * If a memory parameter points to TA private memory we need to 35ef305e54SJens Wiklander * allocate a temporary buffer to avoid exposing the memory 36ef305e54SJens Wiklander * directly to the called TA. 37ef305e54SJens Wiklander */ 38ef305e54SJens Wiklander 39ef305e54SJens Wiklander *tmp_buf = NULL; 40ef305e54SJens Wiklander *tmp_len = 0; 41ef305e54SJens Wiklander for (n = 0; n < TEE_NUM_PARAMS; n++) { 42ef305e54SJens Wiklander tmp_va[n] = NULL; 43ef305e54SJens Wiklander switch (TEE_PARAM_TYPE_GET(param_types, n)) { 44ef305e54SJens Wiklander case TEE_PARAM_TYPE_MEMREF_INPUT: 45ef305e54SJens Wiklander case TEE_PARAM_TYPE_MEMREF_OUTPUT: 46ef305e54SJens Wiklander case TEE_PARAM_TYPE_MEMREF_INOUT: 47ef305e54SJens Wiklander b = params[n].memref.buffer; 48ef305e54SJens Wiklander s = params[n].memref.size; 49ef305e54SJens Wiklander /* 50ef305e54SJens Wiklander * We're only allocating temporary memory if the 51ef305e54SJens Wiklander * buffer is completely within TA memory. If it's 52ef305e54SJens Wiklander * NULL, empty, partially outside or completely 53ef305e54SJens Wiklander * outside TA memory there's nothing more we need 54ef305e54SJens Wiklander * to do here. If there's security/permissions 55ef305e54SJens Wiklander * problem we'll get an error in the 56ef305e54SJens Wiklander * invoke_command/open_session below. 57ef305e54SJens Wiklander */ 58ef305e54SJens Wiklander if (b && s && 59ef305e54SJens Wiklander !TEE_CheckMemoryAccessRights(flags, b, s)) { 60ef305e54SJens Wiklander is_tmp_mem[n] = true; 61ef305e54SJens Wiklander tbl += ROUNDUP(s, tmp_align); 62ef305e54SJens Wiklander } 63ef305e54SJens Wiklander break; 64ef305e54SJens Wiklander default: 65ef305e54SJens Wiklander break; 66ef305e54SJens Wiklander } 67ef305e54SJens Wiklander } 68ef305e54SJens Wiklander 69ef305e54SJens Wiklander if (tbl) { 70ef305e54SJens Wiklander tb = tee_map_zi(tbl, TEE_MEMORY_ACCESS_ANY_OWNER); 71ef305e54SJens Wiklander if (!tb) 72ef305e54SJens Wiklander return TEE_ERROR_OUT_OF_MEMORY; 73ef305e54SJens Wiklander *tmp_buf = tb; 74ef305e54SJens Wiklander *tmp_len = tbl; 75ef305e54SJens Wiklander } 76e86f1266SJens Wiklander 77e86f1266SJens Wiklander up->types = param_types; 78e86f1266SJens Wiklander for (n = 0; n < TEE_NUM_PARAMS; n++) { 79e86f1266SJens Wiklander switch (TEE_PARAM_TYPE_GET(param_types, n)) { 80e86f1266SJens Wiklander case TEE_PARAM_TYPE_VALUE_INPUT: 81e86f1266SJens Wiklander case TEE_PARAM_TYPE_VALUE_INOUT: 82e86f1266SJens Wiklander up->vals[n * 2] = params[n].value.a; 83e86f1266SJens Wiklander up->vals[n * 2 + 1] = params[n].value.b; 84e86f1266SJens Wiklander break; 85e86f1266SJens Wiklander case TEE_PARAM_TYPE_MEMREF_OUTPUT: 86e86f1266SJens Wiklander case TEE_PARAM_TYPE_MEMREF_INOUT: 87ef305e54SJens Wiklander case TEE_PARAM_TYPE_MEMREF_INPUT: 88ef305e54SJens Wiklander s = params[n].memref.size; 89ef305e54SJens Wiklander if (is_tmp_mem[n]) { 90ef305e54SJens Wiklander b = tb; 91ef305e54SJens Wiklander tmp_va[n] = tb; 92ef305e54SJens Wiklander tb += ROUNDUP(s, tmp_align); 93ef305e54SJens Wiklander if (TEE_PARAM_TYPE_GET(param_types, n) != 94ef305e54SJens Wiklander TEE_PARAM_TYPE_MEMREF_OUTPUT) 95ef305e54SJens Wiklander memcpy(b, params[n].memref.buffer, s); 96ef305e54SJens Wiklander } else { 97ef305e54SJens Wiklander b = params[n].memref.buffer; 98ef305e54SJens Wiklander } 99ef305e54SJens Wiklander up->vals[n * 2] = (vaddr_t)b; 100ef305e54SJens Wiklander up->vals[n * 2 + 1] = s; 101e86f1266SJens Wiklander break; 102e86f1266SJens Wiklander default: 103e86f1266SJens Wiklander up->vals[n * 2] = 0; 104e86f1266SJens Wiklander up->vals[n * 2 + 1] = 0; 105e86f1266SJens Wiklander break; 106e86f1266SJens Wiklander } 107e86f1266SJens Wiklander } 108ef305e54SJens Wiklander 109ef305e54SJens Wiklander return TEE_SUCCESS; 110e86f1266SJens Wiklander } 111e86f1266SJens Wiklander 112ef305e54SJens Wiklander static void update_out_param(TEE_Param params[TEE_NUM_PARAMS], 113ef305e54SJens Wiklander void *tmp_va[TEE_NUM_PARAMS], 114ef305e54SJens Wiklander const struct utee_params *up) 115e86f1266SJens Wiklander { 116e86f1266SJens Wiklander size_t n; 117e86f1266SJens Wiklander uint32_t types = up->types; 118e86f1266SJens Wiklander 119e86f1266SJens Wiklander for (n = 0; n < TEE_NUM_PARAMS; n++) { 120e86f1266SJens Wiklander uintptr_t a = up->vals[n * 2]; 121e86f1266SJens Wiklander uintptr_t b = up->vals[n * 2 + 1]; 122e86f1266SJens Wiklander 123e86f1266SJens Wiklander switch (TEE_PARAM_TYPE_GET(types, n)) { 124e86f1266SJens Wiklander case TEE_PARAM_TYPE_VALUE_OUTPUT: 125e86f1266SJens Wiklander case TEE_PARAM_TYPE_VALUE_INOUT: 126e86f1266SJens Wiklander params[n].value.a = a; 127e86f1266SJens Wiklander params[n].value.b = b; 128e86f1266SJens Wiklander break; 129e86f1266SJens Wiklander case TEE_PARAM_TYPE_MEMREF_OUTPUT: 130e86f1266SJens Wiklander case TEE_PARAM_TYPE_MEMREF_INOUT: 131ef305e54SJens Wiklander if (tmp_va[n]) 132ef305e54SJens Wiklander memcpy(params[n].memref.buffer, tmp_va[n], 133ef305e54SJens Wiklander MIN(b, params[n].memref.size)); 134e86f1266SJens Wiklander params[n].memref.size = b; 135e86f1266SJens Wiklander break; 136e86f1266SJens Wiklander default: 137e86f1266SJens Wiklander break; 138e86f1266SJens Wiklander } 139e86f1266SJens Wiklander } 140e86f1266SJens Wiklander } 141e86f1266SJens Wiklander 142b0104773SPascal Brand TEE_Result TEE_OpenTASession(const TEE_UUID *destination, 143b0104773SPascal Brand uint32_t cancellationRequestTimeout, 14468540524SIgor Opaniuk uint32_t paramTypes, 14568540524SIgor Opaniuk TEE_Param params[TEE_NUM_PARAMS], 146b0104773SPascal Brand TEE_TASessionHandle *session, 147b0104773SPascal Brand uint32_t *returnOrigin) 148b0104773SPascal Brand { 149ef305e54SJens Wiklander TEE_Result res = TEE_SUCCESS; 150e86f1266SJens Wiklander struct utee_params up; 151ef305e54SJens Wiklander uint32_t s = 0; 152ef305e54SJens Wiklander void *tmp_buf = NULL; 153ef305e54SJens Wiklander size_t tmp_len = 0; 154ef305e54SJens Wiklander void *tmp_va[TEE_NUM_PARAMS] = { NULL }; 155b0104773SPascal Brand 156*6915bbbbSJens Wiklander if (paramTypes) 157*6915bbbbSJens Wiklander __utee_check_inout_annotation(params, 158*6915bbbbSJens Wiklander sizeof(TEE_Param) * 159*6915bbbbSJens Wiklander TEE_NUM_PARAMS); 160*6915bbbbSJens Wiklander __utee_check_out_annotation(session, sizeof(*session)); 161*6915bbbbSJens Wiklander 162ef305e54SJens Wiklander res = copy_param(&up, paramTypes, params, &tmp_buf, &tmp_len, tmp_va); 163ef305e54SJens Wiklander if (res) 164ef305e54SJens Wiklander goto out; 1652c028fdeSJerome Forissier res = _utee_open_ta_session(destination, cancellationRequestTimeout, 166e86f1266SJens Wiklander &up, &s, returnOrigin); 167ef305e54SJens Wiklander update_out_param(params, tmp_va, &up); 168ef305e54SJens Wiklander if (tmp_buf) { 169ef305e54SJens Wiklander TEE_Result res2 = tee_unmap(tmp_buf, tmp_len); 170ef305e54SJens Wiklander 171ef305e54SJens Wiklander if (res2) 172ef305e54SJens Wiklander TEE_Panic(res2); 173ef305e54SJens Wiklander } 174ef305e54SJens Wiklander 175ef305e54SJens Wiklander out: 176b0104773SPascal Brand /* 177b0104773SPascal Brand * Specification says that *session must hold TEE_HANDLE_NULL is 178b0104773SPascal Brand * TEE_SUCCESS isn't returned. Set it here explicitly in case 179b0104773SPascal Brand * the syscall fails before out parameters has been updated. 180b0104773SPascal Brand */ 181b0104773SPascal Brand if (res != TEE_SUCCESS) 182e86f1266SJens Wiklander s = TEE_HANDLE_NULL; 183b0104773SPascal Brand 184e86f1266SJens Wiklander *session = (TEE_TASessionHandle)(uintptr_t)s; 185b0104773SPascal Brand return res; 186b0104773SPascal Brand } 187b0104773SPascal Brand 188b0104773SPascal Brand void TEE_CloseTASession(TEE_TASessionHandle session) 189b0104773SPascal Brand { 190b0104773SPascal Brand if (session != TEE_HANDLE_NULL) { 1912c028fdeSJerome Forissier TEE_Result res = _utee_close_ta_session((uintptr_t)session); 192e86f1266SJens Wiklander 193b0104773SPascal Brand if (res != TEE_SUCCESS) 194b0104773SPascal Brand TEE_Panic(res); 195b0104773SPascal Brand } 196b0104773SPascal Brand } 197b0104773SPascal Brand 198b0104773SPascal Brand TEE_Result TEE_InvokeTACommand(TEE_TASessionHandle session, 199b0104773SPascal Brand uint32_t cancellationRequestTimeout, 200b0104773SPascal Brand uint32_t commandID, uint32_t paramTypes, 20168540524SIgor Opaniuk TEE_Param params[TEE_NUM_PARAMS], 20268540524SIgor Opaniuk uint32_t *returnOrigin) 203b0104773SPascal Brand { 204ef305e54SJens Wiklander TEE_Result res = TEE_SUCCESS; 205ef305e54SJens Wiklander uint32_t ret_origin = TEE_ORIGIN_TEE; 206e86f1266SJens Wiklander struct utee_params up; 207ef305e54SJens Wiklander void *tmp_buf = NULL; 208ef305e54SJens Wiklander size_t tmp_len = 0; 209ef305e54SJens Wiklander void *tmp_va[TEE_NUM_PARAMS] = { NULL }; 210c15e5835SCedric Chaumont 211*6915bbbbSJens Wiklander if (paramTypes) 212*6915bbbbSJens Wiklander __utee_check_inout_annotation(params, 213*6915bbbbSJens Wiklander sizeof(TEE_Param) * 214*6915bbbbSJens Wiklander TEE_NUM_PARAMS); 215*6915bbbbSJens Wiklander if (returnOrigin) 216*6915bbbbSJens Wiklander __utee_check_out_annotation(returnOrigin, 217*6915bbbbSJens Wiklander sizeof(*returnOrigin)); 218*6915bbbbSJens Wiklander 219ef305e54SJens Wiklander res = copy_param(&up, paramTypes, params, &tmp_buf, &tmp_len, tmp_va); 220ef305e54SJens Wiklander if (res) 221ef305e54SJens Wiklander goto out; 2222c028fdeSJerome Forissier res = _utee_invoke_ta_command((uintptr_t)session, 223e86f1266SJens Wiklander cancellationRequestTimeout, 224e86f1266SJens Wiklander commandID, &up, &ret_origin); 225ef305e54SJens Wiklander update_out_param(params, tmp_va, &up); 226ef305e54SJens Wiklander if (tmp_buf) { 227ef305e54SJens Wiklander TEE_Result res2 = tee_unmap(tmp_buf, tmp_len); 2286709c3eaSCedric Chaumont 229ef305e54SJens Wiklander if (res2) 230ef305e54SJens Wiklander TEE_Panic(res2); 231ef305e54SJens Wiklander } 232ef305e54SJens Wiklander 233ef305e54SJens Wiklander out: 2346709c3eaSCedric Chaumont if (returnOrigin != NULL) 2356709c3eaSCedric Chaumont *returnOrigin = ret_origin; 2366709c3eaSCedric Chaumont 2376709c3eaSCedric Chaumont if (ret_origin == TEE_ORIGIN_TRUSTED_APP) 2386709c3eaSCedric Chaumont return res; 2396709c3eaSCedric Chaumont 240c15e5835SCedric Chaumont if (res != TEE_SUCCESS && 241c15e5835SCedric Chaumont res != TEE_ERROR_OUT_OF_MEMORY && 242c15e5835SCedric Chaumont res != TEE_ERROR_TARGET_DEAD) 243c15e5835SCedric Chaumont TEE_Panic(res); 244c15e5835SCedric Chaumont 245c15e5835SCedric Chaumont return res; 246b0104773SPascal Brand } 247b0104773SPascal Brand 248b0104773SPascal Brand /* System API - Cancellations */ 249b0104773SPascal Brand 250b0104773SPascal Brand bool TEE_GetCancellationFlag(void) 251b0104773SPascal Brand { 252e86f1266SJens Wiklander uint32_t c; 2532c028fdeSJerome Forissier TEE_Result res = _utee_get_cancellation_flag(&c); 254e86f1266SJens Wiklander 255b0104773SPascal Brand if (res != TEE_SUCCESS) 256e86f1266SJens Wiklander c = 0; 257e86f1266SJens Wiklander return !!c; 258b0104773SPascal Brand } 259b0104773SPascal Brand 260b0104773SPascal Brand bool TEE_UnmaskCancellation(void) 261b0104773SPascal Brand { 262e86f1266SJens Wiklander uint32_t old_mask; 2632c028fdeSJerome Forissier TEE_Result res = _utee_unmask_cancellation(&old_mask); 264b0104773SPascal Brand 265b0104773SPascal Brand if (res != TEE_SUCCESS) 266b0104773SPascal Brand TEE_Panic(res); 267e86f1266SJens Wiklander return !!old_mask; 268b0104773SPascal Brand } 269b0104773SPascal Brand 270b0104773SPascal Brand bool TEE_MaskCancellation(void) 271b0104773SPascal Brand { 272e86f1266SJens Wiklander uint32_t old_mask; 2732c028fdeSJerome Forissier TEE_Result res = _utee_mask_cancellation(&old_mask); 274b0104773SPascal Brand 275b0104773SPascal Brand if (res != TEE_SUCCESS) 276b0104773SPascal Brand TEE_Panic(res); 277e86f1266SJens Wiklander return !!old_mask; 278b0104773SPascal Brand } 279b0104773SPascal Brand 280b0104773SPascal Brand /* System API - Memory Management */ 281b0104773SPascal Brand 282b0104773SPascal Brand TEE_Result TEE_CheckMemoryAccessRights(uint32_t accessFlags, void *buffer, 28379a3c601SCedric Chaumont uint32_t size) 284b0104773SPascal Brand { 285b0104773SPascal Brand TEE_Result res; 286b0104773SPascal Brand 287b0104773SPascal Brand if (size == 0) 288b0104773SPascal Brand return TEE_SUCCESS; 289b0104773SPascal Brand 290b0104773SPascal Brand /* Check access rights against memory mapping */ 2912c028fdeSJerome Forissier res = _utee_check_access_rights(accessFlags, buffer, size); 292b0104773SPascal Brand if (res != TEE_SUCCESS) 293b0104773SPascal Brand goto out; 294b0104773SPascal Brand 295b0104773SPascal Brand /* 296b0104773SPascal Brand * Check access rights against input parameters 297b0104773SPascal Brand * Previous legacy code was removed and will need to be restored 298b0104773SPascal Brand */ 299b0104773SPascal Brand 300b0104773SPascal Brand res = TEE_SUCCESS; 301b0104773SPascal Brand out: 302b0104773SPascal Brand return res; 303b0104773SPascal Brand } 304b0104773SPascal Brand 3058f07fe6fSJerome Forissier void TEE_SetInstanceData(const void *instanceData) 306b0104773SPascal Brand { 307b0104773SPascal Brand tee_api_instance_data = instanceData; 308b0104773SPascal Brand } 309b0104773SPascal Brand 3108f07fe6fSJerome Forissier const void *TEE_GetInstanceData(void) 311b0104773SPascal Brand { 312b0104773SPascal Brand return tee_api_instance_data; 313b0104773SPascal Brand } 314b0104773SPascal Brand 315b0104773SPascal Brand void *TEE_MemMove(void *dest, const void *src, uint32_t size) 316b0104773SPascal Brand { 317b0104773SPascal Brand return memmove(dest, src, size); 318b0104773SPascal Brand } 319b0104773SPascal Brand 320b0104773SPascal Brand int32_t TEE_MemCompare(const void *buffer1, const void *buffer2, uint32_t size) 321b0104773SPascal Brand { 32265551e69SJerome Forissier return consttime_memcmp(buffer1, buffer2, size); 323b0104773SPascal Brand } 324b0104773SPascal Brand 325b0104773SPascal Brand void *TEE_MemFill(void *buff, uint32_t x, uint32_t size) 326b0104773SPascal Brand { 327b0104773SPascal Brand return memset(buff, x, size); 328b0104773SPascal Brand } 329b0104773SPascal Brand 330b0104773SPascal Brand /* Date & Time API */ 331b0104773SPascal Brand 332b0104773SPascal Brand void TEE_GetSystemTime(TEE_Time *time) 333b0104773SPascal Brand { 3342c028fdeSJerome Forissier TEE_Result res = _utee_get_time(UTEE_TIME_CAT_SYSTEM, time); 335b0104773SPascal Brand 336b0104773SPascal Brand if (res != TEE_SUCCESS) 337b36311adSJerome Forissier TEE_Panic(res); 338b0104773SPascal Brand } 339b0104773SPascal Brand 340b0104773SPascal Brand TEE_Result TEE_Wait(uint32_t timeout) 341b0104773SPascal Brand { 3422c028fdeSJerome Forissier TEE_Result res = _utee_wait(timeout); 343b0104773SPascal Brand 344b0104773SPascal Brand if (res != TEE_SUCCESS && res != TEE_ERROR_CANCEL) 345b0104773SPascal Brand TEE_Panic(res); 346b0104773SPascal Brand 347b0104773SPascal Brand return res; 348b0104773SPascal Brand } 349b0104773SPascal Brand 350b0104773SPascal Brand TEE_Result TEE_GetTAPersistentTime(TEE_Time *time) 351b0104773SPascal Brand { 352b64d6909SCedric Chaumont TEE_Result res; 353b64d6909SCedric Chaumont 3542c028fdeSJerome Forissier res = _utee_get_time(UTEE_TIME_CAT_TA_PERSISTENT, time); 355b64d6909SCedric Chaumont 356b64d6909SCedric Chaumont if (res != TEE_SUCCESS && res != TEE_ERROR_OVERFLOW) { 357b64d6909SCedric Chaumont time->seconds = 0; 358b64d6909SCedric Chaumont time->millis = 0; 359b64d6909SCedric Chaumont } 360b64d6909SCedric Chaumont 361b64d6909SCedric Chaumont if (res != TEE_SUCCESS && 362b64d6909SCedric Chaumont res != TEE_ERROR_TIME_NOT_SET && 363b64d6909SCedric Chaumont res != TEE_ERROR_TIME_NEEDS_RESET && 364b64d6909SCedric Chaumont res != TEE_ERROR_OVERFLOW && 365b64d6909SCedric Chaumont res != TEE_ERROR_OUT_OF_MEMORY) 366b64d6909SCedric Chaumont TEE_Panic(res); 367b64d6909SCedric Chaumont 368b64d6909SCedric Chaumont return res; 369b0104773SPascal Brand } 370b0104773SPascal Brand 371b0104773SPascal Brand TEE_Result TEE_SetTAPersistentTime(const TEE_Time *time) 372b0104773SPascal Brand { 373b64d6909SCedric Chaumont TEE_Result res; 374b64d6909SCedric Chaumont 3752c028fdeSJerome Forissier res = _utee_set_ta_time(time); 376b64d6909SCedric Chaumont 377b64d6909SCedric Chaumont if (res != TEE_SUCCESS && 378b64d6909SCedric Chaumont res != TEE_ERROR_OUT_OF_MEMORY && 379b64d6909SCedric Chaumont res != TEE_ERROR_STORAGE_NO_SPACE) 380b64d6909SCedric Chaumont TEE_Panic(res); 381b64d6909SCedric Chaumont 382b64d6909SCedric Chaumont return res; 383b0104773SPascal Brand } 384b0104773SPascal Brand 385b0104773SPascal Brand void TEE_GetREETime(TEE_Time *time) 386b0104773SPascal Brand { 3872c028fdeSJerome Forissier TEE_Result res = _utee_get_time(UTEE_TIME_CAT_REE, time); 388b0104773SPascal Brand 389b0104773SPascal Brand if (res != TEE_SUCCESS) 390b36311adSJerome Forissier TEE_Panic(res); 391b0104773SPascal Brand } 392b0104773SPascal Brand 39379a3c601SCedric Chaumont void *TEE_Malloc(uint32_t len, uint32_t hint) 394b0104773SPascal Brand { 39596c1d8c5SJens Wiklander if (hint == TEE_MALLOC_FILL_ZERO) 39696c1d8c5SJens Wiklander return calloc(1, len); 39796c1d8c5SJens Wiklander else if (hint == TEE_USER_MEM_HINT_NO_FILL_ZERO) 39896c1d8c5SJens Wiklander return malloc(len); 39996c1d8c5SJens Wiklander 40096c1d8c5SJens Wiklander EMSG("Invalid hint %#" PRIx32, hint); 40196c1d8c5SJens Wiklander 40296c1d8c5SJens Wiklander return NULL; 403b0104773SPascal Brand } 404b0104773SPascal Brand 405c0ce02edSJens Wiklander void *TEE_Realloc(void *buffer, uint32_t newSize) 406b0104773SPascal Brand { 40796c1d8c5SJens Wiklander return realloc(buffer, newSize); 408b0104773SPascal Brand } 409b0104773SPascal Brand 410b0104773SPascal Brand void TEE_Free(void *buffer) 411b0104773SPascal Brand { 41296c1d8c5SJens Wiklander free(buffer); 413b0104773SPascal Brand } 414fa530828SPascal Brand 415fa530828SPascal Brand /* Cache maintenance support (TA requires the CACHE_MAINTENANCE property) */ 416fa530828SPascal Brand TEE_Result TEE_CacheClean(char *buf, size_t len) 417fa530828SPascal Brand { 4182c028fdeSJerome Forissier return _utee_cache_operation(buf, len, TEE_CACHECLEAN); 419fa530828SPascal Brand } 420fa530828SPascal Brand TEE_Result TEE_CacheFlush(char *buf, size_t len) 421fa530828SPascal Brand { 4222c028fdeSJerome Forissier return _utee_cache_operation(buf, len, TEE_CACHEFLUSH); 423fa530828SPascal Brand } 424fa530828SPascal Brand 425fa530828SPascal Brand TEE_Result TEE_CacheInvalidate(char *buf, size_t len) 426fa530828SPascal Brand { 4272c028fdeSJerome Forissier return _utee_cache_operation(buf, len, TEE_CACHEINVALIDATE); 428fa530828SPascal Brand } 429