kern_select_50.c revision 1.1 1 1.1 pooka /* $NetBSD: kern_select_50.c,v 1.1 2011/01/17 15:57:04 pooka Exp $ */
2 1.1 pooka
3 1.1 pooka /*-
4 1.1 pooka * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 1.1 pooka * All rights reserved.
6 1.1 pooka *
7 1.1 pooka * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pooka * by Christos Zoulas.
9 1.1 pooka *
10 1.1 pooka * Redistribution and use in source and binary forms, with or without
11 1.1 pooka * modification, are permitted provided that the following conditions
12 1.1 pooka * are met:
13 1.1 pooka * 1. Redistributions of source code must retain the above copyright
14 1.1 pooka * notice, this list of conditions and the following disclaimer.
15 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pooka * notice, this list of conditions and the following disclaimer in the
17 1.1 pooka * documentation and/or other materials provided with the distribution.
18 1.1 pooka *
19 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pooka * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pooka */
31 1.1 pooka #include <sys/cdefs.h>
32 1.1 pooka __KERNEL_RCSID(0, "$NetBSD: kern_select_50.c,v 1.1 2011/01/17 15:57:04 pooka Exp $");
33 1.1 pooka
34 1.1 pooka #include <sys/param.h>
35 1.1 pooka #include <sys/event.h>
36 1.1 pooka #include <sys/poll.h>
37 1.1 pooka #include <sys/select.h>
38 1.1 pooka #include <sys/time.h>
39 1.1 pooka #include <sys/syscallargs.h>
40 1.1 pooka
41 1.1 pooka #include <compat/sys/time.h>
42 1.1 pooka
43 1.1 pooka static int
44 1.1 pooka compat_50_kevent_fetch_timeout(const void *src, void *dest, size_t length)
45 1.1 pooka {
46 1.1 pooka struct timespec50 ts50;
47 1.1 pooka int error;
48 1.1 pooka
49 1.1 pooka KASSERT(length == sizeof(struct timespec));
50 1.1 pooka
51 1.1 pooka error = copyin(src, &ts50, sizeof(ts50));
52 1.1 pooka if (error)
53 1.1 pooka return error;
54 1.1 pooka timespec50_to_timespec(&ts50, (struct timespec *)dest);
55 1.1 pooka return 0;
56 1.1 pooka }
57 1.1 pooka
58 1.1 pooka int
59 1.1 pooka compat_50_sys_kevent(struct lwp *l, const struct compat_50_sys_kevent_args *uap,
60 1.1 pooka register_t *retval)
61 1.1 pooka {
62 1.1 pooka /* {
63 1.1 pooka syscallarg(int) fd;
64 1.1 pooka syscallarg(keventp_t) changelist;
65 1.1 pooka syscallarg(size_t) nchanges;
66 1.1 pooka syscallarg(keventp_t) eventlist;
67 1.1 pooka syscallarg(size_t) nevents;
68 1.1 pooka syscallarg(struct timespec50) timeout;
69 1.1 pooka } */
70 1.1 pooka static const struct kevent_ops compat_50_kevent_ops = {
71 1.1 pooka .keo_private = NULL,
72 1.1 pooka .keo_fetch_timeout = compat_50_kevent_fetch_timeout,
73 1.1 pooka .keo_fetch_changes = kevent_fetch_changes,
74 1.1 pooka .keo_put_events = kevent_put_events,
75 1.1 pooka };
76 1.1 pooka
77 1.1 pooka return kevent1(retval, SCARG(uap, fd), SCARG(uap, changelist),
78 1.1 pooka SCARG(uap, nchanges), SCARG(uap, eventlist), SCARG(uap, nevents),
79 1.1 pooka (const struct timespec *)(const void *)SCARG(uap, timeout),
80 1.1 pooka &compat_50_kevent_ops);
81 1.1 pooka }
82 1.1 pooka
83 1.1 pooka int
84 1.1 pooka compat_50_sys_select(struct lwp *l,
85 1.1 pooka const struct compat_50_sys_select_args *uap, register_t *retval)
86 1.1 pooka {
87 1.1 pooka /* {
88 1.1 pooka syscallarg(int) nd;
89 1.1 pooka syscallarg(fd_set *) in;
90 1.1 pooka syscallarg(fd_set *) ou;
91 1.1 pooka syscallarg(fd_set *) ex;
92 1.1 pooka syscallarg(struct timeval50 *) tv;
93 1.1 pooka } */
94 1.1 pooka struct timespec ats, *ts = NULL;
95 1.1 pooka struct timeval50 atv50;
96 1.1 pooka int error;
97 1.1 pooka
98 1.1 pooka if (SCARG(uap, tv)) {
99 1.1 pooka error = copyin(SCARG(uap, tv), (void *)&atv50, sizeof(atv50));
100 1.1 pooka if (error)
101 1.1 pooka return error;
102 1.1 pooka ats.tv_sec = atv50.tv_sec;
103 1.1 pooka ats.tv_nsec = atv50.tv_usec * 1000;
104 1.1 pooka ts = &ats;
105 1.1 pooka }
106 1.1 pooka
107 1.1 pooka return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
108 1.1 pooka SCARG(uap, ou), SCARG(uap, ex), ts, NULL);
109 1.1 pooka }
110 1.1 pooka
111 1.1 pooka int
112 1.1 pooka compat_50_sys_pselect(struct lwp *l,
113 1.1 pooka const struct compat_50_sys_pselect_args *uap, register_t *retval)
114 1.1 pooka {
115 1.1 pooka /* {
116 1.1 pooka syscallarg(int) nd;
117 1.1 pooka syscallarg(fd_set *) in;
118 1.1 pooka syscallarg(fd_set *) ou;
119 1.1 pooka syscallarg(fd_set *) ex;
120 1.1 pooka syscallarg(const struct timespec50 *) ts;
121 1.1 pooka syscallarg(sigset_t *) mask;
122 1.1 pooka } */
123 1.1 pooka struct timespec50 ats50;
124 1.1 pooka struct timespec ats, *ts = NULL;
125 1.1 pooka sigset_t amask, *mask = NULL;
126 1.1 pooka int error;
127 1.1 pooka
128 1.1 pooka if (SCARG(uap, ts)) {
129 1.1 pooka error = copyin(SCARG(uap, ts), &ats50, sizeof(ats50));
130 1.1 pooka if (error)
131 1.1 pooka return error;
132 1.1 pooka timespec50_to_timespec(&ats50, &ats);
133 1.1 pooka ts = &ats;
134 1.1 pooka }
135 1.1 pooka if (SCARG(uap, mask) != NULL) {
136 1.1 pooka error = copyin(SCARG(uap, mask), &amask, sizeof(amask));
137 1.1 pooka if (error)
138 1.1 pooka return error;
139 1.1 pooka mask = &amask;
140 1.1 pooka }
141 1.1 pooka
142 1.1 pooka return selcommon(retval, SCARG(uap, nd), SCARG(uap, in),
143 1.1 pooka SCARG(uap, ou), SCARG(uap, ex), ts, mask);
144 1.1 pooka }
145 1.1 pooka
146 1.1 pooka int
147 1.1 pooka compat_50_sys_pollts(struct lwp *l, const struct compat_50_sys_pollts_args *uap,
148 1.1 pooka register_t *retval)
149 1.1 pooka {
150 1.1 pooka /* {
151 1.1 pooka syscallarg(struct pollfd *) fds;
152 1.1 pooka syscallarg(u_int) nfds;
153 1.1 pooka syscallarg(const struct timespec50 *) ts;
154 1.1 pooka syscallarg(const sigset_t *) mask;
155 1.1 pooka } */
156 1.1 pooka struct timespec ats, *ts = NULL;
157 1.1 pooka struct timespec50 ats50;
158 1.1 pooka sigset_t amask, *mask = NULL;
159 1.1 pooka int error;
160 1.1 pooka
161 1.1 pooka if (SCARG(uap, ts)) {
162 1.1 pooka error = copyin(SCARG(uap, ts), &ats50, sizeof(ats50));
163 1.1 pooka if (error)
164 1.1 pooka return error;
165 1.1 pooka timespec50_to_timespec(&ats50, &ats);
166 1.1 pooka ts = &ats;
167 1.1 pooka }
168 1.1 pooka if (SCARG(uap, mask)) {
169 1.1 pooka error = copyin(SCARG(uap, mask), &amask, sizeof(amask));
170 1.1 pooka if (error)
171 1.1 pooka return error;
172 1.1 pooka mask = &amask;
173 1.1 pooka }
174 1.1 pooka
175 1.1 pooka return pollcommon(retval, SCARG(uap, fds), SCARG(uap, nfds), ts, mask);
176 1.1 pooka }
177