summaryrefslogtreecommitdiff
path: root/semihosting
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2022-04-27 20:44:17 -0700
committerRichard Henderson <richard.henderson@linaro.org>2022-06-28 04:35:06 +0530
commit0a9221810ce08fd5b0c4cff6055e640d4bd6876d (patch)
tree558d8ab12a87e49a6e4c5327d6060883e4413d92 /semihosting
parent259739ce74300ae9e5df7c8c3a8a672341af5546 (diff)
semihosting: Move softmmu-uaccess.h functions out of line
Rather that static (and not even inline) functions within a header, move the functions to semihosting/uaccess.c. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'semihosting')
-rw-r--r--semihosting/meson.build1
-rw-r--r--semihosting/uaccess.c51
2 files changed, 52 insertions, 0 deletions
diff --git a/semihosting/meson.build b/semihosting/meson.build
index 4344e43fb9..10b3b99921 100644
--- a/semihosting/meson.build
+++ b/semihosting/meson.build
@@ -1,6 +1,7 @@
specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files(
'config.c',
'console.c',
+ 'uaccess.c',
))
specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'],
diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c
new file mode 100644
index 0000000000..0d3b32b75d
--- /dev/null
+++ b/semihosting/uaccess.c
@@ -0,0 +1,51 @@
+/*
+ * Helper routines to provide target memory access for semihosting
+ * syscalls in system emulation mode.
+ *
+ * Copyright (c) 2007 CodeSourcery.
+ *
+ * This code is licensed under the GPL
+ */
+
+#include "qemu/osdep.h"
+#include "semihosting/softmmu-uaccess.h"
+
+void *softmmu_lock_user(CPUArchState *env, target_ulong addr,
+ target_ulong len, bool copy)
+{
+ void *p = malloc(len);
+ if (p && copy) {
+ if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) {
+ free(p);
+ p = NULL;
+ }
+ }
+ return p;
+}
+
+char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr)
+{
+ /* TODO: Make this something that isn't fixed size. */
+ char *s = malloc(1024);
+ size_t len = 0;
+
+ if (!s) {
+ return NULL;
+ }
+ do {
+ if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) {
+ free(s);
+ return NULL;
+ }
+ } while (s[len++]);
+ return s;
+}
+
+void softmmu_unlock_user(CPUArchState *env, void *p,
+ target_ulong addr, target_ulong len)
+{
+ if (len) {
+ cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
+ }
+ free(p);
+}