2 # Copyright (C) 2005, 2018, 2023 Axis Communications.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # 2. Neither the name of Axis Communications nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS
17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS
20 # COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # To avoid an abundance of copyright/license messages for boilerplate
30 # code, we instead generate them from this file. Generating the
31 # function code could also be done automatically, but at the cost of
32 # slightly more intricate build machinery and/or scattered syscall
33 # information. Beware that the cat-lines must match the sed regexp
34 # "^cat > \([^ ]*\).*".
36 lu
='/* -*- buffer-read-only: t -*-
37 THIS FILE IS AUTOMATICALLY GENERATED
39 #include "linunistd.h"
40 #define R(x) return (x); }
47 $lui _close (int fd${r}close (fd))
50 $lui _execve (const char *path, char * const *argv, char *const *env${r}execve (path, argv, env))
53 $lu void _exit (int val) { _Sys_exit (val); /* Appease GCC: */ while (1) ; }
56 $lui _fcntl (int fd, int cmd, long arg${r}fcntl (fd, cmd, arg))
59 $lui _fork (void${r}fork ())
62 $lu#include <string.h>
68 _fstat (int fd, struct stat *buf)
71 int retval = _Sys_fstat (fd, &ks);
73 /* Blank before filling it in. */
74 memset (buf, 0, sizeof (*buf));
76 /* We have to translate from the linux struct new_stat.
77 It seems we don't have to translate the contents, though. */
78 buf->st_dev = ks.st_dev;
79 buf->st_ino = ks.st_ino;
80 buf->st_mode = ks.st_mode;
81 buf->st_nlink = ks.st_nlink;
82 buf->st_uid = ks.st_uid;
83 buf->st_gid = ks.st_gid;
84 buf->st_rdev = ks.st_rdev;
85 buf->st_size = ks.st_size;
86 buf->st_blksize = ks.st_blksize;
87 buf->st_blocks = ks.st_blocks;
88 buf->st_atim.tv_sec = ks.st_atime;
89 buf->st_mtim.tv_sec = ks.st_mtime;
90 buf->st_ctim.tv_sec = ks.st_ctime;
94 $lui _getpid (void${r}getpid ())
97 $lu#include <sys/time.h>
98 #include <sys/times.h>
100 _gettimeofday (struct timeval *tp, void *tzp)
102 struct kernel_timeval kt;
103 int retval = _Sys_gettimeofday(&kt, tzp);
106 tp->tv_sec = kt.tv_sec;
107 tp->tv_usec = kt.tv_usec;
113 typedef unsigned int tcflag_t;
114 typedef unsigned char cc_t;
118 tcflag_t c_iflag; /* input mode flags */
119 tcflag_t c_oflag; /* output mode flags */
120 tcflag_t c_cflag; /* control mode flags */
121 tcflag_t c_lflag; /* local mode flags */
122 cc_t c_line; /* line discipline */
123 cc_t c_cc[NCCS]; /* control characters */
126 /* From asm-etrax100/ioctls.h: beware of updates. */
127 #define TCGETS 0x5401
132 struct termios dummy;
133 int save_errno = errno;
134 int ret = _Sys_ioctl (fd, TCGETS, (unsigned long) &dummy);
139 $lui _kill (int pid, int sig${r}kill (pid, sig))
142 $lui _link (const char *old, const char *new${r}link (old, new))
145 $lul _lseek (int fd, long int offset, int whence${r}lseek (fd, offset, whence))
148 $lui _open (const char *fnam, int flags, int mode${r}open (fnam, flags, mode))
151 $lui _read (int fd, void *buf, unsigned long int nbytes${r}read (fd, buf, nbytes))
154 $lui _rename (const char *old, const char *new${r}rename (old, new))
158 /* From asm-etrax100/mman.h: beware of updates. */
159 #define PROT_READ 0x1 /* page can be read */
160 #define PROT_WRITE 0x2 /* page can be written */
161 #define MAP_ANONYMOUS 0x20 /* don't use a file */
165 static long last_alloc = 0;
167 /* FIXME: Things are a whole lot different than elinux. */
170 /* We can't promise linear memory from a predetermined location.
171 We're NO_MM. We're paria. We have to rely on tweaks and unclean
172 behavior. We abuse the fact that the malloc function in newlib
173 accepts nonlinear chunks in return to its sbrk calls (with a minor
176 /* We use an "old" type mmap, which takes a pointer to a vector of 6
177 longs where the parameters are stored. */
180 /* We can't return memory. Well we could, but we would have to keep a
181 list of previous allocations. FIXME: Seems reasonable to do that
184 return (char *) last_alloc;
186 buffer[3] = MAP_ANONYMOUS; /* Not associated with a file. */
187 buffer[4] = -1; /* No file. */
188 buffer[0] = 0; /* Address 0: let mmap pick one. */
189 buffer[1] = d; /* Length. */
190 buffer[2] = (PROT_READ | PROT_WRITE); /* Protection flags. */
191 buffer[5] = 0; /* Offset into file. */
193 last_alloc = _Sys_mmap (buffer);
195 return (char *) last_alloc;
197 #else /* not __elinux__ */
203 last_alloc = _Sys_brk (0);
209 prev_brk = last_alloc;
211 if (_Sys_brk (last_alloc + d) < last_alloc + d)
216 return (char *) prev_brk;
221 $lu#include <string.h>
222 #include <sys/stat.h>
227 _stat (const char *path, struct stat *buf)
230 int retval = _Sys_stat (path, &ks);
232 /* Blank before filling it in. */
233 memset (buf, 0, sizeof (*buf));
235 /* We have to translate from the linux struct new_stat.
236 It seems we don't have to translate the contents, though. */
237 buf->st_dev = ks.st_dev;
238 buf->st_ino = ks.st_ino;
239 buf->st_mode = ks.st_mode;
240 buf->st_nlink = ks.st_nlink;
241 buf->st_uid = ks.st_uid;
242 buf->st_gid = ks.st_gid;
243 buf->st_rdev = ks.st_rdev;
244 buf->st_size = ks.st_size;
245 buf->st_blksize = ks.st_blksize;
246 buf->st_blocks = ks.st_blocks;
247 buf->st_atim.tv_sec = ks.st_atime;
248 buf->st_mtim.tv_sec = ks.st_mtime;
249 buf->st_ctim.tv_sec = ks.st_ctime;
253 $lu#include <sys/times.h>
255 _times (struct tms * tp${r}times (tp))
258 $lui _unlink (const char *f${r}unlink (f))
261 $lui _wait (int *status${r}wait4 (_getpid(), status, 0, 0))
264 $lui _write (int fd, const void *buf, unsigned long int nbytes${r}write (fd, buf, nbytes))