From 90edf67ecf94bce51e6c823ee2a10a7b65f416f8 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 12 Feb 2016 07:38:19 +0000 Subject: [PATCH] POSIX states that #include shall make both mcontext_t and ucontext_t available. Our code even has XXX comment about this. Add a bit of compliance by moving struct __ucontext definition into sys/_ucontext.h and including it into signal.h and sys/ucontext.h. Several machine/ucontext.h headers were changed to use namespace-safe types (like uint64_t->__uint64_t) to not depend on sys/types.h. struct __stack_t from sys/signal.h is made always visible in private namespace to satisfy sys/_ucontext.h requirements. Apparently mips _types.h pollutes global namespace with f_register_t type definition. This commit does not try to fix the issue. PR: 207079 Reported and tested by: Ting-Wei Lan Sponsored by: The FreeBSD Foundation MFC after: 2 weeks --- include/signal.h | 3 +- sys/mips/include/ucontext.h | 10 +++---- sys/powerpc/include/ucontext.h | 10 +++---- sys/sparc64/include/ucontext.h | 10 +++---- sys/sys/_ucontext.h | 52 ++++++++++++++++++++++++++++++++++ sys/sys/signal.h | 23 ++++++++------- sys/sys/ucontext.h | 18 +----------- sys/x86/include/ucontext.h | 5 ++++ 8 files changed, 88 insertions(+), 43 deletions(-) create mode 100644 sys/sys/_ucontext.h diff --git a/include/signal.h b/include/signal.h index 895ccc30bc06..33be55c6dd25 100644 --- a/include/signal.h +++ b/include/signal.h @@ -36,6 +36,8 @@ #include #include #include +#include +#include #if __BSD_VISIBLE /* @@ -114,7 +116,6 @@ void psignal(unsigned int, const char *); #if __BSD_VISIBLE int sigblock(int); -struct __ucontext; /* XXX spec requires a complete declaration. */ int sigreturn(const struct __ucontext *); int sigsetmask(int); int sigstack(const struct sigstack *, struct sigstack *); diff --git a/sys/mips/include/ucontext.h b/sys/mips/include/ucontext.h index a37fe7ec8d72..2b1a952e80f0 100644 --- a/sys/mips/include/ucontext.h +++ b/sys/mips/include/ucontext.h @@ -50,13 +50,13 @@ typedef struct __mcontext { * struct sigcontext and ucontext_t at the same time. */ int mc_onstack; /* sigstack state to restore */ - register_t mc_pc; /* pc at time of signal */ - register_t mc_regs[32]; /* processor regs 0 to 31 */ - register_t sr; /* status register */ - register_t mullo, mulhi; /* mullo and mulhi registers... */ + __register_t mc_pc; /* pc at time of signal */ + __register_t mc_regs[32]; /* processor regs 0 to 31 */ + __register_t sr; /* status register */ + __register_t mullo, mulhi; /* mullo and mulhi registers... */ int mc_fpused; /* fp has been used */ f_register_t mc_fpregs[33]; /* fp regs 0 to 31 and csr */ - register_t mc_fpc_eir; /* fp exception instruction reg */ + __register_t mc_fpc_eir; /* fp exception instruction reg */ void *mc_tls; /* pointer to TLS area */ int __spare__[8]; /* XXX reserved */ } mcontext_t; diff --git a/sys/powerpc/include/ucontext.h b/sys/powerpc/include/ucontext.h index 34e391a9e131..42c39e1d66c9 100644 --- a/sys/powerpc/include/ucontext.h +++ b/sys/powerpc/include/ucontext.h @@ -42,11 +42,11 @@ typedef struct __mcontext { #define _MC_AV_VALID 0x02 int mc_onstack; /* saved onstack flag */ int mc_len; /* sizeof(__mcontext) */ - uint64_t mc_avec[32*2]; /* vector register file */ - uint32_t mc_av[2]; - register_t mc_frame[42]; - uint64_t mc_fpreg[33]; - uint64_t mc_vsxfpreg[32]; /* low-order half of VSR0-31 */ + __uint64_t mc_avec[32*2]; /* vector register file */ + __uint32_t mc_av[2]; + __register_t mc_frame[42]; + __uint64_t mc_fpreg[33]; + __uint64_t mc_vsxfpreg[32]; /* low-order half of VSR0-31 */ } mcontext_t __aligned(16); #if defined(_KERNEL) && defined(__powerpc64__) diff --git a/sys/sparc64/include/ucontext.h b/sys/sparc64/include/ucontext.h index 1c907fef9e6d..42deca8303f9 100644 --- a/sys/sparc64/include/ucontext.h +++ b/sys/sparc64/include/ucontext.h @@ -33,11 +33,11 @@ #define _MACHINE_UCONTEXT_H_ struct __mcontext { - uint64_t mc_global[8]; - uint64_t mc_out[8]; - uint64_t mc_local[8]; - uint64_t mc_in[8]; - uint32_t mc_fp[64]; + __uint64_t mc_global[8]; + __uint64_t mc_out[8]; + __uint64_t mc_local[8]; + __uint64_t mc_in[8]; + __uint32_t mc_fp[64]; } __aligned(64); typedef struct __mcontext mcontext_t; diff --git a/sys/sys/_ucontext.h b/sys/sys/_ucontext.h new file mode 100644 index 000000000000..17b3179dc7a7 --- /dev/null +++ b/sys/sys/_ucontext.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 1999 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__UCONTEXT_H_ +#define _SYS__UCONTEXT_H_ + +typedef struct __ucontext { + /* + * Keep the order of the first two fields. Also, + * keep them the first two fields in the structure. + * This way we can have a union with struct + * sigcontext and ucontext_t. This allows us to + * support them both at the same time. + * note: the union is not defined, though. + */ + __sigset_t uc_sigmask; + mcontext_t uc_mcontext; + + struct __ucontext *uc_link; + struct __stack_t uc_stack; + int uc_flags; + int __spare__[4]; +} ucontext_t; + +#endif /* _SYS__UCONTEXT_H */ diff --git a/sys/sys/signal.h b/sys/sys/signal.h index 259c39aed4f9..ab8fcf48647a 100644 --- a/sys/sys/signal.h +++ b/sys/sys/signal.h @@ -354,18 +354,10 @@ typedef void __siginfohandler_t(int, struct __siginfo *, void *); #endif #if __XSI_VISIBLE -/* - * Structure used in sigaltstack call. - */ #if __BSD_VISIBLE -typedef struct sigaltstack { -#else -typedef struct { +#define __stack_t sigaltstack #endif - void *ss_sp; /* signal stack base */ - __size_t ss_size; /* signal stack length */ - int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ -} stack_t; +typedef struct __stack_t stack_t; #define SS_ONSTACK 0x0001 /* take signal on alternate stack */ #define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */ @@ -373,6 +365,17 @@ typedef struct { #define SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended stack size */ #endif +/* + * Structure used in sigaltstack call. Its definition is always + * needed for __ucontext. If __BSD_VISIBLE is defined, the structure + * tag is actually sigaltstack. + */ +struct __stack_t { + void *ss_sp; /* signal stack base */ + __size_t ss_size; /* signal stack length */ + int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ +}; + #if __BSD_VISIBLE /* * 4.3 compatibility: diff --git a/sys/sys/ucontext.h b/sys/sys/ucontext.h index e80ed503a364..260c15751d2d 100644 --- a/sys/sys/ucontext.h +++ b/sys/sys/ucontext.h @@ -33,25 +33,9 @@ #include #include +#include -typedef struct __ucontext { - /* - * Keep the order of the first two fields. Also, - * keep them the first two fields in the structure. - * This way we can have a union with struct - * sigcontext and ucontext_t. This allows us to - * support them both at the same time. - * note: the union is not defined, though. - */ - sigset_t uc_sigmask; - mcontext_t uc_mcontext; - - struct __ucontext *uc_link; - stack_t uc_stack; - int uc_flags; #define UCF_SWAPPED 0x00000001 /* Used by swapcontext(3). */ - int __spare__[4]; -} ucontext_t; #if defined(_KERNEL) && defined(COMPAT_FREEBSD4) #if defined(__i386__) diff --git a/sys/x86/include/ucontext.h b/sys/x86/include/ucontext.h index 2173efd590cf..c429fd5b0e3a 100644 --- a/sys/x86/include/ucontext.h +++ b/sys/x86/include/ucontext.h @@ -162,4 +162,9 @@ typedef struct __mcontext { } mcontext_t; #endif /* __amd64__ */ +#ifdef __LINT__ +typedef struct __mcontext { +} mcontext_t; +#endif /* __LINT__ */ + #endif /* !_X86_UCONTEXT_H_ */