0
|
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, Version 1.0 only
|
|
6 |
* (the "License"). You may not use this file except in compliance
|
|
7 |
* with the License.
|
|
8 |
*
|
|
9 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
10 |
* or http://www.opensolaris.org/os/licensing.
|
|
11 |
* See the License for the specific language governing permissions
|
|
12 |
* and limitations under the License.
|
|
13 |
*
|
|
14 |
* When distributing Covered Code, include this CDDL HEADER in each
|
|
15 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
16 |
* If applicable, add the following below this CDDL HEADER, with the
|
|
17 |
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
18 |
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
19 |
*
|
|
20 |
* CDDL HEADER END
|
|
21 |
*/
|
|
22 |
/*
|
|
23 |
* Copyright 2004 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 |
#pragma weak port_create = _port_create
|
|
30 |
#pragma weak port_associate = _port_associate
|
|
31 |
#pragma weak port_dissociate = _port_dissociate
|
|
32 |
#pragma weak port_send = _port_send
|
|
33 |
#pragma weak port_sendn = _port_sendn
|
|
34 |
#pragma weak port_get = _port_get
|
|
35 |
#pragma weak port_getn = _port_getn
|
|
36 |
#pragma weak port_alert = _port_alert
|
|
37 |
#pragma weak port_dispatch = _port_dispatch
|
|
38 |
|
|
39 |
#include "lint.h"
|
|
40 |
#include <sys/types.h>
|
|
41 |
#include <sys/stat.h>
|
|
42 |
#include <fcntl.h>
|
|
43 |
#include <unistd.h>
|
|
44 |
#include <sys/port_impl.h>
|
|
45 |
#include <errno.h>
|
|
46 |
#include <stdlib.h>
|
|
47 |
#include <sys/systm.h>
|
|
48 |
#include <libc.h>
|
|
49 |
|
|
50 |
/*
|
|
51 |
* The second argument of _portfs(PORT_CREATE, 0,,,) represents the version
|
|
52 |
* number of the event ports framework. The version number is required to
|
|
53 |
* identify possible changes/extensions of the port_event_t structure. If an
|
|
54 |
* extension is required the port_create() function will be mapped to a second
|
|
55 |
* library create function like port_create_v1(PORT_CREATE, VERSION,,,)
|
|
56 |
* VERSION will be a number > 0.
|
|
57 |
* As long as such an extension is not required the second argument will be
|
|
58 |
* set to 0 and no check will be done in the kernel interface.
|
|
59 |
*/
|
|
60 |
int
|
|
61 |
_port_create()
|
|
62 |
{
|
|
63 |
rval_t r;
|
|
64 |
r.r_vals = _portfs(PORT_CREATE | PORT_SYS_NOPORT, 0, 0, 0, 0, 0);
|
|
65 |
return (r.r_val1);
|
|
66 |
}
|
|
67 |
|
|
68 |
int
|
|
69 |
_port_associate(int port, int source, uintptr_t object, int events, void *user)
|
|
70 |
{
|
|
71 |
rval_t r;
|
|
72 |
r.r_vals = _portfs(PORT_ASSOCIATE, port, source, object, events,
|
|
73 |
(uintptr_t)user);
|
|
74 |
return (r.r_val1);
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
int
|
|
79 |
_port_get(int port, port_event_t *pe, struct timespec *to)
|
|
80 |
{
|
|
81 |
rval_t r;
|
|
82 |
if (to)
|
|
83 |
r.r_vals = _portfs(PORT_GET, port, (uintptr_t)pe, to->tv_sec,
|
|
84 |
to->tv_nsec, (uintptr_t)to);
|
|
85 |
else
|
|
86 |
r.r_vals = _portfs(PORT_GET, port, (uintptr_t)pe, 0, 0, NULL);
|
|
87 |
return (r.r_val1);
|
|
88 |
}
|
|
89 |
|
|
90 |
int
|
|
91 |
_port_getn(int port, port_event_t list[], uint_t max, uint_t *nget,
|
|
92 |
struct timespec *timeout)
|
|
93 |
{
|
|
94 |
rval_t r;
|
|
95 |
if (nget == NULL) {
|
|
96 |
errno = EINVAL;
|
|
97 |
return (-1);
|
|
98 |
}
|
|
99 |
r.r_vals = _portfs(PORT_GETN, port, (uintptr_t)list, max, *nget,
|
|
100 |
(uintptr_t)timeout);
|
|
101 |
if (r.r_val1 == -1) {
|
|
102 |
/* global error, errno is already set */
|
|
103 |
return (-1);
|
|
104 |
}
|
|
105 |
*nget = r.r_val1;
|
|
106 |
if (r.r_val2 == ETIME) {
|
|
107 |
errno = ETIME;
|
|
108 |
return (-1);
|
|
109 |
}
|
|
110 |
return (r.r_val2);
|
|
111 |
}
|
|
112 |
|
|
113 |
int
|
|
114 |
_port_dissociate(int port, int source, uintptr_t object)
|
|
115 |
{
|
|
116 |
rval_t r;
|
|
117 |
r.r_vals = _portfs(PORT_DISSOCIATE, port, source, object, 0, 0);
|
|
118 |
return (r.r_val1);
|
|
119 |
}
|
|
120 |
|
|
121 |
int
|
|
122 |
_port_send(int port, int events, void *user)
|
|
123 |
{
|
|
124 |
rval_t r;
|
|
125 |
r.r_vals = _portfs(PORT_SEND, port, events, (uintptr_t)user, NULL,
|
|
126 |
NULL);
|
|
127 |
return (r.r_val1);
|
|
128 |
}
|
|
129 |
|
|
130 |
/*
|
|
131 |
* port_dispatch() will block if there are not resources available to
|
|
132 |
* satisfy the request.
|
|
133 |
*/
|
|
134 |
|
|
135 |
int
|
|
136 |
_port_dispatch(int port, int flags, int source, int events, uintptr_t object,
|
|
137 |
void *user)
|
|
138 |
{
|
|
139 |
rval_t r;
|
|
140 |
if (flags & PORT_SHARE_EVENT)
|
|
141 |
r.r_vals = _portfs(PORT_DISPATCH, port, source, events, object,
|
|
142 |
(uintptr_t)user);
|
|
143 |
else
|
|
144 |
r.r_vals = _portfs(PORT_DISPATCH | PORT_SYS_NOSHARE, port,
|
|
145 |
source, events, object, (uintptr_t)user);
|
|
146 |
return (r.r_val1);
|
|
147 |
}
|
|
148 |
|
|
149 |
int
|
|
150 |
_port_sendn(int ports[], int errors[], uint_t nent, int events, void *user)
|
|
151 |
{
|
|
152 |
rval_t r;
|
|
153 |
uint_t offset;
|
|
154 |
uint_t lnent;
|
|
155 |
uint_t nevents;
|
|
156 |
if (nent <= PORT_MAX_LIST) {
|
|
157 |
r.r_vals = _portfs(PORT_SENDN | PORT_SYS_NOPORT,
|
|
158 |
(uintptr_t)ports, (uintptr_t)errors, nent, events,
|
|
159 |
(uintptr_t)user);
|
|
160 |
return (r.r_val1);
|
|
161 |
}
|
|
162 |
|
|
163 |
/* use chunks of max PORT_MAX_LIST elements per syscall */
|
|
164 |
nevents = 0;
|
|
165 |
for (offset = 0; offset < nent; ) {
|
|
166 |
lnent = nent - offset;
|
|
167 |
if (nent - offset > PORT_MAX_LIST)
|
|
168 |
lnent = PORT_MAX_LIST;
|
|
169 |
else
|
|
170 |
lnent = nent - offset;
|
|
171 |
r.r_vals = _portfs(PORT_SENDN | PORT_SYS_NOPORT,
|
|
172 |
(uintptr_t)&ports[offset], (uintptr_t)&errors[offset],
|
|
173 |
lnent, events, (uintptr_t)user);
|
|
174 |
if (r.r_val2 == -1) {
|
|
175 |
/* global error, return last no of events submitted */
|
|
176 |
if (nevents)
|
|
177 |
return (nevents);
|
|
178 |
return (-1);
|
|
179 |
}
|
|
180 |
nevents += r.r_val1;
|
|
181 |
offset += lnent;
|
|
182 |
}
|
|
183 |
/* list submitted */
|
|
184 |
return (nevents);
|
|
185 |
}
|
|
186 |
|
|
187 |
int
|
|
188 |
_port_alert(int port, int flags, int events, void *user)
|
|
189 |
{
|
|
190 |
rval_t r;
|
|
191 |
r.r_vals = _portfs(PORT_ALERT, port, flags, events, (uintptr_t)user,
|
|
192 |
NULL);
|
|
193 |
return (r.r_val1);
|
|
194 |
}
|