Pull up following revision(s) (requested by kamil in ticket #552):

sys/arch/aarch64/include/mcontext.h: 1.2
	sys/arch/alpha/include/mcontext.h: 1.9
	sys/arch/amd64/include/mcontext.h: 1.19
	sys/arch/arm/include/mcontext.h: 1.19
	sys/arch/hppa/include/mcontext.h: 1.9
	sys/arch/i386/include/mcontext.h: 1.14
	sys/arch/ia64/include/mcontext.h: 1.6
	sys/arch/m68k/include/mcontext.h: 1.10
	sys/arch/mips/include/mcontext.h: 1.22
	sys/arch/or1k/include/mcontext.h: 1.2
	sys/arch/powerpc/include/mcontext.h: 1.18
	sys/arch/riscv/include/mcontext.h: 1.5
	sys/arch/sh3/include/mcontext.h: 1.11
	sys/arch/sparc/include/mcontext.h: 1.14-1.17
	sys/arch/sparc64/include/mcontext.h: 1.10
	sys/arch/vax/include/mcontext.h: 1.9
	tests/lib/libc/sys/Makefile: 1.50
	tests/lib/libc/sys/t_ucontext.c: 1.2
Introduce _UC_MACHINE_FP() as a macro
_UC_MACHINE_FP() is a helper macro to extract from mcontext a frame pointer.
Don't rely on this interface as a compiler might strip frame pointer or
optimize it making this interface unreliable.
For hppa assume a small frame context, for larger frames FP might be located
in a different register (4 instead of 3).
For ia64 there is no strict frame pointer, and registers might rotate.
Reuse 79 following:
  ./gcc/config/ia64/ia64.h:#define HARD_FRAME_POINTER_REGNUM  LOC_REG (79)
Once ia64 will mature, this should be revisited.
A macro can encapsulate a real function for extracting Frame Pointer on
more complex CPUs / ABIs.
For the remaining CPUs, reuse standard register as defined in appropriate ABI.
The direct users of this macro are LLVM and GCC with Sanitizers.
Proposed on tech-userlevel@.
Sponsored by <The NetBSD Foundation>
--
Improve _UC_MACHINE_FP() for SPARC/SPARC64
Introduce a static inline function _uc_machine_fp() that contains improved
caluclation of a frame pointer.
Algorithm:
  uptr *stk_ptr;
#  if defined (__arch64__)
  stk_ptr = (uptr *) (*sp + 2047);
#  else
  stk_ptr = (uptr *) *sp;
#  endif
  *bp = stk_ptr[15];
Noted by <mrg>
--
Make _UC_MACHINE_FP() compile again and fix it so that it does not add
the offset twice.
--
fix _UC_MACHINE32_FP() -- use 32 bit pointer value so that [15] is
the right offset.  do this by using __greg32_t, which is only in
the sparc64 version, and these are only useful there, so move them.
--
Add new tests in lib/libc/sys/t_ucontext
New tests:
 - ucontext_sp
 - ucontext_fp
 - ucontext_pc
 - ucontext_intrv
They test respectively:
 - _UC_MACHINE_SP
 - _UC_MACHINE_FP
 - _UC_MACHINE_PC
 - _UC_MACHINE_INTRV
These tests attempt to access and print the values from ucontext, without
interpreting the values.
This is a follow up of the _UC_MACHINE_FP() introduction.
These tests use PRIxREGISTER, and require to be built with -D_KERNTYPES.
Sponsored by <The NetBSD Foundation>
This commit is contained in:
snj 2018-02-25 23:50:22 +00:00
parent 176e1316d4
commit c5d757340e
18 changed files with 113 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.1 2014/08/10 05:47:38 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.1.22.1 2018/02/25 23:50:22 snj Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -106,6 +106,7 @@ typedef struct {
#define _UC_TLSBASE 0x00080000 /* see <sys/ucontext.h> */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_X29])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_X0])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.8 2012/09/12 02:00:54 manu Exp $ */
/* $NetBSD: mcontext.h,v 1.8.32.1 2018/02/25 23:50:22 snj Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -96,6 +96,7 @@ typedef struct {
#define _UC_TLSBASE 0x20 /* valid process-unique value in _REG_UNIQUE */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S6])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_V0])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.18 2014/05/12 22:50:03 uebayasi Exp $ */
/* $NetBSD: mcontext.h,v 1.18.20.1 2018/02/25 23:50:22 snj Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -68,6 +68,7 @@ typedef struct {
/* AMD64 ABI 128-bytes "red zone". */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_RSP] - 128)
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_RBP])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_RIP])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_RAX])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.18 2015/03/24 08:38:29 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.18.10.1 2018/02/25 23:50:22 snj Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -110,6 +110,7 @@ typedef struct {
#define _UC_MACHINE_PAD 1 /* Padding appended to ucontext_t */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_R11])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_R0])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.8 2014/02/19 13:01:51 skrll Exp $ */
/* $NetBSD: mcontext.h,v 1.8.22.1 2018/02/25 23:50:22 snj Exp $ */
#ifndef _HPPA_MCONTEXT_H_
#define _HPPA_MCONTEXT_H_
@ -50,6 +50,7 @@ typedef struct {
} mcontext_t;
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[3])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PCOQH])
#define _UC_MACHINE_SET_PC(uc, pc) \
do { \

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.12 2014/02/15 22:20:42 dsl Exp $ */
/* $NetBSD: mcontext.h,v 1.12.22.1 2018/02/25 23:50:22 snj Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -116,6 +116,7 @@ typedef struct {
#ifndef _UC_MACHINE_SP
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_UESP])
#endif
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_EBP])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_EIP])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_EAX])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.5 2016/08/05 17:01:13 scole Exp $ */
/* $NetBSD: mcontext.h,v 1.5.8.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -112,6 +112,7 @@ typedef struct __mcontext {
} mcontext_t;
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.mc_special.sp)
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[79])
/* XXX or assembly "mov Rn = ip" or ...? */
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.mc_special.iip)

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.9 2011/11/22 15:25:28 joerg Exp $ */
/* $NetBSD: mcontext.h,v 1.9.42.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -102,6 +102,7 @@ typedef struct {
#define _UC_TLSBASE 0x00080000
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_A7])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_A6])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_D0])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.21 2015/05/26 02:16:38 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.21.10.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
@ -159,6 +159,7 @@ typedef struct {
#define _UC_TLSBASE 0x00040000
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S8])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_EPC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_V0])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.1 2014/09/03 19:34:26 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.1.12.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -88,6 +88,7 @@ typedef struct {
#define _UC_TLSBASE 0x00080000 /* see <sys/ucontext.h> */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_R2])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_RV])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.17 2014/08/12 20:27:10 joerg Exp $ */
/* $NetBSD: mcontext.h,v 1.17.12.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -133,6 +133,7 @@ typedef struct {
#define _UC_TLSBASE 0x00080000 /* thread context valid in R2 */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_R1])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_R31])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_R3])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.4 2015/04/01 21:55:33 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.4.10.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -118,6 +118,7 @@ typedef struct {
#define _UC_TLSBASE 0x00080000 /* see <sys/ucontext.h> */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S0])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_RV])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.10 2012/09/12 02:00:54 manu Exp $ */
/* $NetBSD: mcontext.h,v 1.10.32.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -82,6 +82,7 @@ typedef struct {
} mcontext_t;
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_R14])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_R0])

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.13 2012/09/12 02:00:54 manu Exp $ */
/* $NetBSD: mcontext.h,v 1.13.32.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -30,11 +30,11 @@
*/
#ifndef _SPARC_MCONTEXT_H_
#define _SPARC_MCONTEXT_H_
#define _SPARC_MCONTEXT_H_
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00080000
#define _UC_SETSTACK 0x00010000
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00080000
/*
* Layout of mcontext_t according the System V Application Binary Interface,
@ -144,13 +144,13 @@ typedef struct {
} mcontext_t;
#ifdef __arch64__
#define _UC_MACHINE_PAD 8 /* Padding appended to ucontext_t */
#define _UC_MACHINE_SP(uc) (((uc)->uc_mcontext.__gregs[_REG_O6])+0x7ff)
#define _UC_MACHINE32_PAD 43 /* compat_netbsd32 variant */
#define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])
#define _UC_MACHINE_PAD 8 /* Padding appended to ucontext_t */
#define _UC_MACHINE_SP(uc) (((uc)->uc_mcontext.__gregs[_REG_O6]) + 0x7ff)
#define _UC_MACHINE_FP(uc) (((__greg_t *)_UC_MACHINE_SP(uc))[15])
#else
#define _UC_MACHINE_PAD 43 /* Padding appended to ucontext_t */
#define _UC_MACHINE_PAD 43 /* Padding appended to ucontext_t */
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])
#define _UC_MACHINE_FP(uc) (((__greg_t *)_UC_MACHINE_SP(uc))[15])
#endif
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_O0])

