Use host_to_gdb_errno to convert host-supplied errnos to their GDB File-I/O remote protocol values, and use them in F reply packets.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2751 Reported-by: Dominik 'Disconnect3d' Czarnota <[email protected]> Signed-off-by: Yodel Eldar <[email protected]> --- gdbstub/user-target.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c index 43231e695e..7ef0282f70 100644 --- a/gdbstub/user-target.c +++ b/gdbstub/user-target.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" #include "gdbstub/commands.h" +#include "gdbstub/syscalls.h" #include "qemu.h" #include "internals.h" #ifdef CONFIG_LINUX @@ -315,7 +316,8 @@ void gdb_handle_v_file_open(GArray *params, void *user_ctx) int fd = open(filename, flags, mode); #endif if (fd < 0) { - g_string_printf(gdbserver_state.str_buf, "F-1,%x", errno); + int gdb_errno = host_to_gdb_errno(errno); + g_string_printf(gdbserver_state.str_buf, "F-1,%x", gdb_errno); } else { g_string_printf(gdbserver_state.str_buf, "F%x", fd); } @@ -327,7 +329,8 @@ void gdb_handle_v_file_close(GArray *params, void *user_ctx) int fd = gdb_get_cmd_param(params, 0)->val_ul; if (close(fd) == -1) { - g_string_printf(gdbserver_state.str_buf, "F-1,%x", errno); + int gdb_errno = host_to_gdb_errno(errno); + g_string_printf(gdbserver_state.str_buf, "F-1,%x", gdb_errno); gdb_put_strbuf(); return; } @@ -350,7 +353,8 @@ void gdb_handle_v_file_pread(GArray *params, void *user_ctx) ssize_t n = pread(fd, buf, bufsiz, offset); if (n < 0) { - g_string_printf(gdbserver_state.str_buf, "F-1,%x", errno); + int gdb_errno = host_to_gdb_errno(errno); + g_string_printf(gdbserver_state.str_buf, "F-1,%x", gdb_errno); gdb_put_strbuf(); return; } @@ -373,7 +377,8 @@ void gdb_handle_v_file_readlink(GArray *params, void *user_ctx) ssize_t n = readlink(filename, buf, BUFSIZ); #endif if (n < 0) { - g_string_printf(gdbserver_state.str_buf, "F-1,%x", errno); + int gdb_errno = host_to_gdb_errno(errno); + g_string_printf(gdbserver_state.str_buf, "F-1,%x", gdb_errno); gdb_put_strbuf(); return; } -- 2.51.1.dirty
