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
|
/* Copyright (C) 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <inline-syscall.h>
#include <port.h>
#include <sys/port_impl.h>
/* SYS_port returns a 64-bit int but the port_* calls return a 32-bit int, so
we can't implement these directly in syscalls.list. Whenever the 2nd
argument is not a port we need to specify PORT_SYS_NOPORT.
port_getn and port_sendn are special in that they may return after only
some of the ports have been acted on before the timeout occured. In this
case, the first 32-bits of the the return specify the number of acted on
ports, and the second 32-bits specify the error that occured (currently
this is always ETIME). */
DECLARE_INLINE_SYSCALL (int64_t, port, int, ...);
int port_create (void)
{
/* The 2nd argument is the version of port_create, currently 0. */
rval_t ret;
ret.rval64 = INLINE_SYSCALL (port, 2,
SYS_SUB_port_create | PORT_SYS_NOPORT, 0);
return ret.rval1;
}
int port_associate (int port, int source, uintptr_t object,
int events, void *user)
{
rval_t ret;
ret.rval64 = INLINE_SYSCALL (port, 6, SYS_SUB_port_associate, port, source,
object, events, user);
return ret.rval1;
}
int port_dissociate (int port, int source, uintptr_t object)
{
rval_t ret;
ret.rval64 = INLINE_SYSCALL (port, 4, SYS_SUB_port_dissociate, port,
source, object);
return ret.rval1;
}
int port_send (int port, int events, void *user)
{
rval_t ret;
ret.rval64 = INLINE_SYSCALL (port, 4, SYS_SUB_port_send, port, events, user);
return ret.rval1;
}
int port_sendn (int ports[], int errors[], unsigned int nent,
int events, void *user)
{
/* Note that we cannot have more than PORT_MAX_LIST ports in a single
syscall so we may need to split ports across multiple syscalls. */
rval_t ret;
int nevents = 0;
for (unsigned int i = 0; i < nent; i += PORT_MAX_LIST)
{
int errval = __systemcall (&ret.rvals, SYS_port, SYS_SUB_port_sendn |
PORT_SYS_NOPORT, &ports[i], &errors[i], MIN (nent - i, PORT_MAX_LIST),
events, user);
if (errval == 0 || errval == ETIME)
nevents += ret.rval1;
if (errval != 0)
{
__set_errno (errval);
break;
}
}
return nevents;
}
int port_get (int port, port_event_t *pe, struct timespec *to)
{
time_t sec = to ? to->tv_sec : 0;
long nsec = to ? to->tv_nsec : 0;
rval_t ret;
ret.rval64 = INLINE_SYSCALL (port, 6, SYS_SUB_port_get, port, pe, sec, nsec, to);
return ret.rval1;
}
int port_getn (int port, port_event_t list[], unsigned int max,
unsigned int *nget, struct timespec *timeout)
{
rval_t ret;
int errval = __systemcall (&ret.rvals, SYS_port, SYS_SUB_port_getn, port, list,
max, *nget, timeout);
if (errval == 0 || errval == ETIME)
*nget = ret.rval1;
if (errval != 0)
{
__set_errno (errval);
return -1;
}
return 0;
}
int port_alert (int port, int flags, int events, void *user)
{
rval_t ret;
ret.rval64 = INLINE_SYSCALL (port, 5, SYS_SUB_port_alert, port, flags,
events, user);
return ret.rval1;
}
|