diff --git a/src/utils/os_zephyr.c b/src/utils/os_zephyr.c index b2c2e41631..5bd725ca13 100644 --- a/src/utils/os_zephyr.c +++ b/src/utils/os_zephyr.c @@ -18,6 +18,10 @@ int clock_gettime(clockid_t clock_id, struct timespec *ts); #include "includes.h" #include "os.h" +#if !defined(CONFIG_WIFI_NM_WPA_SUPPLICANT_GLOBAL_HEAP) +K_HEAP_DEFINE(wifi_nm_wpa_supplicant_mem_pool, CONFIG_WIFI_NM_WPA_SUPPLICANT_HEAP); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_GLOBAL_HEAP */ + void os_sleep(os_time_t sec, os_time_t usec) { k_sleep(K_USEC(usec + USEC_PER_SEC * sec)); @@ -220,12 +224,22 @@ void *os_memdup(const void *src, size_t len) void *os_malloc(size_t size) { +#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT_GLOBAL_HEAP) return k_malloc(size); +#else + return sys_heap_noalign_alloc(&wifi_nm_wpa_supplicant_mem_pool.heap, 0, size); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_GLOBAL_HEAP */ } void os_free(void *ptr) { - k_free(ptr); + if (ptr) { +#if defined(CONFIG_WIFI_NM_WPA_SUPPLICANT_GLOBAL_HEAP) + k_free(ptr); +#else + k_heap_free(&wifi_nm_wpa_supplicant_mem_pool, ptr); +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_GLOBAL_HEAP */ + } } void *os_realloc(void *ptr, size_t newsize) @@ -255,7 +269,7 @@ void *os_realloc(void *ptr, size_t newsize) void *os_zalloc(size_t size) { - void *p = k_malloc(size); + void *p = os_malloc(size); if (p != NULL) { (void)memset(p, 0, size);