1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <sys/isa_defs.h>
28 
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <signal.h>
32 #include <memory.h>
33 #include <errno.h>
34 
35 #include "P32ton.h"
36 #include "libproc.h"
37 
38 /*
39  * sigaction() system call -- executed by subject process.
40  */
41 int
pr_sigaction(struct ps_prochandle * Pr,int sig,const struct sigaction * act,struct sigaction * oact)42 pr_sigaction(struct ps_prochandle *Pr,
43 	int sig, const struct sigaction *act, struct sigaction *oact)
44 {
45 	sysret_t rval;			/* return value from sigaction() */
46 	argdes_t argd[3];		/* arg descriptors for sigaction() */
47 	argdes_t *adp;
48 	int error;
49 #ifdef _LP64
50 	struct sigaction32 act32;
51 	struct sigaction32 oact32;
52 #endif	/* _LP64 */
53 
54 	if (Pr == NULL)		/* no subject process */
55 		return (sigaction(sig, act, oact));
56 
57 	adp = &argd[0];		/* sig argument */
58 	adp->arg_value = sig;
59 	adp->arg_object = NULL;
60 	adp->arg_type = AT_BYVAL;
61 	adp->arg_inout = AI_INPUT;
62 	adp->arg_size = 0;
63 
64 	adp++;			/* act argument */
65 	adp->arg_value = 0;
66 	if (act == NULL) {
67 		adp->arg_type = AT_BYVAL;
68 		adp->arg_inout = AI_INPUT;
69 		adp->arg_object = NULL;
70 		adp->arg_size = 0;
71 	} else {
72 		adp->arg_type = AT_BYREF;
73 		adp->arg_inout = AI_INPUT;
74 #ifdef _LP64
75 		if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
76 			sigaction_n_to_32(act, &act32);
77 			adp->arg_object = &act32;
78 			adp->arg_size = sizeof (act32);
79 		} else {
80 			adp->arg_object = (void *)act;
81 			adp->arg_size = sizeof (*act);
82 		}
83 #else	/* _LP64 */
84 		adp->arg_object = (void *)act;
85 		adp->arg_size = sizeof (*act);
86 #endif	/* _LP64 */
87 	}
88 
89 	adp++;			/* oact argument */
90 	adp->arg_value = 0;
91 	if (oact == NULL) {
92 		adp->arg_type = AT_BYVAL;
93 		adp->arg_inout = AI_INPUT;
94 		adp->arg_object = NULL;
95 		adp->arg_size = 0;
96 	} else {
97 		adp->arg_type = AT_BYREF;
98 		adp->arg_inout = AI_OUTPUT;
99 #ifdef _LP64
100 		if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
101 			adp->arg_object = &oact32;
102 			adp->arg_size = sizeof (oact32);
103 		} else {
104 			adp->arg_object = oact;
105 			adp->arg_size = sizeof (*oact);
106 		}
107 #else	/* _LP64 */
108 		adp->arg_object = oact;
109 		adp->arg_size = sizeof (*oact);
110 #endif	/* _LP64 */
111 	}
112 
113 	error = Psyscall(Pr, &rval, SYS_sigaction, 3, &argd[0]);
114 
115 	if (error) {
116 		errno = (error > 0)? error : ENOSYS;
117 		return (-1);
118 	}
119 #ifdef _LP64
120 	if (oact != NULL && Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
121 		sigaction_32_to_n(&oact32, oact);
122 #endif	/* _LP64 */
123 	return (rval.sys_rval1);
124 }
125