root / bsd-user / syscall.c @ 14899cdf
History | View | Annotate | Download (8.1 kB)
1 | 84778508 | blueswir1 | /*
|
---|---|---|---|
2 | 84778508 | blueswir1 | * BSD syscalls
|
3 | 84778508 | blueswir1 | *
|
4 | 84778508 | blueswir1 | * Copyright (c) 2003 - 2008 Fabrice Bellard
|
5 | 84778508 | blueswir1 | *
|
6 | 84778508 | blueswir1 | * This program is free software; you can redistribute it and/or modify
|
7 | 84778508 | blueswir1 | * it under the terms of the GNU General Public License as published by
|
8 | 84778508 | blueswir1 | * the Free Software Foundation; either version 2 of the License, or
|
9 | 84778508 | blueswir1 | * (at your option) any later version.
|
10 | 84778508 | blueswir1 | *
|
11 | 84778508 | blueswir1 | * This program is distributed in the hope that it will be useful,
|
12 | 84778508 | blueswir1 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 84778508 | blueswir1 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 84778508 | blueswir1 | * GNU General Public License for more details.
|
15 | 84778508 | blueswir1 | *
|
16 | 84778508 | blueswir1 | * You should have received a copy of the GNU General Public License
|
17 | 84778508 | blueswir1 | * along with this program; if not, write to the Free Software
|
18 | 530e7615 | blueswir1 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
19 | 530e7615 | blueswir1 | * MA 02110-1301, USA.
|
20 | 84778508 | blueswir1 | */
|
21 | 84778508 | blueswir1 | #include <stdlib.h> |
22 | 84778508 | blueswir1 | #include <stdio.h> |
23 | 84778508 | blueswir1 | #include <stdint.h> |
24 | 84778508 | blueswir1 | #include <stdarg.h> |
25 | 84778508 | blueswir1 | #include <string.h> |
26 | 84778508 | blueswir1 | #include <errno.h> |
27 | 84778508 | blueswir1 | #include <unistd.h> |
28 | 84778508 | blueswir1 | #include <fcntl.h> |
29 | 84778508 | blueswir1 | #include <time.h> |
30 | 84778508 | blueswir1 | #include <limits.h> |
31 | 84778508 | blueswir1 | #include <sys/types.h> |
32 | 84778508 | blueswir1 | #include <sys/mman.h> |
33 | 84778508 | blueswir1 | #include <sys/syscall.h> |
34 | 84778508 | blueswir1 | #include <signal.h> |
35 | 84778508 | blueswir1 | #include <utime.h> |
36 | 84778508 | blueswir1 | |
37 | 84778508 | blueswir1 | #include "qemu.h" |
38 | 84778508 | blueswir1 | #include "qemu-common.h" |
39 | 84778508 | blueswir1 | |
40 | 84778508 | blueswir1 | //#define DEBUG
|
41 | 84778508 | blueswir1 | |
42 | 84778508 | blueswir1 | static abi_ulong target_brk;
|
43 | 84778508 | blueswir1 | static abi_ulong target_original_brk;
|
44 | 84778508 | blueswir1 | |
45 | 84778508 | blueswir1 | #define get_errno(x) (x)
|
46 | 84778508 | blueswir1 | #define target_to_host_bitmask(x, tbl) (x)
|
47 | 84778508 | blueswir1 | |
48 | 84778508 | blueswir1 | void target_set_brk(abi_ulong new_brk)
|
49 | 84778508 | blueswir1 | { |
50 | 84778508 | blueswir1 | target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk); |
51 | 84778508 | blueswir1 | } |
52 | 84778508 | blueswir1 | |
53 | 84778508 | blueswir1 | /* do_syscall() should always have a single exit point at the end so
|
54 | 84778508 | blueswir1 | that actions, such as logging of syscall results, can be performed.
|
55 | 84778508 | blueswir1 | All errnos that do_syscall() returns must be -TARGET_<errcode>. */
|
56 | 84778508 | blueswir1 | abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, |
57 | 84778508 | blueswir1 | abi_long arg2, abi_long arg3, abi_long arg4, |
58 | 84778508 | blueswir1 | abi_long arg5, abi_long arg6) |
59 | 84778508 | blueswir1 | { |
60 | 84778508 | blueswir1 | abi_long ret; |
61 | 84778508 | blueswir1 | void *p;
|
62 | 84778508 | blueswir1 | |
63 | 84778508 | blueswir1 | #ifdef DEBUG
|
64 | 84778508 | blueswir1 | gemu_log("freebsd syscall %d\n", num);
|
65 | 84778508 | blueswir1 | #endif
|
66 | 84778508 | blueswir1 | if(do_strace)
|
67 | 84778508 | blueswir1 | print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
68 | 84778508 | blueswir1 | |
69 | 84778508 | blueswir1 | switch(num) {
|
70 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_exit:
|
71 | 84778508 | blueswir1 | #ifdef HAVE_GPROF
|
72 | 84778508 | blueswir1 | _mcleanup(); |
73 | 84778508 | blueswir1 | #endif
|
74 | 84778508 | blueswir1 | gdb_exit(cpu_env, arg1); |
75 | 84778508 | blueswir1 | /* XXX: should free thread stack and CPU env */
|
76 | 84778508 | blueswir1 | _exit(arg1); |
77 | 84778508 | blueswir1 | ret = 0; /* avoid warning */ |
78 | 84778508 | blueswir1 | break;
|
79 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_read:
|
80 | 84778508 | blueswir1 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
81 | 84778508 | blueswir1 | goto efault;
|
82 | 84778508 | blueswir1 | ret = get_errno(read(arg1, p, arg3)); |
83 | 84778508 | blueswir1 | unlock_user(p, arg2, ret); |
84 | 84778508 | blueswir1 | break;
|
85 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_write:
|
86 | 84778508 | blueswir1 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
87 | 84778508 | blueswir1 | goto efault;
|
88 | 84778508 | blueswir1 | ret = get_errno(write(arg1, p, arg3)); |
89 | 84778508 | blueswir1 | unlock_user(p, arg2, 0);
|
90 | 84778508 | blueswir1 | break;
|
91 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_open:
|
92 | 84778508 | blueswir1 | if (!(p = lock_user_string(arg1)))
|
93 | 84778508 | blueswir1 | goto efault;
|
94 | 84778508 | blueswir1 | ret = get_errno(open(path(p), |
95 | 84778508 | blueswir1 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
96 | 84778508 | blueswir1 | arg3)); |
97 | 84778508 | blueswir1 | unlock_user(p, arg1, 0);
|
98 | 84778508 | blueswir1 | break;
|
99 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_mmap:
|
100 | 84778508 | blueswir1 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
101 | 84778508 | blueswir1 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
102 | 84778508 | blueswir1 | arg5, |
103 | 84778508 | blueswir1 | arg6)); |
104 | 84778508 | blueswir1 | break;
|
105 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_mprotect:
|
106 | 84778508 | blueswir1 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
107 | 84778508 | blueswir1 | break;
|
108 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR_syscall:
|
109 | 84778508 | blueswir1 | case TARGET_FREEBSD_NR___syscall:
|
110 | 84778508 | blueswir1 | ret = do_freebsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0); |
111 | 84778508 | blueswir1 | break;
|
112 | 84778508 | blueswir1 | default:
|
113 | 84778508 | blueswir1 | ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
114 | 84778508 | blueswir1 | break;
|
115 | 84778508 | blueswir1 | } |
116 | 84778508 | blueswir1 | fail:
|
117 | 84778508 | blueswir1 | #ifdef DEBUG
|
118 | 84778508 | blueswir1 | gemu_log(" = %ld\n", ret);
|
119 | 84778508 | blueswir1 | #endif
|
120 | 84778508 | blueswir1 | if (do_strace)
|
121 | 84778508 | blueswir1 | print_freebsd_syscall_ret(num, ret); |
122 | 84778508 | blueswir1 | return ret;
|
123 | 84778508 | blueswir1 | efault:
|
124 | 84778508 | blueswir1 | ret = -TARGET_EFAULT; |
125 | 84778508 | blueswir1 | goto fail;
|
126 | 84778508 | blueswir1 | } |
127 | 84778508 | blueswir1 | |
128 | 84778508 | blueswir1 | abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, |
129 | 84778508 | blueswir1 | abi_long arg2, abi_long arg3, abi_long arg4, |
130 | 84778508 | blueswir1 | abi_long arg5, abi_long arg6) |
131 | 84778508 | blueswir1 | { |
132 | 84778508 | blueswir1 | abi_long ret; |
133 | 84778508 | blueswir1 | void *p;
|
134 | 84778508 | blueswir1 | |
135 | 84778508 | blueswir1 | #ifdef DEBUG
|
136 | 84778508 | blueswir1 | gemu_log("netbsd syscall %d\n", num);
|
137 | 84778508 | blueswir1 | #endif
|
138 | 84778508 | blueswir1 | if(do_strace)
|
139 | 84778508 | blueswir1 | print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
140 | 84778508 | blueswir1 | |
141 | 84778508 | blueswir1 | switch(num) {
|
142 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_exit:
|
143 | 84778508 | blueswir1 | #ifdef HAVE_GPROF
|
144 | 84778508 | blueswir1 | _mcleanup(); |
145 | 84778508 | blueswir1 | #endif
|
146 | 84778508 | blueswir1 | gdb_exit(cpu_env, arg1); |
147 | 84778508 | blueswir1 | /* XXX: should free thread stack and CPU env */
|
148 | 84778508 | blueswir1 | _exit(arg1); |
149 | 84778508 | blueswir1 | ret = 0; /* avoid warning */ |
150 | 84778508 | blueswir1 | break;
|
151 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_read:
|
152 | 84778508 | blueswir1 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
153 | 84778508 | blueswir1 | goto efault;
|
154 | 84778508 | blueswir1 | ret = get_errno(read(arg1, p, arg3)); |
155 | 84778508 | blueswir1 | unlock_user(p, arg2, ret); |
156 | 84778508 | blueswir1 | break;
|
157 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_write:
|
158 | 84778508 | blueswir1 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
159 | 84778508 | blueswir1 | goto efault;
|
160 | 84778508 | blueswir1 | ret = get_errno(write(arg1, p, arg3)); |
161 | 84778508 | blueswir1 | unlock_user(p, arg2, 0);
|
162 | 84778508 | blueswir1 | break;
|
163 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_open:
|
164 | 84778508 | blueswir1 | if (!(p = lock_user_string(arg1)))
|
165 | 84778508 | blueswir1 | goto efault;
|
166 | 84778508 | blueswir1 | ret = get_errno(open(path(p), |
167 | 84778508 | blueswir1 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
168 | 84778508 | blueswir1 | arg3)); |
169 | 84778508 | blueswir1 | unlock_user(p, arg1, 0);
|
170 | 84778508 | blueswir1 | break;
|
171 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_mmap:
|
172 | 84778508 | blueswir1 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
173 | 84778508 | blueswir1 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
174 | 84778508 | blueswir1 | arg5, |
175 | 84778508 | blueswir1 | arg6)); |
176 | 84778508 | blueswir1 | break;
|
177 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_mprotect:
|
178 | 84778508 | blueswir1 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
179 | 84778508 | blueswir1 | break;
|
180 | 84778508 | blueswir1 | case TARGET_NETBSD_NR_syscall:
|
181 | 84778508 | blueswir1 | case TARGET_NETBSD_NR___syscall:
|
182 | 84778508 | blueswir1 | ret = do_netbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0); |
183 | 84778508 | blueswir1 | break;
|
184 | 84778508 | blueswir1 | default:
|
185 | 84778508 | blueswir1 | ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
186 | 84778508 | blueswir1 | break;
|
187 | 84778508 | blueswir1 | } |
188 | 84778508 | blueswir1 | fail:
|
189 | 84778508 | blueswir1 | #ifdef DEBUG
|
190 | 84778508 | blueswir1 | gemu_log(" = %ld\n", ret);
|
191 | 84778508 | blueswir1 | #endif
|
192 | 84778508 | blueswir1 | if (do_strace)
|
193 | 84778508 | blueswir1 | print_netbsd_syscall_ret(num, ret); |
194 | 84778508 | blueswir1 | return ret;
|
195 | 84778508 | blueswir1 | efault:
|
196 | 84778508 | blueswir1 | ret = -TARGET_EFAULT; |
197 | 84778508 | blueswir1 | goto fail;
|
198 | 84778508 | blueswir1 | } |
199 | 84778508 | blueswir1 | |
200 | 84778508 | blueswir1 | abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, |
201 | 84778508 | blueswir1 | abi_long arg2, abi_long arg3, abi_long arg4, |
202 | 84778508 | blueswir1 | abi_long arg5, abi_long arg6) |
203 | 84778508 | blueswir1 | { |
204 | 84778508 | blueswir1 | abi_long ret; |
205 | 84778508 | blueswir1 | void *p;
|
206 | 84778508 | blueswir1 | |
207 | 84778508 | blueswir1 | #ifdef DEBUG
|
208 | 84778508 | blueswir1 | gemu_log("openbsd syscall %d\n", num);
|
209 | 84778508 | blueswir1 | #endif
|
210 | 84778508 | blueswir1 | if(do_strace)
|
211 | 84778508 | blueswir1 | print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
212 | 84778508 | blueswir1 | |
213 | 84778508 | blueswir1 | switch(num) {
|
214 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_exit:
|
215 | 84778508 | blueswir1 | #ifdef HAVE_GPROF
|
216 | 84778508 | blueswir1 | _mcleanup(); |
217 | 84778508 | blueswir1 | #endif
|
218 | 84778508 | blueswir1 | gdb_exit(cpu_env, arg1); |
219 | 84778508 | blueswir1 | /* XXX: should free thread stack and CPU env */
|
220 | 84778508 | blueswir1 | _exit(arg1); |
221 | 84778508 | blueswir1 | ret = 0; /* avoid warning */ |
222 | 84778508 | blueswir1 | break;
|
223 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_read:
|
224 | 84778508 | blueswir1 | if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0))) |
225 | 84778508 | blueswir1 | goto efault;
|
226 | 84778508 | blueswir1 | ret = get_errno(read(arg1, p, arg3)); |
227 | 84778508 | blueswir1 | unlock_user(p, arg2, ret); |
228 | 84778508 | blueswir1 | break;
|
229 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_write:
|
230 | 84778508 | blueswir1 | if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1))) |
231 | 84778508 | blueswir1 | goto efault;
|
232 | 84778508 | blueswir1 | ret = get_errno(write(arg1, p, arg3)); |
233 | 84778508 | blueswir1 | unlock_user(p, arg2, 0);
|
234 | 84778508 | blueswir1 | break;
|
235 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_open:
|
236 | 84778508 | blueswir1 | if (!(p = lock_user_string(arg1)))
|
237 | 84778508 | blueswir1 | goto efault;
|
238 | 84778508 | blueswir1 | ret = get_errno(open(path(p), |
239 | 84778508 | blueswir1 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
240 | 84778508 | blueswir1 | arg3)); |
241 | 84778508 | blueswir1 | unlock_user(p, arg1, 0);
|
242 | 84778508 | blueswir1 | break;
|
243 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_mmap:
|
244 | 84778508 | blueswir1 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
245 | 84778508 | blueswir1 | target_to_host_bitmask(arg4, mmap_flags_tbl), |
246 | 84778508 | blueswir1 | arg5, |
247 | 84778508 | blueswir1 | arg6)); |
248 | 84778508 | blueswir1 | break;
|
249 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_mprotect:
|
250 | 84778508 | blueswir1 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
251 | 84778508 | blueswir1 | break;
|
252 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR_syscall:
|
253 | 84778508 | blueswir1 | case TARGET_OPENBSD_NR___syscall:
|
254 | 84778508 | blueswir1 | ret = do_openbsd_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0); |
255 | 84778508 | blueswir1 | break;
|
256 | 84778508 | blueswir1 | default:
|
257 | 84778508 | blueswir1 | ret = syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); |
258 | 84778508 | blueswir1 | break;
|
259 | 84778508 | blueswir1 | } |
260 | 84778508 | blueswir1 | fail:
|
261 | 84778508 | blueswir1 | #ifdef DEBUG
|
262 | 84778508 | blueswir1 | gemu_log(" = %ld\n", ret);
|
263 | 84778508 | blueswir1 | #endif
|
264 | 84778508 | blueswir1 | if (do_strace)
|
265 | 84778508 | blueswir1 | print_openbsd_syscall_ret(num, ret); |
266 | 84778508 | blueswir1 | return ret;
|
267 | 84778508 | blueswir1 | efault:
|
268 | 84778508 | blueswir1 | ret = -TARGET_EFAULT; |
269 | 84778508 | blueswir1 | goto fail;
|
270 | 84778508 | blueswir1 | } |
271 | 84778508 | blueswir1 | |
272 | 84778508 | blueswir1 | void syscall_init(void) |
273 | 84778508 | blueswir1 | { |
274 | 84778508 | blueswir1 | } |