diff mbox series

[1/3] linux-user/s390x: Fix sigframe types

Message ID 20210428033204.133471-2-richard.henderson@linaro.org
State New
Headers show
Series linux-user/s390x: some signal fixes | expand

Commit Message

Richard Henderson April 28, 2021, 3:32 a.m. UTC
Noticed via gitlab clang-user job:

  TEST    signals on s390x
../linux-user/s390x/signal.c:258:9: runtime error: \
  1.84467e+19 is outside the range of representable values of \
  type 'unsigned long'

Which points to the fact that we were performing a double-to-uint64_t
conversion while storing the fp registers, instead of just copying
the data across.

Turns out there are several errors:

target_ulong is the size of the target register, whereas abi_ulong
is the target 'unsigned long' type.  Not a big deal here, since we
only support 64-bit s390x, but not correct either.

In target_sigcontext and target ucontext, we used a host pointer
instead of a target pointer, aka abi_ulong.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 linux-user/s390x/signal.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

-- 
2.25.1

Comments

David Hildenbrand April 28, 2021, 1:53 p.m. UTC | #1
On 28.04.21 05:32, Richard Henderson wrote:
> Noticed via gitlab clang-user job:

> 

>    TEST    signals on s390x

> ../linux-user/s390x/signal.c:258:9: runtime error: \

>    1.84467e+19 is outside the range of representable values of \

>    type 'unsigned long'

> 

> Which points to the fact that we were performing a double-to-uint64_t

> conversion while storing the fp registers, instead of just copying

> the data across.

> 

> Turns out there are several errors:

> 

> target_ulong is the size of the target register, whereas abi_ulong

> is the target 'unsigned long' type.  Not a big deal here, since we

> only support 64-bit s390x, but not correct either.

> 

> In target_sigcontext and target ucontext, we used a host pointer

> instead of a target pointer, aka abi_ulong.

> 

> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>   linux-user/s390x/signal.c | 23 ++++++++++++-----------

>   1 file changed, 12 insertions(+), 11 deletions(-)

> 

> diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c

> index b68b44ae7e..e5bc4f0358 100644

> --- a/linux-user/s390x/signal.c

> +++ b/linux-user/s390x/signal.c

> @@ -37,13 +37,14 @@

>   

>   typedef struct {

>       target_psw_t psw;

> -    target_ulong gprs[__NUM_GPRS];

> -    unsigned int acrs[__NUM_ACRS];

> +    abi_ulong gprs[__NUM_GPRS];

> +    abi_uint acrs[__NUM_ACRS];

>   } target_s390_regs_common;

>   

>   typedef struct {

> -    unsigned int fpc;

> -    double   fprs[__NUM_FPRS];

> +    uint32_t fpc;

> +    uint32_t pad;

> +    uint64_t fprs[__NUM_FPRS];

>   } target_s390_fp_regs;

>   

>   typedef struct {

> @@ -51,22 +52,22 @@ typedef struct {

>       target_s390_fp_regs     fpregs;

>   } target_sigregs;

>   

> -struct target_sigcontext {

> -    target_ulong   oldmask[_SIGCONTEXT_NSIG_WORDS];

> -    target_sigregs *sregs;

> -};

> +typedef struct {

> +    abi_ulong oldmask[_SIGCONTEXT_NSIG_WORDS];

> +    abi_ulong sregs;

> +} target_sigcontext;

>   

>   typedef struct {

>       uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];

> -    struct target_sigcontext sc;

> +    target_sigcontext sc;

>       target_sigregs sregs;

>       int signo;

>       uint8_t retcode[S390_SYSCALL_SIZE];

>   } sigframe;

>   

>   struct target_ucontext {

> -    target_ulong tuc_flags;

> -    struct target_ucontext *tuc_link;

> +    abi_ulong tuc_flags;

> +    abi_ulong tuc_link;

>       target_stack_t tuc_stack;

>       target_sigregs tuc_mcontext;

>       target_sigset_t tuc_sigmask;   /* mask last for extensibility */

> 


Reviewed-by: David Hildenbrand <david@redhat.com>


-- 
Thanks,

David / dhildenb
diff mbox series

Patch

diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index b68b44ae7e..e5bc4f0358 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -37,13 +37,14 @@ 
 
 typedef struct {
     target_psw_t psw;
-    target_ulong gprs[__NUM_GPRS];
-    unsigned int acrs[__NUM_ACRS];
+    abi_ulong gprs[__NUM_GPRS];
+    abi_uint acrs[__NUM_ACRS];
 } target_s390_regs_common;
 
 typedef struct {
-    unsigned int fpc;
-    double   fprs[__NUM_FPRS];
+    uint32_t fpc;
+    uint32_t pad;
+    uint64_t fprs[__NUM_FPRS];
 } target_s390_fp_regs;
 
 typedef struct {
@@ -51,22 +52,22 @@  typedef struct {
     target_s390_fp_regs     fpregs;
 } target_sigregs;
 
-struct target_sigcontext {
-    target_ulong   oldmask[_SIGCONTEXT_NSIG_WORDS];
-    target_sigregs *sregs;
-};
+typedef struct {
+    abi_ulong oldmask[_SIGCONTEXT_NSIG_WORDS];
+    abi_ulong sregs;
+} target_sigcontext;
 
 typedef struct {
     uint8_t callee_used_stack[__SIGNAL_FRAMESIZE];
-    struct target_sigcontext sc;
+    target_sigcontext sc;
     target_sigregs sregs;
     int signo;
     uint8_t retcode[S390_SYSCALL_SIZE];
 } sigframe;
 
 struct target_ucontext {
-    target_ulong tuc_flags;
-    struct target_ucontext *tuc_link;
+    abi_ulong tuc_flags;
+    abi_ulong tuc_link;
     target_stack_t tuc_stack;
     target_sigregs tuc_mcontext;
     target_sigset_t tuc_sigmask;   /* mask last for extensibility */