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 5*ae115bc7Smrj * Common Development and Distribution License (the "License"). 6*ae115bc7Smrj * 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*ae115bc7Smrj * Copyright 2007 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 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/param.h> 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 367c478bd9Sstevel@tonic-gate #include <sys/systm.h> 377c478bd9Sstevel@tonic-gate #include <sys/user.h> 387c478bd9Sstevel@tonic-gate #include <sys/errno.h> 397c478bd9Sstevel@tonic-gate #include <sys/proc.h> 407c478bd9Sstevel@tonic-gate #include <sys/fault.h> 417c478bd9Sstevel@tonic-gate #include <sys/signal.h> 427c478bd9Sstevel@tonic-gate #include <sys/siginfo.h> 437c478bd9Sstevel@tonic-gate #include <sys/debug.h> 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate int 467c478bd9Sstevel@tonic-gate sigaction(int sig, struct sigaction *actp, struct sigaction *oactp) 477c478bd9Sstevel@tonic-gate { 487c478bd9Sstevel@tonic-gate struct sigaction act; 497c478bd9Sstevel@tonic-gate struct sigaction oact; 507c478bd9Sstevel@tonic-gate k_sigset_t set; 517c478bd9Sstevel@tonic-gate proc_t *p; 52*ae115bc7Smrj user_t *ua; 537c478bd9Sstevel@tonic-gate int sigcld_look = 0; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate if (sig <= 0 || sig >= NSIG || 567c478bd9Sstevel@tonic-gate (actp != NULL && sigismember(&cantmask, sig))) 577c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* 607c478bd9Sstevel@tonic-gate * act and oact might be the same address, so copyin act first. 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate if (actp) { 637c478bd9Sstevel@tonic-gate #if defined(__sparc) 647c478bd9Sstevel@tonic-gate void (*handler)(); 657c478bd9Sstevel@tonic-gate #endif 667c478bd9Sstevel@tonic-gate if (copyin(actp, &act, sizeof (act))) 677c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 687c478bd9Sstevel@tonic-gate #if defined(__sparc) 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * Check alignment of handler 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate handler = act.sa_handler; 737c478bd9Sstevel@tonic-gate if (handler != SIG_IGN && handler != SIG_DFL && 747c478bd9Sstevel@tonic-gate ((uintptr_t)handler & 0x3) != 0) 757c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 767c478bd9Sstevel@tonic-gate #endif 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate p = curproc; 80*ae115bc7Smrj ua = PTOU(p); 817c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate if (oactp) { 847c478bd9Sstevel@tonic-gate int flags; 857c478bd9Sstevel@tonic-gate void (*disp)(); 867c478bd9Sstevel@tonic-gate 87*ae115bc7Smrj disp = ua->u_signal[sig - 1]; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate flags = 0; 907c478bd9Sstevel@tonic-gate if (disp != SIG_DFL && disp != SIG_IGN) { 91*ae115bc7Smrj set = ua->u_sigmask[sig-1]; 927c478bd9Sstevel@tonic-gate if (sigismember(&p->p_siginfo, sig)) 937c478bd9Sstevel@tonic-gate flags |= SA_SIGINFO; 94*ae115bc7Smrj if (sigismember(&ua->u_sigrestart, sig)) 957c478bd9Sstevel@tonic-gate flags |= SA_RESTART; 96*ae115bc7Smrj if (sigismember(&ua->u_sigonstack, sig)) 977c478bd9Sstevel@tonic-gate flags |= SA_ONSTACK; 98*ae115bc7Smrj if (sigismember(&ua->u_sigresethand, sig)) 997c478bd9Sstevel@tonic-gate flags |= SA_RESETHAND; 100*ae115bc7Smrj if (sigismember(&ua->u_signodefer, sig)) 1017c478bd9Sstevel@tonic-gate flags |= SA_NODEFER; 1027c478bd9Sstevel@tonic-gate } else 1037c478bd9Sstevel@tonic-gate sigemptyset(&set); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate if (sig == SIGCLD) { 1067c478bd9Sstevel@tonic-gate if (p->p_flag & SNOWAIT) 1077c478bd9Sstevel@tonic-gate flags |= SA_NOCLDWAIT; 1087c478bd9Sstevel@tonic-gate if (!(p->p_flag & SJCTL)) 1097c478bd9Sstevel@tonic-gate flags |= SA_NOCLDSTOP; 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate oact.sa_handler = disp; 1137c478bd9Sstevel@tonic-gate oact.sa_flags = flags; 1147c478bd9Sstevel@tonic-gate sigktou(&set, &oact.sa_mask); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate if (actp) { 1187c478bd9Sstevel@tonic-gate if (sig == SIGCLD && 1197c478bd9Sstevel@tonic-gate act.sa_handler != SIG_IGN && 1207c478bd9Sstevel@tonic-gate act.sa_handler != SIG_DFL) 1217c478bd9Sstevel@tonic-gate sigcld_look = 1; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate sigutok(&act.sa_mask, &set); 1247c478bd9Sstevel@tonic-gate setsigact(sig, act.sa_handler, set, act.sa_flags); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if (sigcld_look) 1307c478bd9Sstevel@tonic-gate sigcld_repost(); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate if (oactp && 1337c478bd9Sstevel@tonic-gate copyout(&oact, oactp, sizeof (oact))) 1347c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate return (0); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate int 1427c478bd9Sstevel@tonic-gate sigaction32(int sig, struct sigaction32 *actp, struct sigaction32 *oactp) 1437c478bd9Sstevel@tonic-gate { 1447c478bd9Sstevel@tonic-gate struct sigaction32 act32; 1457c478bd9Sstevel@tonic-gate struct sigaction32 oact32; 1467c478bd9Sstevel@tonic-gate k_sigset_t set; 1477c478bd9Sstevel@tonic-gate proc_t *p; 148*ae115bc7Smrj user_t *ua; 1497c478bd9Sstevel@tonic-gate int sigcld_look = 0; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate if (sig <= 0 || sig >= NSIG || 1527c478bd9Sstevel@tonic-gate (actp != NULL && sigismember(&cantmask, sig))) 1537c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 1567c478bd9Sstevel@tonic-gate * act and oact might be the same address, so copyin act first. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate if (actp) { 1597c478bd9Sstevel@tonic-gate #if defined(__sparc) 1607c478bd9Sstevel@tonic-gate void (*handler)(); 1617c478bd9Sstevel@tonic-gate #endif 1627c478bd9Sstevel@tonic-gate if (copyin(actp, &act32, sizeof (act32))) 1637c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 1647c478bd9Sstevel@tonic-gate #if defined(__sparc) 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * Check alignment of handler 1677c478bd9Sstevel@tonic-gate */ 16875521904Sraf handler = (void (*)())(uintptr_t)act32.sa_handler; 1697c478bd9Sstevel@tonic-gate if (handler != SIG_IGN && handler != SIG_DFL && 1707c478bd9Sstevel@tonic-gate ((uintptr_t)handler & 0x3) != 0) 1717c478bd9Sstevel@tonic-gate return (set_errno(EINVAL)); 1727c478bd9Sstevel@tonic-gate #endif 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate p = curproc; 176*ae115bc7Smrj ua = PTOU(p); 1777c478bd9Sstevel@tonic-gate mutex_enter(&p->p_lock); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate if (oactp) { 1807c478bd9Sstevel@tonic-gate int flags; 1817c478bd9Sstevel@tonic-gate void (*disp)(); 1827c478bd9Sstevel@tonic-gate 183*ae115bc7Smrj disp = ua->u_signal[sig - 1]; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate flags = 0; 1867c478bd9Sstevel@tonic-gate if (disp != SIG_DFL && disp != SIG_IGN) { 187*ae115bc7Smrj set = ua->u_sigmask[sig-1]; 1887c478bd9Sstevel@tonic-gate if (sigismember(&p->p_siginfo, sig)) 1897c478bd9Sstevel@tonic-gate flags |= SA_SIGINFO; 190*ae115bc7Smrj if (sigismember(&ua->u_sigrestart, sig)) 1917c478bd9Sstevel@tonic-gate flags |= SA_RESTART; 192*ae115bc7Smrj if (sigismember(&ua->u_sigonstack, sig)) 1937c478bd9Sstevel@tonic-gate flags |= SA_ONSTACK; 194*ae115bc7Smrj if (sigismember(&ua->u_sigresethand, sig)) 1957c478bd9Sstevel@tonic-gate flags |= SA_RESETHAND; 196*ae115bc7Smrj if (sigismember(&ua->u_signodefer, sig)) 1977c478bd9Sstevel@tonic-gate flags |= SA_NODEFER; 1987c478bd9Sstevel@tonic-gate } else 1997c478bd9Sstevel@tonic-gate sigemptyset(&set); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate if (sig == SIGCLD) { 2027c478bd9Sstevel@tonic-gate if (p->p_flag & SNOWAIT) 2037c478bd9Sstevel@tonic-gate flags |= SA_NOCLDWAIT; 2047c478bd9Sstevel@tonic-gate if (!(p->p_flag & SJCTL)) 2057c478bd9Sstevel@tonic-gate flags |= SA_NOCLDSTOP; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate oact32.sa_handler = (caddr32_t)(uintptr_t)disp; 2097c478bd9Sstevel@tonic-gate oact32.sa_flags = flags; 2107c478bd9Sstevel@tonic-gate sigktou(&set, &oact32.sa_mask); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate if (actp) { 2147c478bd9Sstevel@tonic-gate if (sig == SIGCLD && 2157c478bd9Sstevel@tonic-gate act32.sa_handler != (caddr32_t)SIG_IGN && 2167c478bd9Sstevel@tonic-gate act32.sa_handler != (caddr32_t)SIG_DFL) 2177c478bd9Sstevel@tonic-gate sigcld_look = 1; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate sigutok(&act32.sa_mask, &set); 2207c478bd9Sstevel@tonic-gate setsigact(sig, (void (*)())(uintptr_t)act32.sa_handler, set, 2217c478bd9Sstevel@tonic-gate act32.sa_flags); 2227c478bd9Sstevel@tonic-gate } 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate mutex_exit(&p->p_lock); 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate if (sigcld_look) 2277c478bd9Sstevel@tonic-gate sigcld_repost(); 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate if (oactp && 2307c478bd9Sstevel@tonic-gate copyout(&oact32, oactp, sizeof (oact32))) 2317c478bd9Sstevel@tonic-gate return (set_errno(EFAULT)); 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate return (0); 2347c478bd9Sstevel@tonic-gate } 2357c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */ 236