Skip to contentSkip to conversation

semihosting/uaccess: Compile once

PATCH Superseded Philippe Mathieu-Daudé 2 participants 4 messages May 9, 2025 Arm/Amlogic Meson SoC support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover semihosting/uaccess: Compile once

Replace target_ulong -> vaddr/size_t to compile once.

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

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       |  4 +---
 3 files changed, 12 insertions(+), 14 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 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":

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
#2 lore raw

PATCH v2 2/2 semihosting/uaccess: Compile once

In reply to Philippe Mathieu-Daudé
---
 semihosting/meson.build | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
semihosting/meson.build +1 -3
index f3d38dda91d..d0819891bc3 100644
@@ -3,9 +3,7 @@ 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',
-))
+system_ss.add(when: 'CONFIG_TCG', 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'))
Signature · 1 line
2.47.1
#3 lore raw

Hi Philippe,

Quoted 10 lines · Philippe Mathieu-Daudé
---
  semihosting/meson.build | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
semihosting/meson.build +0 -0
index f3d38dda91d..d0819891bc3 100644

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

Quoted 10 lines
semihosting/meson.build +1 -3
@@ -3,9 +3,7 @@ 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',
-))
+system_ss.add(when: 'CONFIG_TCG', 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'))

It doesn't compile applied on master [1].

Does it compile on your side?
If yes, could you include the additional patches allowing you to get rid of CONFIG_USER_ONLY in included headers?

My previous answer on v1 was giving a solution, and an associated meson patch. In case we can't remove CONFIG_USER_ONLY from the headers included, it's the only possible solution I still see today.

[1] https://github.com/pbo-linaro/qemu-ci/actions/runs/14927715244/job/41936282521

Regards,
Pierrick