Skip to content

Commit

Permalink
Clean up the <sys/ucontext.h> <-> <machine/mcontext.h> interface up
Browse files Browse the repository at this point in the history
a little:
- Define _UC_MD_BIT* constants for the available machine-dependent bits,
  and use those constants to define the machine-dependent bits as well
  as the machine-independent bits that have machine-dependent values.
- Explicitly generate an error if _UC_TLSBASE, _UC_SETSTACK, or
  _UC_CLRSTACK are not defined by <machine/mcontext.h>.
  • Loading branch information
thorpej committed May 18, 2024
1 parent 5384ba9 commit d68fbd3
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 86 deletions.
8 changes: 4 additions & 4 deletions sys/arch/alpha/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.11 2021/05/24 21:00:12 thorpej Exp $ */
/* $NetBSD: mcontext.h,v 1.12 2024/05/18 00:37:40 thorpej Exp $ */

/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -93,9 +93,9 @@ typedef struct {
} mcontext_t;

/* Machine-dependent uc_flags */
#define _UC_TLSBASE 0x20 /* valid process-unique value in _REG_UNIQUE */
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE _UC_MD_BIT5 /* valid value in _REG_UNIQUE */
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S6])
Expand Down
10 changes: 5 additions & 5 deletions sys/arch/amd64/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.20 2019/12/27 00:32:16 kamil Exp $ */
/* $NetBSD: mcontext.h,v 1.21 2024/05/18 00:37:40 thorpej Exp $ */

/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -74,13 +74,13 @@ typedef struct {

#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)

#define _UC_TLSBASE 0x00080000
#define _UC_TLSBASE _UC_MD_BIT19

/*
* mcontext extensions to handle signal delivery.
*/
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17

#define __UCONTEXT_SIZE 784

Expand Down Expand Up @@ -155,7 +155,7 @@ typedef struct {
uint32_t _mc_tlsbase;
} mcontext32_t;

#define _UC_FXSAVE 0x20 /* FP state is in FXSAVE format in XMM space */
#define _UC_FXSAVE _UC_MD_BIT5 /* FP state is in FXSAVE format in XMM space */

#define _UC_MACHINE32_PAD 4
#define __UCONTEXT32_SIZE 776
Expand Down
10 changes: 5 additions & 5 deletions sys/arch/arm/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.23 2021/10/06 05:33:15 skrll Exp $ */
/* $NetBSD: mcontext.h,v 1.24 2024/05/18 00:37:40 thorpej Exp $ */

/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -257,14 +257,14 @@ __END_DECLS
#endif /* _RTLD_SOURCE || _LIBC_SOURCE || __LIBPTHREAD_SOURCE__ */

/* Machine-dependent uc_flags */
#define _UC_TLSBASE 0x00080000 /* see <sys/ucontext.h> */
#define _UC_TLSBASE _UC_MD_BIT19 /* see <sys/ucontext.h> */

/* Machine-dependent uc_flags for arm */
#define _UC_ARM_VFP 0x00010000 /* FPU field is VFP */
#define _UC_ARM_VFP _UC_MD_BIT16 /* FPU field is VFP */

/* used by signal delivery to indicate status of signal stack */
#define _UC_SETSTACK 0x00020000
#define _UC_CLRSTACK 0x00040000
#define _UC_SETSTACK _UC_MD_BIT17
#define _UC_CLRSTACK _UC_MD_BIT18

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_FP])
Expand Down
8 changes: 4 additions & 4 deletions sys/arch/hppa/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.12 2022/06/26 14:37:13 skrll Exp $ */
/* $NetBSD: mcontext.h,v 1.13 2024/05/18 00:37:40 thorpej Exp $ */

#ifndef _HPPA_MCONTEXT_H_
#define _HPPA_MCONTEXT_H_
Expand Down Expand Up @@ -111,8 +111,8 @@ __END_DECLS

#endif /* !__ASSEMBLER__ */

#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00040000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17
#define _UC_TLSBASE _UC_MD_BIT18

#endif /* _HPPA_MCONTEXT_H_ */
12 changes: 6 additions & 6 deletions sys/arch/i386/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.15 2019/12/27 00:32:17 kamil Exp $ */
/* $NetBSD: mcontext.h,v 1.16 2024/05/18 00:37:40 thorpej Exp $ */

