1 /*
2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU Lesser General Public License 2.1.
7 * Please see the COPYING-LGPL-2.1 file for details.
8 */
9 #ifndef _GNU_SOURCE
10 #define _GNU_SOURCE
11 #endif
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <signal.h>
17 #include <sys/stat.h>
18 #include <sys/mman.h>
19 #include <l4/sys/consts.h>
20 #include <l4/re/env.h>
21 #include <sys/utsname.h>
22 #include <sys/resource.h>
23 #include <sched.h>
24
25 int __ctype_b_loc(void);
26 int getloadavg(double loadavg[], int nelem);
27
28 /* Implementations */
__ctype_b_loc(void)29 int __ctype_b_loc(void)
30 {
31 printf("%s: implement me \n", __func__);
32 return 0;
33 }
34
__sched_cpucount(size_t __setsize,const cpu_set_t * __setp)35 int __sched_cpucount(size_t __setsize, const cpu_set_t *__setp)
36 {
37 (void)__setsize;
38 (void)__setp;
39 return 4; // just some number
40 }
41
sysconf(int name)42 long sysconf(int name)
43 {
44 switch (name)
45 {
46 case _SC_NPROCESSORS_ONLN:
47 return __sched_cpucount(0, NULL);
48 case _SC_PAGE_SIZE:
49 return L4_PAGESIZE;
50 case _SC_CLK_TCK:
51 return 1000;
52 case _SC_MONOTONIC_CLOCK:
53 return 200112L;
54 default:
55 break;
56 }
57 printf("%s: unknown command, name=%d\n", __func__, name);
58 return 0;
59 }
60
getloadavg(double loadavg[],int nelem)61 int getloadavg(double loadavg[], int nelem)
62 {
63 (void)nelem;
64 loadavg[0] = 0.7;
65 loadavg[1] = 0.7;
66 loadavg[2] = 0.7;
67 return 3;
68 }
69
getpid(void)70 pid_t getpid(void)
71 {
72 return 2;
73 }
74
fork(void)75 pid_t fork(void)
76 {
77 printf("Unimplemented: fork()\n");
78 errno = -ENOMEM;
79 return -1;
80 }
81
daemon(int nochdir,int noclose)82 int daemon(int nochdir, int noclose)
83 {
84 printf("Unimplemented: daemon(%d, %d)\n", nochdir, noclose);
85 errno = -ENOMEM;
86 return -1;
87 }
88
kill(pid_t pid,int sig)89 int kill(pid_t pid, int sig)
90 {
91 printf("Unimplemented: kill(%d, %d)\n", pid, sig);
92 errno = -EINVAL;
93 return -1;
94 }
95
96 #include <time.h>
97
timer_delete(timer_t timer_id)98 int timer_delete(timer_t timer_id)
99 {
100 printf("Unimplemented: %s(timer_id)\n", __func__);
101 (void)timer_id;
102 errno = -EINVAL;
103 return -1;
104 }
105
timer_gettime(timer_t timer_id,struct itimerspec * setting)106 int timer_gettime(timer_t timer_id, struct itimerspec *setting)
107 {
108 printf("Unimplemented: %s(timer_id)\n", __func__);
109 (void)timer_id;
110 (void)setting;
111 errno = -EINVAL;
112 return -1;
113 }
114
timer_settime(timer_t timer_id,int __flags,__const struct itimerspec * __restrict __value,struct itimerspec * __restrict __ovalue)115 int timer_settime(timer_t timer_id, int __flags,
116 __const struct itimerspec *__restrict __value,
117 struct itimerspec *__restrict __ovalue)
118 {
119 printf("Unimplemented: %s(timer_id)\n", __func__);
120 (void)timer_id;
121 (void)__value;
122 (void)__ovalue;
123 (void)__flags;
124 errno = -EINVAL;
125 return -1;
126 }
127
timer_create(clockid_t __clock_id,struct sigevent * __restrict __evp,timer_t * __restrict __timerid)128 int timer_create (clockid_t __clock_id,
129 struct sigevent *__restrict __evp,
130 timer_t *__restrict __timerid)
131 {
132 printf("Unimplemented: %s(clock_id)\n", __func__);
133 (void)__clock_id;
134 (void)__evp;
135 (void)__timerid;
136 errno = -EINVAL;
137 return -1;
138 }
139
140 #include <sys/times.h>
141
times(struct tms * buf)142 clock_t times(struct tms *buf)
143 {
144 // some arbitrary values
145 buf->tms_utime = (clock_t)l4_kip_clock(l4re_kip());
146 buf->tms_stime = 10;
147 buf->tms_cutime = 0;
148 buf->tms_cstime = 0;
149 return (clock_t)l4_kip_clock(l4re_kip());
150 }
151
152
153 #include <stdlib.h>
154 char *ptsname(int fd);
ptsname(int fd)155 char *ptsname(int fd)
156 {
157 printf("unimplemented: %s(%d)\n", __func__, fd);
158 return "unimplemented-ptsname";
159 }
160
161 #include <pty.h>
162
setuid(uid_t uid)163 int setuid(uid_t uid)
164 {
165 printf("Unimplemented: %s(%d)\n", __func__, uid);
166 return -1;
167 }
168
setsid(void)169 pid_t setsid(void)
170 {
171 printf("Unimplemented: %s()\n", __func__);
172 return -1;
173 }
174
setgid(gid_t gid)175 int setgid(gid_t gid)
176 {
177 printf("Unimplemented: %s(%d)\n", __func__, gid);
178 return -1;
179 }
180
181
umask(mode_t mask)182 mode_t umask(mode_t mask)
183 {
184 printf("Unimplemented: %s(%d)\n", __func__, mask);
185 return 0;
186 }
187
pipe(int pipefd[2])188 int pipe(int pipefd[2])
189 {
190 printf("Unimplemented: %s()\n", __func__);
191 printf(" Caller %p\n", __builtin_return_address(0));
192 (void)pipefd;
193 errno = EINVAL;
194 return -1;
195 }
196
197 #include <sys/wait.h>
waitpid(pid_t pid,int * status,int options)198 pid_t waitpid(pid_t pid, int *status, int options)
199 {
200 printf("Unimplemented: %s(%d)\n", __func__, pid);
201 (void)status;
202 (void)options;
203 errno = EINVAL;
204 return -1;
205 }
206
popen(const char * command,const char * type)207 FILE *popen(const char *command, const char *type)
208 {
209 printf("Unimplemented: %s(%s, %s)\n", __func__, command, type);
210 return NULL;
211 }
212
pclose(FILE * stream)213 int pclose(FILE *stream)
214 {
215 printf("Unimplemented: %s(..)\n", __func__);
216 (void)stream;
217 return 0;
218 }
219
220
221
execv(const char * path,char * const argv[])222 int execv(const char *path, char *const argv[])
223 {
224 printf("Unimplemented: %s(%s)\n", __func__, path);
225 (void)argv;
226 errno = EINVAL;
227 return -1;
228 }
229
execvp(const char * file,char * const argv[])230 int execvp(const char *file, char *const argv[])
231 {
232 printf("Unimplemented: %s(%s)\n", __func__, file);
233 (void)argv;
234 errno = EINVAL;
235 return -1;
236 }
237
execve(const char * filename,char * const argv[],char * const envp[])238 int execve(const char *filename, char *const argv[],
239 char *const envp[])
240 {
241 printf("Unimplemented: %s(%s)\n", __func__, filename);
242 (void)argv;
243 (void)envp;
244 errno = EINVAL;
245 return -1;
246 }
247
execl(const char * path,const char * arg,...)248 int execl(const char *path, const char *arg, ...)
249 {
250 printf("Unimplemented: %s(%s)\n", __func__, path);
251 (void)arg;
252 errno = EINVAL;
253 return -1;
254 }
255
execlp(const char * file,const char * arg,...)256 int execlp(const char *file, const char *arg, ...)
257 {
258 printf("Unimplemented: %s(%s)\n", __func__, file);
259 (void)arg;
260 errno = EINVAL;
261 return -1;
262 }
263
fpathconf(int fd,int name)264 long fpathconf(int fd, int name)
265 {
266 printf("Unimplemented: %s(%d, %d)\n", __func__, fd, name);
267 errno = EINVAL;
268 return -1;
269 }
270
pathconf(const char * path,int name)271 long pathconf(const char *path, int name)
272 {
273 printf("Unimplemented: %s(%s, %d)\n", __func__, path, name);
274 errno = EINVAL;
275 return -1;
276 }
277
278
279
280
281
282 #include <termios.h>
283
tcsendbreak(int fd,int duration)284 int tcsendbreak(int fd, int duration)
285 {
286 printf("Unimplemented: %s()\n", __func__);
287 (void)fd; (void)duration;
288 errno = EINVAL;
289 return -1;
290 }
291
cfmakeraw(struct termios * termios_p)292 void cfmakeraw(struct termios *termios_p)
293 {
294 printf("Unimplemented: %s()\n", __func__);
295 (void)termios_p;
296 }
297
openpty(int * amaster,int * aslave,char * name,struct termios * termp,struct winsize * winp)298 int openpty(int *amaster, int *aslave, char *name,
299 struct termios *termp, struct winsize *winp)
300 {
301 printf("Unimplemented: %s(.., .., %s, ..)\n", __func__, name);
302 (void)amaster; (void)aslave;
303 (void)termp; (void)winp;
304 errno = EINVAL;
305 return -1;
306 }
307
308
309
310
311
getuid(void)312 uid_t getuid(void) { return 123; }
getgid(void)313 uid_t getgid(void) { return 123; }
geteuid(void)314 uid_t geteuid(void) { return 123; }
getegid(void)315 uid_t getegid(void) { return 123; }
getpgrp(void)316 pid_t getpgrp(void) { return 7; }
getppid(void)317 pid_t getppid(void) { return 122; }
318
setpgid(pid_t pid,pid_t pgid)319 int setpgid(pid_t pid, pid_t pgid)
320 {
321 printf("Unimplemented: %s(%d, %d)\n", __func__, pid, pgid);
322 errno = EPERM;
323 return -1;
324 }
325
326
getgroups(int size,gid_t list[])327 int getgroups(int size, gid_t list[])
328 {
329 (void)size; (void)list;
330 printf("Unimplemented: %s()\n", __func__);
331 errno = EPERM;
332 return -1;
333 }
334
wait3(int * status,int options,struct rusage * rusage)335 pid_t wait3(int *status, int options, struct rusage *rusage)
336 {
337 printf("Unimplemented: %s(%p, %d, %p)\n", __func__,
338 status, options, rusage);
339
340 errno = EPERM;
341 return -1;
342 }
343
344
345
346 #include <sys/types.h>
347
getrlimit(__rlimit_resource_t resource,struct rlimit * rlim)348 int getrlimit(__rlimit_resource_t resource, struct rlimit *rlim)
349 {
350 printf("Unimplemented: %s(%d, %p)\n", __func__, resource, rlim);
351 errno = EINVAL;
352 return -1;
353 }
354
getrlimit64(__rlimit_resource_t resource,struct rlimit64 * rlim)355 int getrlimit64(__rlimit_resource_t resource, struct rlimit64 *rlim)
356 {
357 printf("Unimplemented: %s(%d, %p)\n", __func__, resource, rlim);
358 errno = EINVAL;
359 return -1;
360 }
361
setrlimit(__rlimit_resource_t resource,const struct rlimit * rlim)362 int setrlimit(__rlimit_resource_t resource, const struct rlimit *rlim)
363 {
364 printf("Unimplemented: %s(%d, %p)\n", __func__,
365 resource, rlim);
366 errno = EINVAL;
367 return -1;
368 }
369
370 #ifdef __USE_LARGEFILE64
setrlimit64(__rlimit_resource_t resource,const struct rlimit64 * rlim)371 int setrlimit64(__rlimit_resource_t resource, const struct rlimit64 *rlim)
372 {
373 printf("Unimplemented: %s(%d, %p)\n", __func__,
374 resource, rlim);
375 errno = EINVAL;
376 return -1;
377 }
378 #else
379 #warning No large-file support enabled?
380 #endif
381
getpass(const char * prompt)382 char *getpass( const char *prompt)
383 {
384 printf("This would be the prompt: '%s', delivering something static\n",
385 prompt);
386 return "THE FAMOUS PASSWORD";
387 }
388
system(const char * path)389 int system(const char *path)
390 {
391 (void)path;
392 errno = EINVAL;
393 return -1;
394 }
395
396 #include <string.h>
397
uname(struct utsname * u)398 int uname(struct utsname *u)
399 {
400 strncpy(u->sysname, "Fiasco.OC/L4Re", sizeof(u->sysname));
401 u->sysname[sizeof(u->sysname) - 1] = 0;
402
403 strncpy(u->nodename, "localhost", sizeof(u->nodename));
404 u->nodename[sizeof(u->nodename) - 1] = 0;
405
406 strncpy(u->release, "L4Re", sizeof(u->release));
407 u->release[sizeof(u->release) - 1] = 0;
408
409 strncpy(u->version, "0.x", sizeof(u->version));
410 u->version[sizeof(u->version) - 1] = 0;
411
412 #ifdef ARCH_arm
413 strncpy(u->machine, "arm", sizeof(u->machine));
414 #elif defined(ARCH_arm64)
415 strncpy(u->machine, "aarch64", sizeof(u->machine));
416 #elif defined(ARCH_x86)
417 strncpy(u->machine, "i686", sizeof(u->machine));
418 #elif defined(ARCH_amd64)
419 strncpy(u->machine, "x86_64", sizeof(u->machine));
420 #elif defined(ARCH_ppc32)
421 strncpy(u->machine, "ppc32", sizeof(u->machine));
422 #elif defined(ARCH_sparc)
423 strncpy(u->machine, "sparcv8", sizeof(u->machine));
424 #elif defined(ARCH_mips)
425 strncpy(u->machine, "mips", sizeof(u->machine));
426 #else
427 #error Add your arch.
428 #endif
429 u->machine[sizeof(u->machine) - 1] = 0;
430
431 return 0;
432 }
433
434 #include <sys/shm.h>
435
shmget(key_t key,size_t size,int shmflg)436 int shmget(key_t key, size_t size, int shmflg)
437 {
438 printf("%s(%d, %zd, %d)\n", __func__, key, size, shmflg);
439 errno = ENOSYS;
440 return -1;
441 }
442
shmat(int shmid,const void * shmaddr,int shmflg)443 void *shmat(int shmid, const void *shmaddr, int shmflg)
444 {
445 printf("%s(%d, %p, %d)\n", __func__, shmid, shmaddr, shmflg);
446 errno = ENOSYS;
447 return (void *)-1;
448 }
449
shmctl(int shmid,int cmd,struct shmid_ds * buf)450 int shmctl(int shmid, int cmd, struct shmid_ds *buf)
451 {
452 printf("%s(%d, %d, %p)\n", __func__, shmid, cmd, buf);
453 errno = ENOSYS;
454 return -1;
455 }
456
shmdt(const void * shmaddr)457 int shmdt(const void *shmaddr)
458 {
459 printf("%s(%p)\n", __func__, shmaddr);
460 errno = ENOSYS;
461 return -1;
462 }
463
getrusage(int who,struct rusage * usage)464 int getrusage(int who, struct rusage* usage)
465 {
466 (void)who; (void)usage;
467 errno = EINVAL;
468 return -1;
469 }
470
471
472 int prctl(int option, unsigned long arg2, unsigned long arg3,
473 unsigned long arg4, unsigned long arg5);
prctl(int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5)474 int prctl(int option, unsigned long arg2, unsigned long arg3,
475 unsigned long arg4, unsigned long arg5)
476 {
477 printf("prctl(%d, %lx, %lx, %lx, %lx): void\n",
478 option, arg2, arg3, arg4, arg5);
479 return 0;
480 }
481
482 char *secure_getenv(const char *name);
secure_getenv(const char * name)483 char *secure_getenv(const char *name)
484 {
485 return getenv(name);
486 }
487
488 #include <fcntl.h>
489
posix_fadvise64(int fd,off64_t offset,off64_t len,int advice)490 int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice)
491 {
492 printf("posix_fadvise64(%d, %lld, %lld, %d): void\n",
493 fd, (unsigned long long)offset, (unsigned long long)len, advice);
494 return 0;
495 }
496