mbox series

[0/3] arm64/sve: UAPI: Disentangle ptrace.h from sigcontext.h

Message ID 1544556407-19897-1-git-send-email-Dave.Martin@arm.com
Headers show
Series arm64/sve: UAPI: Disentangle ptrace.h from sigcontext.h | expand

Message

Dave Martin Dec. 11, 2018, 7:26 p.m. UTC
This patch refactors the UAPI header definitions for the Arm SVE
extension to avoid multiple-definition problems when userspace mixes its
own sigcontext.h definitions with the kernel's ptrace.h (which is
apparently routine).

A common backend header is created to hold common definitions, suitably
namespaced, and with an appropriate header guard.

See the commit message in patch 3 for further explanation of why this
is needed.

Because of the non-trivial header guard in the new sve_context.h, patch
1 adds support to headers_install.sh to munge #if defined(_UAPI_FOO) in
a similar way to the current handling of #ifndef _UAPI_FOO.

Dave Martin (3):
  kbuild: install_headers.sh: Strip _UAPI from #if-defined() guards
  arm64/sve: ptrace: Fix SVE_PT_REGS_OFFSET definition
  arm64/sve: Disentangle <uapi/asm/ptrace.h> from
    <uapi/asm/sigcontext.h>

 arch/arm64/include/uapi/asm/ptrace.h      | 39 ++++++++++-----------
 arch/arm64/include/uapi/asm/sigcontext.h  | 56 +++++++++++++++----------------
 arch/arm64/include/uapi/asm/sve_context.h | 50 +++++++++++++++++++++++++++
 scripts/headers_install.sh                |  1 +
 4 files changed, 97 insertions(+), 49 deletions(-)
 create mode 100644 arch/arm64/include/uapi/asm/sve_context.h

-- 
2.1.4

Comments

Szabolcs Nagy Dec. 14, 2018, 6:13 p.m. UTC | #1
On 11/12/2018 19:26, Dave Martin wrote:
> This patch refactors the UAPI header definitions for the Arm SVE

> extension to avoid multiple-definition problems when userspace mixes its

> own sigcontext.h definitions with the kernel's ptrace.h (which is

> apparently routine).

> 

> A common backend header is created to hold common definitions, suitably

> namespaced, and with an appropriate header guard.

> 

> See the commit message in patch 3 for further explanation of why this

> is needed.

> 

> Because of the non-trivial header guard in the new sve_context.h, patch

> 1 adds support to headers_install.sh to munge #if defined(_UAPI_FOO) in

> a similar way to the current handling of #ifndef _UAPI_FOO.

> 


thanks for doing this.

the patches fix the gdb build issue on musl libc with an
additional gdb patch:
https://sourceware.org/ml/gdb-patches/2018-12/msg00152.html
(in userspace i'd expect users relying on signal.h providing
whatever is in asm/sigcontext.h.)

i think sve_context.h could be made to work with direct include,
even if that's not useful because there is no public api there.
(and then you dont need the first patch)

> Dave Martin (3):

>   kbuild: install_headers.sh: Strip _UAPI from #if-defined() guards

>   arm64/sve: ptrace: Fix SVE_PT_REGS_OFFSET definition

>   arm64/sve: Disentangle <uapi/asm/ptrace.h> from

>     <uapi/asm/sigcontext.h>

> 

>  arch/arm64/include/uapi/asm/ptrace.h      | 39 ++++++++++-----------

>  arch/arm64/include/uapi/asm/sigcontext.h  | 56 +++++++++++++++----------------

>  arch/arm64/include/uapi/asm/sve_context.h | 50 +++++++++++++++++++++++++++

>  scripts/headers_install.sh                |  1 +

>  4 files changed, 97 insertions(+), 49 deletions(-)

>  create mode 100644 arch/arm64/include/uapi/asm/sve_context.h

>
Dave Martin Dec. 14, 2018, 6:25 p.m. UTC | #2
On Fri, Dec 14, 2018 at 06:13:33PM +0000, Szabolcs Nagy wrote:
> On 11/12/2018 19:26, Dave Martin wrote:

> > This patch refactors the UAPI header definitions for the Arm SVE

> > extension to avoid multiple-definition problems when userspace mixes its

> > own sigcontext.h definitions with the kernel's ptrace.h (which is

> > apparently routine).

> > 

> > A common backend header is created to hold common definitions, suitably

> > namespaced, and with an appropriate header guard.

> > 

> > See the commit message in patch 3 for further explanation of why this

> > is needed.

> > 

> > Because of the non-trivial header guard in the new sve_context.h, patch

> > 1 adds support to headers_install.sh to munge #if defined(_UAPI_FOO) in

> > a similar way to the current handling of #ifndef _UAPI_FOO.

> > 

> 

> thanks for doing this.

> 

> the patches fix the gdb build issue on musl libc with an

> additional gdb patch:

> https://sourceware.org/ml/gdb-patches/2018-12/msg00152.html

> (in userspace i'd expect users relying on signal.h providing

> whatever is in asm/sigcontext.h.)

> 

> i think sve_context.h could be made to work with direct include,

> even if that's not useful because there is no public api there.

> (and then you dont need the first patch)


My general view is that if you want the sigframe types userspace should
usually include <ucontext.h> and refer to mcontext_t.

Because the prototype for sa_sigaction() specifies a void * for the
ucontext argument, I've generally assumed that <signal.h> is not
sufficient to get ucontext_t (or mcontext_t) (but maybe I'm too paranoid
there).

Non-POSIX-flavoured software might include <asm/sigcontext.h> directly.
In glibc/musl libc will that conflict with <signal.h>, or can the two
coexist?

Cheers
---Dave
Szabolcs Nagy Dec. 14, 2018, 7 p.m. UTC | #3
On 14/12/2018 18:25, Dave Martin wrote:
> On Fri, Dec 14, 2018 at 06:13:33PM +0000, Szabolcs Nagy wrote:

>> On 11/12/2018 19:26, Dave Martin wrote:

>>> This patch refactors the UAPI header definitions for the Arm SVE

>>> extension to avoid multiple-definition problems when userspace mixes its

>>> own sigcontext.h definitions with the kernel's ptrace.h (which is

>>> apparently routine).

>>>

>>> A common backend header is created to hold common definitions, suitably

>>> namespaced, and with an appropriate header guard.

>>>

>>> See the commit message in patch 3 for further explanation of why this

>>> is needed.

>>>

>>> Because of the non-trivial header guard in the new sve_context.h, patch

>>> 1 adds support to headers_install.sh to munge #if defined(_UAPI_FOO) in

>>> a similar way to the current handling of #ifndef _UAPI_FOO.

>>>

>>

>> thanks for doing this.

>>

>> the patches fix the gdb build issue on musl libc with an

>> additional gdb patch:

>> https://sourceware.org/ml/gdb-patches/2018-12/msg00152.html

>> (in userspace i'd expect users relying on signal.h providing

>> whatever is in asm/sigcontext.h.)

>>

>> i think sve_context.h could be made to work with direct include,

>> even if that's not useful because there is no public api there.

>> (and then you dont need the first patch)

> 

> My general view is that if you want the sigframe types userspace should

> usually include <ucontext.h> and refer to mcontext_t.

> 


ucontext.h does not expose the asm/sigcontext.h types in glibc,
but it is compatible with the inclusion of asm/sigcontext.h
(or signal.h).

in musl ucontext.h includes signal.h and signal.h provides
the asm/sigcontext.h api with abi compatible definitions.

> Because the prototype for sa_sigaction() specifies a void * for the

> ucontext argument, I've generally assumed that <signal.h> is not

> sufficient to get ucontext_t (or mcontext_t) (but maybe I'm too paranoid

> there).


http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html

"The <signal.h> header shall define the ucontext_t type as a structure
 that shall include at least the following members:
...
 mcontext_t  uc_mcontext A machine-specific representation of the saved
             context."

so signal.h must define ucontext_t but mcontext_t can be opaque.
(it is opaque with posix conform feature tests to avoid
namespace pollution, but with _GNU_SOURCE defined all
asm/sigcontext.h apis are there and mcontext_t matches
struct sigcontext)

> 

> Non-POSIX-flavoured software might include <asm/sigcontext.h> directly.

> In glibc/musl libc will that conflict with <signal.h>, or can the two

> coexist?


if you compile e.g in standard conform mode then
i think signal.h and asm/sigcontext.h are compatible.

> 

> Cheers

> ---Dave

>
Dave Martin Dec. 14, 2018, 7:28 p.m. UTC | #4
On Fri, Dec 14, 2018 at 07:00:07PM +0000, Szabolcs Nagy wrote:
> On 14/12/2018 18:25, Dave Martin wrote:

> > On Fri, Dec 14, 2018 at 06:13:33PM +0000, Szabolcs Nagy wrote:

> >> On 11/12/2018 19:26, Dave Martin wrote:

> >>> This patch refactors the UAPI header definitions for the Arm SVE

> >>> extension to avoid multiple-definition problems when userspace mixes its

> >>> own sigcontext.h definitions with the kernel's ptrace.h (which is

> >>> apparently routine).

> >>>

> >>> A common backend header is created to hold common definitions, suitably

> >>> namespaced, and with an appropriate header guard.

> >>>

> >>> See the commit message in patch 3 for further explanation of why this

> >>> is needed.

> >>>

> >>> Because of the non-trivial header guard in the new sve_context.h, patch

> >>> 1 adds support to headers_install.sh to munge #if defined(_UAPI_FOO) in

> >>> a similar way to the current handling of #ifndef _UAPI_FOO.

> >>>

> >>

> >> thanks for doing this.

> >>

> >> the patches fix the gdb build issue on musl libc with an

> >> additional gdb patch:

> >> https://sourceware.org/ml/gdb-patches/2018-12/msg00152.html

> >> (in userspace i'd expect users relying on signal.h providing

> >> whatever is in asm/sigcontext.h.)

> >>

> >> i think sve_context.h could be made to work with direct include,

> >> even if that's not useful because there is no public api there.

> >> (and then you dont need the first patch)

> > 

> > My general view is that if you want the sigframe types userspace should

> > usually include <ucontext.h> and refer to mcontext_t.

> > 

> 

> ucontext.h does not expose the asm/sigcontext.h types in glibc,

> but it is compatible with the inclusion of asm/sigcontext.h

> (or signal.h).

> 

> in musl ucontext.h includes signal.h and signal.h provides

> the asm/sigcontext.h api with abi compatible definitions.

> 

> > Because the prototype for sa_sigaction() specifies a void * for the

> > ucontext argument, I've generally assumed that <signal.h> is not

> > sufficient to get ucontext_t (or mcontext_t) (but maybe I'm too paranoid

> > there).

> 

> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html

> 

> "The <signal.h> header shall define the ucontext_t type as a structure

>  that shall include at least the following members:

> ...

>  mcontext_t  uc_mcontext A machine-specific representation of the saved

>              context."

> 

> so signal.h must define ucontext_t but mcontext_t can be opaque.

> (it is opaque with posix conform feature tests to avoid

> namespace pollution, but with _GNU_SOURCE defined all

> asm/sigcontext.h apis are there and mcontext_t matches

> struct sigcontext)


I see.  Sounds reasonable.

> > 

> > Non-POSIX-flavoured software might include <asm/sigcontext.h> directly.

> > In glibc/musl libc will that conflict with <signal.h>, or can the two

> > coexist?

> 

> if you compile e.g in standard conform mode then

> i think signal.h and asm/sigcontext.h are compatible.


So long as we don't break any existing usage (?) I guess this is fine.

Cheers
---Dave