syscall.c 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include <rtthread.h>
  11. #include <sys/types.h>
  12. /* global errno */
  13. static volatile int __pico_errno;
  14. int *pico_get_errno(void)
  15. {
  16. rt_thread_t tid = RT_NULL;
  17. if (rt_interrupt_get_nest() != 0)
  18. {
  19. /* it's in interrupt context */
  20. return &__pico_errno;
  21. }
  22. tid = rt_thread_self();
  23. if (tid == RT_NULL)
  24. {
  25. return &__pico_errno;
  26. }
  27. return &tid->error;
  28. }
  29. #ifdef RT_USING_HEAP
  30. void *malloc(size_t n)
  31. {
  32. return rt_malloc(n);
  33. }
  34. RTM_EXPORT(malloc);
  35. void *realloc(void *rmem, size_t newsize)
  36. {
  37. return rt_realloc(rmem, newsize);
  38. }
  39. RTM_EXPORT(realloc);
  40. void *calloc(size_t nelem, size_t elsize)
  41. {
  42. return rt_calloc(nelem, elsize);
  43. }
  44. RTM_EXPORT(calloc);
  45. void free(void *rmem)
  46. {
  47. rt_free(rmem);
  48. }
  49. RTM_EXPORT(free);
  50. #endif /* RT_USING_HEAP */