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 226a478416dSStacey Son case TARGET_FREEBSD_NR_getgroups: /* getgroups(2) */ 227a478416dSStacey Son ret = do_bsd_getgroups(arg1, arg2); 228a478416dSStacey Son break; 229a478416dSStacey Son 230a478416dSStacey Son case TARGET_FREEBSD_NR_setgroups: /* setgroups(2) */ 231a478416dSStacey Son ret = do_bsd_setgroups(arg1, arg2); 232a478416dSStacey Son break; 233a478416dSStacey Son 23482fe5f3aSStacey Son case TARGET_FREEBSD_NR_umask: /* umask(2) */ 23582fe5f3aSStacey Son ret = do_bsd_umask(arg1); 23682fe5f3aSStacey Son break; 23782fe5f3aSStacey Son 23882fe5f3aSStacey Son case TARGET_FREEBSD_NR_setlogin: /* setlogin(2) */ 23982fe5f3aSStacey Son ret = do_bsd_setlogin(arg1); 24082fe5f3aSStacey Son break; 24182fe5f3aSStacey Son 24282fe5f3aSStacey Son case TARGET_FREEBSD_NR_getlogin: /* getlogin(2) */ 24382fe5f3aSStacey Son ret = do_bsd_getlogin(arg1, arg2); 24482fe5f3aSStacey Son break; 24582fe5f3aSStacey Son 24659e801efSStacey Son case TARGET_FREEBSD_NR_getrusage: /* getrusage(2) */ 24759e801efSStacey Son ret = do_bsd_getrusage(arg1, arg2); 24859e801efSStacey Son break; 24959e801efSStacey Son 250*faba8e12SStacey Son case TARGET_FREEBSD_NR_getrlimit: /* getrlimit(2) */ 251*faba8e12SStacey Son ret = do_bsd_getrlimit(arg1, arg2); 252*faba8e12SStacey Son break; 253*faba8e12SStacey Son 254*faba8e12SStacey Son case TARGET_FREEBSD_NR_setrlimit: /* setrlimit(2) */ 255*faba8e12SStacey Son ret = do_bsd_setrlimit(arg1, arg2); 256*faba8e12SStacey Son break; 257*faba8e12SStacey Son 258a478416dSStacey Son 25980da1b00SWarner Losh /* 26080da1b00SWarner Losh * File system calls. 26180da1b00SWarner Losh */ 26280da1b00SWarner Losh case TARGET_FREEBSD_NR_read: /* read(2) */ 26380da1b00SWarner Losh ret = do_bsd_read(arg1, arg2, arg3); 26480da1b00SWarner Losh break; 26580da1b00SWarner Losh 26680da1b00SWarner Losh case TARGET_FREEBSD_NR_pread: /* pread(2) */ 26780da1b00SWarner Losh ret = do_bsd_pread(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 26880da1b00SWarner Losh break; 26980da1b00SWarner Losh 27080da1b00SWarner Losh case TARGET_FREEBSD_NR_readv: /* readv(2) */ 27180da1b00SWarner Losh ret = do_bsd_readv(arg1, arg2, arg3); 27280da1b00SWarner Losh break; 27380da1b00SWarner Losh 27480da1b00SWarner Losh case TARGET_FREEBSD_NR_preadv: /* preadv(2) */ 27580da1b00SWarner Losh ret = do_bsd_preadv(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 276f51e7c41SWarner Losh break; 277770d8abaSWarner Losh 278770d8abaSWarner Losh case TARGET_FREEBSD_NR_write: /* write(2) */ 279770d8abaSWarner Losh ret = do_bsd_write(arg1, arg2, arg3); 280770d8abaSWarner Losh break; 281770d8abaSWarner Losh 282770d8abaSWarner Losh case TARGET_FREEBSD_NR_pwrite: /* pwrite(2) */ 283770d8abaSWarner Losh ret = do_bsd_pwrite(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 284770d8abaSWarner Losh break; 285770d8abaSWarner Losh 286770d8abaSWarner Losh case TARGET_FREEBSD_NR_writev: /* writev(2) */ 287770d8abaSWarner Losh ret = do_bsd_writev(arg1, arg2, arg3); 288770d8abaSWarner Losh break; 289770d8abaSWarner Losh 290770d8abaSWarner Losh case TARGET_FREEBSD_NR_pwritev: /* pwritev(2) */ 291770d8abaSWarner Losh ret = do_bsd_pwritev(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 29280da1b00SWarner Losh break; 29380da1b00SWarner Losh 29477d3522bSWarner Losh case TARGET_FREEBSD_NR_open: /* open(2) */ 29577d3522bSWarner Losh ret = do_bsd_open(arg1, arg2, arg3); 29677d3522bSWarner Losh break; 29777d3522bSWarner Losh 29877d3522bSWarner Losh case TARGET_FREEBSD_NR_openat: /* openat(2) */ 29977d3522bSWarner Losh ret = do_bsd_openat(arg1, arg2, arg3, arg4); 30077d3522bSWarner Losh break; 30177d3522bSWarner Losh 30277d3522bSWarner Losh case TARGET_FREEBSD_NR_close: /* close(2) */ 30377d3522bSWarner Losh ret = do_bsd_close(arg1); 30477d3522bSWarner Losh break; 30577d3522bSWarner Losh 306a2ba6c7bSWarner Losh case TARGET_FREEBSD_NR_fdatasync: /* fdatasync(2) */ 307a2ba6c7bSWarner Losh ret = do_bsd_fdatasync(arg1); 308a2ba6c7bSWarner Losh break; 309a2ba6c7bSWarner Losh 310a2ba6c7bSWarner Losh case TARGET_FREEBSD_NR_fsync: /* fsync(2) */ 311a2ba6c7bSWarner Losh ret = do_bsd_fsync(arg1); 312a2ba6c7bSWarner Losh break; 313a2ba6c7bSWarner Losh 314a2ba6c7bSWarner Losh case TARGET_FREEBSD_NR_freebsd12_closefrom: /* closefrom(2) */ 315a2ba6c7bSWarner Losh ret = do_bsd_closefrom(arg1); 316a2ba6c7bSWarner Losh break; 317a2ba6c7bSWarner Losh 31865c6c4c8SWarner Losh case TARGET_FREEBSD_NR_revoke: /* revoke(2) */ 31965c6c4c8SWarner Losh ret = do_bsd_revoke(arg1); 32065c6c4c8SWarner Losh break; 32165c6c4c8SWarner Losh 32265c6c4c8SWarner Losh case TARGET_FREEBSD_NR_access: /* access(2) */ 32365c6c4c8SWarner Losh ret = do_bsd_access(arg1, arg2); 32465c6c4c8SWarner Losh break; 32565c6c4c8SWarner Losh 32665c6c4c8SWarner Losh case TARGET_FREEBSD_NR_eaccess: /* eaccess(2) */ 32765c6c4c8SWarner Losh ret = do_bsd_eaccess(arg1, arg2); 32865c6c4c8SWarner Losh break; 32965c6c4c8SWarner Losh 33065c6c4c8SWarner Losh case TARGET_FREEBSD_NR_faccessat: /* faccessat(2) */ 33165c6c4c8SWarner Losh ret = do_bsd_faccessat(arg1, arg2, arg3, arg4); 33265c6c4c8SWarner Losh break; 33365c6c4c8SWarner Losh 334390f547eSWarner Losh case TARGET_FREEBSD_NR_chdir: /* chdir(2) */ 335390f547eSWarner Losh ret = do_bsd_chdir(arg1); 336390f547eSWarner Losh break; 337390f547eSWarner Losh 338390f547eSWarner Losh case TARGET_FREEBSD_NR_fchdir: /* fchdir(2) */ 339390f547eSWarner Losh ret = do_bsd_fchdir(arg1); 340390f547eSWarner Losh break; 341390f547eSWarner Losh 342ab5fd2d9SWarner Losh case TARGET_FREEBSD_NR_rename: /* rename(2) */ 343ab5fd2d9SWarner Losh ret = do_bsd_rename(arg1, arg2); 344ab5fd2d9SWarner Losh break; 345ab5fd2d9SWarner Losh 346ab5fd2d9SWarner Losh case TARGET_FREEBSD_NR_renameat: /* renameat(2) */ 347ab5fd2d9SWarner Losh ret = do_bsd_renameat(arg1, arg2, arg3, arg4); 348ab5fd2d9SWarner Losh break; 349ab5fd2d9SWarner Losh 3502d3b7e01SWarner Losh case TARGET_FREEBSD_NR_link: /* link(2) */ 3512d3b7e01SWarner Losh ret = do_bsd_link(arg1, arg2); 3522d3b7e01SWarner Losh break; 3532d3b7e01SWarner Losh 3542d3b7e01SWarner Losh case TARGET_FREEBSD_NR_linkat: /* linkat(2) */ 3552d3b7e01SWarner Losh ret = do_bsd_linkat(arg1, arg2, arg3, arg4, arg5); 3562d3b7e01SWarner Losh break; 3572d3b7e01SWarner Losh 3582d3b7e01SWarner Losh case TARGET_FREEBSD_NR_unlink: /* unlink(2) */ 3592d3b7e01SWarner Losh ret = do_bsd_unlink(arg1); 3602d3b7e01SWarner Losh break; 3612d3b7e01SWarner Losh 3622d3b7e01SWarner Losh case TARGET_FREEBSD_NR_unlinkat: /* unlinkat(2) */ 3632d3b7e01SWarner Losh ret = do_bsd_unlinkat(arg1, arg2, arg3); 3642d3b7e01SWarner Losh break; 3652d3b7e01SWarner Losh 3661ffbd5e7SWarner Losh case TARGET_FREEBSD_NR_mkdir: /* mkdir(2) */ 3671ffbd5e7SWarner Losh ret = do_bsd_mkdir(arg1, arg2); 3681ffbd5e7SWarner Losh break; 3691ffbd5e7SWarner Losh 3701ffbd5e7SWarner Losh case TARGET_FREEBSD_NR_mkdirat: /* mkdirat(2) */ 3711ffbd5e7SWarner Losh ret = do_bsd_mkdirat(arg1, arg2, arg3); 3721ffbd5e7SWarner Losh break; 3731ffbd5e7SWarner Losh 3746af8f76aSWarner Losh case TARGET_FREEBSD_NR_rmdir: /* rmdir(2) (XXX no rmdirat()?) */ 3756af8f76aSWarner Losh ret = do_bsd_rmdir(arg1); 3766af8f76aSWarner Losh break; 3776af8f76aSWarner Losh 3786af8f76aSWarner Losh case TARGET_FREEBSD_NR___getcwd: /* undocumented __getcwd() */ 3796af8f76aSWarner Losh ret = do_bsd___getcwd(arg1, arg2); 3806af8f76aSWarner Losh break; 3816af8f76aSWarner Losh 382a15699acSWarner Losh case TARGET_FREEBSD_NR_dup: /* dup(2) */ 383a15699acSWarner Losh ret = do_bsd_dup(arg1); 384a15699acSWarner Losh break; 385a15699acSWarner Losh 386a15699acSWarner Losh case TARGET_FREEBSD_NR_dup2: /* dup2(2) */ 387a15699acSWarner Losh ret = do_bsd_dup2(arg1, arg2); 388a15699acSWarner Losh break; 389a15699acSWarner Losh 3904b795b14SWarner Losh case TARGET_FREEBSD_NR_truncate: /* truncate(2) */ 3914b795b14SWarner Losh ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4); 3924b795b14SWarner Losh break; 3934b795b14SWarner Losh 3944b795b14SWarner Losh case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */ 3954b795b14SWarner Losh ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4); 3964b795b14SWarner Losh break; 3974b795b14SWarner Losh 398d35020edSWarner Losh case TARGET_FREEBSD_NR_acct: /* acct(2) */ 399d35020edSWarner Losh ret = do_bsd_acct(arg1); 400d35020edSWarner Losh break; 401d35020edSWarner Losh 402d35020edSWarner Losh case TARGET_FREEBSD_NR_sync: /* sync(2) */ 403d35020edSWarner Losh ret = do_bsd_sync(); 404d35020edSWarner Losh break; 405d35020edSWarner Losh 406af2ae2e8SWarner Losh case TARGET_FREEBSD_NR_mount: /* mount(2) */ 407af2ae2e8SWarner Losh ret = do_bsd_mount(arg1, arg2, arg3, arg4); 408af2ae2e8SWarner Losh break; 409af2ae2e8SWarner Losh 410af2ae2e8SWarner Losh case TARGET_FREEBSD_NR_unmount: /* unmount(2) */ 411af2ae2e8SWarner Losh ret = do_bsd_unmount(arg1, arg2); 412af2ae2e8SWarner Losh break; 413af2ae2e8SWarner Losh 414af2ae2e8SWarner Losh case TARGET_FREEBSD_NR_nmount: /* nmount(2) */ 415af2ae2e8SWarner Losh ret = do_bsd_nmount(arg1, arg2, arg3); 416af2ae2e8SWarner Losh break; 417af2ae2e8SWarner Losh 418c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_symlink: /* symlink(2) */ 419c7b62b4aSWarner Losh ret = do_bsd_symlink(arg1, arg2); 420c7b62b4aSWarner Losh break; 421c7b62b4aSWarner Losh 422c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_symlinkat: /* symlinkat(2) */ 423c7b62b4aSWarner Losh ret = do_bsd_symlinkat(arg1, arg2, arg3); 424c7b62b4aSWarner Losh break; 425c7b62b4aSWarner Losh 426c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_readlink: /* readlink(2) */ 427c7b62b4aSWarner Losh ret = do_bsd_readlink(cpu_env, arg1, arg2, arg3); 428c7b62b4aSWarner Losh break; 429c7b62b4aSWarner Losh 430c7b62b4aSWarner Losh case TARGET_FREEBSD_NR_readlinkat: /* readlinkat(2) */ 431c7b62b4aSWarner Losh ret = do_bsd_readlinkat(arg1, arg2, arg3, arg4); 432c7b62b4aSWarner Losh break; 433c7b62b4aSWarner Losh 4340db0db8fSWarner Losh case TARGET_FREEBSD_NR_chmod: /* chmod(2) */ 4350db0db8fSWarner Losh ret = do_bsd_chmod(arg1, arg2); 4360db0db8fSWarner Losh break; 4370db0db8fSWarner Losh 4380db0db8fSWarner Losh case TARGET_FREEBSD_NR_fchmod: /* fchmod(2) */ 4390db0db8fSWarner Losh ret = do_bsd_fchmod(arg1, arg2); 4400db0db8fSWarner Losh break; 4410db0db8fSWarner Losh 4420db0db8fSWarner Losh case TARGET_FREEBSD_NR_lchmod: /* lchmod(2) */ 4430db0db8fSWarner Losh ret = do_bsd_lchmod(arg1, arg2); 4440db0db8fSWarner Losh break; 4450db0db8fSWarner Losh 4460db0db8fSWarner Losh case TARGET_FREEBSD_NR_fchmodat: /* fchmodat(2) */ 4470db0db8fSWarner Losh ret = do_bsd_fchmodat(arg1, arg2, arg3, arg4); 4480db0db8fSWarner Losh break; 4490db0db8fSWarner Losh 45079cfae0cSWarner Losh case TARGET_FREEBSD_NR_freebsd11_mknod: /* mknod(2) */ 45179cfae0cSWarner Losh ret = do_bsd_freebsd11_mknod(arg1, arg2, arg3); 45279cfae0cSWarner Losh break; 45379cfae0cSWarner Losh 45479cfae0cSWarner Losh case TARGET_FREEBSD_NR_freebsd11_mknodat: /* mknodat(2) */ 45579cfae0cSWarner Losh ret = do_bsd_freebsd11_mknodat(arg1, arg2, arg3, arg4); 45679cfae0cSWarner Losh break; 45779cfae0cSWarner Losh 45879cfae0cSWarner Losh case TARGET_FREEBSD_NR_mknodat: /* mknodat(2) */ 45979cfae0cSWarner Losh ret = do_bsd_mknodat(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 46079cfae0cSWarner Losh break; 46179cfae0cSWarner Losh 46258af3e29SWarner Losh case TARGET_FREEBSD_NR_chown: /* chown(2) */ 46358af3e29SWarner Losh ret = do_bsd_chown(arg1, arg2, arg3); 46458af3e29SWarner Losh break; 46558af3e29SWarner Losh 46658af3e29SWarner Losh case TARGET_FREEBSD_NR_fchown: /* fchown(2) */ 46758af3e29SWarner Losh ret = do_bsd_fchown(arg1, arg2, arg3); 46858af3e29SWarner Losh break; 46958af3e29SWarner Losh 47058af3e29SWarner Losh case TARGET_FREEBSD_NR_lchown: /* lchown(2) */ 47158af3e29SWarner Losh ret = do_bsd_lchown(arg1, arg2, arg3); 47258af3e29SWarner Losh break; 47358af3e29SWarner Losh 47458af3e29SWarner Losh case TARGET_FREEBSD_NR_fchownat: /* fchownat(2) */ 47558af3e29SWarner Losh ret = do_bsd_fchownat(arg1, arg2, arg3, arg4, arg5); 47658af3e29SWarner Losh break; 47758af3e29SWarner Losh 478c6f0a7d9SWarner Losh case TARGET_FREEBSD_NR_chflags: /* chflags(2) */ 479c6f0a7d9SWarner Losh ret = do_bsd_chflags(arg1, arg2); 480c6f0a7d9SWarner Losh break; 481c6f0a7d9SWarner Losh 482c6f0a7d9SWarner Losh case TARGET_FREEBSD_NR_lchflags: /* lchflags(2) */ 483c6f0a7d9SWarner Losh ret = do_bsd_lchflags(arg1, arg2); 484c6f0a7d9SWarner Losh break; 485c6f0a7d9SWarner Losh 486c6f0a7d9SWarner Losh case TARGET_FREEBSD_NR_fchflags: /* fchflags(2) */ 487c6f0a7d9SWarner Losh ret = do_bsd_fchflags(arg1, arg2); 488c6f0a7d9SWarner Losh break; 489c6f0a7d9SWarner Losh 49017a4d13cSWarner Losh case TARGET_FREEBSD_NR_chroot: /* chroot(2) */ 49117a4d13cSWarner Losh ret = do_bsd_chroot(arg1); 49217a4d13cSWarner Losh break; 49317a4d13cSWarner Losh 49417a4d13cSWarner Losh case TARGET_FREEBSD_NR_flock: /* flock(2) */ 49517a4d13cSWarner Losh ret = do_bsd_flock(arg1, arg2); 49617a4d13cSWarner Losh break; 49717a4d13cSWarner Losh 4985fbd8011SWarner Losh case TARGET_FREEBSD_NR_mkfifo: /* mkfifo(2) */ 4995fbd8011SWarner Losh ret = do_bsd_mkfifo(arg1, arg2); 5005fbd8011SWarner Losh break; 5015fbd8011SWarner Losh 5025fbd8011SWarner Losh case TARGET_FREEBSD_NR_mkfifoat: /* mkfifoat(2) */ 5035fbd8011SWarner Losh ret = do_bsd_mkfifoat(arg1, arg2, arg3); 5045fbd8011SWarner Losh break; 5055fbd8011SWarner Losh 506d3f29ddaSWarner Losh case TARGET_FREEBSD_NR_pathconf: /* pathconf(2) */ 507d3f29ddaSWarner Losh ret = do_bsd_pathconf(arg1, arg2); 508d3f29ddaSWarner Losh break; 509d3f29ddaSWarner Losh 510d3f29ddaSWarner Losh case TARGET_FREEBSD_NR_lpathconf: /* lpathconf(2) */ 511d3f29ddaSWarner Losh ret = do_bsd_lpathconf(arg1, arg2); 512d3f29ddaSWarner Losh break; 513d3f29ddaSWarner Losh 514d3f29ddaSWarner Losh case TARGET_FREEBSD_NR_fpathconf: /* fpathconf(2) */ 515d3f29ddaSWarner Losh ret = do_bsd_fpathconf(arg1, arg2); 516d3f29ddaSWarner Losh break; 517d3f29ddaSWarner Losh 518952d5d30SWarner Losh case TARGET_FREEBSD_NR_undelete: /* undelete(2) */ 519952d5d30SWarner Losh ret = do_bsd_undelete(arg1); 520952d5d30SWarner Losh break; 521952d5d30SWarner Losh 522fb96f5dfSStacey Son /* 523e800e6c5SWarner Losh * stat system calls 524e800e6c5SWarner Losh */ 525e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_stat: /* stat(2) */ 526e800e6c5SWarner Losh ret = do_freebsd11_stat(arg1, arg2); 527e800e6c5SWarner Losh break; 528e800e6c5SWarner Losh 529e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_lstat: /* lstat(2) */ 530e800e6c5SWarner Losh ret = do_freebsd11_lstat(arg1, arg2); 531e800e6c5SWarner Losh break; 532e800e6c5SWarner Losh 533e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_fstat: /* fstat(2) */ 534e800e6c5SWarner Losh ret = do_freebsd11_fstat(arg1, arg2); 535e800e6c5SWarner Losh break; 536e800e6c5SWarner Losh 537e800e6c5SWarner Losh case TARGET_FREEBSD_NR_fstat: /* fstat(2) */ 538e800e6c5SWarner Losh ret = do_freebsd_fstat(arg1, arg2); 539e800e6c5SWarner Losh break; 540e800e6c5SWarner Losh 541e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_fstatat: /* fstatat(2) */ 542e800e6c5SWarner Losh ret = do_freebsd11_fstatat(arg1, arg2, arg3, arg4); 543e800e6c5SWarner Losh break; 544e800e6c5SWarner Losh 545e800e6c5SWarner Losh case TARGET_FREEBSD_NR_fstatat: /* fstatat(2) */ 546e800e6c5SWarner Losh ret = do_freebsd_fstatat(arg1, arg2, arg3, arg4); 547e800e6c5SWarner Losh break; 548e800e6c5SWarner Losh 549e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_nstat: /* undocumented */ 550e800e6c5SWarner Losh ret = do_freebsd11_nstat(arg1, arg2); 551e800e6c5SWarner Losh break; 552e800e6c5SWarner Losh 553e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_nfstat: /* undocumented */ 554e800e6c5SWarner Losh ret = do_freebsd11_nfstat(arg1, arg2); 555e800e6c5SWarner Losh break; 556e800e6c5SWarner Losh 557e800e6c5SWarner Losh case TARGET_FREEBSD_NR_freebsd11_nlstat: /* undocumented */ 558e800e6c5SWarner Losh ret = do_freebsd11_nlstat(arg1, arg2); 559e800e6c5SWarner Losh break; 560e800e6c5SWarner Losh 5616fe97c6cSWarner Losh case TARGET_FREEBSD_NR_getfh: /* getfh(2) */ 5626fe97c6cSWarner Losh ret = do_freebsd_getfh(arg1, arg2); 5636fe97c6cSWarner Losh break; 5646fe97c6cSWarner Losh 5656fe97c6cSWarner Losh case TARGET_FREEBSD_NR_lgetfh: /* lgetfh(2) */ 5666fe97c6cSWarner Losh ret = do_freebsd_lgetfh(arg1, arg2); 5676fe97c6cSWarner Losh break; 5686fe97c6cSWarner Losh 5696fe97c6cSWarner Losh case TARGET_FREEBSD_NR_fhopen: /* fhopen(2) */ 5706fe97c6cSWarner Losh ret = do_freebsd_fhopen(arg1, arg2); 5716fe97c6cSWarner Losh break; 5726fe97c6cSWarner Losh 5736fe97c6cSWarner Losh case TARGET_FREEBSD_NR_freebsd11_fhstat: /* fhstat(2) */ 5746fe97c6cSWarner Losh ret = do_freebsd11_fhstat(arg1, arg2); 5756fe97c6cSWarner Losh break; 5766fe97c6cSWarner Losh 5776fe97c6cSWarner Losh case TARGET_FREEBSD_NR_fhstat: /* fhstat(2) */ 5786fe97c6cSWarner Losh ret = do_freebsd_fhstat(arg1, arg2); 5796fe97c6cSWarner Losh break; 5806fe97c6cSWarner Losh 5816fe97c6cSWarner Losh case TARGET_FREEBSD_NR_freebsd11_fhstatfs: /* fhstatfs(2) */ 5826fe97c6cSWarner Losh ret = do_freebsd11_fhstatfs(arg1, arg2); 5836fe97c6cSWarner Losh break; 5846fe97c6cSWarner Losh 5856fe97c6cSWarner Losh case TARGET_FREEBSD_NR_fhstatfs: /* fhstatfs(2) */ 5866fe97c6cSWarner Losh ret = do_freebsd_fhstatfs(arg1, arg2); 5876fe97c6cSWarner Losh break; 5886fe97c6cSWarner Losh 589d7e9a545SWarner Losh case TARGET_FREEBSD_NR_freebsd11_statfs: /* statfs(2) */ 590d7e9a545SWarner Losh ret = do_freebsd11_statfs(arg1, arg2); 591d7e9a545SWarner Losh break; 592d7e9a545SWarner Losh 593d7e9a545SWarner Losh case TARGET_FREEBSD_NR_statfs: /* statfs(2) */ 594d7e9a545SWarner Losh ret = do_freebsd_statfs(arg1, arg2); 595d7e9a545SWarner Losh break; 596d7e9a545SWarner Losh 597d7e9a545SWarner Losh case TARGET_FREEBSD_NR_freebsd11_fstatfs: /* fstatfs(2) */ 598d7e9a545SWarner Losh ret = do_freebsd11_fstatfs(arg1, arg2); 599d7e9a545SWarner Losh break; 600d7e9a545SWarner Losh 601d7e9a545SWarner Losh case TARGET_FREEBSD_NR_fstatfs: /* fstatfs(2) */ 602d7e9a545SWarner Losh ret = do_freebsd_fstatfs(arg1, arg2); 603d7e9a545SWarner Losh break; 604d7e9a545SWarner Losh 605d7e9a545SWarner Losh case TARGET_FREEBSD_NR_freebsd11_getfsstat: /* getfsstat(2) */ 606d7e9a545SWarner Losh ret = do_freebsd11_getfsstat(arg1, arg2, arg3); 607d7e9a545SWarner Losh break; 608d7e9a545SWarner Losh 609d7e9a545SWarner Losh case TARGET_FREEBSD_NR_getfsstat: /* getfsstat(2) */ 610d7e9a545SWarner Losh ret = do_freebsd_getfsstat(arg1, arg2, arg3); 611d7e9a545SWarner Losh break; 612d7e9a545SWarner Losh 61397a3c571SWarner Losh case TARGET_FREEBSD_NR_freebsd11_getdents: /* getdents(2) */ 61497a3c571SWarner Losh ret = do_freebsd11_getdents(arg1, arg2, arg3); 61597a3c571SWarner Losh break; 61697a3c571SWarner Losh 61797a3c571SWarner Losh case TARGET_FREEBSD_NR_getdirentries: /* getdirentries(2) */ 61897a3c571SWarner Losh ret = do_freebsd_getdirentries(arg1, arg2, arg3, arg4); 61997a3c571SWarner Losh break; 62097a3c571SWarner Losh 62197a3c571SWarner Losh case TARGET_FREEBSD_NR_freebsd11_getdirentries: /* getdirentries(2) */ 62297a3c571SWarner Losh ret = do_freebsd11_getdirentries(arg1, arg2, arg3, arg4); 62397a3c571SWarner Losh break; 62497a3c571SWarner Losh case TARGET_FREEBSD_NR_fcntl: /* fcntl(2) */ 62597a3c571SWarner Losh ret = do_freebsd_fcntl(arg1, arg2, arg3); 62697a3c571SWarner Losh break; 62797a3c571SWarner Losh 62897a3c571SWarner Losh 629e800e6c5SWarner Losh /* 630fb96f5dfSStacey Son * sys{ctl, arch, call} 631fb96f5dfSStacey Son */ 6327adda6deSKyle Evans case TARGET_FREEBSD_NR___sysctl: /* sysctl(3) */ 6337adda6deSKyle Evans ret = do_freebsd_sysctl(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 6347adda6deSKyle Evans break; 6357adda6deSKyle Evans 6366da777e2SKyle Evans case TARGET_FREEBSD_NR___sysctlbyname: /* sysctlbyname(2) */ 6376da777e2SKyle Evans ret = do_freebsd_sysctlbyname(cpu_env, arg1, arg2, arg3, arg4, arg5, arg6); 6386da777e2SKyle Evans break; 6396da777e2SKyle Evans 640fb96f5dfSStacey Son case TARGET_FREEBSD_NR_sysarch: /* sysarch(2) */ 641fb96f5dfSStacey Son ret = do_freebsd_sysarch(cpu_env, arg1, arg2); 642fb96f5dfSStacey Son break; 643fb96f5dfSStacey Son 644db697887SWarner Losh default: 645db697887SWarner Losh qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); 646db697887SWarner Losh ret = -TARGET_ENOSYS; 647db697887SWarner Losh break; 648db697887SWarner Losh } 649db697887SWarner Losh 650db697887SWarner Losh return ret; 651db697887SWarner Losh } 652db697887SWarner Losh 653db697887SWarner Losh /* 654db697887SWarner Losh * do_freebsd_syscall() should always have a single exit point at the end so 655db697887SWarner Losh * that actions, such as logging of syscall results, can be performed. This 656db697887SWarner Losh * as a wrapper around freebsd_syscall() so that actually happens. Since 657db697887SWarner Losh * that is a singleton, modern compilers will inline it anyway... 65866eed099SWarner Losh */ 65966eed099SWarner Losh abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, 66066eed099SWarner Losh abi_long arg2, abi_long arg3, abi_long arg4, 66166eed099SWarner Losh abi_long arg5, abi_long arg6, abi_long arg7, 66266eed099SWarner Losh abi_long arg8) 66366eed099SWarner Losh { 6644cf41e80SDoug Rabson abi_long ret; 665db697887SWarner Losh 666db697887SWarner Losh if (do_strace) { 667db697887SWarner Losh print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); 668db697887SWarner Losh } 669db697887SWarner Losh 670db697887SWarner Losh ret = freebsd_syscall(cpu_env, num, arg1, arg2, arg3, arg4, arg5, arg6, 671db697887SWarner Losh arg7, arg8); 672db697887SWarner Losh if (do_strace) { 673db697887SWarner Losh print_freebsd_syscall_ret(num, ret); 674db697887SWarner Losh } 675db697887SWarner Losh 676db697887SWarner Losh return ret; 67766eed099SWarner Losh } 67866eed099SWarner Losh 67966eed099SWarner Losh void syscall_init(void) 68066eed099SWarner Losh { 68166eed099SWarner Losh } 682