xref: /onnv-gate/usr/src/lib/libproc/common/pr_waitid.c (revision 5891:0d5c6468bb04)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*5891Sraf  * Common Development and Distribution License (the "License").
6*5891Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*5891Sraf 
220Sstevel@tonic-gate /*
23*5891Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*5891Sraf  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/isa_defs.h>
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <stdlib.h>
320Sstevel@tonic-gate #include <unistd.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <errno.h>
350Sstevel@tonic-gate #include <sys/types.h>
360Sstevel@tonic-gate #include <sys/wait.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #include "P32ton.h"
390Sstevel@tonic-gate #include "libproc.h"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * waitid() system call -- executed by subject process
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate int
pr_waitid(struct ps_prochandle * Pr,idtype_t idtype,id_t id,siginfo_t * infop,int options)450Sstevel@tonic-gate pr_waitid(struct ps_prochandle *Pr,
46*5891Sraf     idtype_t idtype, id_t id, siginfo_t *infop, int options)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate 	sysret_t rval;			/* return value from waitid() */
490Sstevel@tonic-gate 	argdes_t argd[4];		/* arg descriptors for waitid() */
500Sstevel@tonic-gate 	argdes_t *adp;
510Sstevel@tonic-gate 	int error;
520Sstevel@tonic-gate #ifdef _LP64
530Sstevel@tonic-gate 	siginfo32_t siginfo32;
540Sstevel@tonic-gate #endif	/* _LP64 */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	if (Pr == NULL)		/* no subject process */
570Sstevel@tonic-gate 		return (waitid(idtype, id, infop, options));
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	adp = &argd[0];		/* idtype argument */
600Sstevel@tonic-gate 	adp->arg_value = idtype;
610Sstevel@tonic-gate 	adp->arg_object = NULL;
620Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
630Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
640Sstevel@tonic-gate 	adp->arg_size = 0;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	adp++;			/* id argument */
670Sstevel@tonic-gate 	adp->arg_value = id;
680Sstevel@tonic-gate 	adp->arg_object = NULL;
690Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
700Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
710Sstevel@tonic-gate 	adp->arg_size = 0;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	adp++;			/* infop argument */
740Sstevel@tonic-gate 	adp->arg_value = 0;
750Sstevel@tonic-gate 	adp->arg_type = AT_BYREF;
760Sstevel@tonic-gate 	adp->arg_inout = AI_OUTPUT;
770Sstevel@tonic-gate #ifdef _LP64
780Sstevel@tonic-gate 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
790Sstevel@tonic-gate 		adp->arg_object = &siginfo32;
800Sstevel@tonic-gate 		adp->arg_size = sizeof (siginfo32);
810Sstevel@tonic-gate 	} else {
820Sstevel@tonic-gate 		adp->arg_object = infop;
830Sstevel@tonic-gate 		adp->arg_size = sizeof (*infop);
840Sstevel@tonic-gate 	}
850Sstevel@tonic-gate #else	/* _LP64 */
860Sstevel@tonic-gate 	adp->arg_object = infop;
870Sstevel@tonic-gate 	adp->arg_size = sizeof (*infop);
880Sstevel@tonic-gate #endif	/* _LP64 */
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	adp++;			/* options argument */
910Sstevel@tonic-gate 	adp->arg_value = options;
920Sstevel@tonic-gate 	adp->arg_object = NULL;
930Sstevel@tonic-gate 	adp->arg_type = AT_BYVAL;
940Sstevel@tonic-gate 	adp->arg_inout = AI_INPUT;
950Sstevel@tonic-gate 	adp->arg_size = 0;
960Sstevel@tonic-gate 
97*5891Sraf 	error = Psyscall(Pr, &rval, SYS_waitid, 4, &argd[0]);
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	if (error) {
1000Sstevel@tonic-gate 		errno = (error > 0)? error : ENOSYS;
1010Sstevel@tonic-gate 		return (-1);
1020Sstevel@tonic-gate 	}
1030Sstevel@tonic-gate #ifdef _LP64
1040Sstevel@tonic-gate 	if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
1050Sstevel@tonic-gate 		siginfo_32_to_n(&siginfo32, infop);
1060Sstevel@tonic-gate #endif	/* _LP64 */
1070Sstevel@tonic-gate 	return (0);
1080Sstevel@tonic-gate }
109