2 * Helper routines to provide target memory access for semihosting
3 * syscalls in system emulation mode.
5 * Copyright (c) 2007 CodeSourcery.
7 * This code is licensed under the GPL
10 #include "qemu/osdep.h"
11 #include "exec/exec-all.h"
12 #include "semihosting/uaccess.h"
14 void *uaccess_lock_user(CPUArchState
*env
, target_ulong addr
,
15 target_ulong len
, bool copy
)
17 void *p
= malloc(len
);
19 if (cpu_memory_rw_debug(env_cpu(env
), addr
, p
, len
, 0)) {
27 ssize_t
uaccess_strlen_user(CPUArchState
*env
, target_ulong addr
)
29 int mmu_idx
= cpu_mmu_index(env_cpu(env
), false);
37 /* Find the number of bytes remaining in the page. */
38 left_in_page
= TARGET_PAGE_SIZE
- (addr
& ~TARGET_PAGE_MASK
);
40 flags
= probe_access_flags(env
, addr
, 0, MMU_DATA_LOAD
,
41 mmu_idx
, true, &h
, 0);
42 if (flags
& TLB_INVALID_MASK
) {
45 if (flags
& TLB_MMIO
) {
48 if (cpu_memory_rw_debug(env_cpu(env
), addr
, &c
, 1, 0)) {
56 if (len
> INT32_MAX
) {
59 } while (--left_in_page
!= 0);
61 char *p
= memchr(h
, 0, left_in_page
);
64 return len
<= INT32_MAX
? (ssize_t
)len
: -1;
68 if (len
> INT32_MAX
) {
75 char *uaccess_lock_user_string(CPUArchState
*env
, target_ulong addr
)
77 ssize_t len
= uaccess_strlen_user(env
, addr
);
81 return uaccess_lock_user(env
, addr
, len
+ 1, true);
84 void uaccess_unlock_user(CPUArchState
*env
, void *p
,
85 target_ulong addr
, target_ulong len
)
88 cpu_memory_rw_debug(env_cpu(env
), addr
, p
, len
, 1);