1 /* User memory access */
7 /* copy_from_user() and copy_to_user() are usually used to copy data
8 * buffers between the target and host. These internally perform
9 * locking/unlocking of the memory.
11 abi_long
copy_from_user(void *hptr
, abi_ulong gaddr
, size_t len
)
16 if ((ghptr
= lock_user(VERIFY_READ
, gaddr
, len
, 1))) {
17 memcpy(hptr
, ghptr
, len
);
18 unlock_user(ghptr
, gaddr
, 0);
26 abi_long
copy_to_user(abi_ulong gaddr
, void *hptr
, size_t len
)
31 if ((ghptr
= lock_user(VERIFY_WRITE
, gaddr
, len
, 0))) {
32 memcpy(ghptr
, hptr
, len
);
33 unlock_user(ghptr
, gaddr
, len
);
40 /* Return the length of a string in target memory or -TARGET_EFAULT if
42 abi_long
target_strlen(abi_ulong guest_addr1
)
48 guest_addr
= guest_addr1
;
50 max_len
= TARGET_PAGE_SIZE
- (guest_addr
& ~TARGET_PAGE_MASK
);
51 ptr
= lock_user(VERIFY_READ
, guest_addr
, max_len
, 1);
53 return -TARGET_EFAULT
;
54 len
= qemu_strnlen((const char *)ptr
, max_len
);
55 unlock_user(ptr
, guest_addr
, 0);
57 /* we don't allow wrapping or integer overflow */
58 if (guest_addr
== 0 ||
59 (guest_addr
- guest_addr1
) > 0x7fffffff)
60 return -TARGET_EFAULT
;
64 return guest_addr
- guest_addr1
;