libc_stubs.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2015-2020 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. #pragma once
  15. #include <sys/lock.h>
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <reent.h>
  21. #include <errno.h>
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26. * @brief ESP32-S3 ROM code contains implementations of some of C library functions.
  27. * Whenever a function in ROM needs to use a syscall, it calls a pointer to the corresponding syscall
  28. * implementation defined in the following struct.
  29. *
  30. * The table itself, by default, is not allocated in RAM. There are two pointers, `syscall_table_ptr_pro` and
  31. * `syscall_table_ptr_app`, which can be set to point to the locations of syscall tables of CPU 0 (aka PRO CPU)
  32. * and CPU 1 (aka APP CPU). Location of these pointers in .bss segment of ROM code is defined in linker script.
  33. *
  34. * So, before using any of the C library functions (except for pure functions and memcpy/memset functions),
  35. * application must allocate syscall table structure for each CPU being used, and populate it with pointers
  36. * to actual implementations of corresponding syscalls.
  37. *
  38. */
  39. struct syscall_stub_table
  40. {
  41. struct _reent* (*__getreent)(void);
  42. void* (*_malloc_r)(struct _reent *r, size_t);
  43. void (*_free_r)(struct _reent *r, void*);
  44. void* (*_realloc_r)(struct _reent *r, void*, size_t);
  45. void* (*_calloc_r)(struct _reent *r, size_t, size_t);
  46. void (*_abort)(void);
  47. int (*_system_r)(struct _reent *r, const char*);
  48. int (*_rename_r)(struct _reent *r, const char*, const char*);
  49. clock_t (*_times_r)(struct _reent *r, struct tms *);
  50. int (*_gettimeofday_r) (struct _reent *r, struct timeval *, void *);
  51. void (*_raise_r)(struct _reent *r);
  52. int (*_unlink_r)(struct _reent *r, const char*);
  53. int (*_link_r)(struct _reent *r, const char*, const char*);
  54. int (*_stat_r)(struct _reent *r, const char*, struct stat *);
  55. int (*_fstat_r)(struct _reent *r, int, struct stat *);
  56. void* (*_sbrk_r)(struct _reent *r, ptrdiff_t);
  57. int (*_getpid_r)(struct _reent *r);
  58. int (*_kill_r)(struct _reent *r, int, int);
  59. void (*_exit_r)(struct _reent *r, int);
  60. int (*_close_r)(struct _reent *r, int);
  61. int (*_open_r)(struct _reent *r, const char *, int, int);
  62. int (*_write_r)(struct _reent *r, int, const void *, int);
  63. int (*_lseek_r)(struct _reent *r, int, int, int);
  64. int (*_read_r)(struct _reent *r, int, void *, int);
  65. void (*_retarget_lock_init)(_LOCK_T *lock);
  66. void (*_retarget_lock_init_recursive)(_LOCK_T *lock);
  67. void (*_retarget_lock_close)(_LOCK_T lock);
  68. void (*_retarget_lock_close_recursive)(_LOCK_T lock);
  69. void (*_retarget_lock_acquire)(_LOCK_T lock);
  70. void (*_retarget_lock_acquire_recursive)(_LOCK_T lock);
  71. int (*_retarget_lock_try_acquire)(_LOCK_T lock);
  72. int (*_retarget_lock_try_acquire_recursive)(_LOCK_T lock);
  73. void (*_retarget_lock_release)(_LOCK_T lock);
  74. void (*_retarget_lock_release_recursive)(_LOCK_T lock);
  75. int (*_printf_float)(struct _reent *data, void *pdata, FILE * fp, int (*pfunc) (struct _reent *, FILE *, const char *, size_t len), va_list * ap);
  76. int (*_scanf_float) (struct _reent *rptr, void *pdata, FILE *fp, va_list *ap);
  77. void (*__assert_func) (const char *file, int line, const char * func, const char *failedexpr) __attribute__((noreturn));
  78. void (*__sinit) (struct _reent *r);
  79. void (*_cleanup_r) (struct _reent* r);
  80. };
  81. extern struct syscall_stub_table *syscall_table_ptr;
  82. #define syscall_table_ptr_pro syscall_table_ptr
  83. #define syscall_table_ptr_app syscall_table_ptr
  84. #ifdef __cplusplus
  85. } // extern "C"
  86. #endif