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 2166eed099SWarner Losh /* 2266eed099SWarner Losh * We need the FreeBSD "legacy" definitions. Rust needs the FreeBSD 11 system 2366eed099SWarner Losh * calls since it doesn't use libc at all, so we have to emulate that despite 2466eed099SWarner Losh * FreeBSD 11 being EOL'd. 2566eed099SWarner Losh */ 2666eed099SWarner Losh #define _WANT_FREEBSD11_STAT 2766eed099SWarner Losh #define _WANT_FREEBSD11_STATFS 2866eed099SWarner Losh #define _WANT_FREEBSD11_DIRENT 2966eed099SWarner Losh #define _WANT_KERNEL_ERRNO 3066eed099SWarner Losh #define _WANT_SEMUN 3166eed099SWarner Losh #include "qemu/osdep.h" 3266eed099SWarner Losh #include "qemu/cutils.h" 3366eed099SWarner Losh #include "qemu/path.h" 3466eed099SWarner Losh #include <sys/syscall.h> 3579cfae0cSWarner Losh #include <sys/cdefs.h> 3666eed099SWarner Losh #include <sys/param.h> 37af2ae2e8SWarner Losh #include <sys/mount.h> 3866eed099SWarner Losh #include <sys/sysctl.h> 3966eed099SWarner Losh #include <utime.h> 4066eed099SWarner Losh 4166eed099SWarner Losh #include "qemu.h" 4266eed099SWarner Losh #include "signal-common.h" 4366eed099SWarner Losh #include "user/syscall-trace.h" 4466eed099SWarner Losh 45c5c84d16SWarner Losh #include "bsd-file.h" 469554d330SWarner Losh #include "bsd-proc.h" 47c5c84d16SWarner Losh 4880da1b00SWarner Losh /* I/O */ 4977d3522bSWarner Losh safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); 5077d3522bSWarner Losh safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t, 5177d3522bSWarner Losh mode); 5277d3522bSWarner Losh 5380da1b00SWarner Losh safe_syscall3(ssize_t, read, int, fd, void *, buf, size_t, nbytes); 5480da1b00SWarner Losh safe_syscall4(ssize_t, pread, int, fd, void *, buf, size_t, nbytes, off_t, 5580da1b00SWarner Losh offset); 5680da1b00SWarner Losh safe_syscall3(ssize_t, readv, int, fd, const struct iovec *, iov, int, iovcnt); 5780da1b00SWarner Losh safe_syscall4(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt, 5880da1b00SWarner Losh off_t, offset); 5980da1b00SWarner Losh 60770d8abaSWarner Losh safe_syscall3(ssize_t, write, int, fd, void *, buf, size_t, nbytes); 61770d8abaSWarner Losh safe_syscall4(ssize_t, pwrite, int, fd, void *, buf, size_t, nbytes, off_t, 62770d8abaSWarner Losh offset); 63770d8abaSWarner Losh safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt); 64770d8abaSWarner Losh safe_syscall4(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, iovcnt, 65770d8abaSWarner Losh off_t, offset); 66770d8abaSWarner Losh 6766eed099SWarner Losh void target_set_brk(abi_ulong new_brk) 6866eed099SWarner Losh { 6966eed099SWarner Losh } 7066eed099SWarner Losh 71deeff83bSWarner Losh /* 72deeff83bSWarner Losh * errno conversion. 73deeff83bSWarner Losh */ 74deeff83bSWarner Losh abi_long get_errno(abi_long ret) 75deeff83bSWarner Losh { 76deeff83bSWarner Losh if (ret == -1) { 77deeff83bSWarner Losh return -host_to_target_errno(errno); 78deeff83bSWarner Losh } else { 79deeff83bSWarner Losh return ret; 80deeff83bSWarner Losh } 81deeff83bSWarner Losh } 82deeff83bSWarner Losh 83deeff83bSWarner Losh int host_to_target_errno(int err) 84deeff83bSWarner Losh { 85deeff83bSWarner Losh /* 86deeff83bSWarner Losh * All the BSDs have the property that the error numbers are uniform across 87deeff83bSWarner Losh * all architectures for a given BSD, though they may vary between different 88deeff83bSWarner Losh * BSDs. 89deeff83bSWarner Losh */ 90deeff83bSWarner Losh return err; 91deeff83bSWarner Losh } 92deeff83bSWarner Losh 9366eed099SWarner Losh bool is_error(abi_long ret) 9466eed099SWarner Losh { 9566eed099SWarner Losh return (abi_ulong)ret >= (abi_ulong)(-4096); 9666eed099SWarner Losh } 9766eed099SWarner Losh 9866eed099SWarner Losh /* 991ed771b2SWarner Losh * Unlocks a iovec. Unlike unlock_iovec, it assumes the tvec array itself is 1001ed771b2SWarner Losh * already locked from target_addr. It will be unlocked as well as all the iovec 1011ed771b2SWarner Losh * elements. 1021ed771b2SWarner Losh */ 1031ed771b2SWarner Losh static void helper_unlock_iovec(struct target_iovec *target_vec, 1041ed771b2SWarner Losh abi_ulong target_addr, struct iovec *vec, 1051ed771b2SWarner Losh int count, int copy) 1061ed771b2SWarner Losh { 1071ed771b2SWarner Losh for (int i = 0; i < count; i++) { 1081ed771b2SWarner Losh abi_ulong base = tswapal(target_vec[i].iov_base); 1091ed771b2SWarner Losh 1101ed771b2SWarner Losh if (vec[i].iov_base) { 1111ed771b2SWarner Losh unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0); 1121ed771b2SWarner Losh } 1131ed771b2SWarner Losh } 1141ed771b2SWarner Losh unlock_user(target_vec, target_addr, 0); 1151ed771b2SWarner Losh } 1161ed771b2SWarner Losh 1171ed771b2SWarner Losh struct iovec *lock_iovec(int type, abi_ulong target_addr, 1181ed771b2SWarner Losh int count, int copy) 1191ed771b2SWarner Losh { 1201ed771b2SWarner Losh struct target_iovec *target_vec; 1211ed771b2SWarner Losh struct iovec *vec; 1221ed771b2SWarner Losh abi_ulong total_len, max_len; 1231ed771b2SWarner Losh int i; 1241ed771b2SWarner Losh int err = 0; 1251ed771b2SWarner Losh 1261ed771b2SWarner Losh if (count == 0) { 1271ed771b2SWarner Losh errno = 0; 1281ed771b2SWarner Losh return NULL; 1291ed771b2SWarner Losh } 1301ed771b2SWarner Losh if (count < 0 || count > IOV_MAX) { 1311ed771b2SWarner Losh errno = EINVAL; 1321ed771b2SWarner Losh return NULL; 1331ed771b2SWarner Losh } 1341ed771b2SWarner Losh 1351ed771b2SWarner Losh vec = g_try_new0(struct iovec, count); 1361ed771b2SWarner Losh if (vec == NULL) { 1371ed771b2SWarner Losh errno = ENOMEM; 1381ed771b2SWarner Losh return NULL; 1391ed771b2SWarner Losh } 1401ed771b2SWarner Losh 1411ed771b2SWarner Losh target_vec = lock_user(VERIFY_READ, target_addr, 1421ed771b2SWarner Losh count * sizeof(struct target_iovec), 1); 1431ed771b2SWarner Losh if (target_vec == NULL) { 1441ed771b2SWarner Losh err = EFAULT; 1451ed771b2SWarner Losh goto fail2; 1461ed771b2SWarner Losh } 1471ed771b2SWarner Losh 1481ed771b2SWarner Losh max_len = 0x7fffffff & MIN(TARGET_PAGE_MASK, PAGE_MASK); 1491ed771b2SWarner Losh total_len = 0; 1501ed771b2SWarner Losh 1511ed771b2SWarner Losh for (i = 0; i < count; i++) { 1521ed771b2SWarner Losh abi_ulong base = tswapal(target_vec[i].iov_base); 1531ed771b2SWarner Losh abi_long len = tswapal(target_vec[i].iov_len); 1541ed771b2SWarner Losh 1551ed771b2SWarner Losh if (len < 0) { 1561ed771b2SWarner Losh err = EINVAL; 1571ed771b2SWarner Losh goto fail; 1581ed771b2SWarner Losh } else if (len == 0) { 1591ed771b2SWarner Losh /* Zero length pointer is ignored. */ 1601ed771b2SWarner Losh vec[i].iov_base = 0; 1611ed771b2SWarner Losh } else { 1621ed771b2SWarner Losh vec[i].iov_base = lock_user(type, base, len, copy); 1631ed771b2SWarner Losh /* 1641ed771b2SWarner Losh * If the first buffer pointer is bad, this is a fault. But 1651ed771b2SWarner Losh * subsequent bad buffers will result in a partial write; this is 1661ed771b2SWarner Losh * realized by filling the vector with null pointers and zero 1671ed771b2SWarner Losh * lengths. 1681ed771b2SWarner Losh */ 1691ed771b2SWarner Losh if (!vec[i].iov_base) { 1701ed771b2SWarner Losh if (i == 0) { 1711ed771b2SWarner Losh err = EFAULT; 1721ed771b2SWarner Losh goto fail; 1731ed771b2SWarner Losh } else { 1741ed771b2SWarner Losh /* 1751ed771b2SWarner Losh * Fail all the subsequent addresses, they are already 1761ed771b2SWarner Losh * zero'd. 1771ed771b2SWarner Losh */ 1781ed771b2SWarner Losh goto out; 1791ed771b2SWarner Losh } 1801ed771b2SWarner Losh } 1811ed771b2SWarner Losh if (len > max_len - total_len) { 1821ed771b2SWarner Losh len = max_len - total_len; 1831ed771b2SWarner Losh } 1841ed771b2SWarner Losh } 1851ed771b2SWarner Losh vec[i].iov_len = len; 1861ed771b2SWarner Losh total_len += len; 1871ed771b2SWarner Losh } 1881ed771b2SWarner Losh out: 1891ed771b2SWarner Losh unlock_user(target_vec, target_addr, 0); 1901ed771b2SWarner Losh return vec; 1911ed771b2SWarner Losh 1921ed771b2SWarner Losh fail: 1931ed771b2SWarner Losh helper_unlock_iovec(target_vec, target_addr, vec, i, copy); 1941ed771b2SWarner Losh fail2: 1951ed771b2SWarner Losh g_free(vec); 1961ed771b2SWarner Losh errno = err; 1971ed771b2SWarner Losh return NULL; 1981ed771b2SWarner Losh } 1991ed771b2SWarner Losh 200883808d8SWarner Losh void unlock_iovec(struct iovec *vec, abi_ulong target_addr, 201883808d8SWarner Losh int count, int copy) 202883808d8SWarner Losh { 203883808d8SWarner Losh struct target_iovec *target_vec; 204883808d8SWarner Losh 205883808d8SWarner Losh target_vec = lock_user(VERIFY_READ, target_addr, 206883808d8SWarner Losh count * sizeof(struct target_iovec), 1); 207883808d8SWarner Losh if (target_vec) { 208883808d8SWarner Losh helper_unlock_iovec(target_vec, target_addr, vec, count, copy); 209883808d8SWarner Losh } 210883808d8SWarner Losh 211883808d8SWarner Losh g_free(vec); 212883808d8SWarner Losh } 213883808d8SWarner Losh 2141ed771b2SWarner Losh /* 215db697887SWarner Losh * All errnos that freebsd_syscall() returns must be -TARGET_<errcode>. 216db697887SWarner Losh */ 217db697887SWarner Losh static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, 218db697887SWarner Losh abi_long arg2, abi_long arg3, abi_long arg4, 219db697887SWarner Losh abi_long arg5, abi_long arg6, abi_long arg7, 220db697887SWarner Losh abi_long arg8) 221db697887SWarner Losh { 222db697887SWarner Losh abi_long ret; 223db697887SWarner Losh 224db697887SWarner Losh switch (num) { 2259554d330SWarner Losh /* 2269554d330SWarner Losh * process system calls 2279554d330SWarner Losh */ 2289554d330SWarner Losh case TARGET_FREEBSD_NR_exit: /* exit(2) */ 2299554d330SWarner Losh ret = do_bsd_exit(cpu_env, arg1); 2309554d330SWarner Losh break; 23180da1b00SWarner Losh 23280da1b00SWarner Losh /* 23380da1b00SWarner Losh * File system calls. 23480da1b00SWarner Losh */ 23580da1b00SWarner Losh case TARGET_FREEBSD_NR_read: /* read(2) */ 23680da1b00SWarner Losh ret = do_bsd_read(arg1, arg2, arg3); 23780da1b00SWarner Losh break; 23880da1b00SWarner Losh 23980da1b00SWarner Losh case TARGET_FREEBSD_NR_pread: /* pread(2) */ 24080da1b00SWarner Losh ret = do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 24180da1b00SWarner Losh break; 24280da1b00SWarner Losh 24380da1b00SWarner Losh case TARGET_FREEBSD_NR_readv: /* readv(2) */ 24480da1b00SWarner Losh ret = do_bsd_readv(arg1, arg2, arg3); 24580da1b00SWarner Losh break; 24680da1b00SWarner Losh 24780da1b00SWarner Losh case TARGET_FREEBSD_NR_preadv: /* preadv(2) */ 24880da1b00SWarner Losh ret = do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 249770d8abaSWarner Losh 250770d8abaSWarner Losh case TARGET_FREEBSD_NR_write: /* write(2) */ 251770d8abaSWarner Losh ret = do_bsd_write(arg1, arg2, arg3); 252770d8abaSWarner Losh break; 253770d8abaSWarner Losh 254770d8abaSWarner Losh case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */ 255770d8abaSWarner Losh ret = do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 256770d8abaSWarner Losh break; 257770d8abaSWarner Losh 258770d8abaSWarner Losh case TARGET_FREEBSD_NR_writev: /* writev(2) */ 259770d8abaSWarner Losh ret = do_bsd_writev(arg1, arg2, arg3); 260770d8abaSWarner Losh break; 261770d8abaSWarner Losh 262770d8abaSWarner Losh case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */ 263770d8abaSWarner Losh ret = do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 26480da1b00SWarner Losh break; 26580da1b00SWarner Losh 26677d3522bSWarner Losh case TARGET_FREEBSD_NR_open: /* open(2) */ 26777d3522bSWarner Losh ret = do_bsd_open(arg1, arg2, arg3); 26877d3522bSWarner Losh break; 26977d3522bSWarner Losh 27077d3522bSWarner Losh case TARGET_FREEBSD_NR_openat: /* openat(2) */ 27177d3522bSWarner Losh ret = do_bsd_openat(arg1, arg2, arg3, arg4); 27277d3522bSWarner Losh break; 27377d3522bSWarner Losh 27477d3522bSWarner Losh case TARGET_FREEBSD_NR_close: /* close(2) */ 27577d3522bSWarner Losh ret = do_bsd_close(arg1); 27677d3522bSWarner Losh break; 27777d3522bSWarner Losh 278a2ba6c7bSWarner Losh case TARGET_FREEBSD_NR_fdatasync: /* fdatasync(2) */ 279a2ba6c7bSWarner Losh ret = do_bsd_fdatasync(arg1); 280a2ba6c7bSWarner Losh break; 281a2ba6c7bSWarner Losh 282a2ba6c7bSWarner Losh case TARGET_FREEBSD_NR_fsync: /* fsync(2) */ 283a2ba6c7bSWarner Losh ret = do_bsd_fsync(arg1); 284a2ba6c7bSWarner Losh break; 285a2ba6c7bSWarner Losh 286a2ba6c7bSWarner Losh case TARGET_FREEBSD_NR_freebsd12_closefrom: /* closefrom(2) */ 287a2ba6c7bSWarner Losh ret = do_bsd_closefrom(arg1); 288a2ba6c7bSWarner Losh break; 289a2ba6c7bSWarner Losh 29065c6c4c8SWarner Losh case TARGET_FREEBSD_NR_revoke: /* revoke(2) */ 29165c6c4c8SWarner Losh ret = do_bsd_revoke(arg1); 29265c6c4c8SWarner Losh break; 29365c6c4c8SWarner Losh 29465c6c4c8SWarner Losh case TARGET_FREEBSD_NR_access: /* access(2) */ 29565c6c4c8SWarner Losh ret = do_bsd_access(arg1, arg2); 29665c6c4c8SWarner Losh break; 29765c6c4c8SWarner Losh 29865c6c4c8SWarner Losh case TARGET_FREEBSD_NR_eaccess: /* eaccess(2) */ 29965c6c4c8SWarner Losh ret = do_bsd_eaccess(arg1, arg2); 30065c6c4c8SWarner Losh break; 30165c6c4c8SWarner Losh 30265c6c4c8SWarner Losh case TARGET_FREEBSD_NR_faccessat: /* faccessat(2) */ 30365c6c4c8SWarner Losh ret = do_bsd_faccessat(arg1, arg2, arg3, arg4); 30465c6c4c8SWarner Losh break; 30565c6c4c8SWarner Losh 306390f547eSWarner Losh case TARGET_FREEBSD_NR_chdir: /* chdir(2) */ 307390f547eSWarner Losh ret = do_bsd_chdir(arg1); 308390f547eSWarner Losh break; 309390f547eSWarner Losh 310390f547eSWarner Losh case TARGET_FREEBSD_NR_fchdir: /* fchdir(2) */ 311390f547eSWarner Losh ret = do_bsd_fchdir(arg1); 312390f547eSWarner Losh break; 313390f547eSWarner Losh 314ab5fd2d9SWarner Losh case TARGET_FREEBSD_NR_rename: /* rename(2) */ 315ab5fd2d9SWarner Losh ret = do_bsd_rename(arg1, arg2); 316ab5fd2d9SWarner Losh break; 317ab5fd2d9SWarner Losh 318ab5fd2d9SWarner Losh case TARGET_FREEBSD_NR_renameat: /* renameat(2) */ 319ab5fd2d9SWarner Losh ret = do_bsd_renameat(arg1, arg2, arg3, arg4); 320ab5fd2d9SWarner Losh break; 321ab5fd2d9SWarner Losh 3222d3b7e01SWarner Losh case TARGET_FREEBSD_NR_link: /* link(2) */ 3232d3b7e01SWarner Losh ret = do_bsd_link(arg1, arg2); 3242d3b7e01SWarner Losh break; 3252d3b7e01SWarner Losh 3262d3b7e01SWarner Losh case TARGET_FREEBSD_NR_linkat: /* linkat(2) */ 3272d3b7e01SWarner Losh ret = do_bsd_linkat(arg1, arg2, arg3, arg4, arg5); 3282d3b7e01SWarner Losh break; 3292d3b7e01SWarner Losh 3302d3b7e01SWarner Losh case TARGET_FREEBSD_NR_unlink: /* unlink(2) */ 3312d3b7e01SWarner Losh ret = do_bsd_unlink(arg1); 3322d3b7e01SWarner Losh break; 3332d3b7e01SWarner Losh 3342d3b7e01SWarner Losh case TARGET_FREEBSD_NR_unlinkat: /* unlinkat(2) */ 3352d3b7e01SWarner Losh ret = do_bsd_unlinkat(arg1, arg2, arg3); 3362d3b7e01SWarner Losh break; 3372d3b7e01SWarner Losh 3381ffbd5e7SWarner Losh case TARGET_FREEBSD_NR_mkdir: /* mkdir(2) */ 3391ffbd5e7SWarner Losh ret = do_bsd_mkdir(arg1, arg2); 3401ffbd5e7SWarner Losh break; 3411ffbd5e7SWarner Losh 3421ffbd5e7SWarner Losh case TARGET_FREEBSD_NR_mkdirat: /* mkdirat(2) */ 3431ffbd5e7SWarner Losh ret = do_bsd_mkdirat(arg1, arg2, arg3); 3441ffbd5e7SWarner Losh break; 3451ffbd5e7SWarner Losh 3466af8f76aSWarner Losh case TARGET_FREEBSD_NR_rmdir: /* rmdir(2) (XXX no rmdirat()?) */ 3476af8f76aSWarner Losh ret = do_bsd_rmdir(arg1); 3486af8f76aSWarner Losh break; 3496af8f76aSWarner Losh 3506af8f76aSWarner Losh case TARGET_FREEBSD_NR___getcwd: /* undocumented __getcwd() */ 3516af8f76aSWarner Losh ret = do_bsd___getcwd(arg1, arg2); 3526af8f76aSWarner Losh break; 3536af8f76aSWarner Losh 354a15699acSWarner Losh case TARGET_FREEBSD_NR_dup: /* dup(2) */ 355a15699acSWarner Losh ret = do_bsd_dup(arg1); 356a15699acSWarner Losh break; 357a15699acSWarner Losh 358a15699acSWarner Losh case TARGET_FREEBSD_NR_dup2: /* dup2(2) */ 359a15699acSWarner Losh ret = do_bsd_dup2(arg1, arg2); 360a15699acSWarner Losh break; 361a15699acSWarner Losh 3624b795b14SWarner Losh case TARGET_FREEBSD_NR_truncate: /* truncate(2) */ 3634b795b14SWarner Losh ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4); 3644b795b14SWarner Losh break; 3654b795b14SWarner Losh 3664b795b14SWarner Losh case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */ 3674b795b14SWarner Losh ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4); 3684b795b14SWarner Losh break; 3694b795b14SWarner Losh 370d35020edSWarner Losh case TARGET_FREEBSD_NR_acct: /* acct(2) */ 371d35020edSWarner Losh ret = do_bsd_acct(arg1); 372d35020edSWarner Losh break; 373d35020edSWarner Losh 374d35020edSWarner Losh case TARGET_FREEBSD_NR_sync: /* sync(2) */ 375d35020edSWarner Losh ret = do_bsd_sync(); 376d35020edSWarner Losh break; 377d35020edSWarner Losh 378af2ae2e8SWarner Losh case TARGET_FREEBSD_NR_mount: /* mount(2) */ 379af2ae2e8SWarner Losh ret = do_bsd_mount(arg1, arg2, arg3, arg4); 380af2ae2e8SWarner Losh break; 381af2ae2e8SWarner Losh 382af2ae2e8SWarner Losh case TARGET_FREEBSD_NR_unmount: /* unmount(2) */ 383af2ae2e8SWarner Losh ret = do_bsd_unmount(arg1, arg2); 384af2ae2e8SWarner Losh break; 385af2ae2e8SWarner Losh 386af2ae2e8SWarner Losh case TARGET_FREEBSD_NR_nmount: /* nmount(2) */ 387af2ae2e8SWarner Losh ret = do_bsd_nmount(arg1, arg2, arg3); 388af2ae2e8SWarner Losh break; 389af2ae2e8SWarner Losh 390c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_symlink: /* symlink(2) */ 391c7b62b4aSWarner Losh ret = do_bsd_symlink(arg1, arg2); 392c7b62b4aSWarner Losh break; 393c7b62b4aSWarner Losh 394c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_symlinkat: /* symlinkat(2) */ 395c7b62b4aSWarner Losh ret = do_bsd_symlinkat(arg1, arg2, arg3); 396c7b62b4aSWarner Losh break; 397c7b62b4aSWarner Losh 398c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_readlink: /* readlink(2) */ 399c7b62b4aSWarner Losh ret = do_bsd_readlink(cpu_env, arg1, arg2, arg3); 400c7b62b4aSWarner Losh break; 401c7b62b4aSWarner Losh 402c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_readlinkat: /* readlinkat(2) */ 403c7b62b4aSWarner Losh ret = do_bsd_readlinkat(arg1, arg2, arg3, arg4); 404c7b62b4aSWarner Losh break; 405c7b62b4aSWarner Losh 4060db0db8fSWarner Losh case TARGET_FREEBSD_NR_chmod: /* chmod(2) */ 4070db0db8fSWarner Losh ret = do_bsd_chmod(arg1, arg2); 4080db0db8fSWarner Losh break; 4090db0db8fSWarner Losh 4100db0db8fSWarner Losh case TARGET_FREEBSD_NR_fchmod: /* fchmod(2) */ 4110db0db8fSWarner Losh ret = do_bsd_fchmod(arg1, arg2); 4120db0db8fSWarner Losh break; 4130db0db8fSWarner Losh 4140db0db8fSWarner Losh case TARGET_FREEBSD_NR_lchmod: /* lchmod(2) */ 4150db0db8fSWarner Losh ret = do_bsd_lchmod(arg1, arg2); 4160db0db8fSWarner Losh break; 4170db0db8fSWarner Losh 4180db0db8fSWarner Losh case TARGET_FREEBSD_NR_fchmodat: /* fchmodat(2) */ 4190db0db8fSWarner Losh ret = do_bsd_fchmodat(arg1, arg2, arg3, arg4); 4200db0db8fSWarner Losh break; 4210db0db8fSWarner Losh 42279cfae0cSWarner Losh case TARGET_FREEBSD_NR_freebsd11_mknod: /* mknod(2) */ 42379cfae0cSWarner Losh ret = do_bsd_freebsd11_mknod(arg1, arg2, arg3); 42479cfae0cSWarner Losh break; 42579cfae0cSWarner Losh 42679cfae0cSWarner Losh case TARGET_FREEBSD_NR_freebsd11_mknodat: /* mknodat(2) */ 42779cfae0cSWarner Losh ret = do_bsd_freebsd11_mknodat(arg1, arg2, arg3, arg4); 42879cfae0cSWarner Losh break; 42979cfae0cSWarner Losh 43079cfae0cSWarner Losh case TARGET_FREEBSD_NR_mknodat: /* mknodat(2) */ 43179cfae0cSWarner Losh ret = do_bsd_mknodat(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 43279cfae0cSWarner Losh break; 43379cfae0cSWarner Losh 43458af3e29SWarner Losh case TARGET_FREEBSD_NR_chown: /* chown(2) */ 43558af3e29SWarner Losh ret = do_bsd_chown(arg1, arg2, arg3); 43658af3e29SWarner Losh break; 43758af3e29SWarner Losh 43858af3e29SWarner Losh case TARGET_FREEBSD_NR_fchown: /* fchown(2) */ 43958af3e29SWarner Losh ret = do_bsd_fchown(arg1, arg2, arg3); 44058af3e29SWarner Losh break; 44158af3e29SWarner Losh 44258af3e29SWarner Losh case TARGET_FREEBSD_NR_lchown: /* lchown(2) */ 44358af3e29SWarner Losh ret = do_bsd_lchown(arg1, arg2, arg3); 44458af3e29SWarner Losh break; 44558af3e29SWarner Losh 44658af3e29SWarner Losh case TARGET_FREEBSD_NR_fchownat: /* fchownat(2) */ 44758af3e29SWarner Losh ret = do_bsd_fchownat(arg1, arg2, arg3, arg4, arg5); 44858af3e29SWarner Losh break; 44958af3e29SWarner Losh 450c6f0a7d9SWarner Losh case TARGET_FREEBSD_NR_chflags: /* chflags(2) */ 451c6f0a7d9SWarner Losh ret = do_bsd_chflags(arg1, arg2); 452c6f0a7d9SWarner Losh break; 453c6f0a7d9SWarner Losh 454c6f0a7d9SWarner Losh case TARGET_FREEBSD_NR_lchflags: /* lchflags(2) */ 455c6f0a7d9SWarner Losh ret = do_bsd_lchflags(arg1, arg2); 456c6f0a7d9SWarner Losh break; 457c6f0a7d9SWarner Losh 458c6f0a7d9SWarner Losh case TARGET_FREEBSD_NR_fchflags: /* fchflags(2) */ 459c6f0a7d9SWarner Losh ret = do_bsd_fchflags(arg1, arg2); 460c6f0a7d9SWarner Losh break; 461c6f0a7d9SWarner Losh 46217a4d13cSWarner Losh case TARGET_FREEBSD_NR_chroot: /* chroot(2) */ 46317a4d13cSWarner Losh ret = do_bsd_chroot(arg1); 46417a4d13cSWarner Losh break; 46517a4d13cSWarner Losh 46617a4d13cSWarner Losh case TARGET_FREEBSD_NR_flock: /* flock(2) */ 46717a4d13cSWarner Losh ret = do_bsd_flock(arg1, arg2); 46817a4d13cSWarner Losh break; 46917a4d13cSWarner Losh 4705fbd8011SWarner Losh case TARGET_FREEBSD_NR_mkfifo: /* mkfifo(2) */ 4715fbd8011SWarner Losh ret = do_bsd_mkfifo(arg1, arg2); 4725fbd8011SWarner Losh break; 4735fbd8011SWarner Losh 4745fbd8011SWarner Losh case TARGET_FREEBSD_NR_mkfifoat: /* mkfifoat(2) */ 4755fbd8011SWarner Losh ret = do_bsd_mkfifoat(arg1, arg2, arg3); 4765fbd8011SWarner Losh break; 4775fbd8011SWarner Losh 478d3f29ddaSWarner Losh case TARGET_FREEBSD_NR_pathconf: /* pathconf(2) */ 479d3f29ddaSWarner Losh ret = do_bsd_pathconf(arg1, arg2); 480d3f29ddaSWarner Losh break; 481d3f29ddaSWarner Losh 482d3f29ddaSWarner Losh case TARGET_FREEBSD_NR_lpathconf: /* lpathconf(2) */ 483d3f29ddaSWarner Losh ret = do_bsd_lpathconf(arg1, arg2); 484d3f29ddaSWarner Losh break; 485d3f29ddaSWarner Losh 486d3f29ddaSWarner Losh case TARGET_FREEBSD_NR_fpathconf: /* fpathconf(2) */ 487d3f29ddaSWarner Losh ret = do_bsd_fpathconf(arg1, arg2); 488d3f29ddaSWarner Losh break; 489d3f29ddaSWarner Losh 490952d5d30SWarner Losh case TARGET_FREEBSD_NR_undelete: /* undelete(2) */ 491952d5d30SWarner Losh ret = do_bsd_undelete(arg1); 492952d5d30SWarner Losh break; 493952d5d30SWarner Losh 494fb96f5dfSStacey Son /* 495fb96f5dfSStacey Son * sys{ctl, arch, call} 496fb96f5dfSStacey Son */ 4977adda6deSKyle Evans case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */ 4987adda6deSKyle Evans ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 4997adda6deSKyle Evans break; 5007adda6deSKyle Evans 501*6da777e2SKyle Evans case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ 502*6da777e2SKyle Evans ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 503*6da777e2SKyle Evans break; 504*6da777e2SKyle Evans 505fb96f5dfSStacey Son case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ 506fb96f5dfSStacey Son ret = do_freebsd_sysarch(cpu_env, arg1, arg2); 507fb96f5dfSStacey Son break; 508fb96f5dfSStacey Son 509db697887SWarner Losh default: 510db697887SWarner Losh qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); 511db697887SWarner Losh ret = -TARGET_ENOSYS; 512db697887SWarner Losh break; 513db697887SWarner Losh } 514db697887SWarner Losh 515db697887SWarner Losh return ret; 516db697887SWarner Losh } 517db697887SWarner Losh 518db697887SWarner Losh /* 519db697887SWarner Losh * do_freebsd_syscall() should always have a single exit point at the end so 520db697887SWarner Losh * that actions, such as logging of syscall results, can be performed. This 521db697887SWarner Losh * as a wrapper around freebsd_syscall() so that actually happens. Since 522db697887SWarner Losh * that is a singleton, modern compilers will inline it anyway... 52366eed099SWarner Losh */ 52466eed099SWarner Losh abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, 52566eed099SWarner Losh abi_long arg2, abi_long arg3, abi_long arg4, 52666eed099SWarner Losh abi_long arg5, abi_long arg6, abi_long arg7, 52766eed099SWarner Losh abi_long arg8) 52866eed099SWarner Losh { 529db697887SWarner Losh CPUState *cpu = env_cpu(cpu_env); 5304cf41e80SDoug Rabson abi_long ret; 531db697887SWarner Losh 532db697887SWarner Losh trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); 533db697887SWarner Losh if (do_strace) { 534db697887SWarner Losh print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); 535db697887SWarner Losh } 536db697887SWarner Losh 537db697887SWarner Losh ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6, 538db697887SWarner Losh arg7, arg8); 539db697887SWarner Losh if (do_strace) { 540db697887SWarner Losh print_freebsd_syscall_ret(num, ret); 541db697887SWarner Losh } 542db697887SWarner Losh trace_guest_user_syscall_ret(cpu, num, ret); 543db697887SWarner Losh 544db697887SWarner Losh return ret; 54566eed099SWarner Losh } 54666eed099SWarner Losh 54766eed099SWarner Losh void syscall_init(void) 54866eed099SWarner Losh { 54966eed099SWarner Losh } 550