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 5ae115bc7Smrj * Common Development and Distribution License (the "License"). 6ae115bc7Smrj * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 2175521904Sraf 227c478bd9Sstevel@tonic-gate /* 23*bdf0047cSRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <sys/param.h> 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 337c478bd9Sstevel@tonic-gate #include <sys/systm.h> 347c478bd9Sstevel@tonic-gate #include <sys/user.h> 357c478bd9Sstevel@tonic-gate #include <sys/errno.h> 367c478bd9Sstevel@tonic-gate #include <sys/proc.h> 377c478bd9Sstevel@tonic-gate #include <sys/fault.h> 387c478bd9Sstevel@tonic-gate #include <sys/signal.h> 397c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 407c478bd9Sstevel@tonic-gate #include <sys/debug.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate int 437c478bd9Sstevel@tonic-gate sigaction(int sig, struct sigaction *actp, struct sigaction *oactp) 447c478bd9Sstevel@tonic-gate { 457c478bd9Sstevel@tonic-gate struct sigaction act; 467c478bd9Sstevel@tonic-gate struct sigaction oact; 477c478bd9Sstevel@tonic-gate k_sigset_t set; 487c478bd9Sstevel@tonic-gate proc_t *p; 49ae115bc7Smrj user_t *ua; 507c478bd9Sstevel@tonic-gate int sigcld_look = 0; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate if (sig <= 0 || sig >= NSIG || 537c478bd9Sstevel@tonic-gate (actp != NULL && sigismember(&cantmask, sig))) 547c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * act and oact might be the same address, so copyin act first. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate if (actp) { 607c478bd9Sstevel@tonic-gate #if defined(__sparc) 617c478bd9Sstevel@tonic-gate void (*handler)(); 627c478bd9Sstevel@tonic-gate #endif 637c478bd9Sstevel@tonic-gate if (copyin(actp, &act, sizeof (act))) 647c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 657c478bd9Sstevel@tonic-gate #if defined(__sparc) 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Check alignment of handler 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate handler = act.sa_handler; 707c478bd9Sstevel@tonic-gate if (handler != SIG_IGN && handler != SIG_DFL && 717c478bd9Sstevel@tonic-gate ((uintptr_t)handler & 0x3) != 0) 727c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 737c478bd9Sstevel@tonic-gate #endif 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate p = curproc; 77ae115bc7Smrj ua = PTOU(p); 787c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate if (oactp) { 817c478bd9Sstevel@tonic-gate int flags; 827c478bd9Sstevel@tonic-gate void (*disp)(); 837c478bd9Sstevel@tonic-gate 84ae115bc7Smrj disp = ua->u_signal[sig - 1]; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate flags = 0; 877c478bd9Sstevel@tonic-gate if (disp != SIG_DFL && disp != SIG_IGN) { 88ae115bc7Smrj set = ua->u_sigmask[sig-1]; 897c478bd9Sstevel@tonic-gate if (sigismember(&p->p_siginfo, sig)) 907c478bd9Sstevel@tonic-gate flags |= SA_SIGINFO; 91ae115bc7Smrj if (sigismember(&ua->u_sigrestart, sig)) 927c478bd9Sstevel@tonic-gate flags |= SA_RESTART; 93ae115bc7Smrj if (sigismember(&ua->u_sigonstack, sig)) 947c478bd9Sstevel@tonic-gate flags |= SA_ONSTACK; 95ae115bc7Smrj if (sigismember(&ua->u_sigresethand, sig)) 967c478bd9Sstevel@tonic-gate flags |= SA_RESETHAND; 97ae115bc7Smrj if (sigismember(&ua->u_signodefer, sig)) 987c478bd9Sstevel@tonic-gate flags |= SA_NODEFER; 997c478bd9Sstevel@tonic-gate } else 1007c478bd9Sstevel@tonic-gate sigemptyset(&set); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate if (sig == SIGCLD) { 1037c478bd9Sstevel@tonic-gate if (p->p_flag & SNOWAIT) 1047c478bd9Sstevel@tonic-gate flags |= SA_NOCLDWAIT; 1057c478bd9Sstevel@tonic-gate if (!(p->p_flag & SJCTL)) 1067c478bd9Sstevel@tonic-gate flags |= SA_NOCLDSTOP; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate oact.sa_handler = disp; 1107c478bd9Sstevel@tonic-gate oact.sa_flags = flags; 1117c478bd9Sstevel@tonic-gate sigktou(&set, &oact.sa_mask); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate if (actp) { 1153f12bda8SRoger A. Faulkner if (sig == SIGCLD) 1167c478bd9Sstevel@tonic-gate sigcld_look = 1; 1177c478bd9Sstevel@tonic-gate sigutok(&act.sa_mask, &set); 118*bdf0047cSRoger A. Faulkner setsigact(sig, act.sa_handler, &set, act.sa_flags); 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate if (sigcld_look) 1247c478bd9Sstevel@tonic-gate sigcld_repost(); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate if (oactp && 1277c478bd9Sstevel@tonic-gate copyout(&oact, oactp, sizeof (oact))) 1287c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate return (0); 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate int 1367c478bd9Sstevel@tonic-gate sigaction32(int sig, struct sigaction32 *actp, struct sigaction32 *oactp) 1377c478bd9Sstevel@tonic-gate { 1387c478bd9Sstevel@tonic-gate struct sigaction32 act32; 1397c478bd9Sstevel@tonic-gate struct sigaction32 oact32; 1407c478bd9Sstevel@tonic-gate k_sigset_t set; 1417c478bd9Sstevel@tonic-gate proc_t *p; 142ae115bc7Smrj user_t *ua; 1437c478bd9Sstevel@tonic-gate int sigcld_look = 0; 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate if (sig <= 0 || sig >= NSIG || 1467c478bd9Sstevel@tonic-gate (actp != NULL && sigismember(&cantmask, sig))) 1477c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * act and oact might be the same address, so copyin act first. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate if (actp) { 1537c478bd9Sstevel@tonic-gate #if defined(__sparc) 1547c478bd9Sstevel@tonic-gate void (*handler)(); 1557c478bd9Sstevel@tonic-gate #endif 1567c478bd9Sstevel@tonic-gate if (copyin(actp, &act32, sizeof (act32))) 1577c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1587c478bd9Sstevel@tonic-gate #if defined(__sparc) 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * Check alignment of handler 1617c478bd9Sstevel@tonic-gate */ 16275521904Sraf handler = (void (*)())(uintptr_t)act32.sa_handler; 1637c478bd9Sstevel@tonic-gate if (handler != SIG_IGN && handler != SIG_DFL && 1647c478bd9Sstevel@tonic-gate ((uintptr_t)handler & 0x3) != 0) 1657c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1667c478bd9Sstevel@tonic-gate #endif 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate p = curproc; 170ae115bc7Smrj ua = PTOU(p); 1717c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate if (oactp) { 1747c478bd9Sstevel@tonic-gate int flags; 1757c478bd9Sstevel@tonic-gate void (*disp)(); 1767c478bd9Sstevel@tonic-gate 177ae115bc7Smrj disp = ua->u_signal[sig - 1]; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate flags = 0; 1807c478bd9Sstevel@tonic-gate if (disp != SIG_DFL && disp != SIG_IGN) { 181ae115bc7Smrj set = ua->u_sigmask[sig-1]; 1827c478bd9Sstevel@tonic-gate if (sigismember(&p->p_siginfo, sig)) 1837c478bd9Sstevel@tonic-gate flags |= SA_SIGINFO; 184ae115bc7Smrj if (sigismember(&ua->u_sigrestart, sig)) 1857c478bd9Sstevel@tonic-gate flags |= SA_RESTART; 186ae115bc7Smrj if (sigismember(&ua->u_sigonstack, sig)) 1877c478bd9Sstevel@tonic-gate flags |= SA_ONSTACK; 188ae115bc7Smrj if (sigismember(&ua->u_sigresethand, sig)) 1897c478bd9Sstevel@tonic-gate flags |= SA_RESETHAND; 190ae115bc7Smrj if (sigismember(&ua->u_signodefer, sig)) 1917c478bd9Sstevel@tonic-gate flags |= SA_NODEFER; 1927c478bd9Sstevel@tonic-gate } else 1937c478bd9Sstevel@tonic-gate sigemptyset(&set); 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate if (sig == SIGCLD) { 1967c478bd9Sstevel@tonic-gate if (p->p_flag & SNOWAIT) 1977c478bd9Sstevel@tonic-gate flags |= SA_NOCLDWAIT; 1987c478bd9Sstevel@tonic-gate if (!(p->p_flag & SJCTL)) 1997c478bd9Sstevel@tonic-gate flags |= SA_NOCLDSTOP; 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate oact32.sa_handler = (caddr32_t)(uintptr_t)disp; 2037c478bd9Sstevel@tonic-gate oact32.sa_flags = flags; 2047c478bd9Sstevel@tonic-gate sigktou(&set, &oact32.sa_mask); 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if (actp) { 2083f12bda8SRoger A. Faulkner if (sig == SIGCLD) 2097c478bd9Sstevel@tonic-gate sigcld_look = 1; 2107c478bd9Sstevel@tonic-gate sigutok(&act32.sa_mask, &set); 211*bdf0047cSRoger A. Faulkner setsigact(sig, (void (*)())(uintptr_t)act32.sa_handler, &set, 2127c478bd9Sstevel@tonic-gate act32.sa_flags); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate if (sigcld_look) 2187c478bd9Sstevel@tonic-gate sigcld_repost(); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate if (oactp && 2217c478bd9Sstevel@tonic-gate copyout(&oact32, oactp, sizeof (oact32))) 2227c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate return (0); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */ 227