2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include <sys/types.h>
14 #include "user_util.h"
15 #include "kern_util.h"
21 #include "um_malloc.h"
23 static struct pollfd *pollfds = NULL;
24 static int pollfds_num = 0;
25 static int pollfds_size = 0;
27 int os_waiting_for_events(struct irq_fd *active_fds)
29 struct irq_fd *irq_fd;
32 n = poll(pollfds, pollfds_num, 0);
36 printk("sigio_handler: os_waiting_for_events:"
37 " poll returned %d, errno = %d\n", n, errno);
46 for (i = 0; i < pollfds_num; i++) {
47 if (pollfds[i].revents != 0) {
48 irq_fd->current_events = pollfds[i].revents;
51 irq_fd = irq_fd->next;
56 int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds)
58 if (pollfds_num == pollfds_size) {
59 if (size_tmpfds <= pollfds_size * sizeof(pollfds[0])) {
60 /* return min size needed for new pollfds area */
61 return((pollfds_size + 1) * sizeof(pollfds[0]));
64 if (pollfds != NULL) {
65 memcpy(tmp_pfd, pollfds,
66 sizeof(pollfds[0]) * pollfds_size);
67 /* remove old pollfds */
73 kfree(tmp_pfd); /* remove not used tmp_pfd */
75 pollfds[pollfds_num] = ((struct pollfd) { .fd = fd,
83 void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
84 struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2)
90 while (*prev != NULL) {
91 if ((*test)(*prev, arg)) {
92 struct irq_fd *old_fd = *prev;
93 if ((pollfds[i].fd != -1) &&
94 (pollfds[i].fd != (*prev)->fd)) {
95 printk("os_free_irq_by_cb - mismatch between "
96 "active_fds and pollfds, fd %d vs %d\n",
97 (*prev)->fd, pollfds[i].fd);
103 /* This moves the *whole* array after pollfds[i]
104 * (though it doesn't spot as such)!
106 memmove(&pollfds[i], &pollfds[i + 1],
107 (pollfds_num - i) * sizeof(pollfds[0]));
108 if(*last_irq_ptr2 == &old_fd->next)
109 *last_irq_ptr2 = prev;
111 *prev = (*prev)->next;
112 if(old_fd->type == IRQ_WRITE)
113 ignore_sigio_fd(old_fd->fd);
117 prev = &(*prev)->next;
124 int os_get_pollfd(int i)
126 return pollfds[i].fd;
129 void os_set_pollfd(int i, int fd)
134 void os_set_ioignore(void)
136 signal(SIGIO, SIG_IGN);
139 void init_irq_signals(int on_sigstack)
143 flags = on_sigstack ? SA_ONSTACK : 0;
145 set_handler(SIGVTALRM, (__sighandler_t) alarm_handler,
146 flags | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1);
147 set_handler(SIGALRM, (__sighandler_t) alarm_handler,
148 flags | SA_RESTART, SIGUSR1, SIGIO, SIGWINCH, SIGALRM, -1);
149 set_handler(SIGIO, (__sighandler_t) sig_handler, flags | SA_RESTART,
150 SIGUSR1, SIGIO, SIGWINCH, SIGALRM, SIGVTALRM, -1);
151 signal(SIGWINCH, SIG_IGN);