2023-05-17 17:17:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2023-05-17 Flybreak the first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2023-09-19 13:50:22 +08:00
|
|
|
#include <sys/types.h>
|
2023-05-17 17:17:38 +08:00
|
|
|
|
2023-09-19 13:50:22 +08:00
|
|
|
/* global errno */
|
|
|
|
static volatile int __pico_errno;
|
|
|
|
|
|
|
|
int *pico_get_errno(void)
|
2023-05-17 17:17:38 +08:00
|
|
|
{
|
2023-09-19 13:50:22 +08:00
|
|
|
rt_thread_t tid = RT_NULL;
|
|
|
|
|
|
|
|
if (rt_interrupt_get_nest() != 0)
|
|
|
|
{
|
|
|
|
/* it's in interrupt context */
|
2023-12-25 21:08:47 +08:00
|
|
|
return (int *)&__pico_errno;
|
2023-09-19 13:50:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tid = rt_thread_self();
|
|
|
|
if (tid == RT_NULL)
|
|
|
|
{
|
2023-12-25 21:08:47 +08:00
|
|
|
return (int *)&__pico_errno;
|
2023-09-19 13:50:22 +08:00
|
|
|
}
|
|
|
|
|
2023-12-25 21:08:47 +08:00
|
|
|
return (int *)&tid->error;
|
2023-05-17 17:17:38 +08:00
|
|
|
}
|
2023-05-27 00:26:34 +08:00
|
|
|
|
2023-09-19 13:50:22 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2023-05-27 00:26:34 +08:00
|
|
|
void *malloc(size_t n)
|
|
|
|
{
|
|
|
|
return rt_malloc(n);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(malloc);
|
|
|
|
|
|
|
|
void *realloc(void *rmem, size_t newsize)
|
|
|
|
{
|
|
|
|
return rt_realloc(rmem, newsize);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(realloc);
|
|
|
|
|
|
|
|
void *calloc(size_t nelem, size_t elsize)
|
|
|
|
{
|
|
|
|
return rt_calloc(nelem, elsize);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(calloc);
|
|
|
|
|
|
|
|
void free(void *rmem)
|
|
|
|
{
|
|
|
|
rt_free(rmem);
|
|
|
|
}
|
|
|
|
RTM_EXPORT(free);
|
2023-09-19 13:50:22 +08:00
|
|
|
#endif /* RT_USING_HEAP */
|