#include "lint.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/port_impl.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/systm.h>
#include <libc.h>
int
port_create()
{
rval_t r;
r.r_vals = _portfs(PORT_CREATE | PORT_SYS_NOPORT, 0, 0, 0, 0, 0);
return (r.r_val1);
}
int
port_associate(int port, int source, uintptr_t object, int events, void *user)
{
rval_t r;
r.r_vals = _portfs(PORT_ASSOCIATE, port, source, object, events,
(uintptr_t)user);
return (r.r_val1);
}
int
port_get(int port, port_event_t *pe, struct timespec *to)
{
rval_t r;
if (to)
r.r_vals = _portfs(PORT_GET, port, (uintptr_t)pe, to->tv_sec,
to->tv_nsec, (uintptr_t)to);
else
r.r_vals = _portfs(PORT_GET, port, (uintptr_t)pe, 0, 0, 0);
return (r.r_val1);
}
int
port_getn(int port, port_event_t list[], uint_t max, uint_t *nget,
struct timespec *timeout)
{
rval_t r;
if (nget == NULL) {
errno = EINVAL;
return (-1);
}
r.r_vals = _portfs(PORT_GETN, port, (uintptr_t)list, max, *nget,
(uintptr_t)timeout);
if (r.r_val1 == -1) {
return (-1);
}
*nget = r.r_val1;
if (r.r_val2 == ETIME) {
errno = ETIME;
return (-1);
}
return (r.r_val2);
}
int
port_dissociate(int port, int source, uintptr_t object)
{
rval_t r;
r.r_vals = _portfs(PORT_DISSOCIATE, port, source, object, 0, 0);
return (r.r_val1);
}
int
port_send(int port, int events, void *user)
{
rval_t r;
r.r_vals = _portfs(PORT_SEND, port, events, (uintptr_t)user, 0, 0);
return (r.r_val1);
}
int
_port_dispatch(int port, int flags, int source, int events, uintptr_t object,
void *user)
{
rval_t r;
if (flags & PORT_SHARE_EVENT)
r.r_vals = _portfs(PORT_DISPATCH, port, source, events, object,
(uintptr_t)user);
else
r.r_vals = _portfs(PORT_DISPATCH | PORT_SYS_NOSHARE, port,
source, events, object, (uintptr_t)user);
return (r.r_val1);
}
int
port_sendn(int ports[], int errors[], uint_t nent, int events, void *user)
{
rval_t r;
uint_t offset;
uint_t lnent;
uint_t nevents;
if (nent <= PORT_MAX_LIST) {
r.r_vals = _portfs(PORT_SENDN | PORT_SYS_NOPORT,
(uintptr_t)ports, (uintptr_t)errors, nent, events,
(uintptr_t)user);
return (r.r_val1);
}
nevents = 0;
for (offset = 0; offset < nent; ) {
lnent = nent - offset;
if (nent - offset > PORT_MAX_LIST)
lnent = PORT_MAX_LIST;
else
lnent = nent - offset;
r.r_vals = _portfs(PORT_SENDN | PORT_SYS_NOPORT,
(uintptr_t)&ports[offset], (uintptr_t)&errors[offset],
lnent, events, (uintptr_t)user);
if (r.r_val2 == -1) {
if (nevents)
return (nevents);
return (-1);
}
nevents += r.r_val1;
offset += lnent;
}
return (nevents);
}
int
port_alert(int port, int flags, int events, void *user)
{
rval_t r;
r.r_vals = _portfs(PORT_ALERT, port, flags, events, (uintptr_t)user, 0);
return (r.r_val1);
}