xref: /illumos-gate/usr/src/lib/libproc/common/pr_door.c (revision 86d949f9497332fe19be6b5d711d265eb957439f)
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 <stdlib.h>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <door.h>
31 #include "libproc.h"
32 
33 /*
34  * door() system calls -- executed by subject process
35  */
36 
37 int
38 pr_door_info(struct ps_prochandle *Pr, int did, door_info_t *di)
39 {
40 	sysret_t rval;			/* return value from door_info() */
41 	argdes_t argd[6];		/* arg descriptors for door_info() */
42 	argdes_t *adp = &argd[0];	/* first argument */
43 	int error;
44 
45 	if (Pr == NULL)		/* no subject process */
46 		return (door_info(did, di));
47 
48 	adp->arg_value = did;
49 	adp->arg_object = NULL;
50 	adp->arg_type = AT_BYVAL;
51 	adp->arg_inout = AI_INPUT;
52 	adp->arg_size = 0;
53 	adp++;			/* move to door_info_t argument */
54 
55 	adp->arg_value = 0;
56 	adp->arg_object = di;
57 	adp->arg_type = AT_BYREF;
58 	adp->arg_inout = AI_OUTPUT;
59 	adp->arg_size = sizeof (door_info_t);
60 	adp++;			/* move to unused argument */
61 
62 	adp->arg_value = 0;
63 	adp->arg_object = NULL;
64 	adp->arg_type = AT_BYVAL;
65 	adp->arg_inout = AI_INPUT;
66 	adp->arg_size = 0;
67 	adp++;			/* move to unused argument */
68 
69 	adp->arg_value = 0;
70 	adp->arg_object = NULL;
71 	adp->arg_type = AT_BYVAL;
72 	adp->arg_inout = AI_INPUT;
73 	adp->arg_size = 0;
74 	adp++;			/* move to unused argument */
75 
76 	adp->arg_value = 0;
77 	adp->arg_object = NULL;
78 	adp->arg_type = AT_BYVAL;
79 	adp->arg_inout = AI_INPUT;
80 	adp->arg_size = 0;
81 	adp++;			/* move to subcode argument */
82 
83 	adp->arg_value = DOOR_INFO;
84 	adp->arg_object = NULL;
85 	adp->arg_type = AT_BYVAL;
86 	adp->arg_inout = AI_INPUT;
87 	adp->arg_size = 0;
88 
89 	error = Psyscall(Pr, &rval, SYS_door, 6, &argd[0]);
90 
91 	if (error) {
92 		errno = (error < 0)? ENOSYS : error;
93 		return (-1);
94 	}
95 	return (0);
96 }
97