1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

LWS_PLAT_OPTEE: Convert to use TEE_Malloc

OPTEE TAs should allocate via TEE_Malloc
This commit is contained in:
Andy Green 2017-01-30 15:02:54 +08:00
parent 066f4156d6
commit 9395eb62ce
2 changed files with 59 additions and 0 deletions

View file

@ -1,9 +1,61 @@
#include "private-libwebsockets.h"
#if defined(LWS_PLAT_OPTEE)
#define TEE_USER_MEM_HINT_NO_FILL_ZERO 0x80000000
void *__attribute__((weak))
TEE_Malloc(uint32_t size, uint32_t hint)
{
return NULL;
}
void *__attribute__((weak))
TEE_Realloc(void *buffer, uint32_t newSize)
{
return NULL;
}
void __attribute__((weak))
TEE_Free(void *buffer)
{
}
void *lws_realloc(void *ptr, size_t size)
{
return TEE_Realloc(ptr, size);
}
void *lws_malloc(size_t size)
{
return TEE_Malloc(size, TEE_USER_MEM_HINT_NO_FILL_ZERO);
}
void lws_free(void *p)
{
TEE_Free(p);
}
void *lws_zalloc(size_t size)
{
void *ptr = TEE_Malloc(size, TEE_USER_MEM_HINT_NO_FILL_ZERO);
if (ptr)
memset(ptr, 0, size);
return ptr;
}
void lws_set_allocator(void *(*cb)(void *ptr, size_t size))
{
(void)cb;
}
#else
static void *_realloc(void *ptr, size_t size)
{
if (size)
#if defined(LWS_PLAT_OPTEE)
return (void *)TEE_Realloc(ptr, size);
#else
return (void *)realloc(ptr, size);
#endif
else if (ptr)
free(ptr);
return NULL;
@ -28,3 +80,4 @@ void lws_set_allocator(void *(*cb)(void *ptr, size_t size))
{
_lws_realloc = cb;
}
#endif

View file

@ -1964,9 +1964,15 @@ lws_realloc(void *ptr, size_t size);
LWS_EXTERN void * LWS_WARN_UNUSED_RESULT
lws_zalloc(size_t size);
#ifdef LWS_PLAT_OPTEE
void *lws_malloc(size_t size);
void lws_free(void *p);
#define lws_free_set_NULL(P) do { lws_free(P); (P) = NULL; } while(0)
#else
#define lws_malloc(S) lws_realloc(NULL, S)
#define lws_free(P) lws_realloc(P, 0)
#define lws_free_set_NULL(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
#endif
/* lws_plat_ */
LWS_EXTERN void