Message ID | 20210708141121.1731691-8-f4bug@amsat.org |
---|---|
State | New |
Headers | show |
Series | linux-user: target <-> host errno conversion code refactor | expand |
Le 08/07/2021 à 16:11, Philippe Mathieu-Daudé a écrit : > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > linux-user/syscall.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 4842a1987b7..56682b06cbd 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -509,6 +509,11 @@ static inline int next_free_host_timer(void) > > #define ERRNO_TABLE_SIZE 1200 > > +static inline bool errno_exists(int err) > +{ > + return err >= 0 && err < ERRNO_TABLE_SIZE; > +} > + > /* target_to_host_errno_table[] is initialized from > * host_to_target_errno_table[] in syscall_init(). */ > static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { > @@ -672,7 +677,7 @@ const char *target_strerror(int err) > return "Successful exit from sigreturn"; > } > > - if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) { > + if (!errno_exists(err)) { > return NULL; > } > return strerror(target_to_host_errno(err)); > Reviewed-by: Laurent Vivier <laurent@vivier.eu>
On 7/8/21 7:11 AM, Philippe Mathieu-Daudé wrote: > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > linux-user/syscall.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 4842a1987b7..56682b06cbd 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -509,6 +509,11 @@ static inline int next_free_host_timer(void) > > #define ERRNO_TABLE_SIZE 1200 > > +static inline bool errno_exists(int err) > +{ > + return err >= 0 && err < ERRNO_TABLE_SIZE; > +} > + > /* target_to_host_errno_table[] is initialized from > * host_to_target_errno_table[] in syscall_init(). */ > static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { > @@ -672,7 +677,7 @@ const char *target_strerror(int err) > return "Successful exit from sigreturn"; > } > > - if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) { > + if (!errno_exists(err)) { > return NULL; > } > return strerror(target_to_host_errno(err)); After patch 8, you can simply remove this test entirely, as well as the otherwise unused and totally arbitrary ERRNO_TABLE_SIZE. r~
diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 4842a1987b7..56682b06cbd 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -509,6 +509,11 @@ static inline int next_free_host_timer(void) #define ERRNO_TABLE_SIZE 1200 +static inline bool errno_exists(int err) +{ + return err >= 0 && err < ERRNO_TABLE_SIZE; +} + /* target_to_host_errno_table[] is initialized from * host_to_target_errno_table[] in syscall_init(). */ static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { @@ -672,7 +677,7 @@ const char *target_strerror(int err) return "Successful exit from sigreturn"; } - if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) { + if (!errno_exists(err)) { return NULL; } return strerror(target_to_host_errno(err));
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- linux-user/syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)