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., 51 Franklin Street - Fifth Floor, Boston,
31 #include <sys/types.h>
33 #include <sys/syscall.h>
38 #include "qemu-common.h"
42 static abi_ulong target_brk
;
43 static abi_ulong target_original_brk
;
45 #define get_errno(x) (x)
46 #define target_to_host_bitmask(x, tbl) (x)
48 void target_set_brk(abi_ulong new_brk
)
50 target_original_brk
= target_brk
= HOST_PAGE_ALIGN(new_brk
);
53 /* do_syscall() should always have a single exit point at the end so
54 that actions, such as logging of syscall results, can be performed.
55 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
56 abi_long
do_freebsd_syscall(void *cpu_env
, int num
, abi_long arg1
,
57 abi_long arg2
, abi_long arg3
, abi_long arg4
,
58 abi_long arg5
, abi_long arg6
)
64 gemu_log("freebsd syscall %d\n", num
);
67 print_freebsd_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
70 case TARGET_FREEBSD_NR_exit
:
74 gdb_exit(cpu_env
, arg1
);
75 /* XXX: should free thread stack and CPU env */
77 ret
= 0; /* avoid warning */
79 case TARGET_FREEBSD_NR_read
:
80 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
82 ret
= get_errno(read(arg1
, p
, arg3
));
83 unlock_user(p
, arg2
, ret
);
85 case TARGET_FREEBSD_NR_write
:
86 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
88 ret
= get_errno(write(arg1
, p
, arg3
));
89 unlock_user(p
, arg2
, 0);
91 case TARGET_FREEBSD_NR_open
:
92 if (!(p
= lock_user_string(arg1
)))
94 ret
= get_errno(open(path(p
),
95 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
97 unlock_user(p
, arg1
, 0);
99 case TARGET_FREEBSD_NR_mmap
:
100 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
101 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
105 case TARGET_FREEBSD_NR_mprotect
:
106 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
108 case TARGET_FREEBSD_NR_syscall
:
109 case TARGET_FREEBSD_NR___syscall
:
110 ret
= do_freebsd_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
113 ret
= syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
118 gemu_log(" = %ld\n", ret
);
121 print_freebsd_syscall_ret(num
, ret
);
124 ret
= -TARGET_EFAULT
;
128 abi_long
do_netbsd_syscall(void *cpu_env
, int num
, abi_long arg1
,
129 abi_long arg2
, abi_long arg3
, abi_long arg4
,
130 abi_long arg5
, abi_long arg6
)
136 gemu_log("netbsd syscall %d\n", num
);
139 print_netbsd_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
142 case TARGET_NETBSD_NR_exit
:
146 gdb_exit(cpu_env
, arg1
);
147 /* XXX: should free thread stack and CPU env */
149 ret
= 0; /* avoid warning */
151 case TARGET_NETBSD_NR_read
:
152 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
154 ret
= get_errno(read(arg1
, p
, arg3
));
155 unlock_user(p
, arg2
, ret
);
157 case TARGET_NETBSD_NR_write
:
158 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
160 ret
= get_errno(write(arg1
, p
, arg3
));
161 unlock_user(p
, arg2
, 0);
163 case TARGET_NETBSD_NR_open
:
164 if (!(p
= lock_user_string(arg1
)))
166 ret
= get_errno(open(path(p
),
167 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
169 unlock_user(p
, arg1
, 0);
171 case TARGET_NETBSD_NR_mmap
:
172 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
173 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
177 case TARGET_NETBSD_NR_mprotect
:
178 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
180 case TARGET_NETBSD_NR_syscall
:
181 case TARGET_NETBSD_NR___syscall
:
182 ret
= do_netbsd_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
185 ret
= syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
190 gemu_log(" = %ld\n", ret
);
193 print_netbsd_syscall_ret(num
, ret
);
196 ret
= -TARGET_EFAULT
;
200 abi_long
do_openbsd_syscall(void *cpu_env
, int num
, abi_long arg1
,
201 abi_long arg2
, abi_long arg3
, abi_long arg4
,
202 abi_long arg5
, abi_long arg6
)
208 gemu_log("openbsd syscall %d\n", num
);
211 print_openbsd_syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
214 case TARGET_OPENBSD_NR_exit
:
218 gdb_exit(cpu_env
, arg1
);
219 /* XXX: should free thread stack and CPU env */
221 ret
= 0; /* avoid warning */
223 case TARGET_OPENBSD_NR_read
:
224 if (!(p
= lock_user(VERIFY_WRITE
, arg2
, arg3
, 0)))
226 ret
= get_errno(read(arg1
, p
, arg3
));
227 unlock_user(p
, arg2
, ret
);
229 case TARGET_OPENBSD_NR_write
:
230 if (!(p
= lock_user(VERIFY_READ
, arg2
, arg3
, 1)))
232 ret
= get_errno(write(arg1
, p
, arg3
));
233 unlock_user(p
, arg2
, 0);
235 case TARGET_OPENBSD_NR_open
:
236 if (!(p
= lock_user_string(arg1
)))
238 ret
= get_errno(open(path(p
),
239 target_to_host_bitmask(arg2
, fcntl_flags_tbl
),
241 unlock_user(p
, arg1
, 0);
243 case TARGET_OPENBSD_NR_mmap
:
244 ret
= get_errno(target_mmap(arg1
, arg2
, arg3
,
245 target_to_host_bitmask(arg4
, mmap_flags_tbl
),
249 case TARGET_OPENBSD_NR_mprotect
:
250 ret
= get_errno(target_mprotect(arg1
, arg2
, arg3
));
252 case TARGET_OPENBSD_NR_syscall
:
253 case TARGET_OPENBSD_NR___syscall
:
254 ret
= do_openbsd_syscall(cpu_env
,arg1
& 0xffff,arg2
,arg3
,arg4
,arg5
,arg6
,0);
257 ret
= syscall(num
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
262 gemu_log(" = %ld\n", ret
);
265 print_openbsd_syscall_ret(num
, ret
);
268 ret
= -TARGET_EFAULT
;
272 void syscall_init(void)