1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/types.h>
#include <sys/door.h>
#include <sys/note.h>
#include <sys/drctl.h>
#include <sys/drctl_impl.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/dr_util.h>
static door_handle_t drctl_dh; /* Door for upcalls */
int
i_drctl_ioctl(int cmd, intptr_t arg)
{
int rv;
drctl_setup_t setup_rqst;
switch (cmd) {
case DRCTL_IOCTL_CONNECT_SERVER:
if (ddi_copyin((caddr_t)arg,
&setup_rqst, sizeof (setup_rqst), 0) != 0) {
cmn_err(CE_WARN, "i_drctl_ioctl: ddi_copyin failed "
"for DRCTL_IOCTL_CONNECT_SERVER");
rv = EFAULT;
break;
}
drctl_dh = door_ki_lookup(setup_rqst.did);
rv = 0;
break;
default:
rv = EIO;
}
return (rv);
}
int
i_drctl_send(void *msg, size_t size, void **obufp, size_t *osize)
{
int up_err;
int rv = 0;
door_arg_t door_args;
door_handle_t dh = drctl_dh;
static const char me[] = "i_drctl_send";
retry:
if (dh)
door_ki_hold(dh);
else
return (EIO);
door_args.data_ptr = (char *)msg;
door_args.data_size = size;
door_args.desc_ptr = NULL;
door_args.desc_num = 0;
/*
* We don't know the size of the message the daemon
* will pass back to us. By setting rbuf to NULL,
* we force the door code to allocate a buf of the
* appropriate size. We must set rsize > 0, however,
* else the door code acts as if no response was
* expected and doesn't pass the data to us.
*/
door_args.rbuf = NULL;
door_args.rsize = 1;
DR_DBG_CTL("%s: msg %p size %ld obufp %p osize %p\n",
me, msg, size, (void *)obufp, (void *)osize);
up_err = door_ki_upcall_limited(dh, &door_args, NULL, SIZE_MAX, 0);
if (up_err == 0) {
if (door_args.rbuf == NULL)
goto done;
DR_DBG_CTL("%s: rbuf %p rsize %ld\n", me,
(void *)door_args.rbuf, door_args.rsize);
if (obufp != NULL) {
*obufp = door_args.rbuf;
*osize = door_args.rsize;
DR_DBG_KMEM("%s: (door) alloc addr %p size %ld\n",
__func__,
(void *)(door_args.rbuf), door_args.rsize);
} else {
/*
* No output buffer pointer was passed in,
* so the response buffer allocated by the
* door code must be deallocated.
*/
DR_DBG_KMEM("%s: free addr %p size %ld\n", __func__,
(void *)(door_args.rbuf), door_args.rsize);
kmem_free(door_args.rbuf, door_args.rsize);
}
} else {
switch (up_err) {
case EINTR:
DR_DBG_CTL("%s: door call returned EINTR\n", me);
/* FALLTHROUGH */
case EAGAIN:
/*
* Server process may be forking, try again.
*/
door_ki_rele(dh);
delay(hz);
goto retry;
case EBADF:
case EINVAL:
drctl_dh = NULL;
DR_DBG_CTL(
"%s: door call failed with %d\n", me, up_err);
rv = EIO;
break;
default:
DR_DBG_CTL("%s: unexpected return "
"code %d from door_ki_upcall\n", me, up_err);
rv = EIO;
break;
}
}
done:
door_ki_rele(dh);
return (rv);
}
|