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