syscalls.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. void* IRAM_ATTR _malloc_r(struct _reent *r, size_t size)
  25. {
  26. return heap_caps_malloc( size, MALLOC_CAP_8BIT );
  27. }
  28. void IRAM_ATTR _free_r(struct _reent *r, void* ptr)
  29. {
  30. heap_caps_free( ptr );
  31. }
  32. void* IRAM_ATTR _realloc_r(struct _reent *r, void* ptr, size_t size)
  33. {
  34. return heap_caps_realloc( ptr, size, MALLOC_CAP_8BIT );
  35. }
  36. void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
  37. {
  38. void* result = heap_caps_malloc(count * size, MALLOC_CAP_8BIT);
  39. if (result) {
  40. bzero(result, count * size);
  41. }
  42. return result;
  43. }
  44. int _system_r(struct _reent *r, const char *str)
  45. {
  46. __errno_r(r) = ENOSYS;
  47. return -1;
  48. }
  49. void _raise_r(struct _reent *r)
  50. {
  51. abort();
  52. }
  53. void* _sbrk_r(struct _reent *r, ptrdiff_t sz)
  54. {
  55. abort();
  56. }
  57. int _getpid_r(struct _reent *r)
  58. {
  59. __errno_r(r) = ENOSYS;
  60. return -1;
  61. }
  62. int _kill_r(struct _reent *r, int pid, int sig)
  63. {
  64. __errno_r(r) = ENOSYS;
  65. return -1;
  66. }
  67. void _exit(int __status)
  68. {
  69. abort();
  70. }