target/mips: Rewrite UHI errno_mips() to allow building on Haiku OS
cover target/mips: Rewrite UHI errno_mips() to allow building on Haiku OS
Richard Zak reported a build failure on Haiku OS which is due to using POSIX errno as array indexes:
https://www.mail-archive.com/[email protected]/msg820587.html
Work around by using a GHashTable.
Since we were reviewing the UHI (semihosting) spec, fix the errno values and complete to support all the specified errnos.
Regards,
Phil.
Philippe Mathieu-Daudé (4):
target/mips: Fix UHI error values
target/mips: Rename UHI err -> host_errno target/mips: Rewrite UHI errno_mips() using GHashTable target/mips: Complete UHI errno list and log unexpected errors
target/mips/tcg/sysemu/mips-semi.c | 105 ++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 17 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/4 target/mips: Fix UHI error values
The UHI support was posted *before* [1] the specification was released, and merged (commit 2c44b19c199) around the same time [2], using Linux kernel errno values.
Update to use the spec values.
[1] https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg05387.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2015-06/msg05231.html
--- target/mips/tcg/sysemu/mips-semi.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
target/mips/tcg/sysemu/mips-semi.c +9 -4
@@ -1,6 +1,8 @@/* * Unified Hosting Interface syscalls. * +* Specifications: MD01069 Reference Manual (rev 1.1.6, 06 Jul 2015) +* * Copyright (c) 2015 Imagination Technologies * * This library is free software; you can redistribute it and/or
@@ -74,14 +76,17 @@ enum UHIOpenFlags { UHIOpen_EXCL =0x800 }; -/* Errno values taken from asm-mips/errno.h */ +/* +* Unified Hosting Interface (rev 1.1.6) +* Appendix A. "Error values" +*/ static const uint16_t host_to_mips_errno[] = { - [ENAMETOOLONG ] =78 , + [ENAMETOOLONG ] =91 , #ifdef EOVERFLOW - [EOVERFLOW ] =79 , + [EOVERFLOW ] =139 , #endif #ifdef ELOOP - [ELOOP ] =90 , + [ELOOP ] =92 , #endif };
Signature · 1 line
2.31.1
PATCH 2/4 target/mips: Rename UHI err -> host_errno
In reply to Philippe Mathieu-DaudéRename 'err' as 'host_errno' to ease code review.
--- target/mips/tcg/sysemu/mips-semi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/mips/tcg/sysemu/mips-semi.c +5 -5
@@ -90,14 +90,14 @@ static const uint16_t host_to_mips_errno[] = {#endif }; -static int errno_mips (int err) +static int errno_mips (int host_errno) { -if (err <0 || err >=ARRAY_SIZE (host_to_mips_errno)) { +if (host_errno <0 || host_errno >=ARRAY_SIZE (host_to_mips_errno)) {return EINVAL ; - }else if (host_to_mips_errno[err]) { -return host_to_mips_errno[err]; + }else if (host_to_mips_errno[host_errno]) { +return host_to_mips_errno[host_errno]; }else { -return err; +return host_errno; } }
Signature · 1 line
2.31.1
PATCH 3/4 target/mips: Rewrite UHI errno_mips() using GHashTable
In reply to Philippe Mathieu-DaudéLinking on Haiku OS fails:
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
error: libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is too large (0xffff405a bytes) /boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
final link failed: memory exhausted
collect2: error: ld returned 1 exit status
This is because the host_to_mips_errno[] uses errno as index, for example:
static const uint16_t host_to_mips_errno[] = {
[ENAMETOOLONG] = 91,
...and Haiku defines [*] ENAMETOOLONG as:
12 /* Error baselines */
13 #define B_GENERAL_ERROR_BASE INT_MIN
..
22 #define B_STORAGE_ERROR_BASE (B_GENERAL_ERROR_BASE + 0x6000)
...
106 #define B_NAME_TOO_LONG (B_STORAGE_ERROR_BASE + 4)
...
211 #define ENAMETOOLONG B_TO_POSIX_ERROR(B_NAME_TOO_LONG)
so the array ends up beeing indeed too big.
Since POSIX errno can't be use as indexes on Haiku, rewrite errno_mips() using a GHashTable.
[*] https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
--- target/mips/tcg/sysemu/mips-semi.c | 62 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-)
target/mips/tcg/sysemu/mips-semi.c +45 -17
@@ -4,6 +4,7 @@* Specifications: MD01069 Reference Manual (rev 1.1.6, 06 Jul 2015) * * Copyright (c) 2015 Imagination Technologies +* Copyright (c) 2021 Philippe Mathieu-Daudé * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public
@@ -76,29 +77,56 @@ enum UHIOpenFlags { UHIOpen_EXCL =0x800 }; -/* -* Unified Hosting Interface (rev 1.1.6) -* Appendix A. "Error values" -*/ -static const uint16_t host_to_mips_errno[] = { - [ENAMETOOLONG ] =91 , -#ifdef EOVERFLOW - [EOVERFLOW ] =139 , -#endif +static GHashTable *uhi_errno_hash_table; + +static void uhi_errno_insert (int host_errno,int uhi_errno) +{ +gboolean ret = TRUE; + +assert (uhi_errno_hash_table !=NULL ); + ret =g_hash_table_insert (uhi_errno_hash_table, +GINT_TO_POINTER (host_errno), +GINT_TO_POINTER (uhi_errno)); +assert (ret == TRUE); +} + +static void uhi_errno_init (void ) +{ +gboolean ret = TRUE; + + uhi_errno_hash_table =g_hash_table_new (NULL ,NULL ); + +/* +* Unified Hosting Interface (rev 1.1.6) +* Appendix A. "Error values" +*/ +uhi_errno_insert (ENAMETOOLONG ,91 );#ifdef ELOOP - [ELOOP ] =92 , +uhi_errno_insert (ELOOP ,92 );#endif -}; +#ifdef EOVERFLOW +uhi_errno_insert (EOVERFLOW ,139 ); +#endif +assert (ret == TRUE); +}static int errno_mips (int host_errno) { -if (host_errno <0 || host_errno >=ARRAY_SIZE (host_to_mips_errno)) { -return EINVAL ; - }else if (host_to_mips_errno[host_errno]) { -return host_to_mips_errno[host_errno]; - }else { -return host_errno; +gpointer uhi_errno; + +if (uhi_errno_hash_table ==NULL ) { +uhi_errno_init (); } + +if (host_errno ==0 ) { +return 0 ; + } +if (g_hash_table_lookup_extended (uhi_errno_hash_table, +GINT_TO_POINTER (host_errno), +NULL , &uhi_errno)) { +return GPOINTER_TO_INT (uhi_errno); + } +return EINVAL ;/* Not reachable per the specification */ } static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src,
Signature · 1 line
2.31.1
Re: [PATCH 3/4] target/mips: Rewrite UHI errno_mips() using GHashTable
Quoted 52 lines · Philippe Mathieu-Daudé
Linking on Haiku OS fails:
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
error: libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is too large (0xffff405abytes)/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
final link failed: memory exhausted
collect2: error: ld returned 1 exit statusThis is because the host_to_mips_errno[] uses errno as index, for example:
static const uint16_t host_to_mips_errno[] = { [ENAMETOOLONG] = 91, ...and Haiku defines [*] ENAMETOOLONG as:
12 /* Error baselines */
13 #defineB_GENERAL_ERROR_BASEINT_MIN
..
22 #defineB_STORAGE_ERROR_BASE(B_GENERAL_ERROR_BASE+0x6000)
...
106 #defineB_NAME_TOO_LONG(B_STORAGE_ERROR_BASE+ 4)
...
211 #define ENAMETOOLONGB_TO_POSIX_ERROR(B_NAME_TOO_LONG)so the array ends up beeing indeed too big.
Since POSIX errno can't be use as indexes on Haiku, rewrite
errno_mips()using a GHashTable.[*] https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/sysemu/mips-semi.c | 62 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-)static int
errno_mips(int host_errno)
{target/mips/tcg/sysemu/mips-semi.c +4
-6-if (host_errno <0 || host_errno >=ARRAY_SIZE (host_to_mips_errno)) { -return EINVAL ; - }else if (host_to_mips_errno[host_errno]) { -return host_to_mips_errno[host_errno]; - }else { -return host_errno; +gpointer uhi_errno; + +if (uhi_errno_hash_table ==NULL ) { +uhi_errno_init (); }
target/mips/tcg/sysemu/mips-semi.c enum UHIOpenFlags { · line 129
Quoted 10 lines
target/mips/tcg/sysemu/mips-semi.c +10
-0+ +if (host_errno ==0 ) { +return 0 ; + } +if (g_hash_table_lookup_extended (uhi_errno_hash_table, +GINT_TO_POINTER (host_errno), +NULL , &uhi_errno)) { +return GPOINTER_TO_INT (uhi_errno); + } +return EINVAL ;/* Not reachable per the specification */
Per whose specification? This function is passed the errno as set by various host OS functions like open(), lseek(), read(). POSIX allows those functions to set errno to any value, so this "we don't know a guest errno value for that" code is definitely reachable.
thanks
-- PMM
Re: [PATCH 3/4] target/mips: Rewrite UHI errno_mips() using GHashTable
Quoted 60 lines · Peter Maydell
Quoted 59 lines · Philippe Mathieu-Daudé
Linking on Haiku OS fails:
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
error: libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is too large (0xffff405abytes)/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
final link failed: memory exhausted
collect2: error: ld returned 1 exit statusThis is because the host_to_mips_errno[] uses errno as index, for example:
static const uint16_t host_to_mips_errno[] = { [ENAMETOOLONG] = 91, ...and Haiku defines [*] ENAMETOOLONG as:
12 /* Error baselines */
13 #defineB_GENERAL_ERROR_BASEINT_MIN
..
22 #defineB_STORAGE_ERROR_BASE(B_GENERAL_ERROR_BASE+0x6000)
...
106 #defineB_NAME_TOO_LONG(B_STORAGE_ERROR_BASE+ 4)
...
211 #define ENAMETOOLONGB_TO_POSIX_ERROR(B_NAME_TOO_LONG)so the array ends up beeing indeed too big.
Since POSIX errno can't be use as indexes on Haiku, rewrite
errno_mips()using a GHashTable.[*] https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/sysemu/mips-semi.c | 62 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-)static int
errno_mips(int host_errno)
{target/mips/tcg/sysemu/mips-semi.c +11
-6-if (host_errno <0 || host_errno >=ARRAY_SIZE (host_to_mips_errno)) { -return EINVAL ; - }else if (host_to_mips_errno[host_errno]) { -return host_to_mips_errno[host_errno]; - }else { -return host_errno; +gpointer uhi_errno; + +if (uhi_errno_hash_table ==NULL ) { +uhi_errno_init (); } + +if (host_errno ==0 ) { +return 0 ; + } +if (g_hash_table_lookup_extended (uhi_errno_hash_table, +GINT_TO_POINTER (host_errno), +NULL , &uhi_errno)) {
Quoted 8 lines
target/mips/tcg/sysemu/mips-semi.c enum UHIOpenFlags { · line 129
Quoted 3 lines
target/mips/tcg/sysemu/mips-semi.c +3
-0+return GPOINTER_TO_INT (uhi_errno); + } +return EINVAL ;/* Not reachable per the specification */ Per whose specification? This function is passed the errno as set by various host OS functions like
open(),lseek(),read(). POSIX allows those functions to set errno to any value, so this "we don't know a guest errno value for that" code is definitely reachable.
You are right, it is reachable. What I meant is other errnos are not expected, and returning EINVAL for them doesn't seem ideal, but the spec doesn't define a particular errno for unsupported errnos. I'll reword as "Unsupported errno is not specified, use EINVAL".
Re: [PATCH 3/4] target/mips: Rewrite UHI errno_mips() using GHashTable
In reply to Philippe Mathieu-DaudéQuoted 112 lines · Philippe Mathieu-Daudé
Linking on Haiku OS fails:
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
error: libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is too large (0xffff405abytes)/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:
final link failed: memory exhausted
collect2: error: ld returned 1 exit statusThis is because the host_to_mips_errno[] uses errno as index, for example:
static const uint16_t host_to_mips_errno[] = { [ENAMETOOLONG] = 91, ...and Haiku defines [*] ENAMETOOLONG as:
12 /* Error baselines */
13 #defineB_GENERAL_ERROR_BASEINT_MIN
..
22 #defineB_STORAGE_ERROR_BASE(B_GENERAL_ERROR_BASE+0x6000)
...
106 #defineB_NAME_TOO_LONG(B_STORAGE_ERROR_BASE+ 4)
...
211 #define ENAMETOOLONGB_TO_POSIX_ERROR(B_NAME_TOO_LONG)so the array ends up beeing indeed too big.
Since POSIX errno can't be use as indexes on Haiku, rewrite
errno_mips()using a GHashTable.[*] https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/sysemu/mips-semi.c | 62 ++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-)target/mips/tcg/sysemu/mips-semi.c +36
-17@@ -4,6 +4,7 @@* Specifications: MD01069 Reference Manual (rev 1.1.6, 06 Jul 2015) * * Copyright (c) 2015 Imagination Technologies +* Copyright (c) 2021 Philippe Mathieu-Daudé * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -76,29 +77,56 @@ enum UHIOpenFlags { UHIOpen_EXCL =0x800 }; -/* -* Unified Hosting Interface (rev 1.1.6) -* Appendix A. "Error values" -*/ -static const uint16_t host_to_mips_errno[] = { - [ENAMETOOLONG ] =91 , -#ifdef EOVERFLOW - [EOVERFLOW ] =139 , -#endif +static GHashTable *uhi_errno_hash_table; + +static void uhi_errno_insert (int host_errno,int uhi_errno) +{ +gboolean ret = TRUE; + +assert (uhi_errno_hash_table !=NULL ); + ret =g_hash_table_insert (uhi_errno_hash_table, +GINT_TO_POINTER (host_errno), +GINT_TO_POINTER (uhi_errno)); +assert (ret == TRUE); +} + +static void uhi_errno_init (void ) +{ +gboolean ret = TRUE; + + uhi_errno_hash_table =g_hash_table_new (NULL ,NULL ); + +/* +* Unified Hosting Interface (rev 1.1.6) +* Appendix A. "Error values" +*/ +uhi_errno_insert (ENAMETOOLONG ,91 );#ifdef ELOOP - [ELOOP ] =92 , +uhi_errno_insert (ELOOP ,92 );#endif -}; +#ifdef EOVERFLOW +uhi_errno_insert (EOVERFLOW ,139 ); +#endif +assert (ret == TRUE); +}static int errno_mips (int host_errno) { -if (host_errno <0 || host_errno >=ARRAY_SIZE (host_to_mips_errno)) { -return EINVAL ; - }else if (host_to_mips_errno[host_errno]) { -return host_to_mips_errno[host_errno]; - }else { -return host_errno; +gpointer uhi_errno; + +if (uhi_errno_hash_table ==NULL ) { +uhi_errno_init (); } +
target/mips/tcg/sysemu/mips-semi.c enum UHIOpenFlags { · line 130
Quoted 10 lines
target/mips/tcg/sysemu/mips-semi.c +9
-0+if (host_errno ==0 ) { +return 0 ; + } +if (g_hash_table_lookup_extended (uhi_errno_hash_table, +GINT_TO_POINTER (host_errno), +NULL , &uhi_errno)) { +return GPOINTER_TO_INT (uhi_errno); + } +return EINVAL ;/* Not reachable per the specification */ }
Why not simply use a switch-case statement instead? ... that's simpler and still allows to compiler to optimize if the errno values are in a compact range.
Thomas
Re: [PATCH 3/4] target/mips: Rewrite UHI errno_mips() using GHashTable
Quoted 92 lines · Thomas Huth
Quoted 91 lines · Philippe Mathieu-Daudé
Linking on Haiku OS fails:
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:error:
libqemu-mips-softmmu.fa.p/target_mips_tcg_sysemu_mips-semi.c.o(.rodata) is
too large (0xffff405abytes)
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0/../../../../x86_64-unknown-haiku/bin/ld:final link failed: memory exhausted
collect2: error: ld returned 1 exit statusThis is because the host_to_mips_errno[] uses errno as index, for example:
static const
uint16_thost_to_mips_errno[] = {
[ENAMETOOLONG] = 91,
...and Haiku defines [*] ENAMETOOLONG as:
12 /* Error baselines */
13 #define B_GENERAL_ERROR_BASEINT_MIN
..
22 #define B_STORAGE_ERROR_BASE (B_GENERAL_ERROR_BASE
+0x6000)
...
106 #define B_NAME_TOO_LONG (B_STORAGE_ERROR_BASE
+ 4)
...
211 #define ENAMETOOLONGB_TO_POSIX_ERROR(B_NAME_TOO_LONG)so the array ends up beeing indeed too big.
Since POSIX errno can't be use as indexes on Haiku, rewrite
errno_mips()using a GHashTable.[*]
https://github.com/haiku/haiku/blob/r1beta3/headers/os/support/Errors.h#L130Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/mips/tcg/sysemu/mips-semi.c| 62 ++++++++++++++++++++++--------1 file changed, 45 insertions(+), 17 deletions(-)target/mips/tcg/sysemu/mips-semi.c +11
-0+static void uhi_errno_init (void ) +{ + gboolean ret = TRUE; + + uhi_errno_hash_table = g_hash_table_new(NULL, NULL); + + /* + * Unified Hosting Interface (rev 1.1.6) + * Appendix A. "Error values" + */ + uhi_errno_insert(ENAMETOOLONG, 91);#ifdef ELOOP
- [ELOOP] = 92,
+uhi_errno_insert(ELOOP, 92);
#endiftarget/mips/tcg/sysemu/mips-semi.c +5
-1-}; +#ifdef EOVERFLOW + uhi_errno_insert(EOVERFLOW, 139); +#endif + assert(ret == TRUE); +}static int
errno_mips(int host_errno)
{
- if (host_errno< 0 ||host_errno>=ARRAY_SIZE(host_to_mips_errno)) {
- return EINVAL;
- } else if (host_to_mips_errno[host_errno]) {
- return host_to_mips_errno[host_errno];
- } else {
- returnhost_errno;
+ gpointeruhi_errno;
+
+ if (uhi_errno_hash_table== NULL) {
+uhi_errno_init();
}
+
+ if (host_errno== 0) {
+ return 0;
+ }
+ if (g_hash_table_lookup_extended(uhi_errno_hash_table, +GINT_TO_POINTER(host_errno), + NULL,&uhi_errno)) {
Quoted 8 lines
Quoted 4 lines
+ return
GPOINTER_TO_INT(uhi_errno);
+ }
+ return EINVAL; /* Not reachable per the specification */ }Why not simply use a switch-case statement instead? ... that's simpler and still allows to compiler to optimize if the errno values are in a compact range.
I was expecting the #ifdef'ry to be ugly, but there isn't that many actually. Sigh :(
PATCH 4/4 target/mips: Complete UHI errno list and log unexpected errors
In reply to Philippe Mathieu-DaudéThe spec only defines a set of host errno to translate to guest. Complete the current errno set, and log unexpected errno (they are currently replaced by EINVAL, which is dubious, but we don't modify this).
--- target/mips/tcg/sysemu/mips-semi.c | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
target/mips/tcg/sysemu/mips-semi.c +38 -0
@@ -100,10 +100,46 @@ static void uhi_errno_init(void)* Unified Hosting Interface (rev 1.1.6) * Appendix A. "Error values" */ +uhi_errno_insert (EPERM ,1 ); +uhi_errno_insert (ENOENT ,2 ); +uhi_errno_insert (EINTR ,4 ); +uhi_errno_insert (EIO ,5 ); +uhi_errno_insert (ENXIO ,6 ); +uhi_errno_insert (EBADF ,9 ); +uhi_errno_insert (EAGAIN ,11 ); +uhi_errno_insert (EWOULDBLOCK ,11 ); +uhi_errno_insert (ENOMEM ,12 ); +uhi_errno_insert (EACCES ,13 ); +uhi_errno_insert (EBUSY ,16 ); +uhi_errno_insert (EEXIST ,17 ); +uhi_errno_insert (EXDEV ,18 ); +uhi_errno_insert (ENOTDIR ,20 ); +uhi_errno_insert (EISDIR ,21 ); +uhi_errno_insert (EINVAL ,22 ); +uhi_errno_insert (ENFILE ,23 ); +uhi_errno_insert (EMFILE ,24 ); +#ifdef ETXTBSY +uhi_errno_insert (ETXTBSY ,26 ); +#endif +uhi_errno_insert (EFBIG ,27 ); +uhi_errno_insert (ENOSPC ,28 ); +uhi_errno_insert (ESPIPE ,29 ); +uhi_errno_insert (EROFS ,30 ); +uhi_errno_insert (EMLINK ,31 ); +uhi_errno_insert (EPIPE ,32 ); +uhi_errno_insert (ERANGE ,34 ); +uhi_errno_insert (ENOSR ,63 ); +uhi_errno_insert (EBADMSG ,77 );uhi_errno_insert (ENAMETOOLONG ,91 );#ifdef ELOOP uhi_errno_insert (ELOOP ,92 );#endif +uhi_errno_insert (ECONNRESET ,104 ); +uhi_errno_insert (ENOBUFS ,105 ); +uhi_errno_insert (ENETUNREACH ,114 ); +uhi_errno_insert (ENETDOWN ,115 ); +uhi_errno_insert (ETIMEDOUT ,116 ); +uhi_errno_insert (ENOTCONN ,128 );#ifdef EOVERFLOW uhi_errno_insert (EOVERFLOW ,139 );#endif
@@ -126,6 +162,8 @@ static int errno_mips(int host_errno) NULL, &uhi_errno)) {return GPOINTER_TO_INT (uhi_errno); } +qemu_log ("semihosting: Illegal UHI errno: %d\n" , host_errno); +return EINVAL ;/* Not reachable per the specification */ }
Signature · 1 line
2.31.1
Re: [PATCH 4/4] target/mips: Complete UHI errno list and log unexpected errors
Quoted 8 lines · Philippe Mathieu-Daudé
The spec only defines a set of host errno to translate to guest. Complete the current errno set, and log unexpected errno (they are currently replaced by EINVAL, which is dubious, but we don't modify this).
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
This commit adds the definition of the guest EINVAL:
target/mips/tcg/sysemu/mips-semi.c static int errno_mips(int host_errno) · line 168
Quoted 9 lines
target/mips/tcg/sysemu/mips-semi.c +3
-0+uhi_errno_insert (EINVAL ,22 );@@ -126,6 +162,8 @@ static int errno_mips(int host_errno) NULL, &uhi_errno)) {return GPOINTER_TO_INT (uhi_errno); } +qemu_log ("semihosting: Illegal UHI errno: %d\n" , host_errno); +return EINVAL ;/* Not reachable per the specification */ }
...but it leaves the default case returning the host EINVAL.
thanks
-- PMM
Re: [PATCH 4/4] target/mips: Complete UHI errno list and log unexpected errors
Quoted 12 lines · Peter Maydell
Quoted 8 lines · Philippe Mathieu-Daudé
The spec only defines a set of host errno to translate to guest. Complete the current errno set, and log unexpected errno (they are currently replaced by EINVAL, which is dubious, but we don't modify this).
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
This commit adds the definition of the guest EINVAL:
Quoted 11 lines
target/mips/tcg/sysemu/mips-semi.c static int errno_mips(int host_errno) · line 168
Quoted 9 lines
target/mips/tcg/sysemu/mips-semi.c +3
-0+uhi_errno_insert (EINVAL ,22 );@@ -126,6 +162,8 @@ static int errno_mips(int host_errno) NULL, &uhi_errno)) {return GPOINTER_TO_INT (uhi_errno); } +qemu_log ("semihosting: Illegal UHI errno: %d\n" , host_errno); +return EINVAL ;/* Not reachable per the specification */ }...but it leaves the default case returning the host EINVAL.
Good catch, thank you!