|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988 University of Utah. ! 3: * Copyright (c) 1990 The Regents of the University of California. ! 4: * All rights reserved. ! 5: * ! 6: * This code is derived from software contributed to Berkeley by ! 7: * the Systems Programming Group of the University of Utah Computer ! 8: * Science Department. ! 9: * ! 10: * Redistribution and use in source and binary forms, with or without ! 11: * modification, are permitted provided that the following conditions ! 12: * are met: ! 13: * 1. Redistributions of source code must retain the above copyright ! 14: * notice, this list of conditions and the following disclaimer. ! 15: * 2. Redistributions in binary form must reproduce the above copyright ! 16: * notice, this list of conditions and the following disclaimer in the ! 17: * documentation and/or other materials provided with the distribution. ! 18: * 3. All advertising materials mentioning features or use of this software ! 19: * must display the following acknowledgement: ! 20: * This product includes software developed by the University of ! 21: * California, Berkeley and its contributors. ! 22: * 4. Neither the name of the University nor the names of its contributors ! 23: * may be used to endorse or promote products derived from this software ! 24: * without specific prior written permission. ! 25: * ! 26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 36: * SUCH DAMAGE. ! 37: * ! 38: * from: Utah $Hdr: hpux_sig.c 1.1 90/07/09$ ! 39: * ! 40: * @(#)hpux_sig.c 7.8 (Berkeley) 4/20/91 ! 41: */ ! 42: ! 43: /* ! 44: * Signal related HPUX compatibility routines ! 45: */ ! 46: ! 47: #ifdef HPUXCOMPAT ! 48: ! 49: #include "param.h" ! 50: #include "systm.h" ! 51: #include "kernel.h" ! 52: #include "proc.h" ! 53: #include "signalvar.h" ! 54: #include "hpux.h" ! 55: ! 56: /* indexed by HPUX signal number - 1 */ ! 57: char hpuxtobsdsigmap[NSIG] = { ! 58: /*01*/ SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGEMT, SIGFPE, ! 59: /*09*/ SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGALRM, SIGTERM, SIGUSR1, ! 60: /*17*/ SIGUSR2, SIGCHLD, 0, SIGVTALRM,SIGPROF, SIGIO, SIGWINCH, SIGSTOP, ! 61: /*25*/ SIGTSTP, SIGCONT,SIGTTIN, SIGTTOU, SIGURG, 0, 0, 0 ! 62: }; ! 63: ! 64: /* indexed by BSD signal number - 1 */ ! 65: char bsdtohpuxsigmap[NSIG] = { ! 66: /*01*/ 1, 2, 3, 4, 5, 6, 7, 8, ! 67: /*09*/ 9, 10, 11, 12, 13, 14, 15, 29, ! 68: /*17*/ 24, 25, 26, 18, 27, 28, 22, 0, ! 69: /*25*/ 0, 20, 21, 23, 0, 16, 17, 0 ! 70: }; ! 71: ! 72: /* ! 73: * XXX: In addition to mapping the signal number we also have ! 74: * to see if the "old" style signal mechinism is needed. ! 75: * If so, we set the OUSIG flag. This is not really correct ! 76: * as under HP-UX "old" style handling can be set on a per ! 77: * signal basis and we are setting it for all signals in one ! 78: * swell foop. I suspect we can get away with this since I ! 79: * doubt any program of interest mixes the two semantics. ! 80: */ ! 81: hpuxsigvec(p, uap, retval) ! 82: struct proc *p; ! 83: register struct args { ! 84: int signo; ! 85: struct sigvec *nsv; ! 86: struct sigvec *osv; ! 87: } *uap; ! 88: int *retval; ! 89: { ! 90: struct sigvec vec; ! 91: register struct sigacts *ps = p->p_sigacts; ! 92: register struct sigvec *sv; ! 93: register int sig; ! 94: int bit, error; ! 95: ! 96: sig = hpuxtobsdsig(uap->signo); ! 97: if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) ! 98: return (EINVAL); ! 99: sv = &vec; ! 100: if (uap->osv) { ! 101: sv->sv_handler = ps->ps_sigact[sig]; ! 102: sv->sv_mask = ps->ps_catchmask[sig]; ! 103: bit = sigmask(sig); ! 104: sv->sv_flags = 0; ! 105: if ((ps->ps_sigonstack & bit) != 0) ! 106: sv->sv_flags |= SV_ONSTACK; ! 107: if ((ps->ps_sigintr & bit) != 0) ! 108: sv->sv_flags |= SV_INTERRUPT; ! 109: #if 0 ! 110: /* XXX -- SOUSIG no longer exists, do something here */ ! 111: if (p->p_flag & SOUSIG) ! 112: sv->sv_flags |= HPUXSV_RESET; /* XXX */ ! 113: #endif ! 114: error = copyout((caddr_t)sv, (caddr_t)uap->osv, sizeof (vec)); ! 115: if (error) ! 116: return (error); ! 117: } ! 118: if (uap->nsv) { ! 119: error = copyin((caddr_t)uap->nsv, (caddr_t)sv, sizeof (vec)); ! 120: if (error) ! 121: return (error); ! 122: if (sig == SIGCONT && sv->sv_handler == SIG_IGN) ! 123: return (EINVAL); ! 124: sv->sv_flags ^= SA_RESTART; ! 125: setsigvec(p, sig, (struct sigaction *)sv); ! 126: #if 0 ! 127: /* XXX -- SOUSIG no longer exists, do something here */ ! 128: if (sv->sv_flags & HPUXSV_RESET) ! 129: p->p_flag |= SOUSIG; /* XXX */ ! 130: #endif ! 131: } ! 132: return (0); ! 133: } ! 134: ! 135: hpuxsigblock(p, uap, retval) ! 136: register struct proc *p; ! 137: struct args { ! 138: int mask; ! 139: } *uap; ! 140: int *retval; ! 141: { ! 142: ! 143: (void) splhigh(); ! 144: *retval = bsdtohpuxmask(p->p_sigmask); ! 145: p->p_sigmask |= hpuxtobsdmask(uap->mask) &~ sigcantmask; ! 146: (void) spl0(); ! 147: return (0); ! 148: } ! 149: ! 150: hpuxsigsetmask(p, uap, retval) ! 151: struct proc *p; ! 152: struct args { ! 153: int mask; ! 154: } *uap; ! 155: int *retval; ! 156: { ! 157: ! 158: (void) splhigh(); ! 159: *retval = bsdtohpuxmask(p->p_sigmask); ! 160: p->p_sigmask = hpuxtobsdmask(uap->mask) &~ sigcantmask; ! 161: (void) spl0(); ! 162: return (0); ! 163: } ! 164: ! 165: hpuxsigpause(p, uap, retval) ! 166: struct proc *p; ! 167: struct args { ! 168: int mask; ! 169: } *uap; ! 170: int *retval; ! 171: { ! 172: ! 173: uap->mask = hpuxtobsdmask(uap->mask); ! 174: return (sigsuspend(p, uap, retval)); ! 175: } ! 176: ! 177: /* not totally correct, but close enuf' */ ! 178: hpuxkill(p, uap, retval) ! 179: struct proc *p; ! 180: struct args { ! 181: int pid; ! 182: int signo; ! 183: } *uap; ! 184: int *retval; ! 185: { ! 186: ! 187: if (uap->signo) { ! 188: uap->signo = hpuxtobsdsig(uap->signo); ! 189: if (uap->signo == 0) ! 190: uap->signo = NSIG; ! 191: } ! 192: return (kill(p, uap, retval)); ! 193: } ! 194: ! 195: /* ! 196: * The following (sigprocmask, sigpending, sigsuspend, sigaction are ! 197: * POSIX calls. Under BSD, the library routine dereferences the sigset_t ! 198: * pointers before traping. Not so under HP-UX. ! 199: */ ! 200: ! 201: /* ! 202: * Manipulate signal mask. ! 203: * Note that we receive new mask, not pointer, ! 204: * and return old mask as return value; ! 205: * the library stub does the rest. ! 206: */ ! 207: hpuxsigprocmask(p, uap, retval) ! 208: register struct proc *p; ! 209: struct args { ! 210: int how; ! 211: hpuxsigset_t *set; ! 212: hpuxsigset_t *oset; ! 213: } *uap; ! 214: int *retval; ! 215: { ! 216: int mask, error = 0; ! 217: hpuxsigset_t sigset; ! 218: ! 219: /* ! 220: * Copy out old mask first to ensure no errors. ! 221: * (proc sigmask should not be changed if call fails for any reason) ! 222: */ ! 223: if (uap->oset) { ! 224: bzero((caddr_t)&sigset, sizeof(sigset)); ! 225: sigset.sigset[0] = bsdtohpuxmask(p->p_sigmask); ! 226: if (copyout((caddr_t)&sigset, (caddr_t)uap->oset, sizeof(sigset))) ! 227: return (EFAULT); ! 228: } ! 229: if (uap->set) { ! 230: if (copyin((caddr_t)uap->set, (caddr_t)&sigset, sizeof(sigset))) ! 231: return (EFAULT); ! 232: mask = hpuxtobsdmask(sigset.sigset[0]); ! 233: (void) splhigh(); ! 234: switch (uap->how) { ! 235: case HPUXSIG_BLOCK: ! 236: p->p_sigmask |= mask &~ sigcantmask; ! 237: break; ! 238: case HPUXSIG_UNBLOCK: ! 239: p->p_sigmask &= ~mask; ! 240: break; ! 241: case HPUXSIG_SETMASK: ! 242: p->p_sigmask = mask &~ sigcantmask; ! 243: break; ! 244: default: ! 245: error = EINVAL; ! 246: break; ! 247: } ! 248: (void) spl0(); ! 249: } ! 250: return (error); ! 251: } ! 252: ! 253: hpuxsigpending(p, uap, retval) ! 254: register struct proc *p; ! 255: struct args { ! 256: hpuxsigset_t *set; ! 257: } *uap; ! 258: int *retval; ! 259: { ! 260: hpuxsigset_t sigset; ! 261: ! 262: sigset.sigset[0] = bsdtohpuxmask(p->p_sig); ! 263: return (copyout((caddr_t)&sigset, (caddr_t)uap->set, sizeof(sigset))); ! 264: } ! 265: ! 266: hpuxsigsuspend(p, uap, retval) ! 267: register struct proc *p; ! 268: struct args { ! 269: hpuxsigset_t *set; ! 270: } *uap; ! 271: int *retval; ! 272: { ! 273: register struct sigacts *ps = p->p_sigacts; ! 274: hpuxsigset_t sigset; ! 275: int mask; ! 276: ! 277: if (copyin((caddr_t)uap->set, (caddr_t)&sigset, sizeof(sigset))) ! 278: return (EFAULT); ! 279: mask = hpuxtobsdmask(sigset.sigset[0]); ! 280: ps->ps_oldmask = p->p_sigmask; ! 281: ps->ps_flags |= SA_OLDMASK; ! 282: p->p_sigmask = mask &~ sigcantmask; ! 283: (void) tsleep((caddr_t)ps, PPAUSE | PCATCH, "pause", 0); ! 284: /* always return EINTR rather than ERESTART... */ ! 285: return (EINTR); ! 286: } ! 287: ! 288: hpuxsigaction(p, uap, retval) ! 289: struct proc *p; ! 290: register struct args { ! 291: int signo; ! 292: struct hpuxsigaction *nsa; ! 293: struct hpuxsigaction *osa; ! 294: } *uap; ! 295: int *retval; ! 296: { ! 297: struct hpuxsigaction action; ! 298: register struct sigacts *ps = p->p_sigacts; ! 299: register struct hpuxsigaction *sa; ! 300: register int sig; ! 301: int bit; ! 302: ! 303: sig = hpuxtobsdsig(uap->signo); ! 304: if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) ! 305: return (EINVAL); ! 306: ! 307: sa = &action; ! 308: if (uap->osa) { ! 309: sa->sa_handler = ps->ps_sigact[sig]; ! 310: bzero((caddr_t)&sa->sa_mask, sizeof(sa->sa_mask)); ! 311: sa->sa_mask.sigset[0] = bsdtohpuxmask(ps->ps_catchmask[sig]); ! 312: bit = sigmask(sig); ! 313: sa->sa_flags = 0; ! 314: if ((ps->ps_sigonstack & bit) != 0) ! 315: sa->sa_flags |= HPUXSA_ONSTACK; ! 316: #if 0 ! 317: /* XXX -- SOUSIG no longer exists, do something here */ ! 318: if (p->p_flag & SOUSIG) ! 319: sa->sa_flags |= HPUXSA_RESETHAND; /* XXX */ ! 320: #endif ! 321: if (p->p_flag & SNOCLDSTOP) ! 322: sa->sa_flags |= HPUXSA_NOCLDSTOP; ! 323: if (copyout((caddr_t)sa, (caddr_t)uap->osa, sizeof (action))) ! 324: return (EFAULT); ! 325: } ! 326: if (uap->nsa) { ! 327: struct sigaction act; ! 328: ! 329: if (copyin((caddr_t)uap->nsa, (caddr_t)sa, sizeof (action))) ! 330: return (EFAULT); ! 331: if (sig == SIGCONT && sa->sa_handler == SIG_IGN) ! 332: return (EINVAL); ! 333: /* ! 334: * Create a sigaction struct for setsigvec ! 335: */ ! 336: act.sa_handler = sa->sa_handler; ! 337: act.sa_mask = hpuxtobsdmask(sa->sa_mask.sigset[0]); ! 338: act.sa_flags == SA_RESTART; ! 339: if (sa->sa_flags & HPUXSA_ONSTACK) ! 340: act.sa_flags |= SA_ONSTACK; ! 341: if (sa->sa_flags & HPUXSA_NOCLDSTOP) ! 342: act.sa_flags |= SA_NOCLDSTOP; ! 343: setsigvec(p, sig, &act); ! 344: #if 0 ! 345: /* XXX -- SOUSIG no longer exists, do something here */ ! 346: if (sa->sa_flags & HPUXSA_RESETHAND) ! 347: p->p_flag |= SOUSIG; /* XXX */ ! 348: #endif ! 349: } ! 350: return (0); ! 351: } ! 352: ! 353: ohpuxssig(p, uap, retval) ! 354: struct proc *p; ! 355: struct args { ! 356: int signo; ! 357: sig_t fun; ! 358: } *uap; ! 359: int *retval; ! 360: { ! 361: register int a; ! 362: struct sigaction vec; ! 363: register struct sigaction *sa = &vec; ! 364: ! 365: a = hpuxtobsdsig(uap->signo); ! 366: sa->sa_handler = uap->fun; ! 367: /* ! 368: * Kill processes trying to use job control facilities ! 369: * (this'll help us find any vestiges of the old stuff). ! 370: */ ! 371: if ((a &~ 0377) || ! 372: (sa->sa_handler != SIG_DFL && sa->sa_handler != SIG_IGN && ! 373: ((int)sa->sa_handler) & 1)) { ! 374: psignal(p, SIGSYS); ! 375: return (0); ! 376: } ! 377: if (a <= 0 || a >= NSIG || a == SIGKILL || a == SIGSTOP || ! 378: a == SIGCONT && sa->sa_handler == SIG_IGN) ! 379: return (EINVAL); ! 380: sa->sa_mask = 0; ! 381: sa->sa_flags = 0; ! 382: *retval = (int)p->p_sigacts->ps_sigact[a]; ! 383: setsigvec(p, a, sa); ! 384: #if 0 ! 385: p->p_flag |= SOUSIG; /* mark as simulating old stuff */ ! 386: #endif ! 387: return (0); ! 388: } ! 389: ! 390: /* signal numbers: convert from HPUX to BSD */ ! 391: hpuxtobsdsig(sig) ! 392: register int sig; ! 393: { ! 394: if (--sig < 0 || sig >= NSIG) ! 395: return(0); ! 396: return((int)hpuxtobsdsigmap[sig]); ! 397: } ! 398: ! 399: /* signal numbers: convert from BSD to HPUX */ ! 400: bsdtohpuxsig(sig) ! 401: register int sig; ! 402: { ! 403: if (--sig < 0 || sig >= NSIG) ! 404: return(0); ! 405: return((int)bsdtohpuxsigmap[sig]); ! 406: } ! 407: ! 408: /* signal masks: convert from HPUX to BSD (not pretty or fast) */ ! 409: hpuxtobsdmask(mask) ! 410: register int mask; ! 411: { ! 412: register int nmask, sig, nsig; ! 413: ! 414: if (mask == 0 || mask == -1) ! 415: return(mask); ! 416: nmask = 0; ! 417: for (sig = 1; sig < NSIG; sig++) ! 418: if ((mask & sigmask(sig)) && (nsig = hpuxtobsdsig(sig))) ! 419: nmask |= sigmask(nsig); ! 420: return(nmask); ! 421: } ! 422: ! 423: bsdtohpuxmask(mask) ! 424: register int mask; ! 425: { ! 426: register int nmask, sig, nsig; ! 427: ! 428: if (mask == 0 || mask == -1) ! 429: return(mask); ! 430: nmask = 0; ! 431: for (sig = 1; sig < NSIG; sig++) ! 432: if ((mask & sigmask(sig)) && (nsig = bsdtohpuxsig(sig))) ! 433: nmask |= sigmask(nsig); ! 434: return(nmask); ! 435: } ! 436: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.