aboutsummaryrefslogtreecommitdiff
path: root/platforms/chibios/syscall-fallbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/chibios/syscall-fallbacks.c')
-rw-r--r--platforms/chibios/syscall-fallbacks.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/platforms/chibios/syscall-fallbacks.c b/platforms/chibios/syscall-fallbacks.c
new file mode 100644
index 000000000..4569879c7
--- /dev/null
+++ b/platforms/chibios/syscall-fallbacks.c
@@ -0,0 +1,110 @@
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
17#include <errno.h>
18#include <sys/stat.h>
19#include <sys/types.h>
20
21/* To compile the ChibiOS syscall stubs with picolibc
22 * the _reent struct has to be defined. */
23#if defined(USE_PICOLIBC)
24struct _reent;
25#endif
26
27#pragma GCC diagnostic ignored "-Wmissing-prototypes"
28
29__attribute__((weak, used)) int _open_r(struct _reent *r, const char *path, int flag, int m) {
30 __errno_r(r) = ENOENT;
31 return -1;
32}
33
34__attribute__((weak, used)) int _lseek_r(struct _reent *r, int file, int ptr, int dir) {
35 __errno_r(r) = EBADF;
36 return -1;
37}
38
39__attribute__((weak, used)) int _read_r(struct _reent *r, int file, char *ptr, int len) {
40 __errno_r(r) = EBADF;
41 return -1;
42}
43
44__attribute__((weak, used)) int _write_r(struct _reent *r, int file, char *ptr, int len) {
45 __errno_r(r) = EBADF;
46 return -1;
47}
48
49__attribute__((weak, used)) int _close_r(struct _reent *r, int file) {
50 __errno_r(r) = EBADF;
51 return -1;
52}
53
54__attribute__((weak, used)) int _link_r(struct _reent *r, const char *oldpath, const char *newpath) {
55 __errno_r(r) = EPERM;
56 return -1;
57}
58
59__attribute__((weak, used)) int _unlink_r(struct _reent *r, const char *path) {
60 __errno_r(r) = EPERM;
61 return -1;
62}
63
64__attribute__((weak, used)) clock_t _times_r(struct _reent *r, void *t) {
65 __errno_r(r) = EFAULT;
66 return -1;
67}
68
69__attribute__((weak, used)) int _fstat_r(struct _reent *r, int file, struct stat *st) {
70 __errno_r(r) = EBADF;
71 return -1;
72}
73
74__attribute__((weak, used)) int _isatty_r(struct _reent *r, int fd) {
75 __errno_r(r) = EBADF;
76 return 0;
77}
78
79__attribute__((weak, used)) caddr_t _sbrk_r(struct _reent *r, int incr) {
80 __errno_r(r) = ENOMEM;
81 return (caddr_t)-1;
82}
83
84__attribute__((weak, used)) int _kill(int pid, int sig) {
85 errno = EPERM;
86 return -1;
87}
88
89__attribute__((weak, used)) pid_t _getpid(void) { return 1; }
90
91__attribute__((weak, used)) void _fini(void) { return; }
92
93__attribute__((weak, used, noreturn)) void _exit(int i) {
94 while (1)
95 ;
96}
97
98__attribute__((weak, used)) int _gettimeofday_r(struct _reent *r, struct timeval *t, void *tzp) {
99 __errno_r(r) = EPERM;
100 return -1;
101}
102
103__attribute__((weak, used)) void *__dso_handle;
104
105__attribute__((weak, used)) void __cxa_pure_virtual(void) {
106 while (1)
107 ;
108}
109
110#pragma GCC diagnostic pop