syscalls.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <string.h>
  15. #include <stdbool.h>
  16. #include <sys/types.h>
  17. #include <unistd.h>
  18. #include <errno.h>
  19. #include <sys/reent.h>
  20. #include <stdlib.h>
  21. #include "esp_attr.h"
  22. #include "freertos/FreeRTOS.h"
  23. #include "esp_heap_caps.h"
  24. /*
  25. These contain the business logic for the malloc() and realloc() implementation. Because of heap tracing
  26. wrapping reasons, we do not want these to be a public api, however, so they're not defined publicly.
  27. */
  28. extern void *heap_caps_malloc_default( size_t size );
  29. extern void *heap_caps_realloc_default( void *ptr, size_t size );
  30. void* IRAM_ATTR _malloc_r(struct _reent *r, size_t size)
  31. {
  32. return heap_caps_malloc_default( size );
  33. }
  34. void IRAM_ATTR _free_r(struct _reent *r, void* ptr)
  35. {
  36. heap_caps_free( ptr );
  37. }
  38. void* IRAM_ATTR _realloc_r(struct _reent *r, void* ptr, size_t size)
  39. {
  40. return heap_caps_realloc_default( ptr, size );
  41. }
  42. void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
  43. {
  44. void* result = heap_caps_malloc_default(count * size);
  45. if (result) {
  46. bzero(result, count * size);
  47. }
  48. return result;
  49. }
  50. int _system_r(struct _reent *r, const char *str)
  51. {
  52. __errno_r(r) = ENOSYS;
  53. return -1;
  54. }
  55. void _raise_r(struct _reent *r)
  56. {
  57. abort();
  58. }
  59. void* _sbrk_r(struct _reent *r, ptrdiff_t sz)
  60. {
  61. abort();
  62. }
  63. int _getpid_r(struct _reent *r)
  64. {
  65. __errno_r(r) = ENOSYS;
  66. return -1;
  67. }
  68. int _kill_r(struct _reent *r, int pid, int sig)
  69. {
  70. __errno_r(r) = ENOSYS;
  71. return -1;
  72. }
  73. void _exit(int __status)
  74. {
  75. abort();
  76. }