[PATCH 19/24] bsd-user/arm/target_arch_signal.h: arm user context and trapframe for signals

Warner Losh posted 24 patches 4 years, 3 months ago
Maintainers: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Laurent Vivier <laurent@vivier.eu>, Michael Tokarev <mjt@tls.msk.ru>
There is a newer version of this series
[PATCH 19/24] bsd-user/arm/target_arch_signal.h: arm user context and trapframe for signals
Posted by Warner Losh 4 years, 3 months ago
Arm specific user context structures for signal handling and the closely
related trap frame.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/arm/target_arch_signal.h | 38 +++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/bsd-user/arm/target_arch_signal.h b/bsd-user/arm/target_arch_signal.h
index 9fee58ca9c..67355ff28f 100644
--- a/bsd-user/arm/target_arch_signal.h
+++ b/bsd-user/arm/target_arch_signal.h
@@ -90,4 +90,42 @@ typedef struct target_mcontext {
     } __fpu;
 } target_mcontext_t;
 
+typedef struct target_ucontext {
+    target_sigset_t     uc_sigmask;
+    target_mcontext_t   uc_mcontext;
+    abi_ulong           uc_link;
+    target_stack_t      uc_stack;
+    int32_t             uc_flags;
+    int32_t             __spare__[4];
+} target_ucontext_t;
+
+struct target_sigframe {
+    target_siginfo_t    sf_si;  /* saved siginfo */
+    target_ucontext_t   sf_uc;  /* saved ucontext */
+};
+
+
+/* compare to sys/arm/include/frame.h */
+struct target_trapframe {
+    abi_ulong tf_spsr; /* Zero on arm26 */
+    abi_ulong tf_r0;
+    abi_ulong tf_r1;
+    abi_ulong tf_r2;
+    abi_ulong tf_r3;
+    abi_ulong tf_r4;
+    abi_ulong tf_r5;
+    abi_ulong tf_r6;
+    abi_ulong tf_r7;
+    abi_ulong tf_r8;
+    abi_ulong tf_r9;
+    abi_ulong tf_r10;
+    abi_ulong tf_r11;
+    abi_ulong tf_r12;
+    abi_ulong tf_usr_sp;
+    abi_ulong tf_usr_lr;
+    abi_ulong tf_svc_sp; /* Not used on arm26 */
+    abi_ulong tf_svc_lr; /* Not used on arm26 */
+    abi_ulong tf_pc;
+};
+
 #endif /* !_TARGET_ARCH_SIGNAL_H_ */
-- 
2.32.0


Re: [PATCH 19/24] bsd-user/arm/target_arch_signal.h: arm user context and trapframe for signals
Posted by Kyle Evans 4 years, 3 months ago
On Tue, Oct 19, 2021 at 11:45 AM Warner Losh <imp@bsdimp.com> wrote:
>
> Arm specific user context structures for signal handling and the closely
> related trap frame.
>
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>  bsd-user/arm/target_arch_signal.h | 38 +++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
>
> diff --git a/bsd-user/arm/target_arch_signal.h b/bsd-user/arm/target_arch_signal.h
> index 9fee58ca9c..67355ff28f 100644
> --- a/bsd-user/arm/target_arch_signal.h
> +++ b/bsd-user/arm/target_arch_signal.h
> @@ -90,4 +90,42 @@ typedef struct target_mcontext {
>      } __fpu;
>  } target_mcontext_t;
>
> +typedef struct target_ucontext {
> +    target_sigset_t     uc_sigmask;
> +    target_mcontext_t   uc_mcontext;
> +    abi_ulong           uc_link;
> +    target_stack_t      uc_stack;
> +    int32_t             uc_flags;
> +    int32_t             __spare__[4];
> +} target_ucontext_t;
> +
> +struct target_sigframe {
> +    target_siginfo_t    sf_si;  /* saved siginfo */
> +    target_ucontext_t   sf_uc;  /* saved ucontext */
> +};
> +
> +

We might be able to kill this extra newline? I'm not familiar enough
with qemu's style preferences here...

> +/* compare to sys/arm/include/frame.h */
> +struct target_trapframe {
> +    abi_ulong tf_spsr; /* Zero on arm26 */
> +    abi_ulong tf_r0;
> +    abi_ulong tf_r1;
> +    abi_ulong tf_r2;
> +    abi_ulong tf_r3;
> +    abi_ulong tf_r4;
> +    abi_ulong tf_r5;
> +    abi_ulong tf_r6;
> +    abi_ulong tf_r7;
> +    abi_ulong tf_r8;
> +    abi_ulong tf_r9;
> +    abi_ulong tf_r10;
> +    abi_ulong tf_r11;
> +    abi_ulong tf_r12;
> +    abi_ulong tf_usr_sp;
> +    abi_ulong tf_usr_lr;
> +    abi_ulong tf_svc_sp; /* Not used on arm26 */
> +    abi_ulong tf_svc_lr; /* Not used on arm26 */
> +    abi_ulong tf_pc;
> +};
> +
>  #endif /* !_TARGET_ARCH_SIGNAL_H_ */
> --
> 2.32.0
>

