4 * Copyright (c) 2003 - 2008 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
29 #include <sys/types.h>
31 #include <sys/syscall.h>
36 #include "qemu-common.h"
40 static abi_ulong target_brk;
41 static abi_ulong target_original_brk;
43 #define get_errno(x) (x)
44 #define target_to_host_bitmask(x, tbl) (x)
46 void target_set_brk(abi_ulong new_brk)
48 target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk);
51 /* do_syscall() should always have a single exit point at the end so
52 that actions, such as logging of syscall results, can be performed.
53 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
54 abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
55 abi_long arg2, abi_long arg3, abi_long arg4,
56 abi_long arg5, abi_long arg6)
62 gemu_log("freebsd syscall %d\n", num);
65 print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
68 case TARGET_FREEBSD_NR_exit:
72 gdb_exit(cpu_env, arg1);
73 /* XXX: should free thread stack and CPU env */
75 ret = 0; /* avoid warning */
77 case TARGET_FREEBSD_NR_read:
78 if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
80 ret = get_errno(read(arg1, p, arg3));
81 unlock_user(p, arg2, ret);
83 case TARGET_FREEBSD_NR_write:
84 if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
86 ret = get_errno(write(arg1, p, arg3));
87 unlock_user(p, arg2, 0);
89 case TARGET_FREEBSD_NR_open:
90 if (!(p = lock_user_string(arg1)))
92 ret = get_errno(open(path(p),
93 target_to_host_bitmask(arg2, fcntl_flags_tbl),
95 unlock_user(p, arg1, 0);
97 case TARGET_FREEBSD_NR_mmap:
98 ret = get_errno(target_mmap(arg1, arg2, arg3,
99 target_to_host_bitmask(arg4, mmap_flags_tbl),
103 case TARGET_FREEBSD_NR_mprotect:
104 ret = get_errno(target_mprotect(arg1, arg2, arg3));
106 case TARGET_FREEBSD_NR_syscall:
107 case TARGET_FREEBSD_NR___syscall:
108 ret = do_freebsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
111 ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
116 gemu_log(" = %ld\n", ret);
119 print_freebsd_syscall_ret(num, ret);
122 ret = -TARGET_EFAULT;
126 abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
127 abi_long arg2, abi_long arg3, abi_long arg4,
128 abi_long arg5, abi_long arg6)
134 gemu_log("netbsd syscall %d\n", num);
137 print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
140 case TARGET_NETBSD_NR_exit:
144 gdb_exit(cpu_env, arg1);
145 /* XXX: should free thread stack and CPU env */
147 ret = 0; /* avoid warning */
149 case TARGET_NETBSD_NR_read:
150 if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
152 ret = get_errno(read(arg1, p, arg3));
153 unlock_user(p, arg2, ret);
155 case TARGET_NETBSD_NR_write:
156 if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
158 ret = get_errno(write(arg1, p, arg3));
159 unlock_user(p, arg2, 0);
161 case TARGET_NETBSD_NR_open:
162 if (!(p = lock_user_string(arg1)))
164 ret = get_errno(open(path(p),
165 target_to_host_bitmask(arg2, fcntl_flags_tbl),
167 unlock_user(p, arg1, 0);
169 case TARGET_NETBSD_NR_mmap:
170 ret = get_errno(target_mmap(arg1, arg2, arg3,
171 target_to_host_bitmask(arg4, mmap_flags_tbl),
175 case TARGET_NETBSD_NR_mprotect:
176 ret = get_errno(target_mprotect(arg1, arg2, arg3));
178 case TARGET_NETBSD_NR_syscall:
179 case TARGET_NETBSD_NR___syscall:
180 ret = do_netbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
183 ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
188 gemu_log(" = %ld\n", ret);
191 print_netbsd_syscall_ret(num, ret);
194 ret = -TARGET_EFAULT;
198 abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
199 abi_long arg2, abi_long arg3, abi_long arg4,
200 abi_long arg5, abi_long arg6)
206 gemu_log("openbsd syscall %d\n", num);
209 print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
212 case TARGET_OPENBSD_NR_exit:
216 gdb_exit(cpu_env, arg1);
217 /* XXX: should free thread stack and CPU env */
219 ret = 0; /* avoid warning */
221 case TARGET_OPENBSD_NR_read:
222 if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
224 ret = get_errno(read(arg1, p, arg3));
225 unlock_user(p, arg2, ret);
227 case TARGET_OPENBSD_NR_write:
228 if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
230 ret = get_errno(write(arg1, p, arg3));
231 unlock_user(p, arg2, 0);
233 case TARGET_OPENBSD_NR_open:
234 if (!(p = lock_user_string(arg1)))
236 ret = get_errno(open(path(p),
237 target_to_host_bitmask(arg2, fcntl_flags_tbl),
239 unlock_user(p, arg1, 0);
241 case TARGET_OPENBSD_NR_mmap:
242 ret = get_errno(target_mmap(arg1, arg2, arg3,
243 target_to_host_bitmask(arg4, mmap_flags_tbl),
247 case TARGET_OPENBSD_NR_mprotect:
248 ret = get_errno(target_mprotect(arg1, arg2, arg3));
250 case TARGET_OPENBSD_NR_syscall:
251 case TARGET_OPENBSD_NR___syscall:
252 ret = do_openbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0);
255 ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
260 gemu_log(" = %ld\n", ret);
263 print_openbsd_syscall_ret(num, ret);
266 ret = -TARGET_EFAULT;
270 void syscall_init(void)