netbsd32_event.c revision 1.6.14.2 1 1.6.14.2 christos /* $NetBSD: netbsd32_event.c,v 1.6.14.2 2009/01/04 01:56:02 christos Exp $ */
2 1.6.14.2 christos
3 1.6.14.2 christos /*
4 1.6.14.2 christos * Copyright (c) 2005 The NetBSD Foundation.
5 1.6.14.2 christos * All rights reserved.
6 1.6.14.2 christos *
7 1.6.14.2 christos * Redistribution and use in source and binary forms, with or without
8 1.6.14.2 christos * modification, are permitted provided that the following conditions
9 1.6.14.2 christos * are met:
10 1.6.14.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.6.14.2 christos * notice, this list of conditions and the following disclaimer.
12 1.6.14.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.6.14.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.6.14.2 christos * documentation and/or other materials provided with the distribution.
15 1.6.14.2 christos *
16 1.6.14.2 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.6.14.2 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.6.14.2 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.6.14.2 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.6.14.2 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.6.14.2 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.6.14.2 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.6.14.2 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.6.14.2 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.6.14.2 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.6.14.2 christos * POSSIBILITY OF SUCH DAMAGE.
27 1.6.14.2 christos */
28 1.6.14.2 christos
29 1.6.14.2 christos #include <sys/cdefs.h>
30 1.6.14.2 christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_event.c,v 1.6.14.2 2009/01/04 01:56:02 christos Exp $");
31 1.6.14.2 christos
32 1.6.14.2 christos #include <sys/types.h>
33 1.6.14.2 christos #include <sys/param.h>
34 1.6.14.2 christos #include <sys/systm.h>
35 1.6.14.2 christos #include <sys/file.h>
36 1.6.14.2 christos #include <sys/filedesc.h>
37 1.6.14.2 christos #include <sys/select.h>
38 1.6.14.2 christos #include <sys/event.h>
39 1.6.14.2 christos #include <sys/eventvar.h>
40 1.6.14.2 christos #include <sys/malloc.h>
41 1.6.14.2 christos #include <sys/proc.h>
42 1.6.14.2 christos #include <sys/dirent.h>
43 1.6.14.2 christos
44 1.6.14.2 christos #include <compat/netbsd32/netbsd32.h>
45 1.6.14.2 christos #include <compat/netbsd32/netbsd32_syscall.h>
46 1.6.14.2 christos #include <compat/netbsd32/netbsd32_syscallargs.h>
47 1.6.14.2 christos #include <compat/netbsd32/netbsd32_conv.h>
48 1.6.14.2 christos
49 1.6.14.2 christos static int
50 1.6.14.2 christos netbsd32_kevent_fetch_timeout(const void *src, void *dest, size_t length)
51 1.6.14.2 christos {
52 1.6.14.2 christos struct netbsd32_timespec ts32;
53 1.6.14.2 christos int error;
54 1.6.14.2 christos
55 1.6.14.2 christos KASSERT(length == sizeof(struct timespec));
56 1.6.14.2 christos
57 1.6.14.2 christos error = copyin(src, &ts32, sizeof(ts32));
58 1.6.14.2 christos if (error)
59 1.6.14.2 christos return error;
60 1.6.14.2 christos netbsd32_to_timespec(&ts32, (struct timespec *)dest);
61 1.6.14.2 christos return 0;
62 1.6.14.2 christos }
63 1.6.14.2 christos
64 1.6.14.2 christos static int
65 1.6.14.2 christos netbsd32_kevent_fetch_changes(void *private, const struct kevent *changelist,
66 1.6.14.2 christos struct kevent *changes, size_t index, int n)
67 1.6.14.2 christos {
68 1.6.14.2 christos const struct netbsd32_kevent *src =
69 1.6.14.2 christos (const struct netbsd32_kevent *)changelist;
70 1.6.14.2 christos struct netbsd32_kevent *kev32, *changes32 = private;
71 1.6.14.2 christos int error, i;
72 1.6.14.2 christos
73 1.6.14.2 christos error = copyin(src + index, changes32, n * sizeof(*changes32));
74 1.6.14.2 christos if (error)
75 1.6.14.2 christos return error;
76 1.6.14.2 christos for (i = 0, kev32 = changes32; i < n; i++, kev32++, changes++)
77 1.6.14.2 christos netbsd32_to_kevent(kev32, changes);
78 1.6.14.2 christos return 0;
79 1.6.14.2 christos }
80 1.6.14.2 christos
81 1.6.14.2 christos static int
82 1.6.14.2 christos netbsd32_kevent_put_events(void *private, struct kevent *events,
83 1.6.14.2 christos struct kevent *eventlist, size_t index, int n)
84 1.6.14.2 christos {
85 1.6.14.2 christos struct netbsd32_kevent *kev32, *events32 = private;
86 1.6.14.2 christos int i;
87 1.6.14.2 christos
88 1.6.14.2 christos for (i = 0, kev32 = events32; i < n; i++, kev32++, events++)
89 1.6.14.2 christos netbsd32_from_kevent(events, kev32);
90 1.6.14.2 christos kev32 = (struct netbsd32_kevent *)eventlist;
91 1.6.14.2 christos return copyout(events32, kev32, n * sizeof(*events32));
92 1.6.14.2 christos }
93 1.6.14.2 christos
94 1.6.14.2 christos int
95 1.6.14.2 christos netbsd32___kevent50(struct lwp *l,
96 1.6.14.2 christos const struct netbsd32___kevent50_args *uap, register_t *retval)
97 1.6.14.2 christos {
98 1.6.14.2 christos /* {
99 1.6.14.2 christos syscallarg(int) fd;
100 1.6.14.2 christos syscallarg(netbsd32_keventp_t) changelist;
101 1.6.14.2 christos syscallarg(netbsd32_size_t) nchanges;
102 1.6.14.2 christos syscallarg(netbsd32_keventp_t) eventlist;
103 1.6.14.2 christos syscallarg(netbsd32_size_t) nevents;
104 1.6.14.2 christos syscallarg(netbsd32_timespecp_t) timeout;
105 1.6.14.2 christos } */
106 1.6.14.2 christos int error;
107 1.6.14.2 christos size_t maxalloc, nchanges, nevents;
108 1.6.14.2 christos struct kevent_ops netbsd32_kevent_ops = {
109 1.6.14.2 christos keo_fetch_timeout: netbsd32_kevent_fetch_timeout,
110 1.6.14.2 christos keo_fetch_changes: netbsd32_kevent_fetch_changes,
111 1.6.14.2 christos keo_put_events: netbsd32_kevent_put_events,
112 1.6.14.2 christos };
113 1.6.14.2 christos
114 1.6.14.2 christos nchanges = SCARG(uap, nchanges);
115 1.6.14.2 christos nevents = SCARG(uap, nevents);
116 1.6.14.2 christos maxalloc = MIN(KQ_NEVENTS, MAX(nchanges, nevents));
117 1.6.14.2 christos netbsd32_kevent_ops.keo_private =
118 1.6.14.2 christos malloc(maxalloc * sizeof(struct netbsd32_kevent), M_TEMP,
119 1.6.14.2 christos M_WAITOK);
120 1.6.14.2 christos
121 1.6.14.2 christos error = kevent1(retval, SCARG(uap, fd),
122 1.6.14.2 christos NETBSD32PTR64(SCARG(uap, changelist)), nchanges,
123 1.6.14.2 christos NETBSD32PTR64(SCARG(uap, eventlist)), nevents,
124 1.6.14.2 christos NETBSD32PTR64(SCARG(uap, timeout)), &netbsd32_kevent_ops);
125 1.6.14.2 christos
126 1.6.14.2 christos free(netbsd32_kevent_ops.keo_private, M_TEMP);
127 1.6.14.2 christos return error;
128 1.6.14.2 christos }
129