I didn't think we actually supported arm26, but I see those comments
also exist verbatim in machine/frame.h; no objection to reflecting
them here, as well.

Reviewed-by: Kyle Evans <kevans@FreeBSD.org>

Re: [PATCH 19/24] bsd-user/arm/target_arch_signal.h: arm user context and trapframe for signals
Posted by Warner Losh 4 years, 3 months ago
On Tue, Oct 26, 2021 at 12:07 AM Kyle Evans <kevans@freebsd.org> wrote:

> On Tue, Oct 19, 2021 at 11:45 AM Warner Losh <imp@bsdimp.com> wrote:
> >
> > Arm specific user context structures for signal handling and the closely
> > related trap frame.
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >  bsd-user/arm/target_arch_signal.h | 38 +++++++++++++++++++++++++++++++
> >  1 file changed, 38 insertions(+)
> >
> > diff --git a/bsd-user/arm/target_arch_signal.h
> b/bsd-user/arm/target_arch_signal.h
> > index 9fee58ca9c..67355ff28f 100644
> > --- a/bsd-user/arm/target_arch_signal.h
> > +++ b/bsd-user/arm/target_arch_signal.h
> > @@ -90,4 +90,42 @@ typedef struct target_mcontext {
> >      } __fpu;
> >  } target_mcontext_t;
> >
> > +typedef struct target_ucontext {
> > +    target_sigset_t     uc_sigmask;
> > +    target_mcontext_t   uc_mcontext;
> > +    abi_ulong           uc_link;
> > +    target_stack_t      uc_stack;
> > +    int32_t             uc_flags;
> > +    int32_t             __spare__[4];
> > +} target_ucontext_t;
> > +
> > +struct target_sigframe {
> > +    target_siginfo_t    sf_si;  /* saved siginfo */
> > +    target_ucontext_t   sf_uc;  /* saved ucontext */
> > +};
> > +
> > +
>
> We might be able to kill this extra newline? I'm not familiar enough
> with qemu's style preferences here...
>

done.


> > +/* compare to sys/arm/include/frame.h */
> > +struct target_trapframe {
> > +    abi_ulong tf_spsr; /* Zero on arm26 */
> > +    abi_ulong tf_r0;
> > +    abi_ulong tf_r1;
> > +    abi_ulong tf_r2;
> > +    abi_ulong tf_r3;
> > +    abi_ulong tf_r4;
> > +    abi_ulong tf_r5;
> > +    abi_ulong tf_r6;
> > +    abi_ulong tf_r7;
> > +    abi_ulong tf_r8;
> > +    abi_ulong tf_r9;
> > +    abi_ulong tf_r10;
> > +    abi_ulong tf_r11;
> > +    abi_ulong tf_r12;
> > +    abi_ulong tf_usr_sp;
> > +    abi_ulong tf_usr_lr;
> > +    abi_ulong tf_svc_sp; /* Not used on arm26 */
> > +    abi_ulong tf_svc_lr; /* Not used on arm26 */
> > +    abi_ulong tf_pc;
> > +};
> > +
> >  #endif /* !_TARGET_ARCH_SIGNAL_H_ */
> > --
> > 2.32.0
> >
>
> I didn't think we actually supported arm26, but I see those comments
> also exist verbatim in machine/frame.h; no objection to reflecting
> them here, as well.
>

Removed. I'll prep a commit for the fork too and remove them from FreeBSD
since they have never been relevant.


> Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
>

Thanks!
Re: [PATCH 19/24] bsd-user/arm/target_arch_signal.h: arm user context and trapframe for signals
Posted by Richard Henderson 4 years, 3 months ago
On 10/19/21 9:44 AM, Warner Losh wrote:
> Arm specific user context structures for signal handling and the closely
> related trap frame.
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>   bsd-user/arm/target_arch_signal.h | 38 +++++++++++++++++++++++++++++++
>   1 file changed, 38 insertions(+)
> 
> diff --git a/bsd-user/arm/target_arch_signal.h b/bsd-user/arm/target_arch_signal.h
> index 9fee58ca9c..67355ff28f 100644
> --- a/bsd-user/arm/target_arch_signal.h
> +++ b/bsd-user/arm/target_arch_signal.h
> @@ -90,4 +90,42 @@ typedef struct target_mcontext {
>       } __fpu;
>   } target_mcontext_t;
>   
> +typedef struct target_ucontext {
> +    target_sigset_t     uc_sigmask;
> +    target_mcontext_t   uc_mcontext;
> +    abi_ulong           uc_link;
> +    target_stack_t      uc_stack;
> +    int32_t             uc_flags;
> +    int32_t             __spare__[4];
> +} target_ucontext_t;

This is from the common <sys/_ucontext.h>.  Is there any way we can share that here in 
qemu as well?

