Skip to contentSkip to conversation

semihosting/uaccess: Compile once

PATCH Applied Philippe Mathieu-Daudé 3 participants 7 messages May 26, 2025 – Jun 6, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v3 cover semihosting/uaccess: Compile once

Replace target_ulong -> vaddr/size_t to compile once.

since v2:
- fixed build error when TCG enabled (Pierrick)
since v1:
- fixed build error when TCG disabled (Pierrick)

Based-on: <[email protected]>

Philippe Mathieu-Daudé (2):
semihosting/uaccess: Remove uses of target_ulong type semihosting/uaccess: Compile once

 include/semihosting/uaccess.h | 12 ++++++------
 semihosting/uaccess.c         | 10 +++++-----
 semihosting/meson.build       |  5 +----
 3 files changed, 12 insertions(+), 15 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH v3 1/2 semihosting/uaccess: Remove uses of target_ulong type

Replace target_ulong by vaddr or size_t types to match cpu_memory_rw_debug() prototype in "exec/cpu-common.h":

Quoted 3 lines

int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
void *ptr, size_t len, bool is_write);

---
 include/semihosting/uaccess.h | 12 ++++++------
 semihosting/uaccess.c         | 10 +++++-----
 2 files changed, 11 insertions(+), 11 deletions(-)
include/semihosting/uaccess.h +6 -6
index 6bc90b12d6f..2093a498277 100644
@@ -15,9 +15,9 @@
 #endif
 
 #include "exec/cpu-common.h"
-#include "exec/cpu-defs.h"
 #include "exec/tswap.h"
 #include "exec/page-protection.h"
+#include "exec/vaddr.h"
 
 /**
  * get_user_u64:
@@ -89,8 +89,8 @@
  *
  * The returned pointer should be freed using uaccess_unlock_user().
  */
-void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
-                        target_ulong len, bool copy);
+void *uaccess_lock_user(CPUArchState *env, vaddr addr,
+                        size_t len, bool copy);
 /**
  * lock_user:
  *
@@ -103,7 +103,7 @@ void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
  *
  * The returned string should be freed using uaccess_unlock_user().
  */
-char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr);
+char *uaccess_lock_user_string(CPUArchState *env, vaddr addr);
 /**
  * uaccess_lock_user_string:
  *
@@ -112,10 +112,10 @@ char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr);
 #define lock_user_string(p) uaccess_lock_user_string(env, p)
 
 void uaccess_unlock_user(CPUArchState *env, void *p,
-                         target_ulong addr, target_ulong len);
+                         vaddr addr, size_t len);
 #define unlock_user(s, args, len) uaccess_unlock_user(env, s, args, len)
 
-ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr);
+ssize_t uaccess_strlen_user(CPUArchState *env, vaddr addr);
 #define target_strlen(p) uaccess_strlen_user(env, p)
 
 #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */
semihosting/uaccess.c +5 -5
index 4554844e15b..ff944d8c2f7 100644
@@ -14,8 +14,8 @@
 #include "exec/tlb-flags.h"
 #include "semihosting/uaccess.h"
 
-void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
-                        target_ulong len, bool copy)
+void *uaccess_lock_user(CPUArchState *env, vaddr addr,
+                        size_t len, bool copy)
 {
     void *p = malloc(len);
     if (p && copy) {
@@ -27,7 +27,7 @@ void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
     return p;
 }
 
-ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr)
+ssize_t uaccess_strlen_user(CPUArchState *env, vaddr addr)
 {
     int mmu_idx = cpu_mmu_index(env_cpu(env), false);
     size_t len = 0;
@@ -75,7 +75,7 @@ ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr)
     }
 }
 
-char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr)
+char *uaccess_lock_user_string(CPUArchState *env, vaddr addr)
 {
     ssize_t len = uaccess_strlen_user(env, addr);
     if (len < 0) {
@@ -85,7 +85,7 @@ char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr)
 }
 
 void uaccess_unlock_user(CPUArchState *env, void *p,
-                         target_ulong addr, target_ulong len)
+                         vaddr addr, size_t len)
 {
     if (len) {
         cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
Signature · 1 line
2.47.1
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] semihosting/uaccess: Remove uses of target_ulong type

Quoted 7 lines · Philippe Mathieu-Daudé

Replace target_ulong by vaddr or size_t types to match cpu_memory_rw_debug() prototype in "exec/cpu-common.h":

Quoted 3 lines

int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
void *ptr, size_t len, bool is_write);

Quoted 6 lines
---
  include/semihosting/uaccess.h | 12 ++++++------
  semihosting/uaccess.c         | 10 +++++-----
  2 files changed, 11 insertions(+), 11 deletions(-)

r~

#3 lore raw

PATCH v3 2/2 semihosting/uaccess: Compile once

In reply to Philippe Mathieu-Daudé
---
 semihosting/meson.build | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
semihosting/meson.build +1 -4
index f3d38dda91d..b1ab2506c6e 100644
@@ -3,15 +3,12 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
   'syscalls.c',
 ))
 
-specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SYSTEM_ONLY'], if_true: files(
-  'uaccess.c',
-))
-
 common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c'))
 user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('user.c'))
 system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
   'config.c',
   'console.c',
+  'uaccess.c',
 ), if_false: files(
   'stubs-system.c',
 ))
Signature · 1 line
2.47.1
Reviewed-by on v3 2/2
#4 lore raw
Quoted 16 lines · Philippe Mathieu-Daudé
---
  semihosting/meson.build | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
semihosting/meson.build +0 -3
index f3d38dda91d..b1ab2506c6e 100644
@@ -3,15 +3,12 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
    'syscalls.c',
  ))
 
-specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SYSTEM_ONLY'], if_true: files(
-  'uaccess.c',
-))

semihosting/meson.build specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( · line 14

Quoted 10 lines
semihosting/meson.build +1 -1
-
  common_ss.add(when: 'CONFIG_SEMIHOSTING', if_false: files('stubs-all.c'))
  user_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files('user.c'))
  system_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files(
    'config.c',
    'console.c',
+  'uaccess.c',
  ), if_false: files(
    'stubs-system.c',
  ))

r~

#5 lore raw
In reply to Philippe Mathieu-Daudé

ping?

Quoted 18 lines · Philippe Mathieu-Daudé

Replace target_ulong -> vaddr/size_t to compile once.

since v2:
- fixed build error when TCG enabled (Pierrick)
since v1:
- fixed build error when TCG disabled (Pierrick)

Based-on: <[email protected]>

Philippe Mathieu-Daudé (2):
semihosting/uaccess: Remove uses of target_ulong type semihosting/uaccess: Compile once

  include/semihosting/uaccess.h | 12 ++++++------
  semihosting/uaccess.c         | 10 +++++-----
  semihosting/meson.build       |  5 +----
  3 files changed, 12 insertions(+), 15 deletions(-)
Applied
#6 lore raw
Quoted 1 line · Philippe Mathieu-Daudé

ping?

Queued to semihosting/next, thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro