Revision 579a97f7 linux-user/qemu.h
b/linux-user/qemu.h | ||
---|---|---|
146 | 146 |
struct image_info *info); |
147 | 147 |
#endif |
148 | 148 |
|
149 |
void memcpy_to_target(abi_ulong dest, const void *src,
|
|
150 |
unsigned long len); |
|
149 |
abi_long memcpy_to_target(abi_ulong dest, const void *src,
|
|
150 |
unsigned long len);
|
|
151 | 151 |
void target_set_brk(abi_ulong new_brk); |
152 | 152 |
abi_long do_brk(abi_ulong new_brk); |
153 | 153 |
void syscall_init(void); |
... | ... | |
179 | 179 |
void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo); |
180 | 180 |
long do_sigreturn(CPUState *env); |
181 | 181 |
long do_rt_sigreturn(CPUState *env); |
182 |
int do_sigaltstack(const struct target_sigaltstack *uss, |
|
183 |
struct target_sigaltstack *uoss, |
|
184 |
abi_ulong sp); |
|
182 |
abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); |
|
185 | 183 |
|
186 | 184 |
#ifdef TARGET_I386 |
187 | 185 |
/* vm86.c */ |
... | ... | |
207 | 205 |
/* user access */ |
208 | 206 |
|
209 | 207 |
#define VERIFY_READ 0 |
210 |
#define VERIFY_WRITE 1 |
|
208 |
#define VERIFY_WRITE 1 /* implies read access */
|
|
211 | 209 |
|
212 | 210 |
#define access_ok(type,addr,size) \ |
213 | 211 |
(page_check_range((target_ulong)addr,size,(type==VERIFY_READ)?PAGE_READ:PAGE_WRITE)==0) |
214 | 212 |
|
215 | 213 |
/* NOTE __get_user and __put_user use host pointers and don't check access. */ |
214 |
/* These are usually used to access struct data members once the |
|
215 |
* struct has been locked - usually with lock_user_struct(). |
|
216 |
*/ |
|
216 | 217 |
#define __put_user(x, hptr)\ |
217 | 218 |
({\ |
218 | 219 |
int size = sizeof(*hptr);\ |
... | ... | |
257 | 258 |
0;\ |
258 | 259 |
}) |
259 | 260 |
|
260 |
#define put_user(x,ptr)\ |
|
261 |
({\ |
|
262 |
int __ret;\ |
|
263 |
if (access_ok(VERIFY_WRITE, ptr, sizeof(*ptr)))\ |
|
264 |
__ret = __put_user(x, ptr);\ |
|
265 |
else\ |
|
266 |
__ret = -EFAULT;\ |
|
267 |
__ret;\ |
|
261 |
/* put_user()/get_user() take a guest address and check access */ |
|
262 |
/* These are usually used to access an atomic data type, such as an int, |
|
263 |
* that has been passed by address. These internally perform locking |
|
264 |
* and unlocking on the data type. |
|
265 |
*/ |
|
266 |
#define put_user(x, gaddr, target_type) \ |
|
267 |
({ \ |
|
268 |
abi_ulong __gaddr = (gaddr); \ |
|
269 |
target_type *__hptr; \ |
|
270 |
abi_long __ret; \ |
|
271 |
if ((__hptr = lock_user(VERIFY_WRITE, __gaddr, sizeof(target_type), 0))) { \ |
|
272 |
__ret = __put_user((x), __hptr); \ |
|
273 |
unlock_user(__hptr, __gaddr, sizeof(target_type)); \ |
|
274 |
} else \ |
|
275 |
__ret = -TARGET_EFAULT; \ |
|
276 |
__ret; \ |
|
268 | 277 |
}) |
269 | 278 |
|
270 |
#define get_user(x,ptr)\ |
|
271 |
({\ |
|
272 |
int __ret;\ |
|
273 |
if (access_ok(VERIFY_READ, ptr, sizeof(*ptr)))\ |
|
274 |
__ret = __get_user(x, ptr);\ |
|
275 |
else\ |
|
276 |
__ret = -EFAULT;\ |
|
277 |
__ret;\ |
|
279 |
#define get_user(x, gaddr, target_type) \ |
|
280 |
({ \ |
|
281 |
abi_ulong __gaddr = (gaddr); \ |
|
282 |
target_type *__hptr; \ |
|
283 |
abi_long __ret; \ |
|
284 |
if ((__hptr = lock_user(VERIFY_READ, __gaddr, sizeof(target_type), 1))) { \ |
|
285 |
__ret = __get_user((x), __hptr); \ |
|
286 |
unlock_user(__hptr, __gaddr, 0); \ |
|
287 |
} else \ |
|
288 |
__ret = -TARGET_EFAULT; \ |
|
289 |
__ret; \ |
|
278 | 290 |
}) |
279 | 291 |
|
292 |
/* copy_from_user() and copy_to_user() are usually used to copy data |
|
293 |
* buffers between the target and host. These internally perform |
|
294 |
* locking/unlocking of the memory. |
|
295 |
*/ |
|
296 |
abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len); |
|
297 |
abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len); |
|
298 |
|
|
280 | 299 |
/* Functions for accessing guest memory. The tget and tput functions |
281 | 300 |
read/write single values, byteswapping as neccessary. The lock_user |
282 | 301 |
gets a pointer to a contiguous area of guest memory, but does not perform |
... | ... | |
285 | 304 |
|
286 | 305 |
/* Lock an area of guest memory into the host. If copy is true then the |
287 | 306 |
host area will have the same contents as the guest. */ |
288 |
static inline void *lock_user(abi_ulong guest_addr, long len, int copy) |
|
307 |
static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
|
|
289 | 308 |
{ |
309 |
if (!access_ok(type, guest_addr, len)) |
|
310 |
return NULL; |
|
290 | 311 |
#ifdef DEBUG_REMAP |
291 |
void *addr; |
|
292 |
addr = malloc(len); |
|
293 |
if (copy) |
|
294 |
memcpy(addr, g2h(guest_addr), len); |
|
295 |
else |
|
296 |
memset(addr, 0, len); |
|
297 |
return addr; |
|
312 |
{ |
|
313 |
void *addr; |
|
314 |
addr = malloc(len); |
|
315 |
if (copy) |
|
316 |
memcpy(addr, g2h(guest_addr), len); |
|
317 |
else |
|
318 |
memset(addr, 0, len); |
|
319 |
return addr; |
|
320 |
} |
|
298 | 321 |
#else |
299 | 322 |
return g2h(guest_addr); |
300 | 323 |
#endif |
301 | 324 |
} |
302 | 325 |
|
303 |
/* Unlock an area of guest memory. The first LEN bytes must be flushed back |
|
304 |
to guest memory. */ |
|
305 |
static inline void unlock_user(void *host_addr, abi_ulong guest_addr, |
|
326 |
/* Unlock an area of guest memory. The first LEN bytes must be |
|
327 |
flushed back to guest memory. host_ptr = NULL is explicitely |
|
328 |
allowed and does nothing. */ |
|
329 |
static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, |
|
306 | 330 |
long len) |
307 | 331 |
{ |
332 |
|
|
308 | 333 |
#ifdef DEBUG_REMAP |
309 |
if (host_addr == g2h(guest_addr)) |
|
334 |
if (!host_ptr) |
|
335 |
return; |
|
336 |
if (host_ptr == g2h(guest_addr)) |
|
310 | 337 |
return; |
311 | 338 |
if (len > 0) |
312 |
memcpy(g2h(guest_addr), host_addr, len);
|
|
313 |
free(host_addr);
|
|
339 |
memcpy(g2h(guest_ptr), host_ptr, len);
|
|
340 |
free(host_ptr);
|
|
314 | 341 |
#endif |
315 | 342 |
} |
316 | 343 |
|
317 |
/* Return the length of a string in target memory. */ |
|
318 |
static inline int target_strlen(abi_ulong ptr) |
|
319 |
{ |
|
320 |
return strlen(g2h(ptr)); |
|
321 |
} |
|
344 |
/* Return the length of a string in target memory or -TARGET_EFAULT if |
|
345 |
access error. */ |
|
346 |
abi_long target_strlen(abi_ulong gaddr); |
|
322 | 347 |
|
323 | 348 |
/* Like lock_user but for null terminated strings. */ |
324 | 349 |
static inline void *lock_user_string(abi_ulong guest_addr) |
325 | 350 |
{ |
326 |
long len; |
|
327 |
len = target_strlen(guest_addr) + 1; |
|
328 |
return lock_user(guest_addr, len, 1); |
|
351 |
abi_long len; |
|
352 |
len = target_strlen(guest_addr); |
|
353 |
if (len < 0) |
|
354 |
return NULL; |
|
355 |
return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1); |
|
329 | 356 |
} |
330 | 357 |
|
331 | 358 |
/* Helper macros for locking/ulocking a target struct. */ |
332 |
#define lock_user_struct(host_ptr, guest_addr, copy) \
|
|
333 |
host_ptr = lock_user(guest_addr, sizeof(*host_ptr), copy)
|
|
334 |
#define unlock_user_struct(host_ptr, guest_addr, copy) \
|
|
359 |
#define lock_user_struct(type, host_ptr, guest_addr, copy) \
|
|
360 |
(host_ptr = lock_user(type, guest_addr, sizeof(*host_ptr), copy))
|
|
361 |
#define unlock_user_struct(host_ptr, guest_addr, copy) \
|
|
335 | 362 |
unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) |
336 | 363 |
|
337 | 364 |
#define tget8(addr) ldub(addr) |
Also available in: Unified diff