xref: /openbmc/qemu/bsd-user/freebsd/os-syscall.c (revision 36999e6a6bb1e3c7d7d40c751b67d5886f023ee9)
1 /*
2  *  BSD syscalls
3  *
4  *  Copyright (c) 2003-2008 Fabrice Bellard
5  *  Copyright (c) 2013-2014 Stacey D. Son
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "qemu/osdep.h"
21 #include "qemu/cutils.h"
22 #include "qemu/path.h"
23 #include <sys/syscall.h>
24 #include <sys/cdefs.h>
25 #include <sys/param.h>
26 #include <sys/mount.h>
27 #include <sys/sysctl.h>
28 #include <utime.h>
29 
30 #include "include/gdbstub/syscalls.h"
31 
32 #include "qemu.h"
33 #include "signal-common.h"
34 #include "user/syscall-trace.h"
35 
36 #include "bsd-file.h"
37 #include "bsd-proc.h"
38 
39 /* BSD dependent syscall shims */
40 #include "os-stat.h"
41 #include "os-proc.h"
42 
43 /* I/O */
44 safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
45 safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t,
46     mode);
47 
48 safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes);
49 safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t,
50     offset);
51 safe_syscall3(ssize_t, readv, int, fd, const struct iovec *, iov, int, iovcnt);
52 safe_syscall4(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
53     off_t, offset);
54 
55 safe_syscall3(ssize_t, write, int, fd, void *, buf, size_t, nbytes);
56 safe_syscall4(ssize_t, pwrite, int, fd, void *, buf, size_t, nbytes, off_t,
57     offset);
58 safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt);
59 safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt,
60     off_t, offset);
61 
62 void target_set_brk(abi_ulong new_brk)
63 {
64 }
65 
66 /*
67  * errno conversion.
68  */
69 abi_long get_errno(abi_long ret)
70 {
71     if (ret == -1) {
72         return -host_to_target_errno(errno);
73     } else {
74         return ret;
75     }
76 }
77 
78 int host_to_target_errno(int err)
79 {
80     /*
81      * All the BSDs have the property that the error numbers are uniform across
82      * all architectures for a given BSD, though they may vary between different
83      * BSDs.
84      */
85     return err;
86 }
87 
88 bool is_error(abi_long ret)
89 {
90     return (abi_ulong)ret >= (abi_ulong)(-4096);
91 }
92 
93 /*
94  * Unlocks a iovec. Unlike unlock_iovec, it assumes the tvec array itself is
95  * already locked from target_addr. It will be unlocked as well as all the iovec
96  * elements.
97  */
98 static void helper_unlock_iovec(struct target_iovec *target_vec,
99                                 abi_ulong target_addr, struct iovec *vec,
100                                 int count, int copy)
101 {
102     for (int i = 0; i < count; i++) {
103         abi_ulong base = tswapal(target_vec[i].iov_base);
104 
105         if (vec[i].iov_base) {
106             unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
107         }
108     }
109     unlock_user(target_vec, target_addr, 0);
110 }
111 
112 struct iovec *lock_iovec(int type, abi_ulong target_addr,
113         int count, int copy)
114 {
115     struct target_iovec *target_vec;
116     struct iovec *vec;
117     abi_ulong total_len, max_len;
118     int i;
119     int err = 0;
120 
121     if (count == 0) {
122         errno = 0;
123         return NULL;
124     }
125     if (count < 0 || count > IOV_MAX) {
126         errno = EINVAL;
127         return NULL;
128     }
129 
130     vec = g_try_new0(struct iovec, count);
131     if (vec == NULL) {
132         errno = ENOMEM;
133         return NULL;
134     }
135 
136     target_vec = lock_user(VERIFY_READ, target_addr,
137                            count * sizeof(struct target_iovec), 1);
138     if (target_vec == NULL) {
139         err = EFAULT;
140         goto fail2;
141     }
142 
143     max_len = 0x7fffffff & MIN(TARGET_PAGE_MASK, PAGE_MASK);
144     total_len = 0;
145 
146     for (i = 0; i < count; i++) {
147         abi_ulong base = tswapal(target_vec[i].iov_base);
148         abi_long len = tswapal(target_vec[i].iov_len);
149 
150         if (len < 0) {
151             err = EINVAL;
152             goto fail;
153         } else if (len == 0) {
154             /* Zero length pointer is ignored. */
155             vec[i].iov_base = 0;
156         } else {
157             vec[i].iov_base = lock_user(type, base, len, copy);
158             /*
159              * If the first buffer pointer is bad, this is a fault.  But
160              * subsequent bad buffers will result in a partial write; this is
161              * realized by filling the vector with null pointers and zero
162              * lengths.
163              */
164             if (!vec[i].iov_base) {
165                 if (i == 0) {
166                     err = EFAULT;
167                     goto fail;
168                 } else {
169                     /*
170                      * Fail all the subsequent addresses, they are already
171                      * zero'd.
172                      */
173                     goto out;
174                 }
175             }
176             if (len > max_len - total_len) {
177                 len = max_len - total_len;
178             }
179         }
180         vec[i].iov_len = len;
181         total_len += len;
182     }
183 out:
184     unlock_user(target_vec, target_addr, 0);
185     return vec;
186 
187 fail:
188     helper_unlock_iovec(target_vec, target_addr, vec, i, copy);
189 fail2:
190     g_free(vec);
191     errno = err;
192     return NULL;
193 }
194 
195 void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
196         int count, int copy)
197 {
198     struct target_iovec *target_vec;
199 
200     target_vec = lock_user(VERIFY_READ, target_addr,
201                            count * sizeof(struct target_iovec), 1);
202     if (target_vec) {
203         helper_unlock_iovec(target_vec, target_addr, vec, count, copy);
204     }
205 
206     g_free(vec);
207 }
208 
209 /*
210  * All errnos that freebsd_syscall() returns must be -TARGET_<errcode>.
211  */
212 static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
213                                 abi_long arg2, abi_long arg3, abi_long arg4,
214                                 abi_long arg5, abi_long arg6, abi_long arg7,
215                                 abi_long arg8)
216 {
217     abi_long ret;
218 
219     switch (num) {
220         /*
221          * process system calls
222          */
223     case TARGET_FREEBSD_NR_execve: /* execve(2) */
224         ret = do_freebsd_execve(arg1, arg2, arg3);
225         break;
226 
227     case TARGET_FREEBSD_NR_fexecve: /* fexecve(2) */
228         ret = do_freebsd_fexecve(arg1, arg2, arg3);
229         break;
230 
231     case TARGET_FREEBSD_NR_exit: /* exit(2) */
232         ret = do_bsd_exit(cpu_env, arg1);
233         break;
234 
235     case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */
236         ret = do_bsd_getgroups(arg1, arg2);
237         break;
238 
239     case TARGET_FREEBSD_NR_setgroups: /* setgroups(2) */
240         ret = do_bsd_setgroups(arg1, arg2);
241         break;
242 
243     case TARGET_FREEBSD_NR_umask: /* umask(2) */
244         ret = do_bsd_umask(arg1);
245         break;
246 
247     case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */
248         ret = do_bsd_setlogin(arg1);
249         break;
250 
251     case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */
252         ret = do_bsd_getlogin(arg1, arg2);
253         break;
254 
255     case TARGET_FREEBSD_NR_getrusage: /* getrusage(2) */
256         ret = do_bsd_getrusage(arg1, arg2);
257         break;
258 
259     case TARGET_FREEBSD_NR_getrlimit: /* getrlimit(2) */
260         ret = do_bsd_getrlimit(arg1, arg2);
261         break;
262 
263     case TARGET_FREEBSD_NR_setrlimit: /* setrlimit(2) */
264         ret = do_bsd_setrlimit(arg1, arg2);
265         break;
266 
267     case TARGET_FREEBSD_NR_getpid: /* getpid(2) */
268         ret = do_bsd_getpid();
269         break;
270 
271     case TARGET_FREEBSD_NR_getppid: /* getppid(2) */
272         ret = do_bsd_getppid();
273         break;
274 
275     case TARGET_FREEBSD_NR_getuid: /* getuid(2) */
276         ret = do_bsd_getuid();
277         break;
278 
279     case TARGET_FREEBSD_NR_geteuid: /* geteuid(2) */
280         ret = do_bsd_geteuid();
281         break;
282 
283     case TARGET_FREEBSD_NR_getgid: /* getgid(2) */
284         ret = do_bsd_getgid();
285         break;
286 
287     case TARGET_FREEBSD_NR_getegid: /* getegid(2) */
288         ret = do_bsd_getegid();
289         break;
290 
291     case TARGET_FREEBSD_NR_setuid: /* setuid(2) */
292         ret = do_bsd_setuid(arg1);
293         break;
294 
295     case TARGET_FREEBSD_NR_seteuid: /* seteuid(2) */
296         ret = do_bsd_seteuid(arg1);
297         break;
298 
299     case TARGET_FREEBSD_NR_setgid: /* setgid(2) */
300         ret = do_bsd_setgid(arg1);
301         break;
302 
303     case TARGET_FREEBSD_NR_setegid: /* setegid(2) */
304         ret = do_bsd_setegid(arg1);
305         break;
306 
307     case TARGET_FREEBSD_NR_getpgrp: /* getpgrp(2) */
308         ret = do_bsd_getpgrp();
309         break;
310 
311     case TARGET_FREEBSD_NR_getpgid: /* getpgid(2) */
312          ret = do_bsd_getpgid(arg1);
313          break;
314 
315     case TARGET_FREEBSD_NR_setpgid: /* setpgid(2) */
316          ret = do_bsd_setpgid(arg1, arg2);
317          break;
318 
319     case TARGET_FREEBSD_NR_setreuid: /* setreuid(2) */
320         ret = do_bsd_setreuid(arg1, arg2);
321         break;
322 
323     case TARGET_FREEBSD_NR_setregid: /* setregid(2) */
324         ret = do_bsd_setregid(arg1, arg2);
325         break;
326 
327     case TARGET_FREEBSD_NR_getresuid: /* getresuid(2) */
328         ret = do_bsd_getresuid(arg1, arg2, arg3);
329         break;
330 
331     case TARGET_FREEBSD_NR_getresgid: /* getresgid(2) */
332         ret = do_bsd_getresgid(arg1, arg2, arg3);
333         break;
334 
335     case TARGET_FREEBSD_NR_setresuid: /* setresuid(2) */
336         ret = do_bsd_setresuid(arg1, arg2, arg3);
337         break;
338 
339     case TARGET_FREEBSD_NR_setresgid: /* setresgid(2) */
340         ret = do_bsd_setresgid(arg1, arg2, arg3);
341         break;
342 
343     case TARGET_FREEBSD_NR_getsid: /* getsid(2) */
344         ret = do_bsd_getsid(arg1);
345         break;
346 
347     case TARGET_FREEBSD_NR_setsid: /* setsid(2) */
348         ret = do_bsd_setsid();
349         break;
350 
351     case TARGET_FREEBSD_NR_issetugid: /* issetugid(2) */
352         ret = do_bsd_issetugid();
353         break;
354 
355     case TARGET_FREEBSD_NR_profil: /* profil(2) */
356         ret = do_bsd_profil(arg1, arg2, arg3, arg4);
357         break;
358 
359     case TARGET_FREEBSD_NR_ktrace: /* ktrace(2) */
360         ret = do_bsd_ktrace(arg1, arg2, arg3, arg4);
361         break;
362 
363     case TARGET_FREEBSD_NR_utrace: /* utrace(2) */
364         ret = do_bsd_utrace(arg1, arg2);
365         break;
366 
367     case TARGET_FREEBSD_NR_ptrace: /* ptrace(2) */
368         ret = do_bsd_ptrace(arg1, arg2, arg3, arg4);
369         break;
370 
371     case TARGET_FREEBSD_NR_getpriority: /* getpriority(2) */
372         ret = do_bsd_getpriority(arg1, arg2);
373         break;
374 
375     case TARGET_FREEBSD_NR_setpriority: /* setpriority(2) */
376         ret = do_bsd_setpriority(arg1, arg2, arg3);
377         break;
378 
379     case TARGET_FREEBSD_NR_procctl: /* procctl(2) */
380         ret = do_freebsd_procctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
381         break;
382 
383         /*
384          * File system calls.
385          */
386     case TARGET_FREEBSD_NR_read: /* read(2) */
387         ret = do_bsd_read(arg1, arg2, arg3);
388         break;
389 
390     case TARGET_FREEBSD_NR_pread: /* pread(2) */
391         ret = do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
392         break;
393 
394     case TARGET_FREEBSD_NR_readv: /* readv(2) */
395         ret = do_bsd_readv(arg1, arg2, arg3);
396         break;
397 
398     case TARGET_FREEBSD_NR_preadv: /* preadv(2) */
399         ret = do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
400         break;
401 
402     case TARGET_FREEBSD_NR_write: /* write(2) */
403         ret = do_bsd_write(arg1, arg2, arg3);
404         break;
405 
406     case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */
407         ret = do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
408         break;
409 
410     case TARGET_FREEBSD_NR_writev: /* writev(2) */
411         ret = do_bsd_writev(arg1, arg2, arg3);
412         break;
413 
414     case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */
415         ret = do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
416         break;
417 
418     case TARGET_FREEBSD_NR_open: /* open(2) */
419         ret = do_bsd_open(arg1, arg2, arg3);
420         break;
421 
422     case TARGET_FREEBSD_NR_openat: /* openat(2) */
423         ret = do_bsd_openat(arg1, arg2, arg3, arg4);
424         break;
425 
426     case TARGET_FREEBSD_NR_close: /* close(2) */
427         ret = do_bsd_close(arg1);
428         break;
429 
430     case TARGET_FREEBSD_NR_fdatasync: /* fdatasync(2) */
431         ret = do_bsd_fdatasync(arg1);
432         break;
433 
434     case TARGET_FREEBSD_NR_fsync: /* fsync(2) */
435         ret = do_bsd_fsync(arg1);
436         break;
437 
438     case TARGET_FREEBSD_NR_freebsd12_closefrom: /* closefrom(2) */
439         ret = do_bsd_closefrom(arg1);
440         break;
441 
442     case TARGET_FREEBSD_NR_revoke: /* revoke(2) */
443         ret = do_bsd_revoke(arg1);
444         break;
445 
446     case TARGET_FREEBSD_NR_access: /* access(2) */
447         ret = do_bsd_access(arg1, arg2);
448         break;
449 
450     case TARGET_FREEBSD_NR_eaccess: /* eaccess(2) */
451         ret = do_bsd_eaccess(arg1, arg2);
452         break;
453 
454     case TARGET_FREEBSD_NR_faccessat: /* faccessat(2) */
455         ret = do_bsd_faccessat(arg1, arg2, arg3, arg4);
456         break;
457 
458     case TARGET_FREEBSD_NR_chdir: /* chdir(2) */
459         ret = do_bsd_chdir(arg1);
460         break;
461 
462     case TARGET_FREEBSD_NR_fchdir: /* fchdir(2) */
463         ret = do_bsd_fchdir(arg1);
464         break;
465 
466     case TARGET_FREEBSD_NR_rename: /* rename(2) */
467         ret = do_bsd_rename(arg1, arg2);
468         break;
469 
470     case TARGET_FREEBSD_NR_renameat: /* renameat(2) */
471         ret = do_bsd_renameat(arg1, arg2, arg3, arg4);
472         break;
473 
474     case TARGET_FREEBSD_NR_link: /* link(2) */
475         ret = do_bsd_link(arg1, arg2);
476         break;
477 
478     case TARGET_FREEBSD_NR_linkat: /* linkat(2) */
479         ret = do_bsd_linkat(arg1, arg2, arg3, arg4, arg5);
480         break;
481 
482     case TARGET_FREEBSD_NR_unlink: /* unlink(2) */
483         ret = do_bsd_unlink(arg1);
484         break;
485 
486     case TARGET_FREEBSD_NR_unlinkat: /* unlinkat(2) */
487         ret = do_bsd_unlinkat(arg1, arg2, arg3);
488         break;
489 
490     case TARGET_FREEBSD_NR_mkdir: /* mkdir(2) */
491         ret = do_bsd_mkdir(arg1, arg2);
492         break;
493 
494     case TARGET_FREEBSD_NR_mkdirat: /* mkdirat(2) */
495         ret = do_bsd_mkdirat(arg1, arg2, arg3);
496         break;
497 
498     case TARGET_FREEBSD_NR_rmdir: /* rmdir(2) (XXX no rmdirat()?) */
499         ret = do_bsd_rmdir(arg1);
500         break;
501 
502     case TARGET_FREEBSD_NR___getcwd: /* undocumented __getcwd() */
503         ret = do_bsd___getcwd(arg1, arg2);
504         break;
505 
506     case TARGET_FREEBSD_NR_dup: /* dup(2) */
507         ret = do_bsd_dup(arg1);
508         break;
509 
510     case TARGET_FREEBSD_NR_dup2: /* dup2(2) */
511         ret = do_bsd_dup2(arg1, arg2);
512         break;
513 
514     case TARGET_FREEBSD_NR_truncate: /* truncate(2) */
515         ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4);
516         break;
517 
518     case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */
519         ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4);
520         break;
521 
522     case TARGET_FREEBSD_NR_acct: /* acct(2) */
523         ret = do_bsd_acct(arg1);
524         break;
525 
526     case TARGET_FREEBSD_NR_sync: /* sync(2) */
527         ret = do_bsd_sync();
528         break;
529 
530     case TARGET_FREEBSD_NR_mount: /* mount(2) */
531         ret = do_bsd_mount(arg1, arg2, arg3, arg4);
532         break;
533 
534     case TARGET_FREEBSD_NR_unmount: /* unmount(2) */
535         ret = do_bsd_unmount(arg1, arg2);
536         break;
537 
538     case TARGET_FREEBSD_NR_nmount: /* nmount(2) */
539         ret = do_bsd_nmount(arg1, arg2, arg3);
540         break;
541 
542     case TARGET_FREEBSD_NR_symlink: /* symlink(2) */
543         ret = do_bsd_symlink(arg1, arg2);
544         break;
545 
546     case TARGET_FREEBSD_NR_symlinkat: /* symlinkat(2) */
547         ret = do_bsd_symlinkat(arg1, arg2, arg3);
548         break;
549 
550     case TARGET_FREEBSD_NR_readlink: /* readlink(2) */
551         ret = do_bsd_readlink(cpu_env, arg1, arg2, arg3);
552         break;
553 
554     case TARGET_FREEBSD_NR_readlinkat: /* readlinkat(2) */
555         ret = do_bsd_readlinkat(arg1, arg2, arg3, arg4);
556         break;
557 
558     case TARGET_FREEBSD_NR_chmod: /* chmod(2) */
559         ret = do_bsd_chmod(arg1, arg2);
560         break;
561 
562     case TARGET_FREEBSD_NR_fchmod: /* fchmod(2) */
563         ret = do_bsd_fchmod(arg1, arg2);
564         break;
565 
566     case TARGET_FREEBSD_NR_lchmod: /* lchmod(2) */
567         ret = do_bsd_lchmod(arg1, arg2);
568         break;
569 
570     case TARGET_FREEBSD_NR_fchmodat: /* fchmodat(2) */
571         ret = do_bsd_fchmodat(arg1, arg2, arg3, arg4);
572         break;
573 
574     case TARGET_FREEBSD_NR_freebsd11_mknod: /* mknod(2) */
575         ret = do_bsd_freebsd11_mknod(arg1, arg2, arg3);
576         break;
577 
578     case TARGET_FREEBSD_NR_freebsd11_mknodat: /* mknodat(2) */
579         ret = do_bsd_freebsd11_mknodat(arg1, arg2, arg3, arg4);
580         break;
581 
582     case TARGET_FREEBSD_NR_mknodat: /* mknodat(2) */
583         ret = do_bsd_mknodat(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
584         break;
585 
586     case TARGET_FREEBSD_NR_chown: /* chown(2) */
587         ret = do_bsd_chown(arg1, arg2, arg3);
588         break;
589 
590     case TARGET_FREEBSD_NR_fchown: /* fchown(2) */
591         ret = do_bsd_fchown(arg1, arg2, arg3);
592         break;
593 
594     case TARGET_FREEBSD_NR_lchown: /* lchown(2) */
595         ret = do_bsd_lchown(arg1, arg2, arg3);
596         break;
597 
598     case TARGET_FREEBSD_NR_fchownat: /* fchownat(2) */
599         ret = do_bsd_fchownat(arg1, arg2, arg3, arg4, arg5);
600         break;
601 
602     case TARGET_FREEBSD_NR_chflags: /* chflags(2) */
603         ret = do_bsd_chflags(arg1, arg2);
604         break;
605 
606     case TARGET_FREEBSD_NR_lchflags: /* lchflags(2) */
607         ret = do_bsd_lchflags(arg1, arg2);
608         break;
609 
610     case TARGET_FREEBSD_NR_fchflags: /* fchflags(2) */
611         ret = do_bsd_fchflags(arg1, arg2);
612         break;
613 
614     case TARGET_FREEBSD_NR_chroot: /* chroot(2) */
615         ret = do_bsd_chroot(arg1);
616         break;
617 
618     case TARGET_FREEBSD_NR_flock: /* flock(2) */
619         ret = do_bsd_flock(arg1, arg2);
620         break;
621 
622     case TARGET_FREEBSD_NR_mkfifo: /* mkfifo(2) */
623         ret = do_bsd_mkfifo(arg1, arg2);
624         break;
625 
626     case TARGET_FREEBSD_NR_mkfifoat: /* mkfifoat(2) */
627         ret = do_bsd_mkfifoat(arg1, arg2, arg3);
628         break;
629 
630     case TARGET_FREEBSD_NR_pathconf: /* pathconf(2) */
631         ret = do_bsd_pathconf(arg1, arg2);
632         break;
633 
634     case TARGET_FREEBSD_NR_lpathconf: /* lpathconf(2) */
635         ret = do_bsd_lpathconf(arg1, arg2);
636         break;
637 
638     case TARGET_FREEBSD_NR_fpathconf: /* fpathconf(2) */
639         ret = do_bsd_fpathconf(arg1, arg2);
640         break;
641 
642     case TARGET_FREEBSD_NR_undelete: /* undelete(2) */
643         ret = do_bsd_undelete(arg1);
644         break;
645 
646         /*
647          * stat system calls
648          */
649     case TARGET_FREEBSD_NR_freebsd11_stat: /* stat(2) */
650         ret = do_freebsd11_stat(arg1, arg2);
651         break;
652 
653     case TARGET_FREEBSD_NR_freebsd11_lstat: /* lstat(2) */
654         ret = do_freebsd11_lstat(arg1, arg2);
655         break;
656 
657     case TARGET_FREEBSD_NR_freebsd11_fstat: /* fstat(2) */
658         ret = do_freebsd11_fstat(arg1, arg2);
659         break;
660 
661     case TARGET_FREEBSD_NR_fstat: /* fstat(2) */
662         ret = do_freebsd_fstat(arg1, arg2);
663         break;
664 
665     case TARGET_FREEBSD_NR_freebsd11_fstatat: /* fstatat(2) */
666         ret = do_freebsd11_fstatat(arg1, arg2, arg3, arg4);
667         break;
668 
669     case TARGET_FREEBSD_NR_fstatat: /* fstatat(2) */
670         ret = do_freebsd_fstatat(arg1, arg2, arg3, arg4);
671         break;
672 
673     case TARGET_FREEBSD_NR_freebsd11_nstat: /* undocumented */
674         ret = do_freebsd11_nstat(arg1, arg2);
675         break;
676 
677     case TARGET_FREEBSD_NR_freebsd11_nfstat: /* undocumented */
678         ret = do_freebsd11_nfstat(arg1, arg2);
679         break;
680 
681     case TARGET_FREEBSD_NR_freebsd11_nlstat: /* undocumented */
682         ret = do_freebsd11_nlstat(arg1, arg2);
683         break;
684 
685     case TARGET_FREEBSD_NR_getfh: /* getfh(2) */
686         ret = do_freebsd_getfh(arg1, arg2);
687         break;
688 
689     case TARGET_FREEBSD_NR_lgetfh: /* lgetfh(2) */
690         ret = do_freebsd_lgetfh(arg1, arg2);
691         break;
692 
693     case TARGET_FREEBSD_NR_fhopen: /* fhopen(2) */
694         ret = do_freebsd_fhopen(arg1, arg2);
695         break;
696 
697     case TARGET_FREEBSD_NR_freebsd11_fhstat: /* fhstat(2) */
698         ret = do_freebsd11_fhstat(arg1, arg2);
699         break;
700 
701     case TARGET_FREEBSD_NR_fhstat: /* fhstat(2) */
702         ret = do_freebsd_fhstat(arg1, arg2);
703         break;
704 
705     case TARGET_FREEBSD_NR_freebsd11_fhstatfs: /* fhstatfs(2) */
706         ret = do_freebsd11_fhstatfs(arg1, arg2);
707         break;
708 
709     case TARGET_FREEBSD_NR_fhstatfs: /* fhstatfs(2) */
710         ret = do_freebsd_fhstatfs(arg1, arg2);
711         break;
712 
713     case TARGET_FREEBSD_NR_freebsd11_statfs: /* statfs(2) */
714         ret = do_freebsd11_statfs(arg1, arg2);
715         break;
716 
717     case TARGET_FREEBSD_NR_statfs: /* statfs(2) */
718         ret = do_freebsd_statfs(arg1, arg2);
719         break;
720 
721     case TARGET_FREEBSD_NR_freebsd11_fstatfs: /* fstatfs(2) */
722         ret = do_freebsd11_fstatfs(arg1, arg2);
723         break;
724 
725     case TARGET_FREEBSD_NR_fstatfs: /* fstatfs(2) */
726         ret = do_freebsd_fstatfs(arg1, arg2);
727         break;
728 
729     case TARGET_FREEBSD_NR_freebsd11_getfsstat: /* getfsstat(2) */
730         ret = do_freebsd11_getfsstat(arg1, arg2, arg3);
731         break;
732 
733     case TARGET_FREEBSD_NR_getfsstat: /* getfsstat(2) */
734         ret = do_freebsd_getfsstat(arg1, arg2, arg3);
735         break;
736 
737     case TARGET_FREEBSD_NR_freebsd11_getdents: /* getdents(2) */
738         ret = do_freebsd11_getdents(arg1, arg2, arg3);
739         break;
740 
741     case TARGET_FREEBSD_NR_getdirentries: /* getdirentries(2) */
742         ret = do_freebsd_getdirentries(arg1, arg2, arg3, arg4);
743         break;
744 
745     case TARGET_FREEBSD_NR_freebsd11_getdirentries: /* getdirentries(2) */
746         ret = do_freebsd11_getdirentries(arg1, arg2, arg3, arg4);
747         break;
748     case TARGET_FREEBSD_NR_fcntl: /* fcntl(2) */
749         ret = do_freebsd_fcntl(arg1, arg2, arg3);
750         break;
751 
752 
753         /*
754          * sys{ctl, arch, call}
755          */
756     case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */
757         ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
758         break;
759 
760     case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */
761         ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
762         break;
763 
764     case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */
765         ret = do_freebsd_sysarch(cpu_env, arg1, arg2);
766         break;
767 
768     default:
769         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
770         ret = -TARGET_ENOSYS;
771         break;
772     }
773 
774     return ret;
775 }
776 
777 /*
778  * do_freebsd_syscall() should always have a single exit point at the end so
779  * that actions, such as logging of syscall results, can be performed. This
780  * as a wrapper around freebsd_syscall() so that actually happens. Since
781  * that is a singleton, modern compilers will inline it anyway...
782  */
783 abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
784                             abi_long arg2, abi_long arg3, abi_long arg4,
785                             abi_long arg5, abi_long arg6, abi_long arg7,
786                             abi_long arg8)
787 {
788     abi_long ret;
789 
790     if (do_strace) {
791         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
792     }
793 
794     ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6,
795                           arg7, arg8);
796     if (do_strace) {
797         print_freebsd_syscall_ret(num, ret);
798     }
799 
800     return ret;
801 }
802 
803 void syscall_init(void)
804 {
805 }
806