2020-12-10 09:39:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Gunar Schorcht
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Implements various POSIX syscalls
|
|
|
|
* @author Gunar Schorcht <gunar@schorcht.net>
|
|
|
|
*/
|
|
|
|
|
2020-12-10 09:43:55 +01:00
|
|
|
#include "assert.h"
|
2020-12-10 09:39:44 +01:00
|
|
|
#include "irq.h"
|
2020-12-10 09:43:55 +01:00
|
|
|
#include "mutex.h"
|
2020-12-10 09:39:44 +01:00
|
|
|
|
|
|
|
extern void *__real_malloc(size_t size);
|
|
|
|
extern void __real_free(void *ptr);
|
|
|
|
extern void *__real_calloc(size_t nmemb, size_t size);
|
|
|
|
extern void *__real_realloc(void *ptr, size_t size);
|
|
|
|
|
2020-12-10 09:43:55 +01:00
|
|
|
static mutex_t _lock;
|
|
|
|
|
2020-12-10 09:39:44 +01:00
|
|
|
void *__wrap_malloc(size_t size)
|
|
|
|
{
|
2020-12-10 09:43:55 +01:00
|
|
|
assert(!irq_is_in());
|
|
|
|
mutex_lock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
void *ptr = __real_malloc(size);
|
2020-12-10 09:43:55 +01:00
|
|
|
mutex_unlock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __wrap_free(void *ptr)
|
|
|
|
{
|
2020-12-10 09:43:55 +01:00
|
|
|
assert(!irq_is_in());
|
|
|
|
mutex_lock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
__real_free(ptr);
|
2020-12-10 09:43:55 +01:00
|
|
|
mutex_unlock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void *__wrap_calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
2020-12-10 09:43:55 +01:00
|
|
|
assert(!irq_is_in());
|
|
|
|
mutex_lock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
void *ptr = __real_calloc(nmemb, size);
|
2020-12-10 09:43:55 +01:00
|
|
|
mutex_unlock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *__wrap_realloc(void *ptr, size_t size)
|
|
|
|
{
|
2020-12-10 09:43:55 +01:00
|
|
|
assert(!irq_is_in());
|
|
|
|
mutex_lock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
void *new = __real_realloc(ptr, size);
|
2020-12-10 09:43:55 +01:00
|
|
|
mutex_unlock(&_lock);
|
2020-12-10 09:39:44 +01:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|