POSIX states that #include <signal.h> 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 <lantw44@gmail.com>
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
This commit is contained in:
Konstantin Belousov 2016-02-12 07:38:19 +00:00
parent 411c83ccd6
commit 90edf67ecf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=295561
8 changed files with 88 additions and 43 deletions

View File

@ -36,6 +36,8 @@
#include <sys/cdefs.h>
#include <sys/_types.h>
#include <sys/signal.h>
#include <machine/ucontext.h>
#include <sys/_ucontext.h>
#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 *);

View File

@ -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;

View File

@ -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__)

View File

@ -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;

52
sys/sys/_ucontext.h Normal file
View File

@ -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 */

View File

@ -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:

View File

@ -33,25 +33,9 @@
#include <sys/signal.h>
#include <machine/ucontext.h>
#include <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;
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__)

View File

@ -162,4 +162,9 @@ typedef struct __mcontext {
} mcontext_t;
#endif /* __amd64__ */
#ifdef __LINT__
typedef struct __mcontext {
} mcontext_t;
#endif /* __LINT__ */
#endif /* !_X86_UCONTEXT_H_ */