qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: f4bug@amsat.org
Subject: [PATCH v4 03/11] target/mips: Create report_fault for semihosting
Date: Tue,  7 Jun 2022 22:19:37 -0700	[thread overview]
Message-ID: <20220608051945.802339-4-richard.henderson@linaro.org> (raw)
In-Reply-To: <20220608051945.802339-1-richard.henderson@linaro.org>

The UHI specification does not have an EFAULT value,
and further specifies that "undefined UHI operations
should not return control to the target".

So, log the error and abort.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/mips/tcg/sysemu/mips-semi.c | 33 ++++++++++++++----------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c
index 2a039baf4c..33221444e1 100644
--- a/target/mips/tcg/sysemu/mips-semi.c
+++ b/target/mips/tcg/sysemu/mips-semi.c
@@ -114,6 +114,13 @@ enum UHIErrno {
     UHI_EXDEV           = 18,
 };
 
+static void report_fault(CPUMIPSState *env)
+{
+    int op = env->active_tc.gpr[25];
+    error_report("Fault during UHI operation %d", op);
+    abort();
+}
+
 static int errno_mips(int host_errno)
 {
     /* Errno values taken from asm-mips/errno.h */
@@ -136,8 +143,7 @@ static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src,
     hwaddr len = sizeof(struct UHIStat);
     UHIStat *dst = lock_user(VERIFY_WRITE, vaddr, len, 0);
     if (!dst) {
-        errno = EFAULT;
-        return -1;
+        report_fault(env);
     }
 
     dst->uhi_st_dev = tswap16(src->st_dev);
@@ -188,8 +194,7 @@ static int write_to_file(CPUMIPSState *env, target_ulong fd, target_ulong vaddr,
     int num_of_bytes;
     void *dst = lock_user(VERIFY_READ, vaddr, len, 1);
     if (!dst) {
-        errno = EFAULT;
-        return -1;
+        report_fault(env);
     }
 
     if (offset) {
@@ -213,8 +218,7 @@ static int read_from_file(CPUMIPSState *env, target_ulong fd,
     int num_of_bytes;
     void *dst = lock_user(VERIFY_WRITE, vaddr, len, 0);
     if (!dst) {
-        errno = EFAULT;
-        return -1;
+        report_fault(env);
     }
 
     if (offset) {
@@ -237,7 +241,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
     int strsize = strlen(semihosting_get_arg(arg_num)) + 1;
     char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0);
     if (!dst) {
-        return -1;
+        report_fault(env);
     }
 
     strcpy(dst, semihosting_get_arg(arg_num));
@@ -250,9 +254,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
     do {                                        \
         p = lock_user_string(addr);             \
         if (!p) {                               \
-            gpr[2] = -1;                        \
-            gpr[3] = EFAULT;                    \
-            return;                             \
+            report_fault(env);                  \
         }                                       \
     } while (0)
 
@@ -260,16 +262,11 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num,
     do {                                                \
         p = lock_user_string(addr);                     \
         if (!p) {                                       \
-            gpr[2] = -1;                                \
-            gpr[3] = EFAULT;                            \
-            return;                                     \
+            report_fault(env);                          \
         }                                               \
         p2 = lock_user_string(addr2);                   \
         if (!p2) {                                      \
-            unlock_user(p, addr, 0);                    \
-            gpr[2] = -1;                                \
-            gpr[3] = EFAULT;                            \
-            return;                                     \
+            report_fault(env);                          \
         }                                               \
     } while (0)
 
@@ -400,7 +397,7 @@ void mips_semihosting(CPUMIPSState *env)
         break;
 #endif
     default:
-        fprintf(stderr, "Unknown UHI operation %d\n", op);
+        error_report("Unknown UHI operation %d", op);
         abort();
     }
     return;
-- 
2.34.1



  parent reply	other threads:[~2022-06-08  5:29 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08  5:19 [PATCH v4 00/11] target/mips: semihosting cleanup Richard Henderson
2022-06-08  5:19 ` [PATCH v4 01/11] target/mips: Use an exception for semihosting Richard Henderson
2022-06-10 15:07   ` Philippe Mathieu-Daudé via
2022-06-08  5:19 ` [PATCH v4 02/11] target/mips: Add UHI errno values Richard Henderson
2022-06-10 15:07   ` Philippe Mathieu-Daudé via
2022-06-08  5:19 ` Richard Henderson [this message]
2022-06-10 15:05   ` [PATCH v4 03/11] target/mips: Create report_fault for semihosting Philippe Mathieu-Daudé via
2022-06-11 15:53     ` Richard Henderson
2022-06-08  5:19 ` [PATCH v4 04/11] target/mips: Drop link syscall from semihosting Richard Henderson
2022-06-08  5:19 ` [PATCH v4 05/11] target/mips: Drop pread and pwrite syscalls " Richard Henderson
2022-06-10 15:07   ` Philippe Mathieu-Daudé via
2022-06-08  5:19 ` [PATCH v4 06/11] target/mips: Use semihosting/syscalls.h Richard Henderson
2022-06-08  5:19 ` [PATCH v4 07/11] target/mips: Avoid qemu_semihosting_log_out for UHI_plog Richard Henderson
2022-06-08  5:19 ` [PATCH v4 08/11] target/mips: Use error_report for UHI_assert Richard Henderson
2022-06-10 15:10   ` Philippe Mathieu-Daudé via
2022-06-08  5:19 ` [PATCH v4 09/11] semihosting: Remove qemu_semihosting_log_out Richard Henderson
2022-06-10 15:11   ` Philippe Mathieu-Daudé via
2022-06-08  5:19 ` [PATCH v4 10/11] target/mips: Simplify UHI_argnlen and UHI_argn Richard Henderson
2022-06-08  5:19 ` [PATCH v4 11/11] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING Richard Henderson
2022-06-10 15:12   ` Philippe Mathieu-Daudé via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608051945.802339-4-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=f4bug@amsat.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).