1 /* User memory access */
2 #include "qemu/osdep.h"
6 /* copy_from_user() and copy_to_user() are usually used to copy data
7 * buffers between the target and host. These internally perform
8 * locking/unlocking of the memory.
10 abi_long
copy_from_user(void *hptr
, abi_ulong gaddr
, size_t len
)
15 if ((ghptr
= lock_user(VERIFY_READ
, gaddr
, len
, 1))) {
16 memcpy(hptr
, ghptr
, len
);
17 unlock_user(ghptr
, gaddr
, 0);
25 abi_long
copy_to_user(abi_ulong gaddr
, void *hptr
, size_t len
)
30 if ((ghptr
= lock_user(VERIFY_WRITE
, gaddr
, len
, 0))) {
31 memcpy(ghptr
, hptr
, len
);
32 unlock_user(ghptr
, gaddr
, len
);
39 /* Return the length of a string in target memory or -TARGET_EFAULT if
41 abi_long
target_strlen(abi_ulong guest_addr1
)
47 guest_addr
= guest_addr1
;
49 max_len
= TARGET_PAGE_SIZE
- (guest_addr
& ~TARGET_PAGE_MASK
);
50 ptr
= lock_user(VERIFY_READ
, guest_addr
, max_len
, 1);
52 return -TARGET_EFAULT
;
53 len
= qemu_strnlen((const char *)ptr
, max_len
);
54 unlock_user(ptr
, guest_addr
, 0);
56 /* we don't allow wrapping or integer overflow */
57 if (guest_addr
== 0 ||
58 (guest_addr
- guest_addr1
) > 0x7fffffff)
59 return -TARGET_EFAULT
;
63 return guest_addr
- guest_addr1
;