summaryrefslogtreecommitdiff
path: root/thirdparty/lws/alloc.c
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2017-12-21 03:09:18 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2018-02-05 16:11:41 +0100
commitfa33e0f62d9ee186464a725333662674bf1fa871 (patch)
treeaeb72e5f3926925f3f33787b0610c2b58976f38f /thirdparty/lws/alloc.c
parente7cf2b2e77a097a026f883f003ad299b5d451885 (diff)
Add libwebsockets as thirdparty library.
License is LGPLv2.1 + static linking exception, version is 2.4.1
Diffstat (limited to 'thirdparty/lws/alloc.c')
-rw-r--r--thirdparty/lws/alloc.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/thirdparty/lws/alloc.c b/thirdparty/lws/alloc.c
new file mode 100644
index 0000000000..898db12464
--- /dev/null
+++ b/thirdparty/lws/alloc.c
@@ -0,0 +1,90 @@
+#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, const char *reason)
+{
+ return TEE_Realloc(ptr, size);
+}
+
+void *lws_malloc(size_t size, const char *reason)
+{
+ 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, const char *reason)
+{
+ 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, const char *reason))
+{
+ (void)cb;
+}
+#else
+
+static void *_realloc(void *ptr, size_t size, const char *reason)
+{
+ if (size) {
+#if defined(LWS_PLAT_ESP32)
+ lwsl_notice("%s: size %lu: %s\n", __func__, (unsigned long)size, reason);
+#else
+ lwsl_debug("%s: size %lu: %s\n", __func__, (unsigned long)size, reason);
+#endif
+#if defined(LWS_PLAT_OPTEE)
+ return (void *)TEE_Realloc(ptr, size);
+#else
+ return (void *)realloc(ptr, size);
+#endif
+ }
+ if (ptr)
+ free(ptr);
+
+ return NULL;
+}
+
+void *(*_lws_realloc)(void *ptr, size_t size, const char *reason) = _realloc;
+
+void *lws_realloc(void *ptr, size_t size, const char *reason)
+{
+ return _lws_realloc(ptr, size, reason);
+}
+
+void *lws_zalloc(size_t size, const char *reason)
+{
+ void *ptr = _lws_realloc(NULL, size, reason);
+ if (ptr)
+ memset(ptr, 0, size);
+ return ptr;
+}
+
+void lws_set_allocator(void *(*cb)(void *ptr, size_t size, const char *reason))
+{
+ _lws_realloc = cb;
+}
+#endif