syscall_table.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2015-2019 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 <unistd.h>
  17. #include <errno.h>
  18. #include <stdlib.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <sys/signal.h>
  22. #include <sys/unistd.h>
  23. #include <sys/reent.h>
  24. #include "esp_vfs.h"
  25. #include "esp_newlib.h"
  26. #include "sdkconfig.h"
  27. #include "soc/soc_caps.h"
  28. #if CONFIG_IDF_TARGET_ESP32
  29. #include "esp32/rom/libc_stubs.h"
  30. #elif CONFIG_IDF_TARGET_ESP32S2
  31. #include "esp32s2/rom/libc_stubs.h"
  32. #elif CONFIG_IDF_TARGET_ESP32S3
  33. #include "esp32s3/rom/libc_stubs.h"
  34. #endif
  35. static struct _reent s_reent;
  36. extern int _printf_float(struct _reent *rptr,
  37. void *pdata,
  38. FILE * fp,
  39. int (*pfunc) (struct _reent *, FILE *, const char *, size_t len),
  40. va_list * ap);
  41. extern int _scanf_float(struct _reent *rptr,
  42. void *pdata,
  43. FILE *fp,
  44. va_list *ap);
  45. static void raise_r_stub(struct _reent *rptr)
  46. {
  47. _raise_r(rptr, 0);
  48. }
  49. static struct syscall_stub_table s_stub_table = {
  50. .__getreent = &__getreent,
  51. ._malloc_r = &_malloc_r,
  52. ._free_r = &_free_r,
  53. ._realloc_r = &_realloc_r,
  54. ._calloc_r = &_calloc_r,
  55. ._abort = &abort,
  56. ._system_r = &_system_r,
  57. ._rename_r = &_rename_r,
  58. ._times_r = &_times_r,
  59. ._gettimeofday_r = &_gettimeofday_r,
  60. ._raise_r = &raise_r_stub,
  61. ._unlink_r = &_unlink_r,
  62. ._link_r = &_link_r,
  63. ._stat_r = &_stat_r,
  64. ._fstat_r = &_fstat_r,
  65. ._sbrk_r = &_sbrk_r,
  66. ._getpid_r = &_getpid_r,
  67. ._kill_r = &_kill_r,
  68. ._exit_r = NULL, // never called in ROM
  69. ._close_r = &_close_r,
  70. ._open_r = &_open_r,
  71. ._write_r = (int (*)(struct _reent *r, int, const void *, int)) &_write_r,
  72. ._lseek_r = (int (*)(struct _reent *r, int, int, int)) &_lseek_r,
  73. ._read_r = (int (*)(struct _reent *r, int, void *, int)) &_read_r,
  74. ._lock_init = &_lock_init,
  75. ._lock_init_recursive = &_lock_init_recursive,
  76. ._lock_close = &_lock_close,
  77. ._lock_close_recursive = &_lock_close_recursive,
  78. ._lock_acquire = &_lock_acquire,
  79. ._lock_acquire_recursive = &_lock_acquire_recursive,
  80. ._lock_try_acquire = &_lock_try_acquire,
  81. ._lock_try_acquire_recursive = &_lock_try_acquire_recursive,
  82. ._lock_release = &_lock_release,
  83. ._lock_release_recursive = &_lock_release_recursive,
  84. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  85. ._printf_float = &_printf_float,
  86. ._scanf_float = &_scanf_float,
  87. #else
  88. ._printf_float = NULL,
  89. ._scanf_float = NULL,
  90. #endif
  91. };
  92. void esp_setup_syscall_table(void)
  93. {
  94. syscall_table_ptr_pro = &s_stub_table;
  95. #if SOC_CPU_CORES_NUM == 2
  96. syscall_table_ptr_app = &s_stub_table;
  97. #endif
  98. _GLOBAL_REENT = &s_reent;
  99. environ = malloc(sizeof(char*));
  100. environ[0] = NULL;
  101. }