xref: /titanic_52/usr/src/lib/libproc/common/pr_waitid.c (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/isa_defs.h>
30 
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 #include <sys/wait.h>
37 
38 #include "P32ton.h"
39 #include "libproc.h"
40 
41 /*
42  * waitid() system call -- executed by subject process
43  */
44 int
45 pr_waitid(struct ps_prochandle *Pr,
46     idtype_t idtype, id_t id, siginfo_t *infop, int options)
47 {
48 	sysret_t rval;			/* return value from waitid() */
49 	argdes_t argd[4];		/* arg descriptors for waitid() */
50 	argdes_t *adp;
51 	int error;
52 #ifdef _LP64
53 	siginfo32_t siginfo32;
54 #endif	/* _LP64 */
55 
56 	if (Pr == NULL)		/* no subject process */
57 		return (waitid(idtype, id, infop, options));
58 
59 	adp = &argd[0];		/* idtype argument */
60 	adp->arg_value = idtype;
61 	adp->arg_object = NULL;
62 	adp->arg_type = AT_BYVAL;
63 	adp->arg_inout = AI_INPUT;
64 	adp->arg_size = 0;
65 
66 	adp++;			/* id argument */
67 	adp->arg_value = id;
68 	adp->arg_object = NULL;
69 	adp->arg_type = AT_BYVAL;
70 	adp->arg_inout = AI_INPUT;
71 	adp->arg_size = 0;
72 
73 	adp++;			/* infop argument */
74 	adp->arg_value = 0;
75 	adp->arg_type = AT_BYREF;
76 	adp->arg_inout = AI_OUTPUT;
77 #ifdef _LP64
78 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
79 		adp->arg_object = &siginfo32;
80 		adp->arg_size = sizeof (siginfo32);
81 	} else {
82 		adp->arg_object = infop;
83 		adp->arg_size = sizeof (*infop);
84 	}
85 #else	/* _LP64 */
86 	adp->arg_object = infop;
87 	adp->arg_size = sizeof (*infop);
88 #endif	/* _LP64 */
89 
90 	adp++;			/* options argument */
91 	adp->arg_value = options;
92 	adp->arg_object = NULL;
93 	adp->arg_type = AT_BYVAL;
94 	adp->arg_inout = AI_INPUT;
95 	adp->arg_size = 0;
96 
97 	error = Psyscall(Pr, &rval, SYS_waitid, 4, &argd[0]);
98 
99 	if (error) {
100 		errno = (error > 0)? error : ENOSYS;
101 		return (-1);
102 	}
103 #ifdef _LP64
104 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
105 		siginfo_32_to_n(&siginfo32, infop);
106 #endif	/* _LP64 */
107 	return (0);
108 }
109