libc_stubs.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SPDX-FileCopyrightText: 2015-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 <stddef.h>
  9. #include <stdint.h>
  10. #include <stdio.h>
  11. #include <stdarg.h>
  12. #include <time.h>
  13. #include <reent.h>
  14. #include <errno.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /*
  19. ESP32 ROM code contains implementations of some of C library functions.
  20. Whenever a function in ROM needs to use a syscall, it calls a pointer to the corresponding syscall
  21. implementation defined in the following struct.
  22. The table itself, by default, is not allocated in RAM. There are two pointers, `syscall_table_ptr_pro` and
  23. `syscall_table_ptr_app`, which can be set to point to the locations of syscall tables of CPU 0 (aka PRO CPU)
  24. and CPU 1 (aka APP CPU). Location of these pointers in .bss segment of ROM code is defined in linker script.
  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. {
  31. struct _reent* (*__getreent)(void);
  32. void* (*_malloc_r)(struct _reent *r, size_t);
  33. void (*_free_r)(struct _reent *r, void*);
  34. void* (*_realloc_r)(struct _reent *r, void*, size_t);
  35. void* (*_calloc_r)(struct _reent *r, size_t, size_t);
  36. void (*_abort)(void);
  37. int (*_system_r)(struct _reent *r, const char*);
  38. int (*_rename_r)(struct _reent *r, const char*, const char*);
  39. clock_t (*_times_r)(struct _reent *r, struct tms *);
  40. int (*_gettimeofday_r) (struct _reent *r, struct timeval *, void *);
  41. void (*_raise_r)(struct _reent *r); /* function signature is incorrect in ROM */
  42. int (*_unlink_r)(struct _reent *r, const char*);
  43. int (*_link_r)(struct _reent *r, const char*, const char*);
  44. int (*_stat_r)(struct _reent *r, const char*, struct stat *);
  45. int (*_fstat_r)(struct _reent *r, int, struct stat *);
  46. void* (*_sbrk_r)(struct _reent *r, ptrdiff_t);
  47. int (*_getpid_r)(struct _reent *r);
  48. int (*_kill_r)(struct _reent *r, int, int);
  49. void (*_exit_r)(struct _reent *r, int);
  50. int (*_close_r)(struct _reent *r, int);
  51. int (*_open_r)(struct _reent *r, const char *, int, int);
  52. int (*_write_r)(struct _reent *r, int, const void *, int);
  53. int (*_lseek_r)(struct _reent *r, int, int, int);
  54. int (*_read_r)(struct _reent *r, int, void *, int);
  55. void (*_lock_init)(_lock_t *lock);
  56. void (*_lock_init_recursive)(_lock_t *lock);
  57. void (*_lock_close)(_lock_t *lock);
  58. void (*_lock_close_recursive)(_lock_t *lock);
  59. void (*_lock_acquire)(_lock_t *lock);
  60. void (*_lock_acquire_recursive)(_lock_t *lock);
  61. int (*_lock_try_acquire)(_lock_t *lock);
  62. int (*_lock_try_acquire_recursive)(_lock_t *lock);
  63. void (*_lock_release)(_lock_t *lock);
  64. void (*_lock_release_recursive)(_lock_t *lock);
  65. int (*_printf_float)(struct _reent *data, void *pdata, FILE * fp, int (*pfunc) (struct _reent *, FILE *, const char *, size_t len), va_list * ap);
  66. int (*_scanf_float) (struct _reent *rptr, void *pdata, FILE *fp, va_list *ap);
  67. };
  68. extern struct syscall_stub_table* syscall_table_ptr_pro;
  69. extern struct syscall_stub_table* syscall_table_ptr_app;
  70. #ifdef __cplusplus
  71. } // extern "C"
  72. #endif
  73. #endif /* _ROM_LIBC_STUBS_H_ */