diff options
author | Jens Wiklander <jens.wiklander@linaro.org> | 2018-04-24 12:22:32 +0200 |
---|---|---|
committer | Jérôme Forissier <jerome.forissier@linaro.org> | 2018-04-25 12:49:10 +0200 |
commit | 96c1d8c56cdec253565036b7754b5b2d9ab63195 (patch) | |
tree | dd34d1875794cb95f627c79e9fd55eaae527c8c3 | |
parent | c0ce02ed1cb00f59a8cdd66b4228b9798b560887 (diff) |
ta: TEE_Malloc() and friend: skips layers
Prior to this patch TEE_Malloc(), TEE_Realloc() and TEE_Free() were using
two extra layers implemented on top of the well known malloc(),
realloc(), calloc() and free() functions. With this patch the extra layers
are skipped.
When compiled for user TAs realloc() clears all memory that otherwise
would be uninitialized memory since it's required by the spec [1] if
TEE_Malloc() is called with the hint TEE_MALLOC_FILL_ZERO. Since that's
the only recognized hint in the spec realloc() assumes that it's always
needed.
[1] GP TEE Internal Core API Specification v1.1
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
-rw-r--r-- | lib/libutee/tee_api.c | 21 | ||||
-rw-r--r-- | lib/libutils/isoc/bget.c | 5 | ||||
-rw-r--r-- | mk/config.mk | 5 |
3 files changed, 17 insertions, 14 deletions
diff --git a/lib/libutee/tee_api.c b/lib/libutee/tee_api.c index 3eb87148..4d508db2 100644 --- a/lib/libutee/tee_api.c +++ b/lib/libutee/tee_api.c @@ -29,9 +29,9 @@ #include <string.h> #include <tee_api.h> -#include <utee_syscalls.h> +#include <tee_internal_api_extensions.h> #include <user_ta_header.h> -#include "tee_user_mem.h" +#include <utee_syscalls.h> #include "tee_api_private.h" static const void *tee_api_instance_data; @@ -312,21 +312,24 @@ void TEE_GetREETime(TEE_Time *time) void *TEE_Malloc(uint32_t len, uint32_t hint) { - return tee_user_mem_alloc(len, hint); + if (hint == TEE_MALLOC_FILL_ZERO) + return calloc(1, len); + else if (hint == TEE_USER_MEM_HINT_NO_FILL_ZERO) + return malloc(len); + + EMSG("Invalid hint %#" PRIx32, hint); + + return NULL; } void *TEE_Realloc(void *buffer, uint32_t newSize) { - /* - * GP TEE Internal API specifies newSize as 'uint32_t'. - * use unsigned 'size_t' type. it is at least 32bit! - */ - return tee_user_mem_realloc((void *)buffer, (size_t) newSize); + return realloc(buffer, newSize); } void TEE_Free(void *buffer) { - tee_user_mem_free(buffer); + free(buffer); } /* Cache maintenance support (TA requires the CACHE_MAINTENANCE property) */ diff --git a/lib/libutils/isoc/bget.c b/lib/libutils/isoc/bget.c index 33a7a695..b29e13ea 100644 --- a/lib/libutils/isoc/bget.c +++ b/lib/libutils/isoc/bget.c @@ -823,6 +823,11 @@ void *bgetr(buf, size, poolset) assert(osize > 0); V memcpy((char *) nbuf, (char *) buf, /* Copy the data */ (MemSize) ((size < osize) ? size : osize)); +#ifndef __KERNEL__ + /* User space reallocations are always zeroed */ + if (size > osize) + V memset((char *) nbuf + osize, 0, size - osize); +#endif brel(buf, poolset); return nbuf; } diff --git a/mk/config.mk b/mk/config.mk index 70c998a6..fcab13c3 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -59,11 +59,6 @@ CFG_TEE_TA_LOG_LEVEL ?= 1 # CFG_TEE_TA_LOG_LEVEL. Otherwise, they are not output at all CFG_TEE_CORE_TA_TRACE ?= y -# If 1, enable debug features in TA memory allocation. -# Debug features include check of buffer overflow, statistics, mark/check heap -# feature. -CFG_TEE_CORE_USER_MEM_DEBUG ?= 1 - # If y, enable the memory leak detection feature in the bget memory allocator. # When this feature is enabled, calling mdbg_check(1) will print a list of all # the currently allocated buffers and the location of the allocation (file and |