[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 10/11] target/mips: Simplify UHI_argnlen and UHI_argn
From: |
Richard Henderson |
Subject: |
[PATCH v4 10/11] target/mips: Simplify UHI_argnlen and UHI_argn |
Date: |
Tue, 7 Jun 2022 22:19:44 -0700 |
With semihosting_get_arg, we already have a check vs argc, so
there's no point replicating it -- just check the result vs NULL.
Merge copy_argn_to_target into its caller.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/mips/tcg/sysemu/mips-semi.c | 44 ++++++++++++++----------------
1 file changed, 21 insertions(+), 23 deletions(-)
diff --git a/target/mips/tcg/sysemu/mips-semi.c
b/target/mips/tcg/sysemu/mips-semi.c
index ae4b8849b1..b54267681e 100644
--- a/target/mips/tcg/sysemu/mips-semi.c
+++ b/target/mips/tcg/sysemu/mips-semi.c
@@ -198,21 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int
err)
uhi_cb(cs, ret, err);
}
-static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
- target_ulong vaddr)
-{
- int strsize = strlen(semihosting_get_arg(arg_num)) + 1;
- char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0);
- if (!dst) {
- report_fault(env);
- }
-
- strcpy(dst, semihosting_get_arg(arg_num));
-
- unlock_user(dst, vaddr, strsize);
- return 0;
-}
-
#define GET_TARGET_STRING(p, addr) \
do { \
p = lock_user_string(addr); \
@@ -285,18 +270,31 @@ void mips_semihosting(CPUMIPSState *env)
gpr[2] = semihosting_get_argc();
break;
case UHI_argnlen:
- if (gpr[4] >= semihosting_get_argc()) {
- gpr[2] = -1;
- return;
+ {
+ const char *s = semihosting_get_arg(gpr[4]);
+ gpr[2] = s ? strlen(s) : -1;
}
- gpr[2] = strlen(semihosting_get_arg(gpr[4]));
break;
case UHI_argn:
- if (gpr[4] >= semihosting_get_argc()) {
- gpr[2] = -1;
- return;
+ {
+ const char *s = semihosting_get_arg(gpr[4]);
+ target_ulong addr;
+ size_t len;
+
+ if (!s) {
+ gpr[2] = -1;
+ break;
+ }
+ len = strlen(s) + 1;
+ addr = gpr[5];
+ p = lock_user(VERIFY_WRITE, addr, len, 0);
+ if (!p) {
+ report_fault(env);
+ }
+ memcpy(p, s, len);
+ unlock_user(p, addr, len);
+ gpr[2] = 0;
}
- gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]);
break;
case UHI_plog:
--
2.34.1
- Re: [PATCH v4 03/11] target/mips: Create report_fault for semihosting, (continued)
- [PATCH v4 06/11] target/mips: Use semihosting/syscalls.h, Richard Henderson, 2022/06/08
- [PATCH v4 04/11] target/mips: Drop link syscall from semihosting, Richard Henderson, 2022/06/08
- [PATCH v4 09/11] semihosting: Remove qemu_semihosting_log_out, Richard Henderson, 2022/06/08
- [PATCH v4 07/11] target/mips: Avoid qemu_semihosting_log_out for UHI_plog, Richard Henderson, 2022/06/08
- [PATCH v4 05/11] target/mips: Drop pread and pwrite syscalls from semihosting, Richard Henderson, 2022/06/08
- [PATCH v4 08/11] target/mips: Use error_report for UHI_assert, Richard Henderson, 2022/06/08
- [PATCH v4 10/11] target/mips: Simplify UHI_argnlen and UHI_argn,
Richard Henderson <=
- [PATCH v4 11/11] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING, Richard Henderson, 2022/06/08