aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-02-12 10:48:50 -0800
committerPeter Maydell <peter.maydell@linaro.org>2021-02-16 13:06:11 +0000
commit31c048342db09e70ab887aba9c7e0818c18d0fb1 (patch)
tree868233d79e4847de816aa9752bd92c67ec0f6421
parent09f679b62dffd437446307884597273618004b2c (diff)
linux-user: Handle tags in lock_user/unlock_user
Resolve the untagged address once, using thread_cpu. Tidy the DEBUG_REMAP code using glib routines. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210212184902.1251044-20-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--linux-user/uaccess.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c
index 76af6a92b1..c696913016 100644
--- a/linux-user/uaccess.c
+++ b/linux-user/uaccess.c
@@ -6,36 +6,37 @@
void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy)
{
+ void *host_addr;
+
+ guest_addr = cpu_untagged_addr(thread_cpu, guest_addr);
if (!access_ok_untagged(type, guest_addr, len)) {
return NULL;
}
+ host_addr = g2h_untagged(guest_addr);
#ifdef DEBUG_REMAP
- {
- void *addr;
- addr = g_malloc(len);
- if (copy) {
- memcpy(addr, g2h(guest_addr), len);
- } else {
- memset(addr, 0, len);
- }
- return addr;
+ if (copy) {
+ host_addr = g_memdup(host_addr, len);
+ } else {
+ host_addr = g_malloc0(len);
}
-#else
- return g2h_untagged(guest_addr);
#endif
+ return host_addr;
}
#ifdef DEBUG_REMAP
void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len);
{
+ void *host_ptr_conv;
+
if (!host_ptr) {
return;
}
- if (host_ptr == g2h_untagged(guest_addr)) {
+ host_ptr_conv = g2h(thread_cpu, guest_addr);
+ if (host_ptr == host_ptr_conv) {
return;
}
if (len != 0) {
- memcpy(g2h_untagged(guest_addr), host_ptr, len);
+ memcpy(host_ptr_conv, host_ptr, len);
}
g_free(host_ptr);
}