Mon May 24 21:00:12 2021 UTC ()
Add _UC_SETSTACK / _UC_CLRSTACK handling.  Fixes the t_sigaltstack test
on alpha.


(thorpej)
diff -r1.371 -r1.372 src/sys/arch/alpha/alpha/machdep.c
diff -r1.10 -r1.11 src/sys/arch/alpha/include/mcontext.h

cvs diff -r1.371 -r1.372 src/sys/arch/alpha/alpha/machdep.c (expand / switch to unified diff)

--- src/sys/arch/alpha/alpha/machdep.c 2021/05/05 15:36:17 1.371
+++ src/sys/arch/alpha/alpha/machdep.c 2021/05/24 21:00:12 1.372
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: machdep.c,v 1.371 2021/05/05 15:36:17 thorpej Exp $ */ 1/* $NetBSD: machdep.c,v 1.372 2021/05/24 21:00:12 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2000, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2000, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center and by Chris G. Demetriou. 9 * NASA Ames Research Center and by Chris G. Demetriou.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * rights to redistribute these changes. 57 * rights to redistribute these changes.
58 */ 58 */
59 59
60#include "opt_ddb.h" 60#include "opt_ddb.h"
61#include "opt_kgdb.h" 61#include "opt_kgdb.h"
62#include "opt_modular.h" 62#include "opt_modular.h"
63#include "opt_multiprocessor.h" 63#include "opt_multiprocessor.h"
64#include "opt_dec_3000_300.h" 64#include "opt_dec_3000_300.h"
65#include "opt_dec_3000_500.h" 65#include "opt_dec_3000_500.h"
66#include "opt_execfmt.h" 66#include "opt_execfmt.h"
67 67
68#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 68#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
69 69
70__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.371 2021/05/05 15:36:17 thorpej Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.372 2021/05/24 21:00:12 thorpej Exp $");
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/systm.h> 73#include <sys/systm.h>
74#include <sys/signalvar.h> 74#include <sys/signalvar.h>
75#include <sys/kernel.h> 75#include <sys/kernel.h>
76#include <sys/cpu.h> 76#include <sys/cpu.h>
77#include <sys/proc.h> 77#include <sys/proc.h>
78#include <sys/ras.h> 78#include <sys/ras.h>
79#include <sys/sched.h> 79#include <sys/sched.h>
80#include <sys/reboot.h> 80#include <sys/reboot.h>
81#include <sys/device.h> 81#include <sys/device.h>
82#include <sys/malloc.h> 82#include <sys/malloc.h>
83#include <sys/module.h> 83#include <sys/module.h>
@@ -1515,26 +1515,28 @@ sendsig_siginfo(const ksiginfo_t *ksi, c @@ -1515,26 +1515,28 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
1515 1515
1516#ifdef DEBUG 1516#ifdef DEBUG
1517 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) 1517 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
1518 printf("sendsig_siginfo(%d): sig %d ssp %p usp %p\n", p->p_pid, 1518 printf("sendsig_siginfo(%d): sig %d ssp %p usp %p\n", p->p_pid,
1519 sig, &onstack, fp); 1519 sig, &onstack, fp);
1520#endif 1520#endif
1521 1521
1522 /* Build stack frame for signal trampoline. */ 1522 /* Build stack frame for signal trampoline. */
1523 memset(&frame, 0, sizeof(frame)); 1523 memset(&frame, 0, sizeof(frame));
1524 frame.sf_si._info = ksi->ksi_info; 1524 frame.sf_si._info = ksi->ksi_info;
1525 frame.sf_uc.uc_flags = _UC_SIGMASK; 1525 frame.sf_uc.uc_flags = _UC_SIGMASK;
1526 frame.sf_uc.uc_sigmask = *mask; 1526 frame.sf_uc.uc_sigmask = *mask;
1527 frame.sf_uc.uc_link = l->l_ctxlink; 1527 frame.sf_uc.uc_link = l->l_ctxlink;
 1528 frame.sf_uc.uc_flags |= (l->l_sigstk.ss_flags & SS_ONSTACK)
 1529 ? _UC_SETSTACK : _UC_CLRSTACK;
1528 sendsig_reset(l, sig); 1530 sendsig_reset(l, sig);
1529 mutex_exit(p->p_lock); 1531 mutex_exit(p->p_lock);
1530 cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags); 1532 cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
1531 error = copyout(&frame, fp, sizeof(frame)); 1533 error = copyout(&frame, fp, sizeof(frame));
1532 mutex_enter(p->p_lock); 1534 mutex_enter(p->p_lock);
1533 1535
1534 if (error != 0) { 1536 if (error != 0) {
1535 /* 1537 /*
1536 * Process has trashed its stack; give it an illegal 1538 * Process has trashed its stack; give it an illegal
1537 * instruction to halt it in its tracks. 1539 * instruction to halt it in its tracks.
1538 */ 1540 */
1539#ifdef DEBUG 1541#ifdef DEBUG
1540 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) 1542 if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
@@ -1875,37 +1877,46 @@ cpu_setmcontext(struct lwp *l, const mco @@ -1875,37 +1877,46 @@ cpu_setmcontext(struct lwp *l, const mco
1875 /* Check for security violations first. */ 1877 /* Check for security violations first. */
1876 error = cpu_mcontext_validate(l, mcp); 1878 error = cpu_mcontext_validate(l, mcp);
1877 if (error) 1879 if (error)
1878 return error; 1880 return error;
1879 1881
1880 regtoframe((const struct reg *)gr, l->l_md.md_tf); 1882 regtoframe((const struct reg *)gr, l->l_md.md_tf);
1881 if (l == curlwp) 1883 if (l == curlwp)
1882 alpha_pal_wrusp(gr[_REG_SP]); 1884 alpha_pal_wrusp(gr[_REG_SP]);
1883 else 1885 else
1884 pcb->pcb_hw.apcb_usp = gr[_REG_SP]; 1886 pcb->pcb_hw.apcb_usp = gr[_REG_SP];
1885 frame->tf_regs[FRAME_PC] = gr[_REG_PC]; 1887 frame->tf_regs[FRAME_PC] = gr[_REG_PC];
1886 frame->tf_regs[FRAME_PS] = gr[_REG_PS]; 1888 frame->tf_regs[FRAME_PS] = gr[_REG_PS];
1887 } 1889 }
 1890
1888 if (flags & _UC_TLSBASE) 1891 if (flags & _UC_TLSBASE)
1889 lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_UNIQUE]); 1892 lwp_setprivate(l, (void *)(uintptr_t)gr[_REG_UNIQUE]);
 1893
