17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 1996 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 27*5d54f3d8Smuffin #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include "signalmap.h" 307c478bd9Sstevel@tonic-gate #include <sys/signal.h> 317c478bd9Sstevel@tonic-gate #include <sys/errno.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate extern int errno; 347c478bd9Sstevel@tonic-gate void (*handlers[32])(); /* XXX - 32??? NSIG, maybe? */ 357c478bd9Sstevel@tonic-gate 36*5d54f3d8Smuffin void 37*5d54f3d8Smuffin maphandler(int sig, int code, struct sigcontext *scp, char *addr) 387c478bd9Sstevel@tonic-gate { 397c478bd9Sstevel@tonic-gate switch (sig) { 407c478bd9Sstevel@tonic-gate case SIGBUS: 417c478bd9Sstevel@tonic-gate case SIGSEGV: 427c478bd9Sstevel@tonic-gate switch (FC_CODE(code)) { 437c478bd9Sstevel@tonic-gate case 3: /* 5.x value for FC_OBJERR */ 447c478bd9Sstevel@tonic-gate code = FC_MAKE_ERR(FC_ERRNO(code)); 457c478bd9Sstevel@tonic-gate break; 467c478bd9Sstevel@tonic-gate case 5: /* 5.x value for FC_NOMAP */ 477c478bd9Sstevel@tonic-gate code = FC_NOMAP; 487c478bd9Sstevel@tonic-gate break; 497c478bd9Sstevel@tonic-gate } 507c478bd9Sstevel@tonic-gate break; 517c478bd9Sstevel@tonic-gate } 527c478bd9Sstevel@tonic-gate __sendsig(maptooldsig(sig), code, scp, addr, handlers[sig]); 537c478bd9Sstevel@tonic-gate } 547c478bd9Sstevel@tonic-gate 55*5d54f3d8Smuffin void (* 56*5d54f3d8Smuffin signal(int sig, void (*a)(int)))(int) 577c478bd9Sstevel@tonic-gate { 587c478bd9Sstevel@tonic-gate int newsig; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate struct sigvec osv, sv; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate sv.sv_handler = a; 637c478bd9Sstevel@tonic-gate sv.sv_mask = 0; 647c478bd9Sstevel@tonic-gate #ifdef S5EMUL 657c478bd9Sstevel@tonic-gate sv.sv_flags = SV_INTERRUPT|SV_RESETHAND; 667c478bd9Sstevel@tonic-gate #else 677c478bd9Sstevel@tonic-gate sv.sv_flags = 0; 687c478bd9Sstevel@tonic-gate #endif 697c478bd9Sstevel@tonic-gate if (sigvec(sig, &sv, &osv) < 0) 707c478bd9Sstevel@tonic-gate return (BADSIG); 717c478bd9Sstevel@tonic-gate return (osv.sv_handler); 727c478bd9Sstevel@tonic-gate } 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate 75*5d54f3d8Smuffin int 76*5d54f3d8Smuffin sigvec(int sig, struct sigvec *nvec, struct sigvec *ovec) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate int newsig; 797c478bd9Sstevel@tonic-gate struct sigvec tvec, *tvecp; 80*5d54f3d8Smuffin void (*oldhand)(int); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate if ((int)nvec == -1 || (int)ovec == -1) { 837c478bd9Sstevel@tonic-gate errno = EFAULT; 847c478bd9Sstevel@tonic-gate return (-1); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate newsig = maptonewsig(sig); 887c478bd9Sstevel@tonic-gate oldhand = handlers[newsig]; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate if ((tvecp = nvec) != 0) { 917c478bd9Sstevel@tonic-gate tvec = *nvec; 927c478bd9Sstevel@tonic-gate tvecp = &tvec; 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * To be compatible with the behavior of SunOS 4.x: 957c478bd9Sstevel@tonic-gate * If the new signal handler is SIG_IGN or SIG_DFL, 967c478bd9Sstevel@tonic-gate * do not change the signal's entry in the handler array. 977c478bd9Sstevel@tonic-gate * This allows a child of vfork(2) to set signal handlers 987c478bd9Sstevel@tonic-gate * to SIG_IGN or SIG_DFL without affecting the parent. 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate if (tvecp->sv_handler != SIG_DFL && 1017c478bd9Sstevel@tonic-gate tvecp->sv_handler != SIG_IGN) { 1027c478bd9Sstevel@tonic-gate handlers[newsig] = tvecp->sv_handler; 1037c478bd9Sstevel@tonic-gate tvecp->sv_handler = maphandler; 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate if (ucbsigvec(newsig, tvecp, ovec) == -1) { 1087c478bd9Sstevel@tonic-gate handlers[newsig] = oldhand; 1097c478bd9Sstevel@tonic-gate return (-1); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate if (ovec && ovec->sv_handler != SIG_DFL && ovec->sv_handler != SIG_IGN) 1137c478bd9Sstevel@tonic-gate ovec->sv_handler = oldhand; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate return (0); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate 118*5d54f3d8Smuffin int 119*5d54f3d8Smuffin sigsetmask(int mask) 1207c478bd9Sstevel@tonic-gate { 1217c478bd9Sstevel@tonic-gate int ret; 1227c478bd9Sstevel@tonic-gate ret = ucbsigsetmask(maptonewmask(mask)); 1237c478bd9Sstevel@tonic-gate return (maptooldmask(ret)); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 126*5d54f3d8Smuffin int 127*5d54f3d8Smuffin sigblock(int mask) 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate int ret; 1307c478bd9Sstevel@tonic-gate ret = ucbsigblock(maptonewmask(mask)); 1317c478bd9Sstevel@tonic-gate return (maptooldmask(ret)); 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate 135*5d54f3d8Smuffin int 136*5d54f3d8Smuffin sigpause(int mask) 1377c478bd9Sstevel@tonic-gate { 1387c478bd9Sstevel@tonic-gate int ret; 1397c478bd9Sstevel@tonic-gate return (ucbsigpause(maptonewmask(mask))); 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate 142*5d54f3d8Smuffin int 143*5d54f3d8Smuffin siginterrupt(int sig, int flag) 1447c478bd9Sstevel@tonic-gate { 1457c478bd9Sstevel@tonic-gate return (ucbsiginterrupt(maptonewsig(sig), flag)); 1467c478bd9Sstevel@tonic-gate } 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate 149*5d54f3d8Smuffin int 150*5d54f3d8Smuffin maptonewsig(int sig) 1517c478bd9Sstevel@tonic-gate { 1527c478bd9Sstevel@tonic-gate switch (sig) { 1537c478bd9Sstevel@tonic-gate case SIGURG: /* urgent condition on IO channel */ 1547c478bd9Sstevel@tonic-gate return (XSIGURG); 1557c478bd9Sstevel@tonic-gate case SIGSTOP: /* sendable stop signal not from tty */ 1567c478bd9Sstevel@tonic-gate return (XSIGSTOP); 1577c478bd9Sstevel@tonic-gate case SIGTSTP: /* stop signal from tty */ 1587c478bd9Sstevel@tonic-gate return (XSIGTSTP); 1597c478bd9Sstevel@tonic-gate case SIGCONT: /* continue a stopped process */ 1607c478bd9Sstevel@tonic-gate return (XSIGCONT); 1617c478bd9Sstevel@tonic-gate case SIGCLD: /* System V name for SIGCHLD */ 1627c478bd9Sstevel@tonic-gate return (XSIGCLD); 1637c478bd9Sstevel@tonic-gate case SIGTTIN: /* to readers pgrp upon background tty read */ 1647c478bd9Sstevel@tonic-gate return (XSIGTTIN); 1657c478bd9Sstevel@tonic-gate case SIGTTOU: /* like TTIN for output */ 1667c478bd9Sstevel@tonic-gate return (XSIGTTOU); 1677c478bd9Sstevel@tonic-gate case SIGIO: /* input/output possible signal */ 1687c478bd9Sstevel@tonic-gate return (XSIGIO); 1697c478bd9Sstevel@tonic-gate case SIGXCPU: /* exceeded CPU time limit */ 1707c478bd9Sstevel@tonic-gate return (XSIGXCPU); 1717c478bd9Sstevel@tonic-gate case SIGXFSZ: /* exceeded file size limit */ 1727c478bd9Sstevel@tonic-gate return (XSIGXFSZ); 1737c478bd9Sstevel@tonic-gate case SIGVTALRM: /* virtual time alarm */ 1747c478bd9Sstevel@tonic-gate return (XSIGVTALRM); 1757c478bd9Sstevel@tonic-gate case SIGPROF: /* profiling time alarm */ 1767c478bd9Sstevel@tonic-gate return (XSIGPROF); 1777c478bd9Sstevel@tonic-gate case SIGWINCH: /* window changed */ 1787c478bd9Sstevel@tonic-gate return (XSIGWINCH); 1797c478bd9Sstevel@tonic-gate case SIGLOST: /* resource lost, not supported */ 1807c478bd9Sstevel@tonic-gate return (-1); 1817c478bd9Sstevel@tonic-gate case SIGUSR1: 1827c478bd9Sstevel@tonic-gate return (XSIGUSR1); 1837c478bd9Sstevel@tonic-gate case SIGUSR2: /* user defined signal 2 */ 1847c478bd9Sstevel@tonic-gate return (XSIGUSR2); 1857c478bd9Sstevel@tonic-gate default: 1867c478bd9Sstevel@tonic-gate return (sig); 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate 190*5d54f3d8Smuffin int 191*5d54f3d8Smuffin maptooldsig(int sig) 1927c478bd9Sstevel@tonic-gate { 1937c478bd9Sstevel@tonic-gate switch (sig) { 1947c478bd9Sstevel@tonic-gate case XSIGURG: /* urgent condition on IO channel */ 1957c478bd9Sstevel@tonic-gate return (SIGURG); 1967c478bd9Sstevel@tonic-gate case XSIGSTOP: /* sendable stop signal not from tty */ 1977c478bd9Sstevel@tonic-gate return (SIGSTOP); 1987c478bd9Sstevel@tonic-gate case XSIGTSTP: /* stop signal from tty */ 1997c478bd9Sstevel@tonic-gate return (SIGTSTP); 2007c478bd9Sstevel@tonic-gate case XSIGCONT: /* continue a stopped process */ 2017c478bd9Sstevel@tonic-gate return (SIGCONT); 2027c478bd9Sstevel@tonic-gate case XSIGCLD: /* System V name for SIGCHLD */ 2037c478bd9Sstevel@tonic-gate return (SIGCLD); 2047c478bd9Sstevel@tonic-gate case XSIGTTIN: /* to readers pgrp upon background tty read */ 2057c478bd9Sstevel@tonic-gate return (SIGTTIN); 2067c478bd9Sstevel@tonic-gate case XSIGTTOU: /* like TTIN for output */ 2077c478bd9Sstevel@tonic-gate return (SIGTTOU); 2087c478bd9Sstevel@tonic-gate case XSIGIO: /* input/output possible signal */ 2097c478bd9Sstevel@tonic-gate return (SIGIO); 2107c478bd9Sstevel@tonic-gate case XSIGXCPU: /* exceeded CPU time limit */ 2117c478bd9Sstevel@tonic-gate return (SIGXCPU); 2127c478bd9Sstevel@tonic-gate case XSIGXFSZ: /* exceeded file size limit */ 2137c478bd9Sstevel@tonic-gate return (SIGXFSZ); 2147c478bd9Sstevel@tonic-gate case XSIGVTALRM: /* virtual time alarm */ 2157c478bd9Sstevel@tonic-gate return (SIGVTALRM); 2167c478bd9Sstevel@tonic-gate case XSIGPROF: /* profiling time alarm */ 2177c478bd9Sstevel@tonic-gate return (SIGPROF); 2187c478bd9Sstevel@tonic-gate case XSIGWINCH: /* window changed */ 2197c478bd9Sstevel@tonic-gate return (SIGWINCH); 2207c478bd9Sstevel@tonic-gate case XSIGUSR1: 2217c478bd9Sstevel@tonic-gate return (SIGUSR1); 2227c478bd9Sstevel@tonic-gate case XSIGUSR2: /* user defined signal 2 */ 2237c478bd9Sstevel@tonic-gate return (SIGUSR2); 2247c478bd9Sstevel@tonic-gate case XSIGPWR: /* user defined signal 2 */ 2257c478bd9Sstevel@tonic-gate return (-1); 2267c478bd9Sstevel@tonic-gate default: 2277c478bd9Sstevel@tonic-gate return (sig); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 231*5d54f3d8Smuffin int 232*5d54f3d8Smuffin maptooldmask(int mask) 2337c478bd9Sstevel@tonic-gate { 2347c478bd9Sstevel@tonic-gate int omask; 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate omask = mask & 0x7FFF; /* these signo are same */ 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGURG)) 2397c478bd9Sstevel@tonic-gate omask |= sigmask(SIGURG); 2407c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGSTOP)) 2417c478bd9Sstevel@tonic-gate omask |= sigmask(SIGSTOP); 2427c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGTSTP)) 2437c478bd9Sstevel@tonic-gate omask |= sigmask(SIGTSTP); 2447c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGCONT)) 2457c478bd9Sstevel@tonic-gate omask |= sigmask(SIGCONT); 2467c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGCLD)) 2477c478bd9Sstevel@tonic-gate omask |= sigmask(SIGCLD); 2487c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGTTIN)) 2497c478bd9Sstevel@tonic-gate omask |= sigmask(SIGTTIN); 2507c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGTTOU)) 2517c478bd9Sstevel@tonic-gate omask |= sigmask(SIGTTOU); 2527c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGIO)) 2537c478bd9Sstevel@tonic-gate omask |= sigmask(SIGIO); 2547c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGXCPU)) 2557c478bd9Sstevel@tonic-gate omask |= sigmask(SIGXCPU); 2567c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGXFSZ)) 2577c478bd9Sstevel@tonic-gate omask |= sigmask(SIGXFSZ); 2587c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGVTALRM)) 2597c478bd9Sstevel@tonic-gate omask |= sigmask(SIGVTALRM); 2607c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGPROF)) 2617c478bd9Sstevel@tonic-gate omask |= sigmask(SIGPROF); 2627c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGWINCH)) 2637c478bd9Sstevel@tonic-gate omask |= sigmask(SIGWINCH); 2647c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGUSR1)) 2657c478bd9Sstevel@tonic-gate omask |= sigmask(SIGUSR1); 2667c478bd9Sstevel@tonic-gate if (mask & sigmask(XSIGUSR2)) 2677c478bd9Sstevel@tonic-gate omask |= sigmask(SIGUSR2); 2687c478bd9Sstevel@tonic-gate return (omask); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate 272*5d54f3d8Smuffin int 273*5d54f3d8Smuffin maptonewmask(int omask) 2747c478bd9Sstevel@tonic-gate { 2757c478bd9Sstevel@tonic-gate int mask; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate if (omask == -1) { 2787c478bd9Sstevel@tonic-gate return (-1); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate mask = omask & 0x7FFF; /* these signo are the same */ 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGURG)) 2847c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGURG); 2857c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGSTOP)) 2867c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGSTOP); 2877c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGTSTP)) 2887c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGTSTP); 2897c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGCONT)) 2907c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGCONT); 2917c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGCLD)) 2927c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGCLD); 2937c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGTTIN)) 2947c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGTTIN); 2957c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGTTOU)) 2967c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGTTOU); 2977c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGIO)) 2987c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGIO); 2997c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGXCPU)) 3007c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGXCPU); 3017c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGXFSZ)) 3027c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGXFSZ); 3037c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGVTALRM)) 3047c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGVTALRM); 3057c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGPROF)) 3067c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGPROF); 3077c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGWINCH)) 3087c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGWINCH); 3097c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGUSR1)) 3107c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGUSR1); 3117c478bd9Sstevel@tonic-gate if (omask & sigmask(SIGUSR2)) 3127c478bd9Sstevel@tonic-gate mask |= sigmask(XSIGUSR2); 3137c478bd9Sstevel@tonic-gate return (mask); 3147c478bd9Sstevel@tonic-gate } 315