mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-06 19:20:09 +00:00
parent
ed73feddc5
commit
e281174dae
@ -66,11 +66,6 @@ namespace Libc {
|
|||||||
*/
|
*/
|
||||||
void init_select(Suspend &, Resume &, Select &);
|
void init_select(Suspend &, Resume &, Select &);
|
||||||
|
|
||||||
/**
|
|
||||||
* Poll support
|
|
||||||
*/
|
|
||||||
void init_poll(Suspend &);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support for querying available RAM quota in sysctl functions
|
* Support for querying available RAM quota in sysctl functions
|
||||||
*/
|
*/
|
||||||
|
@ -323,7 +323,6 @@ Libc::Kernel::Kernel(Genode::Env &env, Genode::Allocator &heap)
|
|||||||
init_sleep(*this);
|
init_sleep(*this);
|
||||||
init_vfs_plugin(*this);
|
init_vfs_plugin(*this);
|
||||||
init_time(*this, _rtc_path, *this);
|
init_time(*this, _rtc_path, *this);
|
||||||
init_poll(*this);
|
|
||||||
init_select(*this, *this, *this);
|
init_select(*this, *this, *this);
|
||||||
init_socket_fs(*this);
|
init_socket_fs(*this);
|
||||||
init_passwd(_passwd_config());
|
init_passwd(_passwd_config());
|
||||||
|
@ -26,87 +26,92 @@
|
|||||||
using namespace Libc;
|
using namespace Libc;
|
||||||
|
|
||||||
|
|
||||||
static Suspend *_suspend_ptr;
|
/**
|
||||||
|
* The poll function was taken from OpenSSH portable (bsd-poll.c) and adepted
|
||||||
|
* to better fit within Genode's libc.
|
||||||
void Libc::init_poll(Suspend &suspend)
|
*
|
||||||
|
* Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au).
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
extern "C" int
|
||||||
|
__attribute__((weak))
|
||||||
|
poll(struct pollfd fds[], nfds_t nfds, int timeout)
|
||||||
{
|
{
|
||||||
_suspend_ptr = &suspend;
|
nfds_t i;
|
||||||
}
|
int ret, fd, maxfd = 0;
|
||||||
|
fd_set readfds, writefds, exceptfds;
|
||||||
|
struct timeval tv, *tvp = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < nfds; i++) {
|
||||||
|
fd = fds[i].fd;
|
||||||
|
if (fd >= (int)FD_SETSIZE) {
|
||||||
|
/*errno = EINVAL;*/
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
maxfd = MAX(maxfd, fd);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" __attribute__((weak))
|
/* populate event bit vectors for the events we're interested in */
|
||||||
int poll(struct pollfd fds[], nfds_t nfds, int timeout_ms)
|
|
||||||
{
|
|
||||||
using Genode::uint64_t;
|
|
||||||
|
|
||||||
if (!fds || nfds == 0) return Errno(EINVAL);
|
FD_ZERO(&readfds);
|
||||||
|
FD_ZERO(&writefds);
|
||||||
|
FD_ZERO(&exceptfds);
|
||||||
|
|
||||||
struct Check : Suspend_functor
|
for (i = 0; i < nfds; i++) {
|
||||||
{
|
fd = fds[i].fd;
|
||||||
pollfd *_fds;
|
if (fd == -1)
|
||||||
nfds_t const _nfds;
|
|
||||||
|
|
||||||
int nready { 0 };
|
|
||||||
|
|
||||||
Check(struct pollfd fds[], nfds_t nfds)
|
|
||||||
: _fds(fds), _nfds(nfds) { }
|
|
||||||
|
|
||||||
bool suspend() override
|
|
||||||
{
|
|
||||||
bool polling = false;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < _nfds; ++i)
|
|
||||||
{
|
|
||||||
pollfd &pfd = _fds[i];
|
|
||||||
File_descriptor *libc_fd = libc_fd_to_fd(pfd.fd, "poll");
|
|
||||||
if (!libc_fd) {
|
|
||||||
pfd.revents |= POLLNVAL;
|
|
||||||
++nready;
|
|
||||||
continue;
|
continue;
|
||||||
|
if (fds[i].events & POLLIN) {
|
||||||
|
FD_SET(fd, &readfds);
|
||||||
|
FD_SET(fd, &exceptfds);
|
||||||
|
}
|
||||||
|
if (fds[i].events & POLLOUT) {
|
||||||
|
FD_SET(fd, &writefds);
|
||||||
|
FD_SET(fd, &exceptfds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!libc_fd->plugin || !libc_fd->plugin->supports_poll()) {
|
/* poll timeout is msec, select is timeval (sec + usec) */
|
||||||
warning("poll not supported for file descriptor ", pfd.fd);
|
if (timeout >= 0) {
|
||||||
|
tv.tv_sec = timeout / 1000;
|
||||||
|
tv.tv_usec = (timeout % 1000) * 1000;
|
||||||
|
tvp = &tv;
|
||||||
|
}
|
||||||
|
ret = select(maxfd + 1, &readfds, &writefds, &exceptfds, tvp);
|
||||||
|
/*saved_errno = errno;*/
|
||||||
|
/* scan through select results and set poll() flags */
|
||||||
|
for (i = 0; i < nfds; i++) {
|
||||||
|
fd = fds[i].fd;
|
||||||
|
fds[i].revents = 0;
|
||||||
|
if (fd == -1)
|
||||||
continue;
|
continue;
|
||||||
|
if ((fds[i].events & POLLIN) && FD_ISSET(fd, &readfds)) {
|
||||||
|
fds[i].revents |= POLLIN;
|
||||||
}
|
}
|
||||||
|
if ((fds[i].events & POLLOUT) && FD_ISSET(fd, &writefds)) {
|
||||||
nready += libc_fd->plugin->poll(*libc_fd, pfd);
|
fds[i].revents |= POLLOUT;
|
||||||
polling = true;
|
|
||||||
}
|
}
|
||||||
|
if (FD_ISSET(fd, &exceptfds)) {
|
||||||
return (polling && nready == 0);
|
fds[i].revents |= POLLERR;
|
||||||
}
|
|
||||||
|
|
||||||
} check (fds, nfds);
|
|
||||||
|
|
||||||
check.suspend();
|
|
||||||
|
|
||||||
if (timeout_ms == 0) {
|
|
||||||
return check.nready;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto suspend = [&] (uint64_t timeout_ms)
|
|
||||||
{
|
|
||||||
struct Missing_call_of_init_poll : Exception { };
|
|
||||||
if (!_suspend_ptr)
|
|
||||||
throw Missing_call_of_init_poll();
|
|
||||||
|
|
||||||
return _suspend_ptr->suspend(check, timeout_ms);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (timeout_ms == -1) {
|
|
||||||
while (check.nready == 0) {
|
|
||||||
suspend(0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
uint64_t remaining_ms = timeout_ms;
|
|
||||||
while (check.nready == 0 && remaining_ms > 0) {
|
|
||||||
remaining_ms = suspend(remaining_ms);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return check.nready;
|
/*
|
||||||
|
if (ret == -1)
|
||||||
|
errno = saved_errno;
|
||||||
|
*/
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user