/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -36,10 +36,10 @@
/*
* mcontext extensions to handle signal delivery.
*/
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_VM 0x00040000
#define _UC_TLSBASE 0x00080000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17
#define _UC_VM _UC_MD_BIT18
#define _UC_TLSBASE _UC_MD_BIT19

/*
* Layout of mcontext_t according to the System V Application Binary Interface,
Expand Down Expand Up @@ -96,7 +96,7 @@ typedef struct {
__greg_t _mc_tlsbase;
} mcontext_t;

#define _UC_FXSAVE 0x20 /* FP state is in FXSAVE format in XMM space */
#define _UC_FXSAVE _UC_MD_BIT5 /* FP state is in FXSAVE format in XMM space */

#define _UC_MACHINE_PAD 4 /* Padding appended to ucontext_t */

Expand Down
10 changes: 5 additions & 5 deletions sys/arch/m68k/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.12 2020/10/04 10:34:18 rin Exp $ */
/* $NetBSD: mcontext.h,v 1.13 2024/05/18 00:37:41 thorpej Exp $ */

/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -39,8 +39,8 @@
/*
* mcontext extensions to handle signal delivery.
*/
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17

/*
* General register state
Expand Down Expand Up @@ -98,8 +98,8 @@ typedef struct {
/* Note: no additional padding is to be performed in ucontext_t. */

/* Machine-specific uc_flags value */
#define _UC_M68K_UC_USER 0x40000000
#define _UC_TLSBASE 0x00080000
#define _UC_M68K_UC_USER _UC_MD_BIT30
#define _UC_TLSBASE _UC_MD_BIT19

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_A7])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_A6])
Expand Down
12 changes: 6 additions & 6 deletions sys/arch/powerpc/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.22 2020/10/04 10:34:18 rin Exp $ */
/* $NetBSD: mcontext.h,v 1.23 2024/05/18 00:37:41 thorpej Exp $ */

/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -128,11 +128,11 @@ typedef struct {
#endif

/* Machine-dependent uc_flags */
#define _UC_POWERPC_VEC 0x00010000 /* Vector Register File valid */
#define _UC_POWERPC_SPE 0x00020000 /* Vector Register File valid */
#define _UC_TLSBASE 0x00080000 /* thread context valid in R2 */
#define _UC_SETSTACK 0x00100000
#define _UC_CLRSTACK 0x00200000
#define _UC_POWERPC_VEC _UC_MD_BIT16 /* Vector Register File valid */
#define _UC_POWERPC_SPE _UC_MD_BIT17 /* Vector Register File valid */
#define _UC_TLSBASE _UC_MD_BIT19 /* thread context valid in R2 */
#define _UC_SETSTACK _UC_MD_BIT20
#define _UC_CLRSTACK _UC_MD_BIT21

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_R1])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_R31])
Expand Down
8 changes: 4 additions & 4 deletions sys/arch/sh3/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.12 2019/12/27 00:32:17 kamil Exp $ */
/* $NetBSD: mcontext.h,v 1.13 2024/05/18 00:37:41 thorpej Exp $ */