1890 /* Restore floating point register context, if any. */ 1894 /* Restore floating point register context, if any. */
1891 if (flags & _UC_FPU) { 1895 if (flags & _UC_FPU) {
1892 /* If we have an FP register context, get rid of it. */ 1896 /* If we have an FP register context, get rid of it. */
1893 fpu_discard(l, true); 1897 fpu_discard(l, true);
1894 (void)memcpy(&pcb->pcb_fp, &mcp->__fpregs, 1898 (void)memcpy(&pcb->pcb_fp, &mcp->__fpregs,
1895 sizeof (pcb->pcb_fp)); 1899 sizeof (pcb->pcb_fp));
1896 l->l_md.md_flags = mcp->__fpregs.__fp_fpcr & MDLWP_FP_C; 1900 l->l_md.md_flags = mcp->__fpregs.__fp_fpcr & MDLWP_FP_C;
1897 } 1901 }
1898 1902
 1903 mutex_enter(l->l_proc->p_lock);
 1904 if (flags & _UC_SETSTACK)
 1905 l->l_sigstk.ss_flags |= SS_ONSTACK;
 1906 if (flags & _UC_CLRSTACK)
 1907 l->l_sigstk.ss_flags &= ~SS_ONSTACK;
 1908 mutex_exit(l->l_proc->p_lock);
 1909
1899 return (0); 1910 return (0);
1900} 1911}
1901 1912
1902static void 1913static void
1903cpu_kick(struct cpu_info * const ci) 1914cpu_kick(struct cpu_info * const ci)
1904{ 1915{
1905#if defined(MULTIPROCESSOR) 1916#if defined(MULTIPROCESSOR)
1906 alpha_send_ipi(ci->ci_cpuid, ALPHA_IPI_AST); 1917 alpha_send_ipi(ci->ci_cpuid, ALPHA_IPI_AST);
1907#endif /* MULTIPROCESSOR */ 1918#endif /* MULTIPROCESSOR */
1908} 1919}
1909 1920
1910/* 1921/*
1911 * Preempt the current process if in interrupt from user mode, 1922 * Preempt the current process if in interrupt from user mode,

cvs diff -r1.10 -r1.11 src/sys/arch/alpha/include/mcontext.h (expand / switch to unified diff)

--- src/sys/arch/alpha/include/mcontext.h 2019/12/27 00:32:16 1.10
+++ src/sys/arch/alpha/include/mcontext.h 2021/05/24 21:00:12 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mcontext.h,v 1.10 2019/12/27 00:32:16 kamil Exp $ */ 1/* $NetBSD: mcontext.h,v 1.11 2021/05/24 21:00:12 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Klaus Klein. 8 * by Klaus Klein.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -84,26 +84,28 @@ typedef struct { @@ -84,26 +84,28 @@ typedef struct {
84 unsigned long __fp_regs[32]; 84 unsigned long __fp_regs[32];
85 double __fp_dregs[32]; 85 double __fp_dregs[32];
86 } __fp_fr; 86 } __fp_fr;
87 unsigned long __fp_fpcr; 87 unsigned long __fp_fpcr;
88} __fpregset_t; 88} __fpregset_t;
89 89
90typedef struct { 90typedef struct {
91 __gregset_t __gregs; 91 __gregset_t __gregs;
92 __fpregset_t __fpregs; 92 __fpregset_t __fpregs;
93} mcontext_t; 93} mcontext_t;
94 94
95/* Machine-dependent uc_flags */ 95/* Machine-dependent uc_flags */
96#define _UC_TLSBASE 0x20 /* valid process-unique value in _REG_UNIQUE */ 96#define _UC_TLSBASE 0x20 /* valid process-unique value in _REG_UNIQUE */
 97#define _UC_SETSTACK 0x00010000
 98#define _UC_CLRSTACK 0x00020000
97 99
98#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP]) 100#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
99#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S6]) 101#define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S6])
100#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC]) 102#define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
101#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_V0]) 103#define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_V0])
102 104
103#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc) 105#define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)
104 106
105#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \ 107#if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
106 defined(__LIBPTHREAD_SOURCE__) 108 defined(__LIBPTHREAD_SOURCE__)
107#include <sys/tls.h> 109#include <sys/tls.h>
108 110
109__BEGIN_DECLS 111__BEGIN_DECLS