summaryrefslogtreecommitdiff
path: root/os/src/malloc.c
blob: a24a87f776c07ac7c123648f1b5aa1021f9a94ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <reent.h>
#include <malloc.h>
#include <osdebug.h>

static xSemaphoreHandle malloc_sem = NULL;

__attribute__((constructor)) static void malloc_init() {
    malloc_sem = xSemaphoreCreateMutex();
}

void * malloc(size_t size) {
    void * ptr;
    
    if (malloc_sem)
        xSemaphoreTake(malloc_sem, portMAX_DELAY);
    ptr =_malloc_r(_impure_ptr, size);
    if (malloc_sem)
        xSemaphoreGive(malloc_sem);
}