/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -91,9 +91,9 @@ typedef struct {
/*
* Machine dependent uc_flags
*/
#define _UC_SETSTACK 0x10000
#define _UC_CLRSTACK 0x20000
#define _UC_TLSBASE 0x80000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17
#define _UC_TLSBASE _UC_MD_BIT19

#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
defined(__LIBPTHREAD_SOURCE__)
Expand Down
8 changes: 4 additions & 4 deletions sys/arch/sparc/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.18 2019/12/27 00:32:17 kamil Exp $ */
/* $NetBSD: mcontext.h,v 1.19 2024/05/18 00:37:41 thorpej Exp $ */

/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -32,9 +32,9 @@
#ifndef _SPARC_MCONTEXT_H_
#define _SPARC_MCONTEXT_H_

#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00080000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17
#define _UC_TLSBASE _UC_MD_BIT19

/*
* Layout of mcontext_t according the System V Application Binary Interface,
Expand Down
8 changes: 4 additions & 4 deletions sys/arch/sparc64/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.10 2018/02/19 08:31:13 mrg Exp $ */
/* $NetBSD: mcontext.h,v 1.11 2024/05/18 00:37:41 thorpej Exp $ */

#ifndef _SPARC64_MCONTEXT_H_
#define _SPARC64_MCONTEXT_H_
Expand Down Expand Up @@ -72,9 +72,9 @@ typedef struct {
__xrs32_t __xrs; /* may indicate extra reg state */
} mcontext32_t;

#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00080000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17
#define _UC_TLSBASE _UC_MD_BIT19

#define _UC_MACHINE32_PAD 43 /* compat_netbsd32 variant */
#define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])
Expand Down
8 changes: 4 additions & 4 deletions sys/arch/vax/include/mcontext.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.11 2024/05/17 21:37:07 thorpej Exp $ */
/* $NetBSD: mcontext.h,v 1.12 2024/05/18 00:37:41 thorpej Exp $ */

/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -65,9 +65,9 @@ typedef struct {
} mcontext_t;

/* Machine-dependent uc_flags */
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00080000
#define _UC_SETSTACK _UC_MD_BIT16
#define _UC_CLRSTACK _UC_MD_BIT17
#define _UC_TLSBASE _UC_MD_BIT19

#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_FP])
Expand Down
62 changes: 27 additions & 35 deletions sys/sys/ucontext.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* $NetBSD: ucontext.h,v 1.19 2018/02/27 23:09:02 uwe Exp $ */
/* $NetBSD: ucontext.h,v 1.20 2024/05/18 00:37:41 thorpej Exp $ */

/*-
* Copyright (c) 1999, 2003 The NetBSD Foundation, Inc.
* Copyright (c) 1999, 2003, 2024 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
Expand Down Expand Up @@ -57,50 +57,42 @@ struct __ucontext {
#define _UC_STACK 0x02 /* valid uc_stack */
#define _UC_CPU 0x04 /* valid GPR context in uc_mcontext */
#define _UC_FPU 0x08 /* valid FPU context in uc_mcontext */
#define _UC_MD 0x400f0020 /* MD bits. see below */
#define _UC_MD_BIT5 0x00000020 /* MD bits. see below */
#define _UC_MD_BIT16 0x00010000
#define _UC_MD_BIT17 0x00020000
#define _UC_MD_BIT18 0x00040000
#define _UC_MD_BIT19 0x00080000
#define _UC_MD_BIT20 0x00100000
#define _UC_MD_BIT21 0x00200000
#define _UC_MD_BIT30 0x40000000

/*
* if your port needs more MD bits, please try to choose bits from _UC_MD
* first, rather than picking random unused bits.
* if your port needs more MD bits, please choose bits from _UC_MD_BIT*
* rather than picking random unused bits.
*
* _UC_MD details
* For historical reasons, some common flags have machine-dependent
* definitions. All platforms must define and handle those flags,
* which are:
*
* _UC_TLSBASE Context contains valid pthread private pointer
* All ports must define this MD flag
* 0x00040000 hppa, mips
* 0x00000020 alpha
* 0x00080000 all other ports
*
* _UC_SETSTACK Context uses signal stack
* 0x00020000 arm
* [undefined] alpha, powerpc and vax
* 0x00010000 other ports
*
* _UC_CLRSTACK Context does not use signal stack
* 0x00040000 arm
* [undefined] alpha, powerpc and vax
* 0x00020000 other ports
*
* _UC_POWERPC_VEC Context contains valid AltiVec context
* 0x00010000 powerpc only
*
* _UC_POWERPC_SPE Context contains valid SPE context
* 0x00020000 powerpc only
*
* _UC_M68K_UC_USER Used by m68k machdep code, but undocumented
* 0x40000000 m68k only
*
* _UC_ARM_VFP Unused
* 0x00010000 arm only
*
* _UC_VM Context contains valid virtual 8086 context
* 0x00040000 i386, amd64 only
*
* _UC_FXSAVE Context contains FPU context in that
* is in FXSAVE format in XMM space
* 0x00000020 i386, amd64 only
*/

#ifndef _UC_TLSBASE
#error _UC_TLSBASE not defined.
#endif

#ifndef _UC_SETSTACK
#error _UC_SETSTACK not defined.
#endif

#ifndef _UC_CLRSTACK
#error _UC_CLRSTACK not defined.
#endif

#ifdef _KERNEL
struct lwp;

Expand Down

0 comments on commit d68fbd3

Please sign in to comment.