1 /*
2  * Copyright 2023 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #if defined(__GNUC__)
9 #include <stdint.h>
10 #include <errno.h>
11 #include <sys/stat.h>
12 #endif
13 
14 /*
15  * This file defines the libnosys.a syscall functions.
16  * After upgraded to ARMGCC 12.2.1 with binutils 2.39, there are build warnings
17  * when link the libnosys.a, such as using -lnosys or using --specs=--specs=nosys.specs.
18  *
19  * The build warnings are like:
20  * (libc_a-closer.o): in function `_close_r': closer.c:(.text._close_r+0xc):
21  * warning: _close is not implemented and will always fail
22  *
23  * If you don't want to use the functions in this file, then define SDK_USE_SYSCALL_STUB
24  * as 0.
25  */
26 
27 /*******************************************************************************
28  * Definitions
29  ******************************************************************************/
30 #ifndef SDK_USE_SYSCALL_STUB
31 #define SDK_USE_SYSCALL_STUB 1
32 #endif
33 
34 /*******************************************************************************
35  * Code
36  ******************************************************************************/
37 #if defined(__GNUC__)
38 
39 #if SDK_USE_SYSCALL_STUB
40 
41 /*
42  * When SDK_DEBUGCONSOLE_UART defined, the _write and _read will be defined in
43  * fsl_debug_console.
44  */
45 #if !defined(SDK_DEBUGCONSOLE_UART)
46 int __attribute__((weak)) _write(int handle, char *buffer, int size);
_write(int handle,char * buffer,int size)47 int __attribute__((weak)) _write(int handle, char *buffer, int size)
48 {
49     errno = ENOSYS;
50     return -1;
51 }
52 
53 int __attribute__((weak)) _read(int handle, char *buffer, int size);
_read(int handle,char * buffer,int size)54 int __attribute__((weak)) _read(int handle, char *buffer, int size)
55 {
56     errno = ENOSYS;
57     return -1;
58 }
59 #endif /* SDK_DEBUGCONSOLE_UART */
60 
61 int __attribute__((weak)) _close(int f);
_close(int f)62 int __attribute__((weak)) _close(int f)
63 {
64     errno = ENOSYS;
65     return -1;
66 }
67 
68 int __attribute__((weak)) _lseek(int f, int ptr, int dir);
_lseek(int f,int ptr,int dir)69 int __attribute__((weak)) _lseek(int f, int ptr, int dir)
70 {
71     errno = ENOSYS;
72     return -1;
73 }
74 
75 int __attribute__((weak)) _fstat(int fs, struct stat *st);
_fstat(int fs,struct stat * st)76 int __attribute__((weak)) _fstat(int fs, struct stat *st)
77 {
78     errno = ENOSYS;
79     return -1;
80 }
81 
82 int __attribute__((weak)) _getpid(void);
_getpid(void)83 int __attribute__((weak)) _getpid(void)
84 {
85     errno = ENOSYS;
86     return -1;
87 }
88 
89 int __attribute__((weak)) _isatty(int f);
_isatty(int f)90 int __attribute__((weak)) _isatty(int f)
91 {
92     errno = ENOSYS;
93     return 0;
94 }
95 
96 int __attribute__((weak)) _kill(int pid, int sig);
_kill(int pid,int sig)97 int __attribute__((weak)) _kill(int pid, int sig)
98 {
99     errno = ENOSYS;
100     return -1;
101 }
102 
103 int __attribute__((weak)) _link(const char *path1, const char *path2);
_link(const char * path1,const char * path2)104 int __attribute__((weak)) _link(const char *path1, const char *path2)
105 {
106     errno = ENOSYS;
107     return -1;
108 }
109 
110 int __attribute__((weak)) _unlink(const char *path);
_unlink(const char * path)111 int __attribute__((weak)) _unlink(const char *path)
112 {
113     errno = ENOSYS;
114     return -1;
115 }
116 
117 int __attribute__((weak)) _open(const char *filename, int oflag);
_open(const char * filename,int oflag)118 int __attribute__((weak)) _open(const char *filename, int oflag)
119 {
120     errno = ENOSYS;
121     return -1;
122 }
123 
124 int __attribute__((weak)) _stat (const char *f, struct stat *st);
_stat(const char * f,struct stat * st)125 int __attribute__((weak)) _stat (const char *f, struct stat *st)
126 {
127     errno = ENOSYS;
128     return -1;
129 }
130 
131 #endif /* SDK_USE_SYSCALL_STUB */
132 
133 #endif /* __GNUC__ */
134