syscall_table.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <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 "rom/libc_stubs.h"
  25. #include "esp_vfs.h"
  26. #include "esp_newlib.h"
  27. static struct _reent s_reent;
  28. extern int _printf_float(struct _reent *rptr,
  29. void *pdata,
  30. FILE * fp,
  31. int (*pfunc) (struct _reent *, FILE *, _CONST char *, size_t len),
  32. va_list * ap);
  33. extern int _scanf_float(struct _reent *rptr,
  34. void *pdata,
  35. FILE *fp,
  36. va_list *ap);
  37. static struct syscall_stub_table s_stub_table = {
  38. .__getreent = &__getreent,
  39. ._malloc_r = &_malloc_r,
  40. ._free_r = &_free_r,
  41. ._realloc_r = &_realloc_r,
  42. ._calloc_r = &_calloc_r,
  43. ._abort = &abort,
  44. ._system_r = &_system_r,
  45. ._rename_r = &esp_vfs_rename,
  46. ._times_r = &_times_r,
  47. ._gettimeofday_r = &_gettimeofday_r,
  48. ._raise_r = (void (*)(struct _reent *r)) &_raise_r,
  49. ._unlink_r = &esp_vfs_unlink,
  50. ._link_r = &esp_vfs_link,
  51. ._stat_r = &esp_vfs_stat,
  52. ._fstat_r = &esp_vfs_fstat,
  53. ._sbrk_r = &_sbrk_r,
  54. ._getpid_r = &_getpid_r,
  55. ._kill_r = &_kill_r,
  56. ._exit_r = NULL, // never called in ROM
  57. ._close_r = &esp_vfs_close,
  58. ._open_r = &esp_vfs_open,
  59. ._write_r = (int (*)(struct _reent *r, int, const void *, int)) &esp_vfs_write,
  60. ._lseek_r = (int (*)(struct _reent *r, int, int, int)) &esp_vfs_lseek,
  61. ._read_r = (int (*)(struct _reent *r, int, void *, int)) &esp_vfs_read,
  62. ._lock_init = &_lock_init,
  63. ._lock_init_recursive = &_lock_init_recursive,
  64. ._lock_close = &_lock_close,
  65. ._lock_close_recursive = &_lock_close,
  66. ._lock_acquire = &_lock_acquire,
  67. ._lock_acquire_recursive = &_lock_acquire_recursive,
  68. ._lock_try_acquire = &_lock_try_acquire,
  69. ._lock_try_acquire_recursive = &_lock_try_acquire_recursive,
  70. ._lock_release = &_lock_release,
  71. ._lock_release_recursive = &_lock_release_recursive,
  72. ._printf_float = &_printf_float,
  73. ._scanf_float = &_scanf_float,
  74. };
  75. void esp_setup_syscall_table()
  76. {
  77. syscall_table_ptr_pro = &s_stub_table;
  78. syscall_table_ptr_app = &s_stub_table;
  79. _GLOBAL_REENT = &s_reent;
  80. environ = malloc(sizeof(char*));
  81. environ[0] = NULL;
  82. }