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> 3566eed099SWarner Losh #include <sys/param.h> 3666eed099SWarner Losh #include <sys/sysctl.h> 3766eed099SWarner Losh #include <utime.h> 3866eed099SWarner Losh 3966eed099SWarner Losh #include "qemu.h" 4066eed099SWarner Losh #include "qemu-common.h" 4166eed099SWarner Losh #include "signal-common.h" 4266eed099SWarner Losh #include "user/syscall-trace.h" 4366eed099SWarner Losh 44*c5c84d16SWarner Losh #include "bsd-file.h" 45*c5c84d16SWarner Losh 4666eed099SWarner Losh void target_set_brk(abi_ulong new_brk) 4766eed099SWarner Losh { 4866eed099SWarner Losh } 4966eed099SWarner Losh 50deeff83bSWarner Losh /* 51deeff83bSWarner Losh * errno conversion. 52deeff83bSWarner Losh */ 53deeff83bSWarner Losh abi_long get_errno(abi_long ret) 54deeff83bSWarner Losh { 55deeff83bSWarner Losh if (ret == -1) { 56deeff83bSWarner Losh return -host_to_target_errno(errno); 57deeff83bSWarner Losh } else { 58deeff83bSWarner Losh return ret; 59deeff83bSWarner Losh } 60deeff83bSWarner Losh } 61deeff83bSWarner Losh 62deeff83bSWarner Losh int host_to_target_errno(int err) 63deeff83bSWarner Losh { 64deeff83bSWarner Losh /* 65deeff83bSWarner Losh * All the BSDs have the property that the error numbers are uniform across 66deeff83bSWarner Losh * all architectures for a given BSD, though they may vary between different 67deeff83bSWarner Losh * BSDs. 68deeff83bSWarner Losh */ 69deeff83bSWarner Losh return err; 70deeff83bSWarner Losh } 71deeff83bSWarner Losh 7266eed099SWarner Losh bool is_error(abi_long ret) 7366eed099SWarner Losh { 7466eed099SWarner Losh return (abi_ulong)ret >= (abi_ulong)(-4096); 7566eed099SWarner Losh } 7666eed099SWarner Losh 7766eed099SWarner Losh /* 7866eed099SWarner Losh * do_syscall() should always have a single exit point at the end so that 7966eed099SWarner Losh * actions, such as logging of syscall results, can be performed. All errnos 8066eed099SWarner Losh * that do_syscall() returns must be -TARGET_<errcode>. 8166eed099SWarner Losh */ 8266eed099SWarner Losh abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, 8366eed099SWarner Losh abi_long arg2, abi_long arg3, abi_long arg4, 8466eed099SWarner Losh abi_long arg5, abi_long arg6, abi_long arg7, 8566eed099SWarner Losh abi_long arg8) 8666eed099SWarner Losh { 8766eed099SWarner Losh return 0; 8866eed099SWarner Losh } 8966eed099SWarner Losh 9066eed099SWarner Losh void syscall_init(void) 9166eed099SWarner Losh { 9266eed099SWarner Losh } 93