xref: /openbmc/qemu/bsd-user/freebsd/os-syscall.c (revision 6fe97c6c)
166eed099SWarner Losh /*
266eed099SWarner Losh  *  BSD syscalls
366eed099SWarner Losh  *
466eed099SWarner Losh  *  Copyright (c) 2003-2008 Fabrice Bellard
566eed099SWarner Losh  *  Copyright (c) 2013-2014 Stacey D. Son
666eed099SWarner Losh  *
766eed099SWarner Losh  *  This program is free software; you can redistribute it and/or modify
866eed099SWarner Losh  *  it under the terms of the GNU General Public License as published by
966eed099SWarner Losh  *  the Free Software Foundation; either version 2 of the License, or
1066eed099SWarner Losh  *  (at your option) any later version.
1166eed099SWarner Losh  *
1266eed099SWarner Losh  *  This program is distributed in the hope that it will be useful,
1366eed099SWarner Losh  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1466eed099SWarner Losh  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1566eed099SWarner Losh  *  GNU General Public License for more details.
1666eed099SWarner Losh  *
1766eed099SWarner Losh  *  You should have received a copy of the GNU General Public License
1866eed099SWarner Losh  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
1966eed099SWarner Losh  */
2066eed099SWarner Losh #include "qemu/osdep.h"
2166eed099SWarner Losh #include "qemu/cutils.h"
2266eed099SWarner Losh #include "qemu/path.h"
2366eed099SWarner Losh #include <sys/syscall.h>
2479cfae0cSWarner Losh #include <sys/cdefs.h>
2566eed099SWarner Losh #include <sys/param.h>
26af2ae2e8SWarner Losh #include <sys/mount.h>
2766eed099SWarner Losh #include <sys/sysctl.h>
2866eed099SWarner Losh #include <utime.h>
2966eed099SWarner Losh 
30c566080cSAlex Bennée #include "include/gdbstub/syscalls.h"
31c566080cSAlex Bennée 
3266eed099SWarner Losh #include "qemu.h"
3366eed099SWarner Losh #include "signal-common.h"
3466eed099SWarner Losh #include "user/syscall-trace.h"
3566eed099SWarner Losh 
36c5c84d16SWarner Losh #include "bsd-file.h"
379554d330SWarner Losh #include "bsd-proc.h"
38c5c84d16SWarner Losh 
39e800e6c5SWarner Losh /* *BSD dependent syscall shims */
40e800e6c5SWarner Losh #include "os-stat.h"
41e800e6c5SWarner Losh 
4280da1b00SWarner Losh /* I/O */
4377d3522bSWarner Losh safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
4477d3522bSWarner Losh safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t,
4577d3522bSWarner Losh     mode);
4677d3522bSWarner Losh 
4780da1b00SWarner Losh safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes);
4880da1b00SWarner Losh safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t,
4980da1b00SWarner Losh     offset);
5080da1b00SWarner Losh safe_syscall3(ssize_t, readv, int, fd, const struct iovec *, iov, int, iovcnt);
5180da1b00SWarner Losh safe_syscall4(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
5280da1b00SWarner Losh     off_t, offset);
5380da1b00SWarner Losh 
54770d8abaSWarner Losh safe_syscall3(ssize_t, write, int, fd, void *, buf, size_t, nbytes);
55770d8abaSWarner Losh safe_syscall4(ssize_t, pwrite, int, fd, void *, buf, size_t, nbytes, off_t,
56770d8abaSWarner Losh     offset);
57770d8abaSWarner Losh safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt);
58770d8abaSWarner Losh safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt,
59770d8abaSWarner Losh     off_t, offset);
60770d8abaSWarner Losh 
6166eed099SWarner Losh void target_set_brk(abi_ulong new_brk)
6266eed099SWarner Losh {
6366eed099SWarner Losh }
6466eed099SWarner Losh 
65deeff83bSWarner Losh /*
66deeff83bSWarner Losh  * errno conversion.
67deeff83bSWarner Losh  */
68deeff83bSWarner Losh abi_long get_errno(abi_long ret)
69deeff83bSWarner Losh {
70deeff83bSWarner Losh     if (ret == -1) {
71deeff83bSWarner Losh         return -host_to_target_errno(errno);
72deeff83bSWarner Losh     } else {
73deeff83bSWarner Losh         return ret;
74deeff83bSWarner Losh     }
75deeff83bSWarner Losh }
76deeff83bSWarner Losh 
77deeff83bSWarner Losh int host_to_target_errno(int err)
78deeff83bSWarner Losh {
79deeff83bSWarner Losh     /*
80deeff83bSWarner Losh      * All the BSDs have the property that the error numbers are uniform across
81deeff83bSWarner Losh      * all architectures for a given BSD, though they may vary between different
82deeff83bSWarner Losh      * BSDs.
83deeff83bSWarner Losh      */
84deeff83bSWarner Losh     return err;
85deeff83bSWarner Losh }
86deeff83bSWarner Losh 
8766eed099SWarner Losh bool is_error(abi_long ret)
8866eed099SWarner Losh {
8966eed099SWarner Losh     return (abi_ulong)ret >= (abi_ulong)(-4096);
9066eed099SWarner Losh }
9166eed099SWarner Losh 
9266eed099SWarner Losh /*
931ed771b2SWarner Losh  * Unlocks a iovec. Unlike unlock_iovec, it assumes the tvec array itself is
941ed771b2SWarner Losh  * already locked from target_addr. It will be unlocked as well as all the iovec
951ed771b2SWarner Losh  * elements.
961ed771b2SWarner Losh  */
971ed771b2SWarner Losh static void helper_unlock_iovec(struct target_iovec *target_vec,
981ed771b2SWarner Losh                                 abi_ulong target_addr, struct iovec *vec,
991ed771b2SWarner Losh                                 int count, int copy)
1001ed771b2SWarner Losh {
1011ed771b2SWarner Losh     for (int i = 0; i < count; i++) {
1021ed771b2SWarner Losh         abi_ulong base = tswapal(target_vec[i].iov_base);
1031ed771b2SWarner Losh 
1041ed771b2SWarner Losh         if (vec[i].iov_base) {
1051ed771b2SWarner Losh             unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
1061ed771b2SWarner Losh         }
1071ed771b2SWarner Losh     }
1081ed771b2SWarner Losh     unlock_user(target_vec, target_addr, 0);
1091ed771b2SWarner Losh }
1101ed771b2SWarner Losh 
1111ed771b2SWarner Losh struct iovec *lock_iovec(int type, abi_ulong target_addr,
1121ed771b2SWarner Losh         int count, int copy)
1131ed771b2SWarner Losh {
1141ed771b2SWarner Losh     struct target_iovec *target_vec;
1151ed771b2SWarner Losh     struct iovec *vec;
1161ed771b2SWarner Losh     abi_ulong total_len, max_len;
1171ed771b2SWarner Losh     int i;
1181ed771b2SWarner Losh     int err = 0;
1191ed771b2SWarner Losh 
1201ed771b2SWarner Losh     if (count == 0) {
1211ed771b2SWarner Losh         errno = 0;
1221ed771b2SWarner Losh         return NULL;
1231ed771b2SWarner Losh     }
1241ed771b2SWarner Losh     if (count < 0 || count > IOV_MAX) {
1251ed771b2SWarner Losh         errno = EINVAL;
1261ed771b2SWarner Losh         return NULL;
1271ed771b2SWarner Losh     }
1281ed771b2SWarner Losh 
1291ed771b2SWarner Losh     vec = g_try_new0(struct iovec, count);
1301ed771b2SWarner Losh     if (vec == NULL) {
1311ed771b2SWarner Losh         errno = ENOMEM;
1321ed771b2SWarner Losh         return NULL;
1331ed771b2SWarner Losh     }
1341ed771b2SWarner Losh 
1351ed771b2SWarner Losh     target_vec = lock_user(VERIFY_READ, target_addr,
1361ed771b2SWarner Losh                            count * sizeof(struct target_iovec), 1);
1371ed771b2SWarner Losh     if (target_vec == NULL) {
1381ed771b2SWarner Losh         err = EFAULT;
1391ed771b2SWarner Losh         goto fail2;
1401ed771b2SWarner Losh     }
1411ed771b2SWarner Losh 
1421ed771b2SWarner Losh     max_len = 0x7fffffff & MIN(TARGET_PAGE_MASK, PAGE_MASK);
1431ed771b2SWarner Losh     total_len = 0;
1441ed771b2SWarner Losh 
1451ed771b2SWarner Losh     for (i = 0; i < count; i++) {
1461ed771b2SWarner Losh         abi_ulong base = tswapal(target_vec[i].iov_base);
1471ed771b2SWarner Losh         abi_long len = tswapal(target_vec[i].iov_len);
1481ed771b2SWarner Losh 
1491ed771b2SWarner Losh         if (len < 0) {
1501ed771b2SWarner Losh             err = EINVAL;
1511ed771b2SWarner Losh             goto fail;
1521ed771b2SWarner Losh         } else if (len == 0) {
1531ed771b2SWarner Losh             /* Zero length pointer is ignored. */
1541ed771b2SWarner Losh             vec[i].iov_base = 0;
1551ed771b2SWarner Losh         } else {
1561ed771b2SWarner Losh             vec[i].iov_base = lock_user(type, base, len, copy);
1571ed771b2SWarner Losh             /*
1581ed771b2SWarner Losh              * If the first buffer pointer is bad, this is a fault.  But
1591ed771b2SWarner Losh              * subsequent bad buffers will result in a partial write; this is
1601ed771b2SWarner Losh              * realized by filling the vector with null pointers and zero
1611ed771b2SWarner Losh              * lengths.
1621ed771b2SWarner Losh              */
1631ed771b2SWarner Losh             if (!vec[i].iov_base) {
1641ed771b2SWarner Losh                 if (i == 0) {
1651ed771b2SWarner Losh                     err = EFAULT;
1661ed771b2SWarner Losh                     goto fail;
1671ed771b2SWarner Losh                 } else {
1681ed771b2SWarner Losh                     /*
1691ed771b2SWarner Losh                      * Fail all the subsequent addresses, they are already
1701ed771b2SWarner Losh                      * zero'd.
1711ed771b2SWarner Losh                      */
1721ed771b2SWarner Losh                     goto out;
1731ed771b2SWarner Losh                 }
1741ed771b2SWarner Losh             }
1751ed771b2SWarner Losh             if (len > max_len - total_len) {
1761ed771b2SWarner Losh                 len = max_len - total_len;
1771ed771b2SWarner Losh             }
1781ed771b2SWarner Losh         }
1791ed771b2SWarner Losh         vec[i].iov_len = len;
1801ed771b2SWarner Losh         total_len += len;
1811ed771b2SWarner Losh     }
1821ed771b2SWarner Losh out:
1831ed771b2SWarner Losh     unlock_user(target_vec, target_addr, 0);
1841ed771b2SWarner Losh     return vec;
1851ed771b2SWarner Losh 
1861ed771b2SWarner Losh fail:
1871ed771b2SWarner Losh     helper_unlock_iovec(target_vec, target_addr, vec, i, copy);
1881ed771b2SWarner Losh fail2:
1891ed771b2SWarner Losh     g_free(vec);
1901ed771b2SWarner Losh     errno = err;
1911ed771b2SWarner Losh     return NULL;
1921ed771b2SWarner Losh }
1931ed771b2SWarner Losh 
194883808d8SWarner Losh void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
195883808d8SWarner Losh         int count, int copy)
196883808d8SWarner Losh {
197883808d8SWarner Losh     struct target_iovec *target_vec;
198883808d8SWarner Losh 
199883808d8SWarner Losh     target_vec = lock_user(VERIFY_READ, target_addr,
200883808d8SWarner Losh                            count * sizeof(struct target_iovec), 1);
201883808d8SWarner Losh     if (target_vec) {
202883808d8SWarner Losh         helper_unlock_iovec(target_vec, target_addr, vec, count, copy);
203883808d8SWarner Losh     }
204883808d8SWarner Losh 
205883808d8SWarner Losh     g_free(vec);
206883808d8SWarner Losh }
207883808d8SWarner Losh 
2081ed771b2SWarner Losh /*
209db697887SWarner Losh  * All errnos that freebsd_syscall() returns must be -TARGET_<errcode>.
210db697887SWarner Losh  */
211db697887SWarner Losh static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
212db697887SWarner Losh                                 abi_long arg2, abi_long arg3, abi_long arg4,
213db697887SWarner Losh                                 abi_long arg5, abi_long arg6, abi_long arg7,
214db697887SWarner Losh                                 abi_long arg8)
215db697887SWarner Losh {
216db697887SWarner Losh     abi_long ret;
217db697887SWarner Losh 
218db697887SWarner Losh     switch (num) {
2199554d330SWarner Losh         /*
2209554d330SWarner Losh          * process system calls
2219554d330SWarner Losh          */
2229554d330SWarner Losh     case TARGET_FREEBSD_NR_exit: /* exit(2) */
2239554d330SWarner Losh         ret = do_bsd_exit(cpu_env, arg1);
2249554d330SWarner Losh         break;
22580da1b00SWarner Losh 
22680da1b00SWarner Losh         /*
22780da1b00SWarner Losh          * File system calls.
22880da1b00SWarner Losh          */
22980da1b00SWarner Losh     case TARGET_FREEBSD_NR_read: /* read(2) */
23080da1b00SWarner Losh         ret = do_bsd_read(arg1, arg2, arg3);
23180da1b00SWarner Losh         break;
23280da1b00SWarner Losh 
23380da1b00SWarner Losh     case TARGET_FREEBSD_NR_pread: /* pread(2) */
23480da1b00SWarner Losh         ret = do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
23580da1b00SWarner Losh         break;
23680da1b00SWarner Losh 
23780da1b00SWarner Losh     case TARGET_FREEBSD_NR_readv: /* readv(2) */
23880da1b00SWarner Losh         ret = do_bsd_readv(arg1, arg2, arg3);
23980da1b00SWarner Losh         break;
24080da1b00SWarner Losh 
24180da1b00SWarner Losh     case TARGET_FREEBSD_NR_preadv: /* preadv(2) */
24280da1b00SWarner Losh         ret = do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
243770d8abaSWarner Losh 
244770d8abaSWarner Losh     case TARGET_FREEBSD_NR_write: /* write(2) */
245770d8abaSWarner Losh         ret = do_bsd_write(arg1, arg2, arg3);
246770d8abaSWarner Losh         break;
247770d8abaSWarner Losh 
248770d8abaSWarner Losh     case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */
249770d8abaSWarner Losh         ret = do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
250770d8abaSWarner Losh         break;
251770d8abaSWarner Losh 
252770d8abaSWarner Losh     case TARGET_FREEBSD_NR_writev: /* writev(2) */
253770d8abaSWarner Losh         ret = do_bsd_writev(arg1, arg2, arg3);
254770d8abaSWarner Losh         break;
255770d8abaSWarner Losh 
256770d8abaSWarner Losh     case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */
257770d8abaSWarner Losh         ret = do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
25880da1b00SWarner Losh         break;
25980da1b00SWarner Losh 
26077d3522bSWarner Losh     case TARGET_FREEBSD_NR_open: /* open(2) */
26177d3522bSWarner Losh         ret = do_bsd_open(arg1, arg2, arg3);
26277d3522bSWarner Losh         break;
26377d3522bSWarner Losh 
26477d3522bSWarner Losh     case TARGET_FREEBSD_NR_openat: /* openat(2) */
26577d3522bSWarner Losh         ret = do_bsd_openat(arg1, arg2, arg3, arg4);
26677d3522bSWarner Losh         break;
26777d3522bSWarner Losh 
26877d3522bSWarner Losh     case TARGET_FREEBSD_NR_close: /* close(2) */
26977d3522bSWarner Losh         ret = do_bsd_close(arg1);
27077d3522bSWarner Losh         break;
27177d3522bSWarner Losh 
272a2ba6c7bSWarner Losh     case TARGET_FREEBSD_NR_fdatasync: /* fdatasync(2) */
273a2ba6c7bSWarner Losh         ret = do_bsd_fdatasync(arg1);
274a2ba6c7bSWarner Losh         break;
275a2ba6c7bSWarner Losh 
276a2ba6c7bSWarner Losh     case TARGET_FREEBSD_NR_fsync: /* fsync(2) */
277a2ba6c7bSWarner Losh         ret = do_bsd_fsync(arg1);
278a2ba6c7bSWarner Losh         break;
279a2ba6c7bSWarner Losh 
280a2ba6c7bSWarner Losh     case TARGET_FREEBSD_NR_freebsd12_closefrom: /* closefrom(2) */
281a2ba6c7bSWarner Losh         ret = do_bsd_closefrom(arg1);
282a2ba6c7bSWarner Losh         break;
283a2ba6c7bSWarner Losh 
28465c6c4c8SWarner Losh     case TARGET_FREEBSD_NR_revoke: /* revoke(2) */
28565c6c4c8SWarner Losh         ret = do_bsd_revoke(arg1);
28665c6c4c8SWarner Losh         break;
28765c6c4c8SWarner Losh 
28865c6c4c8SWarner Losh     case TARGET_FREEBSD_NR_access: /* access(2) */
28965c6c4c8SWarner Losh         ret = do_bsd_access(arg1, arg2);
29065c6c4c8SWarner Losh         break;
29165c6c4c8SWarner Losh 
29265c6c4c8SWarner Losh     case TARGET_FREEBSD_NR_eaccess: /* eaccess(2) */
29365c6c4c8SWarner Losh         ret = do_bsd_eaccess(arg1, arg2);
29465c6c4c8SWarner Losh         break;
29565c6c4c8SWarner Losh 
29665c6c4c8SWarner Losh     case TARGET_FREEBSD_NR_faccessat: /* faccessat(2) */
29765c6c4c8SWarner Losh         ret = do_bsd_faccessat(arg1, arg2, arg3, arg4);
29865c6c4c8SWarner Losh         break;
29965c6c4c8SWarner Losh 
300390f547eSWarner Losh     case TARGET_FREEBSD_NR_chdir: /* chdir(2) */
301390f547eSWarner Losh         ret = do_bsd_chdir(arg1);
302390f547eSWarner Losh         break;
303390f547eSWarner Losh 
304390f547eSWarner Losh     case TARGET_FREEBSD_NR_fchdir: /* fchdir(2) */
305390f547eSWarner Losh         ret = do_bsd_fchdir(arg1);
306390f547eSWarner Losh         break;
307390f547eSWarner Losh 
308ab5fd2d9SWarner Losh     case TARGET_FREEBSD_NR_rename: /* rename(2) */
309ab5fd2d9SWarner Losh         ret = do_bsd_rename(arg1, arg2);
310ab5fd2d9SWarner Losh         break;
311ab5fd2d9SWarner Losh 
312ab5fd2d9SWarner Losh     case TARGET_FREEBSD_NR_renameat: /* renameat(2) */
313ab5fd2d9SWarner Losh         ret = do_bsd_renameat(arg1, arg2, arg3, arg4);
314ab5fd2d9SWarner Losh         break;
315ab5fd2d9SWarner Losh 
3162d3b7e01SWarner Losh     case TARGET_FREEBSD_NR_link: /* link(2) */
3172d3b7e01SWarner Losh         ret = do_bsd_link(arg1, arg2);
3182d3b7e01SWarner Losh         break;
3192d3b7e01SWarner Losh 
3202d3b7e01SWarner Losh     case TARGET_FREEBSD_NR_linkat: /* linkat(2) */
3212d3b7e01SWarner Losh         ret = do_bsd_linkat(arg1, arg2, arg3, arg4, arg5);
3222d3b7e01SWarner Losh         break;
3232d3b7e01SWarner Losh 
3242d3b7e01SWarner Losh     case TARGET_FREEBSD_NR_unlink: /* unlink(2) */
3252d3b7e01SWarner Losh         ret = do_bsd_unlink(arg1);
3262d3b7e01SWarner Losh         break;
3272d3b7e01SWarner Losh 
3282d3b7e01SWarner Losh     case TARGET_FREEBSD_NR_unlinkat: /* unlinkat(2) */
3292d3b7e01SWarner Losh         ret = do_bsd_unlinkat(arg1, arg2, arg3);
3302d3b7e01SWarner Losh         break;
3312d3b7e01SWarner Losh 
3321ffbd5e7SWarner Losh     case TARGET_FREEBSD_NR_mkdir: /* mkdir(2) */
3331ffbd5e7SWarner Losh         ret = do_bsd_mkdir(arg1, arg2);
3341ffbd5e7SWarner Losh         break;
3351ffbd5e7SWarner Losh 
3361ffbd5e7SWarner Losh     case TARGET_FREEBSD_NR_mkdirat: /* mkdirat(2) */
3371ffbd5e7SWarner Losh         ret = do_bsd_mkdirat(arg1, arg2, arg3);
3381ffbd5e7SWarner Losh         break;
3391ffbd5e7SWarner Losh 
3406af8f76aSWarner Losh     case TARGET_FREEBSD_NR_rmdir: /* rmdir(2) (XXX no rmdirat()?) */
3416af8f76aSWarner Losh         ret = do_bsd_rmdir(arg1);
3426af8f76aSWarner Losh         break;
3436af8f76aSWarner Losh 
3446af8f76aSWarner Losh     case TARGET_FREEBSD_NR___getcwd: /* undocumented __getcwd() */
3456af8f76aSWarner Losh         ret = do_bsd___getcwd(arg1, arg2);
3466af8f76aSWarner Losh         break;
3476af8f76aSWarner Losh 
348a15699acSWarner Losh     case TARGET_FREEBSD_NR_dup: /* dup(2) */
349a15699acSWarner Losh         ret = do_bsd_dup(arg1);
350a15699acSWarner Losh         break;
351a15699acSWarner Losh 
352a15699acSWarner Losh     case TARGET_FREEBSD_NR_dup2: /* dup2(2) */
353a15699acSWarner Losh         ret = do_bsd_dup2(arg1, arg2);
354a15699acSWarner Losh         break;
355a15699acSWarner Losh 
3564b795b14SWarner Losh     case TARGET_FREEBSD_NR_truncate: /* truncate(2) */
3574b795b14SWarner Losh         ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4);
3584b795b14SWarner Losh         break;
3594b795b14SWarner Losh 
3604b795b14SWarner Losh     case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */
3614b795b14SWarner Losh         ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4);
3624b795b14SWarner Losh         break;
3634b795b14SWarner Losh 
364d35020edSWarner Losh     case TARGET_FREEBSD_NR_acct: /* acct(2) */
365d35020edSWarner Losh         ret = do_bsd_acct(arg1);
366d35020edSWarner Losh         break;
367d35020edSWarner Losh 
368d35020edSWarner Losh     case TARGET_FREEBSD_NR_sync: /* sync(2) */
369d35020edSWarner Losh         ret = do_bsd_sync();
370d35020edSWarner Losh         break;
371d35020edSWarner Losh 
372af2ae2e8SWarner Losh     case TARGET_FREEBSD_NR_mount: /* mount(2) */
373af2ae2e8SWarner Losh         ret = do_bsd_mount(arg1, arg2, arg3, arg4);
374af2ae2e8SWarner Losh         break;
375af2ae2e8SWarner Losh 
376af2ae2e8SWarner Losh     case TARGET_FREEBSD_NR_unmount: /* unmount(2) */
377af2ae2e8SWarner Losh         ret = do_bsd_unmount(arg1, arg2);
378af2ae2e8SWarner Losh         break;
379af2ae2e8SWarner Losh 
380af2ae2e8SWarner Losh     case TARGET_FREEBSD_NR_nmount: /* nmount(2) */
381af2ae2e8SWarner Losh         ret = do_bsd_nmount(arg1, arg2, arg3);
382af2ae2e8SWarner Losh         break;
383af2ae2e8SWarner Losh 
384c7b62b4aSWarner Losh     case TARGET_FREEBSD_NR_symlink: /* symlink(2) */
385c7b62b4aSWarner Losh         ret = do_bsd_symlink(arg1, arg2);
386c7b62b4aSWarner Losh         break;
387c7b62b4aSWarner Losh 
388c7b62b4aSWarner Losh     case TARGET_FREEBSD_NR_symlinkat: /* symlinkat(2) */
389c7b62b4aSWarner Losh         ret = do_bsd_symlinkat(arg1, arg2, arg3);
390c7b62b4aSWarner Losh         break;
391c7b62b4aSWarner Losh 
392c7b62b4aSWarner Losh     case TARGET_FREEBSD_NR_readlink: /* readlink(2) */
393c7b62b4aSWarner Losh         ret = do_bsd_readlink(cpu_env, arg1, arg2, arg3);
394c7b62b4aSWarner Losh         break;
395c7b62b4aSWarner Losh 
396c7b62b4aSWarner Losh     case TARGET_FREEBSD_NR_readlinkat: /* readlinkat(2) */
397c7b62b4aSWarner Losh         ret = do_bsd_readlinkat(arg1, arg2, arg3, arg4);
398c7b62b4aSWarner Losh         break;
399c7b62b4aSWarner Losh 
4000db0db8fSWarner Losh     case TARGET_FREEBSD_NR_chmod: /* chmod(2) */
4010db0db8fSWarner Losh         ret = do_bsd_chmod(arg1, arg2);
4020db0db8fSWarner Losh         break;
4030db0db8fSWarner Losh 
4040db0db8fSWarner Losh     case TARGET_FREEBSD_NR_fchmod: /* fchmod(2) */
4050db0db8fSWarner Losh         ret = do_bsd_fchmod(arg1, arg2);
4060db0db8fSWarner Losh         break;
4070db0db8fSWarner Losh 
4080db0db8fSWarner Losh     case TARGET_FREEBSD_NR_lchmod: /* lchmod(2) */
4090db0db8fSWarner Losh         ret = do_bsd_lchmod(arg1, arg2);
4100db0db8fSWarner Losh         break;
4110db0db8fSWarner Losh 
4120db0db8fSWarner Losh     case TARGET_FREEBSD_NR_fchmodat: /* fchmodat(2) */
4130db0db8fSWarner Losh         ret = do_bsd_fchmodat(arg1, arg2, arg3, arg4);
4140db0db8fSWarner Losh         break;
4150db0db8fSWarner Losh 
41679cfae0cSWarner Losh     case TARGET_FREEBSD_NR_freebsd11_mknod: /* mknod(2) */
41779cfae0cSWarner Losh         ret = do_bsd_freebsd11_mknod(arg1, arg2, arg3);
41879cfae0cSWarner Losh         break;
41979cfae0cSWarner Losh 
42079cfae0cSWarner Losh     case TARGET_FREEBSD_NR_freebsd11_mknodat: /* mknodat(2) */
42179cfae0cSWarner Losh         ret = do_bsd_freebsd11_mknodat(arg1, arg2, arg3, arg4);
42279cfae0cSWarner Losh         break;
42379cfae0cSWarner Losh 
42479cfae0cSWarner Losh     case TARGET_FREEBSD_NR_mknodat: /* mknodat(2) */
42579cfae0cSWarner Losh         ret = do_bsd_mknodat(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
42679cfae0cSWarner Losh         break;
42779cfae0cSWarner Losh 
42858af3e29SWarner Losh     case TARGET_FREEBSD_NR_chown: /* chown(2) */
42958af3e29SWarner Losh         ret = do_bsd_chown(arg1, arg2, arg3);
43058af3e29SWarner Losh         break;
43158af3e29SWarner Losh 
43258af3e29SWarner Losh     case TARGET_FREEBSD_NR_fchown: /* fchown(2) */
43358af3e29SWarner Losh         ret = do_bsd_fchown(arg1, arg2, arg3);
43458af3e29SWarner Losh         break;
43558af3e29SWarner Losh 
43658af3e29SWarner Losh     case TARGET_FREEBSD_NR_lchown: /* lchown(2) */
43758af3e29SWarner Losh         ret = do_bsd_lchown(arg1, arg2, arg3);
43858af3e29SWarner Losh         break;
43958af3e29SWarner Losh 
44058af3e29SWarner Losh     case TARGET_FREEBSD_NR_fchownat: /* fchownat(2) */
44158af3e29SWarner Losh         ret = do_bsd_fchownat(arg1, arg2, arg3, arg4, arg5);
44258af3e29SWarner Losh         break;
44358af3e29SWarner Losh 
444c6f0a7d9SWarner Losh     case TARGET_FREEBSD_NR_chflags: /* chflags(2) */
445c6f0a7d9SWarner Losh         ret = do_bsd_chflags(arg1, arg2);
446c6f0a7d9SWarner Losh         break;
447c6f0a7d9SWarner Losh 
448c6f0a7d9SWarner Losh     case TARGET_FREEBSD_NR_lchflags: /* lchflags(2) */
449c6f0a7d9SWarner Losh         ret = do_bsd_lchflags(arg1, arg2);
450c6f0a7d9SWarner Losh         break;
451c6f0a7d9SWarner Losh 
452c6f0a7d9SWarner Losh     case TARGET_FREEBSD_NR_fchflags: /* fchflags(2) */
453c6f0a7d9SWarner Losh         ret = do_bsd_fchflags(arg1, arg2);
454c6f0a7d9SWarner Losh         break;
455c6f0a7d9SWarner Losh 
45617a4d13cSWarner Losh     case TARGET_FREEBSD_NR_chroot: /* chroot(2) */
45717a4d13cSWarner Losh         ret = do_bsd_chroot(arg1);
45817a4d13cSWarner Losh         break;
45917a4d13cSWarner Losh 
46017a4d13cSWarner Losh     case TARGET_FREEBSD_NR_flock: /* flock(2) */
46117a4d13cSWarner Losh         ret = do_bsd_flock(arg1, arg2);
46217a4d13cSWarner Losh         break;
46317a4d13cSWarner Losh 
4645fbd8011SWarner Losh     case TARGET_FREEBSD_NR_mkfifo: /* mkfifo(2) */
4655fbd8011SWarner Losh         ret = do_bsd_mkfifo(arg1, arg2);
4665fbd8011SWarner Losh         break;
4675fbd8011SWarner Losh 
4685fbd8011SWarner Losh     case TARGET_FREEBSD_NR_mkfifoat: /* mkfifoat(2) */
4695fbd8011SWarner Losh         ret = do_bsd_mkfifoat(arg1, arg2, arg3);
4705fbd8011SWarner Losh         break;
4715fbd8011SWarner Losh 
472d3f29ddaSWarner Losh     case TARGET_FREEBSD_NR_pathconf: /* pathconf(2) */
473d3f29ddaSWarner Losh         ret = do_bsd_pathconf(arg1, arg2);
474d3f29ddaSWarner Losh         break;
475d3f29ddaSWarner Losh 
476d3f29ddaSWarner Losh     case TARGET_FREEBSD_NR_lpathconf: /* lpathconf(2) */
477d3f29ddaSWarner Losh         ret = do_bsd_lpathconf(arg1, arg2);
478d3f29ddaSWarner Losh         break;
479d3f29ddaSWarner Losh 
480d3f29ddaSWarner Losh     case TARGET_FREEBSD_NR_fpathconf: /* fpathconf(2) */
481d3f29ddaSWarner Losh         ret = do_bsd_fpathconf(arg1, arg2);
482d3f29ddaSWarner Losh         break;
483d3f29ddaSWarner Losh 
484952d5d30SWarner Losh     case TARGET_FREEBSD_NR_undelete: /* undelete(2) */
485952d5d30SWarner Losh         ret = do_bsd_undelete(arg1);
486952d5d30SWarner Losh         break;
487952d5d30SWarner Losh 
488fb96f5dfSStacey Son         /*
489e800e6c5SWarner Losh          * stat system calls
490e800e6c5SWarner Losh          */
491e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_stat: /* stat(2) */
492e800e6c5SWarner Losh         ret = do_freebsd11_stat(arg1, arg2);
493e800e6c5SWarner Losh         break;
494e800e6c5SWarner Losh 
495e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_lstat: /* lstat(2) */
496e800e6c5SWarner Losh         ret = do_freebsd11_lstat(arg1, arg2);
497e800e6c5SWarner Losh         break;
498e800e6c5SWarner Losh 
499e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_fstat: /* fstat(2) */
500e800e6c5SWarner Losh         ret = do_freebsd11_fstat(arg1, arg2);
501e800e6c5SWarner Losh         break;
502e800e6c5SWarner Losh 
503e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_fstat: /* fstat(2) */
504e800e6c5SWarner Losh         ret = do_freebsd_fstat(arg1, arg2);
505e800e6c5SWarner Losh         break;
506e800e6c5SWarner Losh 
507e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_fstatat: /* fstatat(2) */
508e800e6c5SWarner Losh         ret = do_freebsd11_fstatat(arg1, arg2, arg3, arg4);
509e800e6c5SWarner Losh         break;
510e800e6c5SWarner Losh 
511e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_fstatat: /* fstatat(2) */
512e800e6c5SWarner Losh         ret = do_freebsd_fstatat(arg1, arg2, arg3, arg4);
513e800e6c5SWarner Losh         break;
514e800e6c5SWarner Losh 
515e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_nstat: /* undocumented */
516e800e6c5SWarner Losh         ret = do_freebsd11_nstat(arg1, arg2);
517e800e6c5SWarner Losh         break;
518e800e6c5SWarner Losh 
519e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_nfstat: /* undocumented */
520e800e6c5SWarner Losh         ret = do_freebsd11_nfstat(arg1, arg2);
521e800e6c5SWarner Losh         break;
522e800e6c5SWarner Losh 
523e800e6c5SWarner Losh     case TARGET_FREEBSD_NR_freebsd11_nlstat: /* undocumented */
524e800e6c5SWarner Losh         ret = do_freebsd11_nlstat(arg1, arg2);
525e800e6c5SWarner Losh         break;
526e800e6c5SWarner Losh 
527*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_getfh: /* getfh(2) */
528*6fe97c6cSWarner Losh         ret = do_freebsd_getfh(arg1, arg2);
529*6fe97c6cSWarner Losh         break;
530*6fe97c6cSWarner Losh 
531*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_lgetfh: /* lgetfh(2) */
532*6fe97c6cSWarner Losh         ret = do_freebsd_lgetfh(arg1, arg2);
533*6fe97c6cSWarner Losh         break;
534*6fe97c6cSWarner Losh 
535*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_fhopen: /* fhopen(2) */
536*6fe97c6cSWarner Losh         ret = do_freebsd_fhopen(arg1, arg2);
537*6fe97c6cSWarner Losh         break;
538*6fe97c6cSWarner Losh 
539*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_freebsd11_fhstat: /* fhstat(2) */
540*6fe97c6cSWarner Losh         ret = do_freebsd11_fhstat(arg1, arg2);
541*6fe97c6cSWarner Losh         break;
542*6fe97c6cSWarner Losh 
543*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_fhstat: /* fhstat(2) */
544*6fe97c6cSWarner Losh         ret = do_freebsd_fhstat(arg1, arg2);
545*6fe97c6cSWarner Losh         break;
546*6fe97c6cSWarner Losh 
547*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_freebsd11_fhstatfs: /* fhstatfs(2) */
548*6fe97c6cSWarner Losh         ret = do_freebsd11_fhstatfs(arg1, arg2);
549*6fe97c6cSWarner Losh         break;
550*6fe97c6cSWarner Losh 
551*6fe97c6cSWarner Losh     case TARGET_FREEBSD_NR_fhstatfs: /* fhstatfs(2) */
552*6fe97c6cSWarner Losh         ret = do_freebsd_fhstatfs(arg1, arg2);
553*6fe97c6cSWarner Losh         break;
554*6fe97c6cSWarner Losh 
555e800e6c5SWarner Losh         /*
556fb96f5dfSStacey Son          * sys{ctl, arch, call}
557fb96f5dfSStacey Son          */
5587adda6deSKyle Evans     case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */
5597adda6deSKyle Evans         ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
5607adda6deSKyle Evans         break;
5617adda6deSKyle Evans 
5626da777e2SKyle Evans     case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */
5636da777e2SKyle Evans         ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6);
5646da777e2SKyle Evans         break;
5656da777e2SKyle Evans 
566fb96f5dfSStacey Son     case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */
567fb96f5dfSStacey Son         ret = do_freebsd_sysarch(cpu_env, arg1, arg2);
568fb96f5dfSStacey Son         break;
569fb96f5dfSStacey Son 
570db697887SWarner Losh     default:
571db697887SWarner Losh         qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num);
572db697887SWarner Losh         ret = -TARGET_ENOSYS;
573db697887SWarner Losh         break;
574db697887SWarner Losh     }
575db697887SWarner Losh 
576db697887SWarner Losh     return ret;
577db697887SWarner Losh }
578db697887SWarner Losh 
579db697887SWarner Losh /*
580db697887SWarner Losh  * do_freebsd_syscall() should always have a single exit point at the end so
581db697887SWarner Losh  * that actions, such as logging of syscall results, can be performed. This
582db697887SWarner Losh  * as a wrapper around freebsd_syscall() so that actually happens. Since
583db697887SWarner Losh  * that is a singleton, modern compilers will inline it anyway...
58466eed099SWarner Losh  */
58566eed099SWarner Losh abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
58666eed099SWarner Losh                             abi_long arg2, abi_long arg3, abi_long arg4,
58766eed099SWarner Losh                             abi_long arg5, abi_long arg6, abi_long arg7,
58866eed099SWarner Losh                             abi_long arg8)
58966eed099SWarner Losh {
5904cf41e80SDoug Rabson     abi_long ret;
591db697887SWarner Losh 
592db697887SWarner Losh     if (do_strace) {
593db697887SWarner Losh         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
594db697887SWarner Losh     }
595db697887SWarner Losh 
596db697887SWarner Losh     ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6,
597db697887SWarner Losh                           arg7, arg8);
598db697887SWarner Losh     if (do_strace) {
599db697887SWarner Losh         print_freebsd_syscall_ret(num, ret);
600db697887SWarner Losh     }
601db697887SWarner Losh 
602db697887SWarner Losh     return ret;
60366eed099SWarner Losh }
60466eed099SWarner Losh 
60566eed099SWarner Losh void syscall_init(void)
60666eed099SWarner Losh {
60766eed099SWarner Losh }
608