1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2023-05-17     Flybreak     the first version
9  */
10 
11 #include <rtthread.h>
12 #include <sys/types.h>
13 
14 /* global errno */
15 static volatile int __pico_errno;
16 
pico_get_errno(void)17 int *pico_get_errno(void)
18 {
19     rt_thread_t tid = RT_NULL;
20 
21     if (rt_interrupt_get_nest() != 0)
22     {
23         /* it's in interrupt context */
24         return (int *)&__pico_errno;
25     }
26 
27     tid = rt_thread_self();
28     if (tid == RT_NULL)
29     {
30         return (int *)&__pico_errno;
31     }
32 
33     return (int *)&tid->error;
34 }
35 
36 #ifdef RT_USING_HEAP
malloc(size_t n)37 void *malloc(size_t n)
38 {
39     return rt_malloc(n);
40 }
41 RTM_EXPORT(malloc);
42 
realloc(void * rmem,size_t newsize)43 void *realloc(void *rmem, size_t newsize)
44 {
45     return rt_realloc(rmem, newsize);
46 }
47 RTM_EXPORT(realloc);
48 
calloc(size_t nelem,size_t elsize)49 void *calloc(size_t nelem, size_t elsize)
50 {
51     return rt_calloc(nelem, elsize);
52 }
53 RTM_EXPORT(calloc);
54 
free(void * rmem)55 void free(void *rmem)
56 {
57     rt_free(rmem);
58 }
59 RTM_EXPORT(free);
60 #endif /* RT_USING_HEAP */
61