libc_stubs.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ROM_LIBC_STUBS_H_
  7. #define _ROM_LIBC_STUBS_H_
  8. #include <sys/lock.h>
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include <time.h>
  14. #include <reent.h>
  15. #include <errno.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /*
  20. ESP32-C6 ROM code contains implementations of some of C library functions.
  21. Whenever a function in ROM needs to use a syscall, it calls a pointer to the corresponding syscall
  22. implementation defined in the following struct.
  23. The table itself, by default, is not allocated in RAM. A global pointer syscall_table_ptr is used to
  24. set the address
  25. So, before using any of the C library functions (except for pure functions and memcpy/memset functions),
  26. application must allocate syscall table structure for each CPU being used, and populate it with pointers
  27. to actual implementations of corresponding syscalls.
  28. */
  29. struct syscall_stub_table {
  30. struct _reent *(*__getreent)(void);
  31. void *(*_malloc_r)(struct _reent *r, size_t);
  32. void (*_free_r)(struct _reent *r, void *);
  33. void *(*_realloc_r)(struct _reent *r, void *, size_t);
  34. void *(*_calloc_r)(struct _reent *r, size_t, size_t);
  35. void (*_abort)(void);
  36. int (*_system_r)(struct _reent *r, const char *);
  37. int (*_rename_r)(struct _reent *r, const char *, const char *);
  38. clock_t (*_times_r)(struct _reent *r, struct tms *);
  39. int (*_gettimeofday_r) (struct _reent *r, struct timeval *, void *);
  40. void (*_raise_r)(struct _reent *r);
  41. int (*_unlink_r)(struct _reent *r, const char *);
  42. int (*_link_r)(struct _reent *r, const char *, const char *);
  43. int (*_stat_r)(struct _reent *r, const char *, struct stat *);
  44. int (*_fstat_r)(struct _reent *r, int, struct stat *);
  45. void *(*_sbrk_r)(struct _reent *r, ptrdiff_t);
  46. int (*_getpid_r)(struct _reent *r);
  47. int (*_kill_r)(struct _reent *r, int, int);
  48. void (*_exit_r)(struct _reent *r, int);
  49. int (*_close_r)(struct _reent *r, int);
  50. int (*_open_r)(struct _reent *r, const char *, int, int);
  51. int (*_write_r)(struct _reent *r, int, const void *, int);
  52. int (*_lseek_r)(struct _reent *r, int, int, int);
  53. int (*_read_r)(struct _reent *r, int, void *, int);
  54. void (*_retarget_lock_init)(_LOCK_T *lock);
  55. void (*_retarget_lock_init_recursive)(_LOCK_T *lock);
  56. void (*_retarget_lock_close)(_LOCK_T lock);
  57. void (*_retarget_lock_close_recursive)(_LOCK_T lock);
  58. void (*_retarget_lock_acquire)(_LOCK_T lock);
  59. void (*_retarget_lock_acquire_recursive)(_LOCK_T lock);
  60. int (*_retarget_lock_try_acquire)(_LOCK_T lock);
  61. int (*_retarget_lock_try_acquire_recursive)(_LOCK_T lock);
  62. void (*_retarget_lock_release)(_LOCK_T lock);
  63. void (*_retarget_lock_release_recursive)(_LOCK_T lock);
  64. int (*_printf_float)(struct _reent *data, void *pdata, FILE *fp, int (*pfunc) (struct _reent *, FILE *, const char *, size_t len), va_list *ap);
  65. int (*_scanf_float) (struct _reent *rptr, void *pdata, FILE *fp, va_list *ap);
  66. void (*__assert_func) (const char *file, int line, const char *func, const char *failedexpr) __attribute__((noreturn));
  67. void (*__sinit) (struct _reent *r);
  68. void (*_cleanup_r) (struct _reent *r);
  69. };
  70. extern struct syscall_stub_table *syscall_table_ptr;
  71. #ifdef __cplusplus
  72. } // extern "C"
  73. #endif
  74. #endif /* _ROM_LIBC_STUBS_H_ */