| @@ -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 | |
1902 | static void | | 1913 | static void |
1903 | cpu_kick(struct cpu_info * const ci) | | 1914 | cpu_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, |