syscall-fallbacks.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright 2021 Nick Brassel, QMK
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <errno.h>
  17. #include <sys/stat.h>
  18. #include <sys/types.h>
  19. /* To compile the ChibiOS syscall stubs with picolibc
  20. * the _reent struct has to be defined. */
  21. #if defined(USE_PICOLIBC)
  22. struct _reent;
  23. #endif
  24. #pragma GCC diagnostic ignored "-Wmissing-prototypes"
  25. __attribute__((weak, used)) int _open_r(struct _reent *r, const char *path, int flag, int m) {
  26. __errno_r(r) = ENOENT;
  27. return -1;
  28. }
  29. __attribute__((weak, used)) int _lseek_r(struct _reent *r, int file, int ptr, int dir) {
  30. __errno_r(r) = EBADF;
  31. return -1;
  32. }
  33. __attribute__((weak, used)) int _read_r(struct _reent *r, int file, char *ptr, int len) {
  34. __errno_r(r) = EBADF;
  35. return -1;
  36. }
  37. __attribute__((weak, used)) int _write_r(struct _reent *r, int file, char *ptr, int len) {
  38. __errno_r(r) = EBADF;
  39. return -1;
  40. }
  41. __attribute__((weak, used)) int _close_r(struct _reent *r, int file) {
  42. __errno_r(r) = EBADF;
  43. return -1;
  44. }
  45. __attribute__((weak, used)) int _link_r(struct _reent *r, const char *oldpath, const char *newpath) {
  46. __errno_r(r) = EPERM;
  47. return -1;
  48. }
  49. __attribute__((weak, used)) int _unlink_r(struct _reent *r, const char *path) {
  50. __errno_r(r) = EPERM;
  51. return -1;
  52. }
  53. __attribute__((weak, used)) clock_t _times_r(struct _reent *r, void *t) {
  54. __errno_r(r) = EFAULT;
  55. return -1;
  56. }
  57. __attribute__((weak, used)) int _fstat_r(struct _reent *r, int file, struct stat *st) {
  58. __errno_r(r) = EBADF;
  59. return -1;
  60. }
  61. __attribute__((weak, used)) int _isatty_r(struct _reent *r, int fd) {
  62. __errno_r(r) = EBADF;
  63. return 0;
  64. }
  65. __attribute__((weak, used)) caddr_t _sbrk_r(struct _reent *r, int incr) {
  66. __errno_r(r) = ENOMEM;
  67. return (caddr_t)-1;
  68. }
  69. __attribute__((weak, used)) int _kill(int pid, int sig) {
  70. errno = EPERM;
  71. return -1;
  72. }
  73. __attribute__((weak, used)) pid_t _getpid(void) { return 1; }
  74. __attribute__((weak, used)) void _fini(void) { return; }
  75. __attribute__((weak, used, noreturn)) void _exit(int i) {
  76. while (1)
  77. ;
  78. }
  79. __attribute__((weak, used)) int _gettimeofday_r(struct _reent *r, struct timeval *t, void *tzp) {
  80. __errno_r(r) = EPERM;
  81. return -1;
  82. }
  83. __attribute__((weak, used)) void *__dso_handle;
  84. __attribute__((weak, used)) void __cxa_pure_virtual(void) {
  85. while (1)
  86. ;
  87. }
  88. #pragma GCC diagnostic pop