xref: /illumos-gate/usr/src/lib/libproc/common/pr_waitid.c (revision e3ae4b35c024af1196582063ecee3ab79367227d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 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 <string.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 #include <sys/wait.h>
35 
36 #include "P32ton.h"
37 #include "libproc.h"
38 
39 /*
40  * waitid() system call -- executed by subject process
41  */
42 int
43 pr_waitid(struct ps_prochandle *Pr,
44     idtype_t idtype, id_t id, siginfo_t *infop, int options)
45 {
46 	sysret_t rval;			/* return value from waitid() */
47 	argdes_t argd[4];		/* arg descriptors for waitid() */
48 	argdes_t *adp;
49 	int error;
50 #ifdef _LP64
51 	siginfo32_t siginfo32;
52 #endif	/* _LP64 */
53 
54 	if (Pr == NULL)		/* no subject process */
55 		return (waitid(idtype, id, infop, options));
56 
57 	adp = &argd[0];		/* idtype argument */
58 	adp->arg_value = idtype;
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++;			/* id argument */
65 	adp->arg_value = id;
66 	adp->arg_object = NULL;
67 	adp->arg_type = AT_BYVAL;
68 	adp->arg_inout = AI_INPUT;
69 	adp->arg_size = 0;
70 
71 	adp++;			/* infop argument */
72 	adp->arg_value = 0;
73 	adp->arg_type = AT_BYREF;
74 	adp->arg_inout = AI_OUTPUT;
75 #ifdef _LP64
76 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
77 		adp->arg_object = &siginfo32;
78 		adp->arg_size = sizeof (siginfo32);
79 	} else {
80 		adp->arg_object = infop;
81 		adp->arg_size = sizeof (*infop);
82 	}
83 #else	/* _LP64 */
84 	adp->arg_object = infop;
85 	adp->arg_size = sizeof (*infop);
86 #endif	/* _LP64 */
87 
88 	adp++;			/* options argument */
89 	adp->arg_value = options;
90 	adp->arg_object = NULL;
91 	adp->arg_type = AT_BYVAL;
92 	adp->arg_inout = AI_INPUT;
93 	adp->arg_size = 0;
94 
95 	error = Psyscall(Pr, &rval, SYS_waitid, 4, &argd[0]);
96 
97 	if (error) {
98 		errno = (error > 0)? error : ENOSYS;
99 		return (-1);
100 	}
101 #ifdef _LP64
102 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
103 		siginfo_32_to_n(&siginfo32, infop);
104 #endif	/* _LP64 */
105 	return (0);
106 }
107