> +struct target_sigframe {
> +    target_siginfo_t    sf_si;  /* saved siginfo */
> +    target_ucontext_t   sf_uc;  /* saved ucontext */
> +};

You're missing the storage for

   mcontext_vfp_t  sf_vfp

the address of which goes in mcontext_t.mc_vfp_ptr (which isn't in the version of 
mcontext_t from patch 18).

> +/* compare to sys/arm/include/frame.h */
> +struct target_trapframe {
> +    abi_ulong tf_spsr; /* Zero on arm26 */
> +    abi_ulong tf_r0;
> +    abi_ulong tf_r1;
> +    abi_ulong tf_r2;
> +    abi_ulong tf_r3;
> +    abi_ulong tf_r4;
> +    abi_ulong tf_r5;
> +    abi_ulong tf_r6;
> +    abi_ulong tf_r7;
> +    abi_ulong tf_r8;
> +    abi_ulong tf_r9;
> +    abi_ulong tf_r10;
> +    abi_ulong tf_r11;
> +    abi_ulong tf_r12;
> +    abi_ulong tf_usr_sp;
> +    abi_ulong tf_usr_lr;
> +    abi_ulong tf_svc_sp; /* Not used on arm26 */
> +    abi_ulong tf_svc_lr; /* Not used on arm26 */
> +    abi_ulong tf_pc;
> +};

This is not used by the user abi for signals.  It is a kernel structure for its own 
internal trap handling.  Why are you including it?


r~

Re: [PATCH 19/24] bsd-user/arm/target_arch_signal.h: arm user context and trapframe for signals
Posted by Warner Losh 4 years, 3 months ago
On Thu, Oct 28, 2021 at 11:22 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 10/19/21 9:44 AM, Warner Losh wrote:
> > Arm specific user context structures for signal handling and the closely
> > related trap frame.
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Warner Losh <imp@bsdimp.com>
> > ---
> >   bsd-user/arm/target_arch_signal.h | 38 +++++++++++++++++++++++++++++++
> >   1 file changed, 38 insertions(+)
> >
> > diff --git a/bsd-user/arm/target_arch_signal.h
> b/bsd-user/arm/target_arch_signal.h
> > index 9fee58ca9c..67355ff28f 100644
> > --- a/bsd-user/arm/target_arch_signal.h
> > +++ b/bsd-user/arm/target_arch_signal.h
> > @@ -90,4 +90,42 @@ typedef struct target_mcontext {
> >       } __fpu;
> >   } target_mcontext_t;
> >
> > +typedef struct target_ucontext {
> > +    target_sigset_t     uc_sigmask;
> > +    target_mcontext_t   uc_mcontext;
> > +    abi_ulong           uc_link;
> > +    target_stack_t      uc_stack;
> > +    int32_t             uc_flags;
> > +    int32_t             __spare__[4];
> > +} target_ucontext_t;
>
> This is from the common <sys/_ucontext.h>.  Is there any way we can share
> that here in
> qemu as well?
>

That's a good idea.


> > +struct target_sigframe {
> > +    target_siginfo_t    sf_si;  /* saved siginfo */
> > +    target_ucontext_t   sf_uc;  /* saved ucontext */
> > +};
>
> You're missing the storage for
>    mcontext_vfp_t  sf_vfp
>
the address of which goes in mcontext_t.mc_vfp_ptr


Added.


> (which isn't in the version of
> mcontext_t from patch 18).
>

Added to my revised patch 18.


> > +/* compare to sys/arm/include/frame.h */
> > +struct target_trapframe {
> > +    abi_ulong tf_spsr; /* Zero on arm26 */
> > +    abi_ulong tf_r0;
> > +    abi_ulong tf_r1;
> > +    abi_ulong tf_r2;
> > +    abi_ulong tf_r3;
> > +    abi_ulong tf_r4;
> > +    abi_ulong tf_r5;
> > +    abi_ulong tf_r6;
> > +    abi_ulong tf_r7;
> > +    abi_ulong tf_r8;
> > +    abi_ulong tf_r9;
> > +    abi_ulong tf_r10;
> > +    abi_ulong tf_r11;
> > +    abi_ulong tf_r12;
> > +    abi_ulong tf_usr_sp;
> > +    abi_ulong tf_usr_lr;
> > +    abi_ulong tf_svc_sp; /* Not used on arm26 */
> > +    abi_ulong tf_svc_lr; /* Not used on arm26 */
> > +    abi_ulong tf_pc;
> > +};
>
> This is not used by the user abi for signals.  It is a kernel structure
> for its own
> internal trap handling.  Why are you including it?
>

This code pre-dates my time... But I think it was included because the code
in target_arch_thread.h in patch 13 took its size.  But it turns out that's
bogus too. It
accidentally gets things aligned correctly, but should just be removed with
this struct as well. The kernel doesn't use it.

What's worse, ppc, aarch64 and riscv all copied this bogus trope :(. At
least I'll have a chance to fix it before you see it...

I've updated x86 that's upstream in my patch series as well... I'll send it
out Monday or maybe over the weekend.

Warner