View File

@ -1,11 +1,11 @@
/* $NetBSD: mcontext.h,v 1.9 2012/09/12 02:00:54 manu Exp $ */
/* $NetBSD: mcontext.h,v 1.9.32.1 2018/02/25 23:50:23 snj Exp $ */
#ifndef _SPARC64_MCONTEXT_H_
#define _SPARC64_MCONTEXT_H_
#define _SPARC64_MCONTEXT_H_
#include <sparc/mcontext.h>
#define _NGREG32 19 /* %psr, pc, npc, %g1-7, %o0-7 */
#define _NGREG32 19 /* %psr, pc, npc, %g1-7, %o0-7 */
typedef int __greg32_t;
typedef __greg32_t __gregset32_t[_NGREG32];
@ -76,4 +76,8 @@ typedef struct {
#define _UC_CLRSTACK 0x00020000
#define _UC_TLSBASE 0x00080000
#define _UC_MACHINE32_PAD 43 /* compat_netbsd32 variant */
#define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])
#define _UC_MACHINE32_FP(uc) (((__greg32_t *)_UC_MACHINE32_SP(uc))[15])
#endif /* _SPARC64_MCONTEXT_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.8 2012/02/02 18:32:16 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.8.40.1 2018/02/25 23:50:23 snj Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -68,6 +68,7 @@ typedef struct {
#define _UC_TLSBASE 0x00080000
#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_FP])
#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_R0])

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.49 2017/04/02 21:44:00 kamil Exp $
# $NetBSD: Makefile,v 1.49.4.1 2018/02/25 23:50:23 snj Exp $
MKMAN= no
@ -96,6 +96,7 @@ CPPFLAGS.t_ptrace_wait4.c += -D_KERNTYPES
CPPFLAGS.t_ptrace_wait6.c += -D_KERNTYPES
CPPFLAGS.t_ptrace_waitid.c += -D_KERNTYPES
CPPFLAGS.t_ptrace_waitpid.c += -D_KERNTYPES
CPPFLAGS.t_ucontext.c += -D_KERNTYPES
FILES= truncate_test.root_owned
FILESBUILD= yes

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_ucontext.c,v 1.1 2011/10/15 06:54:52 jruoho Exp $ */
/* $NetBSD: t_ucontext.c,v 1.1.34.1 2018/02/25 23:50:23 snj Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -29,7 +29,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
__RCSID("$NetBSD: t_ucontext.c,v 1.1 2011/10/15 06:54:52 jruoho Exp $");
__RCSID("$NetBSD: t_ucontext.c,v 1.1.34.1 2018/02/25 23:50:23 snj Exp $");
#include <atf-c.h>
#include <stdio.h>
@ -68,9 +68,73 @@ ATF_TC_BODY(ucontext_basic, tc)
ATF_REQUIRE_EQ(y, 21);
}
ATF_TC(ucontext_sp);
ATF_TC_HEAD(ucontext_sp, tc)
{
atf_tc_set_md_var(tc, "descr", "Retrive _UC_MACHINE_SP()");
}
ATF_TC_BODY(ucontext_sp, tc)
{
ucontext_t u;
getcontext(&u);
printf("_UC_MACHINE_SP(u)=%" PRIxREGISTER "\n", _UC_MACHINE_SP(&u));
}
ATF_TC(ucontext_fp);
ATF_TC_HEAD(ucontext_fp, tc)
{
atf_tc_set_md_var(tc, "descr", "Retrive _UC_MACHINE_FP()");
}
ATF_TC_BODY(ucontext_fp, tc)
{
ucontext_t u;
getcontext(&u);
printf("_UC_MACHINE_FP(u)=%" PRIxREGISTER "\n", _UC_MACHINE_FP(&u));
}
ATF_TC(ucontext_pc);
ATF_TC_HEAD(ucontext_pc, tc)
{
atf_tc_set_md_var(tc, "descr", "Retrive _UC_MACHINE_PC()");
}
ATF_TC_BODY(ucontext_pc, tc)
{
ucontext_t u;
getcontext(&u);
printf("_UC_MACHINE_PC(u)=%" PRIxREGISTER "\n", _UC_MACHINE_PC(&u));
}
ATF_TC(ucontext_intrv);
ATF_TC_HEAD(ucontext_intrv, tc)
{
atf_tc_set_md_var(tc, "descr", "Retrive _UC_MACHINE_INTRV()");
}
ATF_TC_BODY(ucontext_intrv, tc)
{
ucontext_t u;
getcontext(&u);
printf("_UC_MACHINE_INTRV(u)=%" PRIxREGISTER "\n", _UC_MACHINE_INTRV(&u));
}
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, ucontext_basic);
ATF_TP_ADD_TC(tp, ucontext_sp);
ATF_TP_ADD_TC(tp, ucontext_fp);
ATF_TP_ADD_TC(tp, ucontext_pc);
ATF_TP_ADD_TC(tp, ucontext_intrv);
return atf_no_error();
}