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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <sys/types.h>
32 #include <sys/syscall.h>
37 #include "qemu-common.h"
41 static abi_ulong target_brk
;
42 static abi_ulong target_original_brk
;
44 #define get_errno(x) (x)
45 #define target_to_host_bitmask(x, tbl) (x)
47 void target_set_brk(abi_ulong new_brk
)
49 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
52 /* do_syscall() should always have a single exit point at the end so
53 that actions, such as logging of syscall results, can be performed.
54 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
55 abi_long
do_freebsd_syscall(void *cpu_env
, int num
, abi_long arg1
,
56 abi_long arg2
, abi_long arg3
, abi_long arg4
,
57 abi_long arg5
, abi_long arg6
)
63 gemu_log("freebsd syscall %d\n", num
);
66 print_freebsd_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
69 case TARGET_FREEBSD_NR_exit
:
73 gdb_exit(cpu_env
, arg1
);
74 /* XXX: should free thread stack and CPU env */
76 ret
= 0; /* avoid warning */
78 case TARGET_FREEBSD_NR_read
:
79 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
81 ret
= get_errno(read(arg1
, p
, arg3
));
82 unlock_user(p
, arg2
, ret
);
84 case TARGET_FREEBSD_NR_write
:
85 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
87 ret
= get_errno(write(arg1
, p
, arg3
));
88 unlock_user(p
, arg2
, 0);
90 case TARGET_FREEBSD_NR_open
:
91 if (!(p
= lock_user_string(arg1
)))
93 ret
= get_errno(open(path(p
),
94 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
96 unlock_user(p
, arg1
, 0);
98 case TARGET_FREEBSD_NR_mmap
:
99 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
100 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
104 case TARGET_FREEBSD_NR_mprotect
:
105 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
107 case TARGET_FREEBSD_NR_syscall
:
108 case TARGET_FREEBSD_NR___syscall
:
109 ret
= do_freebsd_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
112 ret
= syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
117 gemu_log(" = %ld\n", ret
);
120 print_freebsd_syscall_ret(num
, ret
);
123 ret
= -TARGET_EFAULT
;
127 abi_long
do_netbsd_syscall(void *cpu_env
, int num
, abi_long arg1
,
128 abi_long arg2
, abi_long arg3
, abi_long arg4
,
129 abi_long arg5
, abi_long arg6
)
135 gemu_log("netbsd syscall %d\n", num
);
138 print_netbsd_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
141 case TARGET_NETBSD_NR_exit
:
145 gdb_exit(cpu_env
, arg1
);
146 /* XXX: should free thread stack and CPU env */
148 ret
= 0; /* avoid warning */
150 case TARGET_NETBSD_NR_read
:
151 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
153 ret
= get_errno(read(arg1
, p
, arg3
));
154 unlock_user(p
, arg2
, ret
);
156 case TARGET_NETBSD_NR_write
:
157 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
159 ret
= get_errno(write(arg1
, p
, arg3
));
160 unlock_user(p
, arg2
, 0);
162 case TARGET_NETBSD_NR_open
:
163 if (!(p
= lock_user_string(arg1
)))
165 ret
= get_errno(open(path(p
),
166 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
168 unlock_user(p
, arg1
, 0);
170 case TARGET_NETBSD_NR_mmap
:
171 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
172 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
176 case TARGET_NETBSD_NR_mprotect
:
177 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
179 case TARGET_NETBSD_NR_syscall
:
180 case TARGET_NETBSD_NR___syscall
:
181 ret
= do_netbsd_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
184 ret
= syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
189 gemu_log(" = %ld\n", ret
);
192 print_netbsd_syscall_ret(num
, ret
);
195 ret
= -TARGET_EFAULT
;
199 abi_long
do_openbsd_syscall(void *cpu_env
, int num
, abi_long arg1
,
200 abi_long arg2
, abi_long arg3
, abi_long arg4
,
201 abi_long arg5
, abi_long arg6
)
207 gemu_log("openbsd syscall %d\n", num
);
210 print_openbsd_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
213 case TARGET_OPENBSD_NR_exit
:
217 gdb_exit(cpu_env
, arg1
);
218 /* XXX: should free thread stack and CPU env */
220 ret
= 0; /* avoid warning */
222 case TARGET_OPENBSD_NR_read
:
223 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
225 ret
= get_errno(read(arg1
, p
, arg3
));
226 unlock_user(p
, arg2
, ret
);
228 case TARGET_OPENBSD_NR_write
:
229 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
231 ret
= get_errno(write(arg1
, p
, arg3
));
232 unlock_user(p
, arg2
, 0);
234 case TARGET_OPENBSD_NR_open
:
235 if (!(p
= lock_user_string(arg1
)))
237 ret
= get_errno(open(path(p
),
238 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
240 unlock_user(p
, arg1
, 0);
242 case TARGET_OPENBSD_NR_mmap
:
243 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
244 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
248 case TARGET_OPENBSD_NR_mprotect
:
249 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
251 case TARGET_OPENBSD_NR_syscall
:
252 case TARGET_OPENBSD_NR___syscall
:
253 ret
= do_openbsd_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
256 ret
= syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
261 gemu_log(" = %ld\n", ret
);
264 print_openbsd_syscall_ret(num
, ret
);
267 ret
= -TARGET_EFAULT
;
271 void syscall_init(void)