diff mbox series

[v4,19/53] gdbstub: Convert GDB error numbers to host error numbers

Message ID 20220607204557.658541-20-richard.henderson@linaro.org
State Superseded
Headers show
Series semihosting cleanup | expand

Commit Message

Richard Henderson June 7, 2022, 8:45 p.m. UTC
Provide the callback with consistent state -- always use
host error numbers.  The individual callback can then
decide if the errno requires conversion for the guest.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 gdbstub.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Luc Michel June 22, 2022, 7:53 a.m. UTC | #1
On 13:45 Tue 07 Jun     , Richard Henderson wrote:
> Provide the callback with consistent state -- always use
> host error numbers.  The individual callback can then
> decide if the errno requires conversion for the guest.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Luc Michel <lmichel@kalray.eu>

> ---
>  gdbstub.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index a3ff8702ce..ecc9d9cd6f 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1878,6 +1878,37 @@ static void handle_file_io(GArray *params, void *user_ctx)
>          } else {
>              err = 0;
>          }
> +
> +        /* Convert GDB error numbers back to host error numbers. */
> +#define E(X)  case GDB_E##X: err = E##X; break
> +        switch (err) {
> +        case 0:
> +            break;
> +        E(PERM);
> +        E(NOENT);
> +        E(INTR);
> +        E(BADF);
> +        E(ACCES);
> +        E(FAULT);
> +        E(BUSY);
> +        E(EXIST);
> +        E(NODEV);
> +        E(NOTDIR);
> +        E(ISDIR);
> +        E(INVAL);
> +        E(NFILE);
> +        E(MFILE);
> +        E(FBIG);
> +        E(NOSPC);
> +        E(SPIPE);
> +        E(ROFS);
> +        E(NAMETOOLONG);
> +        default:
> +            err = EINVAL;
> +            break;
> +        }
> +#undef E
> +
>          gdbserver_state.current_syscall_cb(gdbserver_state.c_cpu, ret, err);
>          gdbserver_state.current_syscall_cb = NULL;
>      }
> -- 
> 2.34.1
> 
> 
> 
> 
> To declare a filtering error, please use the following link : https://www.security-mail.net/reporter.php?mid=12eb3.629fd0dd.8c7c2.0&r=lmichel%40kalrayinc.com&s=qemu-devel-bounces%2Blmichel%3Dkalrayinc.com%40nongnu.org&o=%5BPATCH+v4+19%2F53%5D+gdbstub%3A+Convert+GDB+error+numbers+to+host+error+numbers&verdict=C&c=cdb84b0ad101f626e700d163f173cb52e6d969f7
> 

--
diff mbox series

Patch

diff --git a/gdbstub.c b/gdbstub.c
index a3ff8702ce..ecc9d9cd6f 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1878,6 +1878,37 @@  static void handle_file_io(GArray *params, void *user_ctx)
         } else {
             err = 0;
         }
+
+        /* Convert GDB error numbers back to host error numbers. */
+#define E(X)  case GDB_E##X: err = E##X; break
+        switch (err) {
+        case 0:
+            break;
+        E(PERM);
+        E(NOENT);
+        E(INTR);
+        E(BADF);
+        E(ACCES);
+        E(FAULT);
+        E(BUSY);
+        E(EXIST);
+        E(NODEV);
+        E(NOTDIR);
+        E(ISDIR);
+        E(INVAL);
+        E(NFILE);
+        E(MFILE);
+        E(FBIG);
+        E(NOSPC);
+        E(SPIPE);
+        E(ROFS);
+        E(NAMETOOLONG);
+        default:
+            err = EINVAL;
+            break;
+        }
+#undef E
+
         gdbserver_state.current_syscall_cb(gdbserver_state.c_cpu, ret, err);
         gdbserver_state.current_syscall_cb = NULL;
     }