1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 32*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate /* 40*7c478bd9Sstevel@tonic-gate * 4.3BSD signal compatibility functions 41*7c478bd9Sstevel@tonic-gate * 42*7c478bd9Sstevel@tonic-gate * the implementation interprets signal masks equal to -1 as "all of the 43*7c478bd9Sstevel@tonic-gate * signals in the signal set", thereby allowing signals with numbers 44*7c478bd9Sstevel@tonic-gate * above 32 to be blocked when referenced in code such as: 45*7c478bd9Sstevel@tonic-gate * 46*7c478bd9Sstevel@tonic-gate * for (i = 0; i < NSIG; i++) 47*7c478bd9Sstevel@tonic-gate * mask |= sigmask(i) 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 51*7c478bd9Sstevel@tonic-gate #include <ucontext.h> 52*7c478bd9Sstevel@tonic-gate #include <signal.h> 53*7c478bd9Sstevel@tonic-gate #include <errno.h> 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #undef BUS_OBJERR /* namespace conflict */ 56*7c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 57*7c478bd9Sstevel@tonic-gate #include "libc.h" 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #pragma weak sigvechandler = _sigvechandler 60*7c478bd9Sstevel@tonic-gate #pragma weak sigsetmask = _sigsetmask 61*7c478bd9Sstevel@tonic-gate #pragma weak sigblock = _sigblock 62*7c478bd9Sstevel@tonic-gate #pragma weak sigpause = usigpause 63*7c478bd9Sstevel@tonic-gate #pragma weak sigvec = _sigvec 64*7c478bd9Sstevel@tonic-gate #pragma weak sigstack = _sigstack 65*7c478bd9Sstevel@tonic-gate #pragma weak signal = usignal 66*7c478bd9Sstevel@tonic-gate #pragma weak siginterrupt = _siginterrupt 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * DO NOT remove the _ from these 3 functions or the subsequent 70*7c478bd9Sstevel@tonic-gate * calls to them below. The non _ versions of these functions 71*7c478bd9Sstevel@tonic-gate * are the wrong functions to call. This is BCP. Extra 72*7c478bd9Sstevel@tonic-gate * care should be taken when modifying this code. 73*7c478bd9Sstevel@tonic-gate */ 74*7c478bd9Sstevel@tonic-gate extern int _sigfillset(sigset_t *); 75*7c478bd9Sstevel@tonic-gate extern int _sigemptyset(sigset_t *); 76*7c478bd9Sstevel@tonic-gate extern int _sigprocmask(int, const sigset_t *, sigset_t *); 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate #define set2mask(setp) ((setp)->__sigbits[0]) 79*7c478bd9Sstevel@tonic-gate #define mask2set(mask, setp) \ 80*7c478bd9Sstevel@tonic-gate ((mask) == -1 ? _sigfillset(setp) : \ 81*7c478bd9Sstevel@tonic-gate ((void) _sigemptyset(setp), (((setp)->__sigbits[0]) = (int)(mask)))) 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate void (*_siguhandler[NSIG])() = { 0 }; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * forward declarations 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate int ucbsiginterrupt(int, int); 89*7c478bd9Sstevel@tonic-gate int ucbsigvec(int, struct sigvec *, struct sigvec *); 90*7c478bd9Sstevel@tonic-gate int ucbsigpause(int); 91*7c478bd9Sstevel@tonic-gate int ucbsigblock(int); 92*7c478bd9Sstevel@tonic-gate int ucbsigsetmask(int); 93*7c478bd9Sstevel@tonic-gate static void ucbsigvechandler(int, siginfo_t *, ucontext_t *); 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate /* 96*7c478bd9Sstevel@tonic-gate * sigvechandler is the real signal handler installed for all 97*7c478bd9Sstevel@tonic-gate * signals handled in the 4.3BSD compatibility interface - it translates 98*7c478bd9Sstevel@tonic-gate * SVR4 signal hander arguments into 4.3BSD signal handler arguments 99*7c478bd9Sstevel@tonic-gate * and then calls the real handler 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate int 103*7c478bd9Sstevel@tonic-gate _sigvechandler(int sig, siginfo_t *sip, ucontext_t *ucp) 104*7c478bd9Sstevel@tonic-gate { 105*7c478bd9Sstevel@tonic-gate ucbsigvechandler(sig, sip, ucp); 106*7c478bd9Sstevel@tonic-gate return (0); /* keep the same as the original prototype */ 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate static void 110*7c478bd9Sstevel@tonic-gate ucbsigvechandler(int sig, siginfo_t *sip, ucontext_t *ucp) 111*7c478bd9Sstevel@tonic-gate { 112*7c478bd9Sstevel@tonic-gate struct sigcontext sc; 113*7c478bd9Sstevel@tonic-gate int code; 114*7c478bd9Sstevel@tonic-gate char *addr; 115*7c478bd9Sstevel@tonic-gate #ifdef NEVER 116*7c478bd9Sstevel@tonic-gate int gwinswitch = 0; 117*7c478bd9Sstevel@tonic-gate #endif 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate sc.sc_onstack = ((ucp->uc_stack.ss_flags & SS_ONSTACK) != 0); 120*7c478bd9Sstevel@tonic-gate sc.sc_mask = set2mask(&ucp->uc_sigmask); 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 123*7c478bd9Sstevel@tonic-gate if (sig == SIGFPE && sip != NULL && SI_FROMKERNEL(sip) && 124*7c478bd9Sstevel@tonic-gate (sip->si_code == FPE_INTDIV || sip->si_code == FPE_INTOVF)) { 125*7c478bd9Sstevel@tonic-gate /* 126*7c478bd9Sstevel@tonic-gate * Hack to emulate the 4.x kernel behavior of incrementing 127*7c478bd9Sstevel@tonic-gate * the PC on integer divide by zero and integer overflow 128*7c478bd9Sstevel@tonic-gate * on sparc machines. (5.x does not increment the PC.) 129*7c478bd9Sstevel@tonic-gate */ 130*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_PC] = 131*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_nPC]; 132*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_nPC] += 4; 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate sc.sc_sp = ucp->uc_mcontext.gregs[REG_SP]; 135*7c478bd9Sstevel@tonic-gate sc.sc_pc = ucp->uc_mcontext.gregs[REG_PC]; 136*7c478bd9Sstevel@tonic-gate sc.sc_npc = ucp->uc_mcontext.gregs[REG_nPC]; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate /* XX64 There is no REG_PSR for sparcv9, we map in REG_CCR for now */ 139*7c478bd9Sstevel@tonic-gate #if defined(__sparcv9) 140*7c478bd9Sstevel@tonic-gate sc.sc_psr = ucp->uc_mcontext.gregs[REG_CCR]; 141*7c478bd9Sstevel@tonic-gate #else 142*7c478bd9Sstevel@tonic-gate sc.sc_psr = ucp->uc_mcontext.gregs[REG_PSR]; 143*7c478bd9Sstevel@tonic-gate #endif 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate sc.sc_g1 = ucp->uc_mcontext.gregs[REG_G1]; 146*7c478bd9Sstevel@tonic-gate sc.sc_o0 = ucp->uc_mcontext.gregs[REG_O0]; 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate /* 149*7c478bd9Sstevel@tonic-gate * XXX - What a kludge! 150*7c478bd9Sstevel@tonic-gate * Store a pointer to the original ucontext_t in the sigcontext 151*7c478bd9Sstevel@tonic-gate * so that it's available to the sigcleanup call that needs to 152*7c478bd9Sstevel@tonic-gate * return from the signal handler. Otherwise, vital information 153*7c478bd9Sstevel@tonic-gate * (e.g., the "out" registers) that's only saved in the 154*7c478bd9Sstevel@tonic-gate * ucontext_t isn't available to sigcleanup. 155*7c478bd9Sstevel@tonic-gate */ 156*7c478bd9Sstevel@tonic-gate sc.sc_wbcnt = (int)(sizeof (*ucp)); 157*7c478bd9Sstevel@tonic-gate sc.sc_spbuf[0] = (char *)sig; 158*7c478bd9Sstevel@tonic-gate sc.sc_spbuf[1] = (char *)ucp; 159*7c478bd9Sstevel@tonic-gate #ifdef NEVER 160*7c478bd9Sstevel@tonic-gate /* 161*7c478bd9Sstevel@tonic-gate * XXX - Sorry, we can never pass the saved register windows 162*7c478bd9Sstevel@tonic-gate * on in the sigcontext because we use that space to save the 163*7c478bd9Sstevel@tonic-gate * ucontext_t. 164*7c478bd9Sstevel@tonic-gate */ 165*7c478bd9Sstevel@tonic-gate if (ucp->uc_mcontext.gwins != (gwindows_t *)0) { 166*7c478bd9Sstevel@tonic-gate int i, j; 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate gwinswitch = 1; 169*7c478bd9Sstevel@tonic-gate sc.sc_wbcnt = ucp->uc_mcontext.gwins->wbcnt; 170*7c478bd9Sstevel@tonic-gate /* XXX - should use bcopy to move this in bulk */ 171*7c478bd9Sstevel@tonic-gate for (i = 0; i < ucp->uc_mcontext.gwins; i++) { 172*7c478bd9Sstevel@tonic-gate sc.sc_spbuf[i] = ucp->uc_mcontext.gwins->spbuf[i]; 173*7c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++) 174*7c478bd9Sstevel@tonic-gate sc.sc_wbuf[i][j] = 175*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gwins->wbuf[i].rw_local[j]; 176*7c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++) 177*7c478bd9Sstevel@tonic-gate sc.sc_wbuf[i][j+8] = 178*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gwins->wbuf[i].rw_in[j]; 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate #endif 182*7c478bd9Sstevel@tonic-gate #endif 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate /* 185*7c478bd9Sstevel@tonic-gate * Translate signal codes from new to old. 186*7c478bd9Sstevel@tonic-gate * /usr/include/sys/siginfo.h contains new codes. 187*7c478bd9Sstevel@tonic-gate * /usr/ucbinclude/sys/signal.h contains old codes. 188*7c478bd9Sstevel@tonic-gate */ 189*7c478bd9Sstevel@tonic-gate code = 0; 190*7c478bd9Sstevel@tonic-gate addr = SIG_NOADDR; 191*7c478bd9Sstevel@tonic-gate if (sip != NULL && SI_FROMKERNEL(sip)) { 192*7c478bd9Sstevel@tonic-gate addr = sip->si_addr; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate switch (sig) { 195*7c478bd9Sstevel@tonic-gate case SIGILL: 196*7c478bd9Sstevel@tonic-gate switch (sip->si_code) { 197*7c478bd9Sstevel@tonic-gate case ILL_PRVOPC: 198*7c478bd9Sstevel@tonic-gate code = ILL_PRIVINSTR_FAULT; 199*7c478bd9Sstevel@tonic-gate break; 200*7c478bd9Sstevel@tonic-gate case ILL_BADSTK: 201*7c478bd9Sstevel@tonic-gate code = ILL_STACK; 202*7c478bd9Sstevel@tonic-gate break; 203*7c478bd9Sstevel@tonic-gate case ILL_ILLTRP: 204*7c478bd9Sstevel@tonic-gate code = ILL_TRAP_FAULT(sip->si_trapno); 205*7c478bd9Sstevel@tonic-gate break; 206*7c478bd9Sstevel@tonic-gate default: 207*7c478bd9Sstevel@tonic-gate code = ILL_ILLINSTR_FAULT; 208*7c478bd9Sstevel@tonic-gate break; 209*7c478bd9Sstevel@tonic-gate } 210*7c478bd9Sstevel@tonic-gate break; 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate case SIGEMT: 213*7c478bd9Sstevel@tonic-gate code = EMT_TAG; 214*7c478bd9Sstevel@tonic-gate break; 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate case SIGFPE: 217*7c478bd9Sstevel@tonic-gate switch (sip->si_code) { 218*7c478bd9Sstevel@tonic-gate case FPE_INTDIV: 219*7c478bd9Sstevel@tonic-gate code = FPE_INTDIV_TRAP; 220*7c478bd9Sstevel@tonic-gate break; 221*7c478bd9Sstevel@tonic-gate case FPE_INTOVF: 222*7c478bd9Sstevel@tonic-gate code = FPE_INTOVF_TRAP; 223*7c478bd9Sstevel@tonic-gate break; 224*7c478bd9Sstevel@tonic-gate case FPE_FLTDIV: 225*7c478bd9Sstevel@tonic-gate code = FPE_FLTDIV_TRAP; 226*7c478bd9Sstevel@tonic-gate break; 227*7c478bd9Sstevel@tonic-gate case FPE_FLTOVF: 228*7c478bd9Sstevel@tonic-gate code = FPE_FLTOVF_TRAP; 229*7c478bd9Sstevel@tonic-gate break; 230*7c478bd9Sstevel@tonic-gate case FPE_FLTUND: 231*7c478bd9Sstevel@tonic-gate code = FPE_FLTUND_TRAP; 232*7c478bd9Sstevel@tonic-gate break; 233*7c478bd9Sstevel@tonic-gate case FPE_FLTRES: 234*7c478bd9Sstevel@tonic-gate code = FPE_FLTINEX_TRAP; 235*7c478bd9Sstevel@tonic-gate break; 236*7c478bd9Sstevel@tonic-gate default: 237*7c478bd9Sstevel@tonic-gate code = FPE_FLTOPERR_TRAP; 238*7c478bd9Sstevel@tonic-gate break; 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate break; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate case SIGBUS: 243*7c478bd9Sstevel@tonic-gate switch (sip->si_code) { 244*7c478bd9Sstevel@tonic-gate case BUS_ADRALN: 245*7c478bd9Sstevel@tonic-gate code = BUS_ALIGN; 246*7c478bd9Sstevel@tonic-gate break; 247*7c478bd9Sstevel@tonic-gate case BUS_ADRERR: 248*7c478bd9Sstevel@tonic-gate code = BUS_HWERR; 249*7c478bd9Sstevel@tonic-gate break; 250*7c478bd9Sstevel@tonic-gate default: /* BUS_OBJERR */ 251*7c478bd9Sstevel@tonic-gate code = FC_MAKE_ERR(sip->si_errno); 252*7c478bd9Sstevel@tonic-gate break; 253*7c478bd9Sstevel@tonic-gate } 254*7c478bd9Sstevel@tonic-gate break; 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate case SIGSEGV: 257*7c478bd9Sstevel@tonic-gate switch (sip->si_code) { 258*7c478bd9Sstevel@tonic-gate case SEGV_MAPERR: 259*7c478bd9Sstevel@tonic-gate code = SEGV_NOMAP; 260*7c478bd9Sstevel@tonic-gate break; 261*7c478bd9Sstevel@tonic-gate case SEGV_ACCERR: 262*7c478bd9Sstevel@tonic-gate code = SEGV_PROT; 263*7c478bd9Sstevel@tonic-gate break; 264*7c478bd9Sstevel@tonic-gate default: 265*7c478bd9Sstevel@tonic-gate code = FC_MAKE_ERR(sip->si_errno); 266*7c478bd9Sstevel@tonic-gate break; 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate break; 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate default: 271*7c478bd9Sstevel@tonic-gate addr = SIG_NOADDR; 272*7c478bd9Sstevel@tonic-gate break; 273*7c478bd9Sstevel@tonic-gate } 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate (*_siguhandler[sig])(sig, code, &sc, addr); 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate if (sc.sc_onstack) 279*7c478bd9Sstevel@tonic-gate ucp->uc_stack.ss_flags |= SS_ONSTACK; 280*7c478bd9Sstevel@tonic-gate else 281*7c478bd9Sstevel@tonic-gate ucp->uc_stack.ss_flags &= ~SS_ONSTACK; 282*7c478bd9Sstevel@tonic-gate mask2set(sc.sc_mask, &ucp->uc_sigmask); 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 285*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_SP] = sc.sc_sp; 286*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_PC] = sc.sc_pc; 287*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_nPC] = sc.sc_npc; 288*7c478bd9Sstevel@tonic-gate #if defined(__sparcv9) 289*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_CCR] = sc.sc_psr; 290*7c478bd9Sstevel@tonic-gate #else 291*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_PSR] = sc.sc_psr; 292*7c478bd9Sstevel@tonic-gate #endif 293*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_G1] = sc.sc_g1; 294*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_O0] = sc.sc_o0; 295*7c478bd9Sstevel@tonic-gate #ifdef NEVER 296*7c478bd9Sstevel@tonic-gate if (gwinswitch == 1) { 297*7c478bd9Sstevel@tonic-gate int i, j; 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gwins->wbcnt = sc.sc_wbcnt; 300*7c478bd9Sstevel@tonic-gate /* XXX - should use bcopy to move this in bulk */ 301*7c478bd9Sstevel@tonic-gate for (i = 0; i < sc.sc_wbcnt; i++) { 302*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gwins->spbuf[i] = sc.sc_spbuf[i]; 303*7c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++) 304*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gwins->wbuf[i].rw_local[j] = 305*7c478bd9Sstevel@tonic-gate sc.sc_wbuf[i][j]; 306*7c478bd9Sstevel@tonic-gate for (j = 0; j < 8; j++) 307*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gwins->wbuf[i].rw_in[j] = 308*7c478bd9Sstevel@tonic-gate sc.sc_wbuf[i][j+8]; 309*7c478bd9Sstevel@tonic-gate } 310*7c478bd9Sstevel@tonic-gate } 311*7c478bd9Sstevel@tonic-gate #endif 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate if (sig == SIGFPE) { 314*7c478bd9Sstevel@tonic-gate if (ucp->uc_mcontext.fpregs.fpu_qcnt > 0) { 315*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.fpregs.fpu_qcnt--; 316*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.fpregs.fpu_q++; 317*7c478bd9Sstevel@tonic-gate } 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate #endif 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate (void) setcontext(ucp); 322*7c478bd9Sstevel@tonic-gate } 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate #if defined(__sparc) 325*7c478bd9Sstevel@tonic-gate /* 326*7c478bd9Sstevel@tonic-gate * Emulate the special sigcleanup trap. 327*7c478bd9Sstevel@tonic-gate * This is only used by statically linked 4.x applications 328*7c478bd9Sstevel@tonic-gate * and thus is only called by the static BCP support. 329*7c478bd9Sstevel@tonic-gate * It lives here because of its close relationship with 330*7c478bd9Sstevel@tonic-gate * the ucbsigvechandler code above. 331*7c478bd9Sstevel@tonic-gate * 332*7c478bd9Sstevel@tonic-gate * It's used by 4.x applications to: 333*7c478bd9Sstevel@tonic-gate * 1. return from a signal handler (in __sigtramp) 334*7c478bd9Sstevel@tonic-gate * 2. [sig]longjmp 335*7c478bd9Sstevel@tonic-gate * 3. context switch, in the old 4.x liblwp 336*7c478bd9Sstevel@tonic-gate */ 337*7c478bd9Sstevel@tonic-gate 338*7c478bd9Sstevel@tonic-gate void 339*7c478bd9Sstevel@tonic-gate __sigcleanup(struct sigcontext *scp) 340*7c478bd9Sstevel@tonic-gate { 341*7c478bd9Sstevel@tonic-gate ucontext_t uc, *ucp; 342*7c478bd9Sstevel@tonic-gate int sig; 343*7c478bd9Sstevel@tonic-gate 344*7c478bd9Sstevel@tonic-gate /* 345*7c478bd9Sstevel@tonic-gate * If there's a pointer to a ucontext_t hiding in the sigcontext, 346*7c478bd9Sstevel@tonic-gate * we *must* use that to return, since it contains important data 347*7c478bd9Sstevel@tonic-gate * such as the original "out" registers when the signal occurred. 348*7c478bd9Sstevel@tonic-gate */ 349*7c478bd9Sstevel@tonic-gate if (scp->sc_wbcnt == sizeof (*ucp)) { 350*7c478bd9Sstevel@tonic-gate sig = (int)scp->sc_spbuf[0]; 351*7c478bd9Sstevel@tonic-gate ucp = (ucontext_t *)scp->sc_spbuf[1]; 352*7c478bd9Sstevel@tonic-gate } else { 353*7c478bd9Sstevel@tonic-gate /* 354*7c478bd9Sstevel@tonic-gate * Otherwise, use a local ucontext_t and 355*7c478bd9Sstevel@tonic-gate * initialize it with getcontext. 356*7c478bd9Sstevel@tonic-gate */ 357*7c478bd9Sstevel@tonic-gate sig = 0; 358*7c478bd9Sstevel@tonic-gate ucp = &uc; 359*7c478bd9Sstevel@tonic-gate (void) getcontext(ucp); 360*7c478bd9Sstevel@tonic-gate } 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate if (scp->sc_onstack) { 363*7c478bd9Sstevel@tonic-gate ucp->uc_stack.ss_flags |= SS_ONSTACK; 364*7c478bd9Sstevel@tonic-gate } else 365*7c478bd9Sstevel@tonic-gate ucp->uc_stack.ss_flags &= ~SS_ONSTACK; 366*7c478bd9Sstevel@tonic-gate mask2set(scp->sc_mask, &ucp->uc_sigmask); 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_SP] = scp->sc_sp; 369*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_PC] = scp->sc_pc; 370*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_nPC] = scp->sc_npc; 371*7c478bd9Sstevel@tonic-gate #if defined(__sparcv9) 372*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_CCR] = scp->sc_psr; 373*7c478bd9Sstevel@tonic-gate #else 374*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_PSR] = scp->sc_psr; 375*7c478bd9Sstevel@tonic-gate #endif 376*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_G1] = scp->sc_g1; 377*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.gregs[REG_O0] = scp->sc_o0; 378*7c478bd9Sstevel@tonic-gate 379*7c478bd9Sstevel@tonic-gate if (sig == SIGFPE) { 380*7c478bd9Sstevel@tonic-gate if (ucp->uc_mcontext.fpregs.fpu_qcnt > 0) { 381*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.fpregs.fpu_qcnt--; 382*7c478bd9Sstevel@tonic-gate ucp->uc_mcontext.fpregs.fpu_q++; 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate } 385*7c478bd9Sstevel@tonic-gate (void) setcontext(ucp); 386*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 387*7c478bd9Sstevel@tonic-gate } 388*7c478bd9Sstevel@tonic-gate #endif 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate int 391*7c478bd9Sstevel@tonic-gate _sigsetmask(int mask) 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate return (ucbsigsetmask(mask)); 394*7c478bd9Sstevel@tonic-gate } 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate int 397*7c478bd9Sstevel@tonic-gate ucbsigsetmask(int mask) 398*7c478bd9Sstevel@tonic-gate { 399*7c478bd9Sstevel@tonic-gate sigset_t oset; 400*7c478bd9Sstevel@tonic-gate sigset_t nset; 401*7c478bd9Sstevel@tonic-gate 402*7c478bd9Sstevel@tonic-gate (void) _sigprocmask(0, (sigset_t *)0, &nset); 403*7c478bd9Sstevel@tonic-gate mask2set(mask, &nset); 404*7c478bd9Sstevel@tonic-gate (void) _sigprocmask(SIG_SETMASK, &nset, &oset); 405*7c478bd9Sstevel@tonic-gate return (set2mask(&oset)); 406*7c478bd9Sstevel@tonic-gate } 407*7c478bd9Sstevel@tonic-gate 408*7c478bd9Sstevel@tonic-gate int 409*7c478bd9Sstevel@tonic-gate _sigblock(int mask) 410*7c478bd9Sstevel@tonic-gate { 411*7c478bd9Sstevel@tonic-gate return (ucbsigblock(mask)); 412*7c478bd9Sstevel@tonic-gate } 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate int 415*7c478bd9Sstevel@tonic-gate ucbsigblock(int mask) 416*7c478bd9Sstevel@tonic-gate { 417*7c478bd9Sstevel@tonic-gate sigset_t oset; 418*7c478bd9Sstevel@tonic-gate sigset_t nset; 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate (void) _sigprocmask(0, (sigset_t *)0, &nset); 421*7c478bd9Sstevel@tonic-gate mask2set(mask, &nset); 422*7c478bd9Sstevel@tonic-gate (void) _sigprocmask(SIG_BLOCK, &nset, &oset); 423*7c478bd9Sstevel@tonic-gate return (set2mask(&oset)); 424*7c478bd9Sstevel@tonic-gate } 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate int 427*7c478bd9Sstevel@tonic-gate usigpause(int mask) 428*7c478bd9Sstevel@tonic-gate { 429*7c478bd9Sstevel@tonic-gate return (ucbsigpause(mask)); 430*7c478bd9Sstevel@tonic-gate } 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate int 433*7c478bd9Sstevel@tonic-gate ucbsigpause(int mask) 434*7c478bd9Sstevel@tonic-gate { 435*7c478bd9Sstevel@tonic-gate sigset_t set, oset; 436*7c478bd9Sstevel@tonic-gate int ret; 437*7c478bd9Sstevel@tonic-gate 438*7c478bd9Sstevel@tonic-gate (void) _sigprocmask(0, (sigset_t *)0, &set); 439*7c478bd9Sstevel@tonic-gate oset = set; 440*7c478bd9Sstevel@tonic-gate mask2set(mask, &set); 441*7c478bd9Sstevel@tonic-gate ret = sigsuspend(&set); 442*7c478bd9Sstevel@tonic-gate (void) _sigprocmask(SIG_SETMASK, &oset, (sigset_t *)0); 443*7c478bd9Sstevel@tonic-gate return (ret); 444*7c478bd9Sstevel@tonic-gate } 445*7c478bd9Sstevel@tonic-gate 446*7c478bd9Sstevel@tonic-gate int 447*7c478bd9Sstevel@tonic-gate _sigvec(int sig, struct sigvec *nvec, struct sigvec *ovec) 448*7c478bd9Sstevel@tonic-gate { 449*7c478bd9Sstevel@tonic-gate return (ucbsigvec(sig, nvec, ovec)); 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate int 453*7c478bd9Sstevel@tonic-gate ucbsigvec(int sig, struct sigvec *nvec, struct sigvec *ovec) 454*7c478bd9Sstevel@tonic-gate { 455*7c478bd9Sstevel@tonic-gate struct sigaction nact; 456*7c478bd9Sstevel@tonic-gate struct sigaction oact; 457*7c478bd9Sstevel@tonic-gate struct sigaction *nactp; 458*7c478bd9Sstevel@tonic-gate void (*ohandler)(int, int, struct sigcontext *, char *); 459*7c478bd9Sstevel@tonic-gate void (*nhandler)(int, int, struct sigcontext *, char *); 460*7c478bd9Sstevel@tonic-gate 461*7c478bd9Sstevel@tonic-gate if (sig <= 0 || sig >= NSIG) { 462*7c478bd9Sstevel@tonic-gate errno = EINVAL; 463*7c478bd9Sstevel@tonic-gate return (-1); 464*7c478bd9Sstevel@tonic-gate } 465*7c478bd9Sstevel@tonic-gate 466*7c478bd9Sstevel@tonic-gate if ((long)ovec == -1L || (long)nvec == -1L) { 467*7c478bd9Sstevel@tonic-gate errno = EFAULT; 468*7c478bd9Sstevel@tonic-gate return (-1); 469*7c478bd9Sstevel@tonic-gate } 470*7c478bd9Sstevel@tonic-gate 471*7c478bd9Sstevel@tonic-gate ohandler = _siguhandler[sig]; 472*7c478bd9Sstevel@tonic-gate 473*7c478bd9Sstevel@tonic-gate if (nvec) { 474*7c478bd9Sstevel@tonic-gate (void) _sigaction(sig, (struct sigaction *)0, &nact); 475*7c478bd9Sstevel@tonic-gate nhandler = nvec->sv_handler; 476*7c478bd9Sstevel@tonic-gate /* 477*7c478bd9Sstevel@tonic-gate * To be compatible with the behavior of SunOS 4.x: 478*7c478bd9Sstevel@tonic-gate * If the new signal handler is SIG_IGN or SIG_DFL, 479*7c478bd9Sstevel@tonic-gate * do not change the signal's entry in the handler array. 480*7c478bd9Sstevel@tonic-gate * This allows a child of vfork(2) to set signal handlers 481*7c478bd9Sstevel@tonic-gate * to SIG_IGN or SIG_DFL without affecting the parent. 482*7c478bd9Sstevel@tonic-gate */ 483*7c478bd9Sstevel@tonic-gate if ((void (*)(int))nhandler != SIG_DFL && 484*7c478bd9Sstevel@tonic-gate (void (*)(int))nhandler != SIG_IGN) { 485*7c478bd9Sstevel@tonic-gate _siguhandler[sig] = nhandler; 486*7c478bd9Sstevel@tonic-gate nact.sa_handler = (void (*)(int))ucbsigvechandler; 487*7c478bd9Sstevel@tonic-gate } else { 488*7c478bd9Sstevel@tonic-gate nact.sa_handler = (void (*)(int))nhandler; 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate mask2set(nvec->sv_mask, &nact.sa_mask); 491*7c478bd9Sstevel@tonic-gate if (sig == SIGKILL || sig == SIGSTOP) 492*7c478bd9Sstevel@tonic-gate nact.sa_handler = SIG_DFL; 493*7c478bd9Sstevel@tonic-gate nact.sa_flags = SA_SIGINFO; 494*7c478bd9Sstevel@tonic-gate if (!(nvec->sv_flags & SV_INTERRUPT)) 495*7c478bd9Sstevel@tonic-gate nact.sa_flags |= SA_RESTART; 496*7c478bd9Sstevel@tonic-gate if (nvec->sv_flags & SV_RESETHAND) 497*7c478bd9Sstevel@tonic-gate nact.sa_flags |= SA_RESETHAND; 498*7c478bd9Sstevel@tonic-gate if (nvec->sv_flags & SV_ONSTACK) 499*7c478bd9Sstevel@tonic-gate nact.sa_flags |= SA_ONSTACK; 500*7c478bd9Sstevel@tonic-gate nactp = &nact; 501*7c478bd9Sstevel@tonic-gate } else 502*7c478bd9Sstevel@tonic-gate nactp = (struct sigaction *)0; 503*7c478bd9Sstevel@tonic-gate 504*7c478bd9Sstevel@tonic-gate if (_sigaction(sig, nactp, &oact) < 0) { 505*7c478bd9Sstevel@tonic-gate _siguhandler[sig] = ohandler; 506*7c478bd9Sstevel@tonic-gate return (-1); 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate 509*7c478bd9Sstevel@tonic-gate if (ovec) { 510*7c478bd9Sstevel@tonic-gate if (oact.sa_handler == SIG_DFL || oact.sa_handler == SIG_IGN) 511*7c478bd9Sstevel@tonic-gate ovec->sv_handler = 512*7c478bd9Sstevel@tonic-gate (void (*) (int, int, struct sigcontext *, char *)) 513*7c478bd9Sstevel@tonic-gate oact.sa_handler; 514*7c478bd9Sstevel@tonic-gate else 515*7c478bd9Sstevel@tonic-gate ovec->sv_handler = ohandler; 516*7c478bd9Sstevel@tonic-gate ovec->sv_mask = set2mask(&oact.sa_mask); 517*7c478bd9Sstevel@tonic-gate ovec->sv_flags = 0; 518*7c478bd9Sstevel@tonic-gate if (oact.sa_flags & SA_ONSTACK) 519*7c478bd9Sstevel@tonic-gate ovec->sv_flags |= SV_ONSTACK; 520*7c478bd9Sstevel@tonic-gate if (oact.sa_flags & SA_RESETHAND) 521*7c478bd9Sstevel@tonic-gate ovec->sv_flags |= SV_RESETHAND; 522*7c478bd9Sstevel@tonic-gate if (!(oact.sa_flags & SA_RESTART)) 523*7c478bd9Sstevel@tonic-gate ovec->sv_flags |= SV_INTERRUPT; 524*7c478bd9Sstevel@tonic-gate } 525*7c478bd9Sstevel@tonic-gate 526*7c478bd9Sstevel@tonic-gate return (0); 527*7c478bd9Sstevel@tonic-gate } 528*7c478bd9Sstevel@tonic-gate 529*7c478bd9Sstevel@tonic-gate int 530*7c478bd9Sstevel@tonic-gate _sigstack(struct sigstack *nss, struct sigstack *oss) 531*7c478bd9Sstevel@tonic-gate { 532*7c478bd9Sstevel@tonic-gate struct sigaltstack nalt; 533*7c478bd9Sstevel@tonic-gate struct sigaltstack oalt; 534*7c478bd9Sstevel@tonic-gate struct sigaltstack *naltp; 535*7c478bd9Sstevel@tonic-gate 536*7c478bd9Sstevel@tonic-gate if (nss) { 537*7c478bd9Sstevel@tonic-gate /* 538*7c478bd9Sstevel@tonic-gate * XXX: assumes stack growth is down (like sparc) 539*7c478bd9Sstevel@tonic-gate */ 540*7c478bd9Sstevel@tonic-gate nalt.ss_sp = nss->ss_sp - SIGSTKSZ; 541*7c478bd9Sstevel@tonic-gate nalt.ss_size = SIGSTKSZ; 542*7c478bd9Sstevel@tonic-gate nalt.ss_flags = 0; 543*7c478bd9Sstevel@tonic-gate naltp = &nalt; 544*7c478bd9Sstevel@tonic-gate } else 545*7c478bd9Sstevel@tonic-gate naltp = (struct sigaltstack *)0; 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate if (sigaltstack(naltp, &oalt) < 0) 548*7c478bd9Sstevel@tonic-gate return (-1); 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate if (oss) { 551*7c478bd9Sstevel@tonic-gate /* 552*7c478bd9Sstevel@tonic-gate * XXX: assumes stack growth is down (like sparc) 553*7c478bd9Sstevel@tonic-gate */ 554*7c478bd9Sstevel@tonic-gate oss->ss_sp = oalt.ss_sp + oalt.ss_size; 555*7c478bd9Sstevel@tonic-gate oss->ss_onstack = ((oalt.ss_flags & SS_ONSTACK) != 0); 556*7c478bd9Sstevel@tonic-gate } 557*7c478bd9Sstevel@tonic-gate 558*7c478bd9Sstevel@tonic-gate return (0); 559*7c478bd9Sstevel@tonic-gate } 560*7c478bd9Sstevel@tonic-gate 561*7c478bd9Sstevel@tonic-gate void (* 562*7c478bd9Sstevel@tonic-gate ucbsignal(int s, void (*a)(int)))(int) 563*7c478bd9Sstevel@tonic-gate { 564*7c478bd9Sstevel@tonic-gate struct sigvec osv; 565*7c478bd9Sstevel@tonic-gate struct sigvec nsv; 566*7c478bd9Sstevel@tonic-gate static int mask[NSIG]; 567*7c478bd9Sstevel@tonic-gate static int flags[NSIG]; 568*7c478bd9Sstevel@tonic-gate 569*7c478bd9Sstevel@tonic-gate nsv.sv_handler = (void (*) (int, int, struct sigcontext *, char *)) a; 570*7c478bd9Sstevel@tonic-gate nsv.sv_mask = mask[s]; 571*7c478bd9Sstevel@tonic-gate nsv.sv_flags = flags[s]; 572*7c478bd9Sstevel@tonic-gate if (ucbsigvec(s, &nsv, &osv) < 0) 573*7c478bd9Sstevel@tonic-gate return (SIG_ERR); 574*7c478bd9Sstevel@tonic-gate if (nsv.sv_mask != osv.sv_mask || nsv.sv_flags != osv.sv_flags) { 575*7c478bd9Sstevel@tonic-gate mask[s] = nsv.sv_mask = osv.sv_mask; 576*7c478bd9Sstevel@tonic-gate flags[s] = nsv.sv_flags = 577*7c478bd9Sstevel@tonic-gate osv.sv_flags & ~(SV_RESETHAND|SV_INTERRUPT); 578*7c478bd9Sstevel@tonic-gate if (ucbsigvec(s, &nsv, (struct sigvec *)0) < 0) 579*7c478bd9Sstevel@tonic-gate return (SIG_ERR); 580*7c478bd9Sstevel@tonic-gate } 581*7c478bd9Sstevel@tonic-gate return ((void (*) (int)) osv.sv_handler); 582*7c478bd9Sstevel@tonic-gate } 583*7c478bd9Sstevel@tonic-gate 584*7c478bd9Sstevel@tonic-gate void (* 585*7c478bd9Sstevel@tonic-gate usignal(int s, void (*a) (int)))(int) 586*7c478bd9Sstevel@tonic-gate { 587*7c478bd9Sstevel@tonic-gate return (ucbsignal(s, a)); 588*7c478bd9Sstevel@tonic-gate } 589*7c478bd9Sstevel@tonic-gate 590*7c478bd9Sstevel@tonic-gate /* 591*7c478bd9Sstevel@tonic-gate * Set signal state to prevent restart of system calls 592*7c478bd9Sstevel@tonic-gate * after an instance of the indicated signal. 593*7c478bd9Sstevel@tonic-gate */ 594*7c478bd9Sstevel@tonic-gate 595*7c478bd9Sstevel@tonic-gate int 596*7c478bd9Sstevel@tonic-gate _siginterrupt(int sig, int flag) 597*7c478bd9Sstevel@tonic-gate { 598*7c478bd9Sstevel@tonic-gate return (ucbsiginterrupt(sig, flag)); 599*7c478bd9Sstevel@tonic-gate } 600*7c478bd9Sstevel@tonic-gate 601*7c478bd9Sstevel@tonic-gate int 602*7c478bd9Sstevel@tonic-gate ucbsiginterrupt(int sig, int flag) 603*7c478bd9Sstevel@tonic-gate { 604*7c478bd9Sstevel@tonic-gate struct sigvec sv; 605*7c478bd9Sstevel@tonic-gate int ret; 606*7c478bd9Sstevel@tonic-gate 607*7c478bd9Sstevel@tonic-gate if ((ret = ucbsigvec(sig, 0, &sv)) < 0) 608*7c478bd9Sstevel@tonic-gate return (ret); 609*7c478bd9Sstevel@tonic-gate if (flag) 610*7c478bd9Sstevel@tonic-gate sv.sv_flags |= SV_INTERRUPT; 611*7c478bd9Sstevel@tonic-gate else 612*7c478bd9Sstevel@tonic-gate sv.sv_flags &= ~SV_INTERRUPT; 613*7c478bd9Sstevel@tonic-gate return (ucbsigvec(sig, &sv, 0)); 614*7c478bd9Sstevel@tonic-gate } 615