2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include <sys/types.h>
14 #include "kern_util.h"
20 #include "um_malloc.h"
23 * Locked by irq_lock in arch/um/kernel/irq.c. Changed by os_create_pollfd
24 * and os_free_irq_by_cb, which are called under irq_lock.
26 static struct pollfd
*pollfds
= NULL
;
27 static int pollfds_num
= 0;
28 static int pollfds_size
= 0;
30 int os_waiting_for_events(struct irq_fd
*active_fds
)
32 struct irq_fd
*irq_fd
;
35 n
= poll(pollfds
, pollfds_num
, 0);
39 printk("sigio_handler: os_waiting_for_events:"
40 " poll returned %d, errno = %d\n", n
, errno
);
49 for (i
= 0; i
< pollfds_num
; i
++) {
50 if (pollfds
[i
].revents
!= 0) {
51 irq_fd
->current_events
= pollfds
[i
].revents
;
54 irq_fd
= irq_fd
->next
;
59 int os_create_pollfd(int fd
, int events
, void *tmp_pfd
, int size_tmpfds
)
61 if (pollfds_num
== pollfds_size
) {
62 if (size_tmpfds
<= pollfds_size
* sizeof(pollfds
[0])) {
63 /* return min size needed for new pollfds area */
64 return (pollfds_size
+ 1) * sizeof(pollfds
[0]);
67 if (pollfds
!= NULL
) {
68 memcpy(tmp_pfd
, pollfds
,
69 sizeof(pollfds
[0]) * pollfds_size
);
70 /* remove old pollfds */
76 kfree(tmp_pfd
); /* remove not used tmp_pfd */
78 pollfds
[pollfds_num
] = ((struct pollfd
) { .fd
= fd
,
86 void os_free_irq_by_cb(int (*test
)(struct irq_fd
*, void *), void *arg
,
87 struct irq_fd
*active_fds
, struct irq_fd
***last_irq_ptr2
)
93 while (*prev
!= NULL
) {
94 if ((*test
)(*prev
, arg
)) {
95 struct irq_fd
*old_fd
= *prev
;
96 if ((pollfds
[i
].fd
!= -1) &&
97 (pollfds
[i
].fd
!= (*prev
)->fd
)) {
98 printk("os_free_irq_by_cb - mismatch between "
99 "active_fds and pollfds, fd %d vs %d\n",
100 (*prev
)->fd
, pollfds
[i
].fd
);
106 /* This moves the *whole* array after pollfds[i]
107 * (though it doesn't spot as such)!
109 memmove(&pollfds
[i
], &pollfds
[i
+ 1],
110 (pollfds_num
- i
) * sizeof(pollfds
[0]));
111 if(*last_irq_ptr2
== &old_fd
->next
)
112 *last_irq_ptr2
= prev
;
114 *prev
= (*prev
)->next
;
115 if(old_fd
->type
== IRQ_WRITE
)
116 ignore_sigio_fd(old_fd
->fd
);
120 prev
= &(*prev
)->next
;
127 int os_get_pollfd(int i
)
129 return pollfds
[i
].fd
;
132 void os_set_pollfd(int i
, int fd
)
137 void os_set_ioignore(void)
139 signal(SIGIO
, SIG_IGN
);
142 void init_irq_signals(int on_sigstack
)
146 flags
= on_sigstack
? SA_ONSTACK
: 0;
148 set_handler(SIGVTALRM
, (__sighandler_t
) alarm_handler
,
149 flags
| SA_RESTART
, SIGUSR1
, SIGIO
, SIGWINCH
, SIGALRM
, -1);
150 set_handler(SIGALRM
, (__sighandler_t
) alarm_handler
,
151 flags
| SA_RESTART
, SIGUSR1
, SIGIO
, SIGWINCH
, SIGALRM
, -1);
152 set_handler(SIGIO
, (__sighandler_t
) sig_handler
, flags
| SA_RESTART
,
153 SIGUSR1
, SIGIO
, SIGWINCH
, SIGALRM
, SIGVTALRM
, -1);
154 signal(SIGWINCH
, SIG_IGN
);