Add pselect syscall.
[dragonfly.git] / sys / kern / sys_generic.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
39 * $FreeBSD: src/sys/kern/sys_generic.c,v 1.55.2.10 2001/03/17 10:39:32 peter Exp $
ae7cb1b5 40 * $DragonFly: src/sys/kern/sys_generic.c,v 1.47 2008/01/10 22:30:27 nth Exp $
984263bc
MD
41 */
42
43#include "opt_ktrace.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>
48#include <sys/filedesc.h>
49#include <sys/filio.h>
50#include <sys/fcntl.h>
51#include <sys/file.h>
52#include <sys/proc.h>
53#include <sys/signalvar.h>
54#include <sys/socketvar.h>
55#include <sys/uio.h>
56#include <sys/kernel.h>
ba023347 57#include <sys/kern_syscall.h>
984263bc 58#include <sys/malloc.h>
a0c5fc96 59#include <sys/mapped_ioctl.h>
984263bc 60#include <sys/poll.h>
a0c5fc96 61#include <sys/queue.h>
984263bc
MD
62#include <sys/resourcevar.h>
63#include <sys/sysctl.h>
64#include <sys/sysent.h>
65#include <sys/buf.h>
66#ifdef KTRACE
67#include <sys/ktrace.h>
68#endif
69#include <vm/vm.h>
70#include <vm/vm_page.h>
dadab5e9 71#include <sys/file2.h>
984263bc
MD
72
73#include <machine/limits.h>
74
75static MALLOC_DEFINE(M_IOCTLOPS, "ioctlops", "ioctl data buffer");
a0c5fc96 76static MALLOC_DEFINE(M_IOCTLMAP, "ioctlmap", "mapped ioctl handler buffer");
984263bc
MD
77static MALLOC_DEFINE(M_SELECT, "select", "select() buffer");
78MALLOC_DEFINE(M_IOV, "iov", "large iov's");
79
ae7cb1b5
NT
80static int doselect(int nd, fd_set *in, fd_set *ou, fd_set *ex,
81 struct timeval *tv, int *res);
402ed7e1
RG
82static int pollscan (struct proc *, struct pollfd *, u_int, int *);
83static int selscan (struct proc *, fd_mask **, fd_mask **,
84 int, int *);
7f83ed38
MD
85static int dofileread(int, struct file *, struct uio *, int, int *);
86static int dofilewrite(int, struct file *, struct uio *, int, int *);
87
984263bc
MD
88/*
89 * Read system call.
f832287e
MD
90 *
91 * MPSAFE
984263bc 92 */
984263bc 93int
753fd850 94sys_read(struct read_args *uap)
984263bc 95{
dadab5e9 96 struct thread *td = curthread;
ba023347
DRJ
97 struct uio auio;
98 struct iovec aiov;
984263bc
MD
99 int error;
100
ba023347
DRJ
101 aiov.iov_base = uap->buf;
102 aiov.iov_len = uap->nbyte;
103 auio.uio_iov = &aiov;
104 auio.uio_iovcnt = 1;
105 auio.uio_offset = -1;
106 auio.uio_resid = uap->nbyte;
107 auio.uio_rw = UIO_READ;
108 auio.uio_segflg = UIO_USERSPACE;
109 auio.uio_td = td;
110
ef5c76d7
MD
111 if (auio.uio_resid < 0)
112 error = EINVAL;
113 else
114 error = kern_preadv(uap->fd, &auio, 0, &uap->sysmsg_result);
984263bc
MD
115 return(error);
116}
117
118/*
7f83ed38 119 * Positioned (Pread) read system call
f832287e
MD
120 *
121 * MPSAFE
984263bc 122 */
984263bc 123int
b09fd398 124sys_extpread(struct extpread_args *uap)
984263bc 125{
dadab5e9 126 struct thread *td = curthread;
ba023347
DRJ
127 struct uio auio;
128 struct iovec aiov;
984263bc 129 int error;
9ba76b73 130 int flags;
984263bc 131
ba023347
DRJ
132 aiov.iov_base = uap->buf;
133 aiov.iov_len = uap->nbyte;
134 auio.uio_iov = &aiov;
135 auio.uio_iovcnt = 1;
136 auio.uio_offset = uap->offset;
137 auio.uio_resid = uap->nbyte;
138 auio.uio_rw = UIO_READ;
139 auio.uio_segflg = UIO_USERSPACE;
140 auio.uio_td = td;
141
9ba76b73
MD
142 flags = uap->flags & O_FMASK;
143 if (uap->offset != (off_t)-1)
144 flags |= O_FOFFSET;
145
ef5c76d7
MD
146 if (auio.uio_resid < 0)
147 error = EINVAL;
148 else
9ba76b73 149 error = kern_preadv(uap->fd, &auio, flags, &uap->sysmsg_result);
984263bc
MD
150 return(error);
151}
152
7f83ed38
MD
153/*
154 * Scatter read system call.
f832287e
MD
155 *
156 * MPSAFE
7f83ed38 157 */
984263bc 158int
753fd850 159sys_readv(struct readv_args *uap)
984263bc 160{
dadab5e9 161 struct thread *td = curthread;
984263bc 162 struct uio auio;
ba023347
DRJ
163 struct iovec aiov[UIO_SMALLIOV], *iov = NULL;
164 int error;
984263bc 165
ba023347 166 error = iovec_copyin(uap->iovp, &iov, aiov, uap->iovcnt,
ef5c76d7 167 &auio.uio_resid);
ba023347
DRJ
168 if (error)
169 return (error);
170 auio.uio_iov = iov;
171 auio.uio_iovcnt = uap->iovcnt;
172 auio.uio_offset = -1;
984263bc
MD
173 auio.uio_rw = UIO_READ;
174 auio.uio_segflg = UIO_USERSPACE;
dadab5e9 175 auio.uio_td = td;
984263bc 176
7f83ed38 177 error = kern_preadv(uap->fd, &auio, 0, &uap->sysmsg_result);
ba023347
DRJ
178
179 iovec_free(&iov, aiov);
984263bc
MD
180 return (error);
181}
182
7f83ed38
MD
183
184/*
185 * Scatter positioned read system call.
f832287e
MD
186 *
187 * MPSAFE
7f83ed38
MD
188 */
189int
b09fd398 190sys_extpreadv(struct extpreadv_args *uap)
7f83ed38
MD
191{
192 struct thread *td = curthread;
193 struct uio auio;
194 struct iovec aiov[UIO_SMALLIOV], *iov = NULL;
195 int error;
9ba76b73 196 int flags;
7f83ed38
MD
197
198 error = iovec_copyin(uap->iovp, &iov, aiov, uap->iovcnt,
ef5c76d7 199 &auio.uio_resid);
7f83ed38
MD
200 if (error)
201 return (error);
202 auio.uio_iov = iov;
203 auio.uio_iovcnt = uap->iovcnt;
204 auio.uio_offset = uap->offset;
205 auio.uio_rw = UIO_READ;
206 auio.uio_segflg = UIO_USERSPACE;
207 auio.uio_td = td;
208
9ba76b73
MD
209 flags = uap->flags & O_FMASK;
210 if (uap->offset != (off_t)-1)
211 flags |= O_FOFFSET;
212
213 error = kern_preadv(uap->fd, &auio, flags, &uap->sysmsg_result);
7f83ed38
MD
214
215 iovec_free(&iov, aiov);
216 return(error);
217}
218
f832287e
MD
219/*
220 * MPSAFE
221 */
984263bc 222int
7f83ed38 223kern_preadv(int fd, struct uio *auio, int flags, int *res)
984263bc 224{
dadab5e9
MD
225 struct thread *td = curthread;
226 struct proc *p = td->td_proc;
41c20dac 227 struct file *fp;
7f83ed38 228 int error;
984263bc 229
ba023347
DRJ
230 KKASSERT(p);
231
228b401d 232 fp = holdfp(p->p_fd, fd, FREAD);
ba023347 233 if (fp == NULL)
984263bc 234 return (EBADF);
9ba76b73 235 if (flags & O_FOFFSET && fp->f_type != DTYPE_VNODE) {
ba023347 236 error = ESPIPE;
7f83ed38 237 } else if (auio->uio_resid < 0) {
ba023347 238 error = EINVAL;
7f83ed38
MD
239 } else {
240 error = dofileread(fd, fp, auio, flags, res);
984263bc 241 }
9f87144f 242 fdrop(fp);
7f83ed38
MD
243 return(error);
244}
245
246/*
247 * Common code for readv and preadv that reads data in
248 * from a file using the passed in uio, offset, and flags.
f832287e
MD
249 *
250 * MPALMOSTSAFE - ktrace needs help
7f83ed38
MD
251 */
252static int
253dofileread(int fd, struct file *fp, struct uio *auio, int flags, int *res)
254{
255 struct thread *td = curthread;
256 struct proc *p = td->td_proc;
7f83ed38 257 int error;
ef5c76d7 258 int len;
7f83ed38
MD
259#ifdef KTRACE
260 struct iovec *ktriov = NULL;
261 struct uio ktruio;
262#endif
263
984263bc
MD
264#ifdef KTRACE
265 /*
266 * if tracing, save a copy of iovec
267 */
dadab5e9 268 if (KTRPOINT(td, KTR_GENIO)) {
ba023347
DRJ
269 int iovlen = auio->uio_iovcnt * sizeof(struct iovec);
270
984263bc 271 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
ba023347
DRJ
272 bcopy((caddr_t)auio->uio_iov, (caddr_t)ktriov, iovlen);
273 ktruio = *auio;
984263bc
MD
274 }
275#endif
ba023347 276 len = auio->uio_resid;
87de5057 277 error = fo_read(fp, auio, fp->f_cred, flags);
ba023347
DRJ
278 if (error) {
279 if (auio->uio_resid != len && (error == ERESTART ||
984263bc
MD
280 error == EINTR || error == EWOULDBLOCK))
281 error = 0;
282 }
984263bc
MD
283#ifdef KTRACE
284 if (ktriov != NULL) {
285 if (error == 0) {
286 ktruio.uio_iov = ktriov;
ba023347 287 ktruio.uio_resid = len - auio->uio_resid;
f832287e 288 get_mplock();
a9b80e23 289 ktrgenio(p, fd, UIO_READ, &ktruio, error);
f832287e 290 rel_mplock();
984263bc
MD
291 }
292 FREE(ktriov, M_TEMP);
293 }
294#endif
ba023347
DRJ
295 if (error == 0)
296 *res = len - auio->uio_resid;
7f83ed38
MD
297
298 return(error);
984263bc
MD
299}
300
301/*
302 * Write system call
f832287e
MD
303 *
304 * MPSAFE
984263bc 305 */
984263bc 306int
753fd850 307sys_write(struct write_args *uap)
984263bc 308{
dadab5e9 309 struct thread *td = curthread;
ba023347
DRJ
310 struct uio auio;
311 struct iovec aiov;
984263bc
MD
312 int error;
313
ba023347
DRJ
314 aiov.iov_base = (void *)(uintptr_t)uap->buf;
315 aiov.iov_len = uap->nbyte;
316 auio.uio_iov = &aiov;
317 auio.uio_iovcnt = 1;
318 auio.uio_offset = -1;
319 auio.uio_resid = uap->nbyte;
320 auio.uio_rw = UIO_WRITE;
321 auio.uio_segflg = UIO_USERSPACE;
322 auio.uio_td = td;
323
ef5c76d7
MD
324 if (auio.uio_resid < 0)
325 error = EINVAL;
326 else
327 error = kern_pwritev(uap->fd, &auio, 0, &uap->sysmsg_result);
dadab5e9 328
984263bc
MD
329 return(error);
330}
331
332/*
333 * Pwrite system call
f832287e
MD
334 *
335 * MPSAFE
984263bc 336 */
984263bc 337int
b09fd398 338sys_extpwrite(struct extpwrite_args *uap)
984263bc 339{
dadab5e9 340 struct thread *td = curthread;
ba023347
DRJ
341 struct uio auio;
342 struct iovec aiov;
984263bc 343 int error;
9ba76b73 344 int flags;
984263bc 345
ba023347
DRJ
346 aiov.iov_base = (void *)(uintptr_t)uap->buf;
347 aiov.iov_len = uap->nbyte;
348 auio.uio_iov = &aiov;
349 auio.uio_iovcnt = 1;
350 auio.uio_offset = uap->offset;
351 auio.uio_resid = uap->nbyte;
352 auio.uio_rw = UIO_WRITE;
353 auio.uio_segflg = UIO_USERSPACE;
354 auio.uio_td = td;
355
9ba76b73
MD
356 flags = uap->flags & O_FMASK;
357 if (uap->offset != (off_t)-1)
358 flags |= O_FOFFSET;
359
ef5c76d7
MD
360 if (auio.uio_resid < 0)
361 error = EINVAL;
362 else
9ba76b73 363 error = kern_pwritev(uap->fd, &auio, flags, &uap->sysmsg_result);
ba023347 364
984263bc
MD
365 return(error);
366}
367
f832287e
MD
368/*
369 * MPSAFE
370 */
ba023347 371int
753fd850 372sys_writev(struct writev_args *uap)
ba023347 373{
dadab5e9 374 struct thread *td = curthread;
984263bc 375 struct uio auio;
ba023347
DRJ
376 struct iovec aiov[UIO_SMALLIOV], *iov = NULL;
377 int error;
984263bc 378
ba023347 379 error = iovec_copyin(uap->iovp, &iov, aiov, uap->iovcnt,
ef5c76d7 380 &auio.uio_resid);
ba023347
DRJ
381 if (error)
382 return (error);
383 auio.uio_iov = iov;
384 auio.uio_iovcnt = uap->iovcnt;
385 auio.uio_offset = -1;
984263bc
MD
386 auio.uio_rw = UIO_WRITE;
387 auio.uio_segflg = UIO_USERSPACE;
dadab5e9 388 auio.uio_td = td;
ba023347 389
7f83ed38 390 error = kern_pwritev(uap->fd, &auio, 0, &uap->sysmsg_result);
ba023347
DRJ
391
392 iovec_free(&iov, aiov);
984263bc
MD
393 return (error);
394}
395
7f83ed38 396
984263bc 397/*
7f83ed38 398 * Gather positioned write system call
f832287e
MD
399 *
400 * MPSAFE
984263bc 401 */
984263bc 402int
b09fd398 403sys_extpwritev(struct extpwritev_args *uap)
7f83ed38
MD
404{
405 struct thread *td = curthread;
406 struct uio auio;
407 struct iovec aiov[UIO_SMALLIOV], *iov = NULL;
408 int error;
9ba76b73 409 int flags;
7f83ed38
MD
410
411 error = iovec_copyin(uap->iovp, &iov, aiov, uap->iovcnt,
ef5c76d7 412 &auio.uio_resid);
7f83ed38
MD
413 if (error)
414 return (error);
415 auio.uio_iov = iov;
416 auio.uio_iovcnt = uap->iovcnt;
417 auio.uio_offset = uap->offset;
418 auio.uio_rw = UIO_WRITE;
419 auio.uio_segflg = UIO_USERSPACE;
420 auio.uio_td = td;
421
9ba76b73
MD
422 flags = uap->flags & O_FMASK;
423 if (uap->offset != (off_t)-1)
424 flags |= O_FOFFSET;
425
426 error = kern_pwritev(uap->fd, &auio, flags, &uap->sysmsg_result);
7f83ed38
MD
427
428 iovec_free(&iov, aiov);
429 return(error);
430}
431
f832287e
MD
432/*
433 * MPSAFE
434 */
7f83ed38
MD
435int
436kern_pwritev(int fd, struct uio *auio, int flags, int *res)
984263bc 437{
dadab5e9
MD
438 struct thread *td = curthread;
439 struct proc *p = td->td_proc;
41c20dac 440 struct file *fp;
7f83ed38 441 int error;
984263bc 442
dadab5e9 443 KKASSERT(p);
dadab5e9 444
228b401d 445 fp = holdfp(p->p_fd, fd, FWRITE);
ba023347 446 if (fp == NULL)
984263bc 447 return (EBADF);
9ba76b73 448 else if ((flags & O_FOFFSET) && fp->f_type != DTYPE_VNODE) {
ba023347 449 error = ESPIPE;
7f83ed38
MD
450 } else {
451 error = dofilewrite(fd, fp, auio, flags, res);
984263bc 452 }
7f83ed38 453
9f87144f 454 fdrop(fp);
7f83ed38
MD
455 return (error);
456}
457
458/*
459 * Common code for writev and pwritev that writes data to
460 * a file using the passed in uio, offset, and flags.
f832287e
MD
461 *
462 * MPALMOSTSAFE - ktrace needs help
7f83ed38
MD
463 */
464static int
465dofilewrite(int fd, struct file *fp, struct uio *auio, int flags, int *res)
466{
467 struct thread *td = curthread;
7278a846 468 struct lwp *lp = td->td_lwp;
7f83ed38 469 struct proc *p = td->td_proc;
7f83ed38 470 int error;
ef5c76d7 471 int len;
7f83ed38
MD
472#ifdef KTRACE
473 struct iovec *ktriov = NULL;
474 struct uio ktruio;
475#endif
476
984263bc
MD
477#ifdef KTRACE
478 /*
479 * if tracing, save a copy of iovec and uio
480 */
dadab5e9 481 if (KTRPOINT(td, KTR_GENIO)) {
ba023347
DRJ
482 int iovlen = auio->uio_iovcnt * sizeof(struct iovec);
483
984263bc 484 MALLOC(ktriov, struct iovec *, iovlen, M_TEMP, M_WAITOK);
ba023347
DRJ
485 bcopy((caddr_t)auio->uio_iov, (caddr_t)ktriov, iovlen);
486 ktruio = *auio;
984263bc
MD
487 }
488#endif
ba023347 489 len = auio->uio_resid;
984263bc
MD
490 if (fp->f_type == DTYPE_VNODE)
491 bwillwrite();
87de5057 492 error = fo_write(fp, auio, fp->f_cred, flags);
ba023347
DRJ
493 if (error) {
494 if (auio->uio_resid != len && (error == ERESTART ||
984263bc
MD
495 error == EINTR || error == EWOULDBLOCK))
496 error = 0;
7f83ed38 497 /* Socket layer is responsible for issuing SIGPIPE. */
f832287e
MD
498 if (error == EPIPE) {
499 get_mplock();
7278a846 500 lwpsignal(p, lp, SIGPIPE);
f832287e
MD
501 rel_mplock();
502 }
984263bc 503 }
984263bc
MD
504#ifdef KTRACE
505 if (ktriov != NULL) {
506 if (error == 0) {
507 ktruio.uio_iov = ktriov;
ba023347 508 ktruio.uio_resid = len - auio->uio_resid;
f832287e 509 get_mplock();
a9b80e23 510 ktrgenio(p, fd, UIO_WRITE, &ktruio, error);
f832287e 511 rel_mplock();
984263bc
MD
512 }
513 FREE(ktriov, M_TEMP);
514 }
515#endif
ba023347
DRJ
516 if (error == 0)
517 *res = len - auio->uio_resid;
7f83ed38
MD
518
519 return(error);
984263bc
MD
520}
521
522/*
523 * Ioctl system call
524 */
984263bc
MD
525/* ARGSUSED */
526int
753fd850 527sys_ioctl(struct ioctl_args *uap)
a0c5fc96
JS
528{
529 return(mapped_ioctl(uap->fd, uap->com, uap->data, NULL));
530}
531
532struct ioctl_map_entry {
533 const char *subsys;
534 struct ioctl_map_range *cmd_ranges;
535 LIST_ENTRY(ioctl_map_entry) entries;
536};
537
25b5b94d
SS
538/*
539 * The true heart of all ioctl syscall handlers (native, emulation).
540 * If map != NULL, it will be searched for a matching entry for com,
541 * and appropriate conversions/conversion functions will be utilized.
542 */
a0c5fc96
JS
543int
544mapped_ioctl(int fd, u_long com, caddr_t uspc_data, struct ioctl_map *map)
984263bc 545{
dadab5e9
MD
546 struct thread *td = curthread;
547 struct proc *p = td->td_proc;
87de5057 548 struct ucred *cred;
41c20dac 549 struct file *fp;
a0c5fc96 550 struct ioctl_map_range *iomc = NULL;
984263bc 551 int error;
1fd87d54 552 u_int size;
a0c5fc96 553 u_long ocom = com;
984263bc
MD
554 caddr_t data, memp;
555 int tmp;
556#define STK_PARAMS 128
557 union {
558 char stkbuf[STK_PARAMS];
559 long align;
560 } ubuf;
561
dadab5e9 562 KKASSERT(p);
87de5057 563 cred = p->p_ucred;
984263bc 564
228b401d
MD
565 fp = holdfp(p->p_fd, fd, FREAD|FWRITE);
566 if (fp == NULL)
a0c5fc96
JS
567 return(EBADF);
568
569 if (map != NULL) { /* obey translation map */
570 u_long maskcmd;
571 struct ioctl_map_entry *e;
572
573 maskcmd = com & map->mask;
574
575 LIST_FOREACH(e, &map->mapping, entries) {
576 for (iomc = e->cmd_ranges; iomc->start != 0 ||
25b5b94d
SS
577 iomc->maptocmd != 0 || iomc->wrapfunc != NULL ||
578 iomc->mapfunc != NULL;
a0c5fc96
JS
579 iomc++) {
580 if (maskcmd >= iomc->start &&
581 maskcmd <= iomc->end)
582 break;
583 }
584
585 /* Did we find a match? */
586 if (iomc->start != 0 || iomc->maptocmd != 0 ||
25b5b94d 587 iomc->wrapfunc != NULL || iomc->mapfunc != NULL)
a0c5fc96
JS
588 break;
589 }
590
591 if (iomc == NULL ||
592 (iomc->start == 0 && iomc->maptocmd == 0
25b5b94d 593 && iomc->wrapfunc == NULL && iomc->mapfunc == NULL)) {
6ea70f76 594 kprintf("%s: 'ioctl' fd=%d, cmd=0x%lx ('%c',%d) not implemented\n",
a0c5fc96
JS
595 map->sys, fd, maskcmd,
596 (int)((maskcmd >> 8) & 0xff),
597 (int)(maskcmd & 0xff));
228b401d
MD
598 error = EINVAL;
599 goto done;
a0c5fc96 600 }
984263bc 601
25b5b94d
SS
602 /*
603 * If it's a non-range one to one mapping, maptocmd should be
604 * correct. If it's a ranged one to one mapping, we pass the
605 * original value of com, and for a range mapped to a different
606 * range, we always need a mapping function to translate the
607 * ioctl to our native ioctl. Ex. 6500-65ff <-> 9500-95ff
608 */
609 if (iomc->start == iomc->end && iomc->maptocmd == iomc->maptoend) {
610 com = iomc->maptocmd;
611 } else if (iomc->start == iomc->maptocmd && iomc->end == iomc->maptoend) {
612 if (iomc->mapfunc != NULL)
613 com = iomc->mapfunc(iomc->start, iomc->end,
614 iomc->start, iomc->end,
615 com, com);
616 } else {
617 if (iomc->mapfunc != NULL) {
618 com = iomc->mapfunc(iomc->start, iomc->end,
619 iomc->maptocmd, iomc->maptoend,
620 com, ocom);
621 } else {
6ea70f76 622 kprintf("%s: Invalid mapping for fd=%d, cmd=%#lx ('%c',%d)\n",
25b5b94d
SS
623 map->sys, fd, maskcmd,
624 (int)((maskcmd >> 8) & 0xff),
625 (int)(maskcmd & 0xff));
228b401d
MD
626 error = EINVAL;
627 goto done;
25b5b94d
SS
628 }
629 }
a0c5fc96
JS
630 }
631
632 switch (com) {
984263bc 633 case FIONCLEX:
228b401d
MD
634 error = fclrfdflags(p->p_fd, fd, UF_EXCLOSE);
635 goto done;
984263bc 636 case FIOCLEX:
228b401d
MD
637 error = fsetfdflags(p->p_fd, fd, UF_EXCLOSE);
638 goto done;
984263bc
MD
639 }
640
641 /*
642 * Interpret high order word to find amount of data to be
643 * copied to/from the user's address space.
644 */
645 size = IOCPARM_LEN(com);
228b401d
MD
646 if (size > IOCPARM_MAX) {
647 error = ENOTTY;
648 goto done;
649 }
984263bc
MD
650
651 memp = NULL;
652 if (size > sizeof (ubuf.stkbuf)) {
efda3bd0 653 memp = kmalloc(size, M_IOCTLOPS, M_WAITOK);
984263bc
MD
654 data = memp;
655 } else {
656 data = ubuf.stkbuf;
657 }
a0c5fc96
JS
658 if ((com & IOC_IN) != 0) {
659 if (size != 0) {
660 error = copyin(uspc_data, data, (u_int)size);
984263bc 661 if (error) {
a0c5fc96 662 if (memp != NULL)
efda3bd0 663 kfree(memp, M_IOCTLOPS);
228b401d 664 goto done;
984263bc
MD
665 }
666 } else {
a0c5fc96 667 *(caddr_t *)data = uspc_data;
984263bc 668 }
a0c5fc96 669 } else if ((com & IOC_OUT) != 0 && size) {
984263bc
MD
670 /*
671 * Zero the buffer so the user always
672 * gets back something deterministic.
673 */
674 bzero(data, size);
a0c5fc96
JS
675 } else if ((com & IOC_VOID) != 0) {
676 *(caddr_t *)data = uspc_data;
984263bc
MD
677 }
678
679 switch (com) {
984263bc
MD
680 case FIONBIO:
681 if ((tmp = *(int *)data))
682 fp->f_flag |= FNONBLOCK;
683 else
684 fp->f_flag &= ~FNONBLOCK;
9ba76b73 685 error = 0;
984263bc
MD
686 break;
687
688 case FIOASYNC:
689 if ((tmp = *(int *)data))
690 fp->f_flag |= FASYNC;
691 else
692 fp->f_flag &= ~FASYNC;
87de5057 693 error = fo_ioctl(fp, FIOASYNC, (caddr_t)&tmp, cred);
984263bc
MD
694 break;
695
696 default:
a0c5fc96
JS
697 /*
698 * If there is a override function,
699 * call it instead of directly routing the call
700 */
25b5b94d 701 if (map != NULL && iomc->wrapfunc != NULL)
87de5057 702 error = iomc->wrapfunc(fp, com, ocom, data, cred);
a0c5fc96 703 else
87de5057 704 error = fo_ioctl(fp, com, data, cred);
984263bc
MD
705 /*
706 * Copy any data to user, size was
707 * already set and checked above.
708 */
a0c5fc96
JS
709 if (error == 0 && (com & IOC_OUT) != 0 && size != 0)
710 error = copyout(data, uspc_data, (u_int)size);
984263bc
MD
711 break;
712 }
a0c5fc96 713 if (memp != NULL)
efda3bd0 714 kfree(memp, M_IOCTLOPS);
228b401d 715done:
9f87144f 716 fdrop(fp);
a0c5fc96
JS
717 return(error);
718}
719
720int
721mapped_ioctl_register_handler(struct ioctl_map_handler *he)
722{
723 struct ioctl_map_entry *ne;
724
725 KKASSERT(he != NULL && he->map != NULL && he->cmd_ranges != NULL &&
726 he->subsys != NULL && *he->subsys != '\0');
727
efda3bd0 728 ne = kmalloc(sizeof(struct ioctl_map_entry), M_IOCTLMAP, M_WAITOK);
a0c5fc96
JS
729
730 ne->subsys = he->subsys;
731 ne->cmd_ranges = he->cmd_ranges;
732
733 LIST_INSERT_HEAD(&he->map->mapping, ne, entries);
734
735 return(0);
736}
737
738int
739mapped_ioctl_unregister_handler(struct ioctl_map_handler *he)
740{
741 struct ioctl_map_entry *ne;
742
743 KKASSERT(he != NULL && he->map != NULL && he->cmd_ranges != NULL);
744
745 LIST_FOREACH(ne, &he->map->mapping, entries) {
746 if (ne->cmd_ranges != he->cmd_ranges)
747 continue;
748 LIST_REMOVE(ne, entries);
efda3bd0 749 kfree(ne, M_IOCTLMAP);
a0c5fc96
JS
750 return(0);
751 }
752 return(EINVAL);
984263bc
MD
753}
754
755static int nselcoll; /* Select collisions since boot */
756int selwait;
757SYSCTL_INT(_kern, OID_AUTO, nselcoll, CTLFLAG_RD, &nselcoll, 0, "");
758
759/*
760 * Select system call.
761 */
984263bc 762int
753fd850 763sys_select(struct select_args *uap)
ae7cb1b5
NT
764{
765 struct timeval ktv;
766 struct timeval *ktvp;
767 int error;
768
769 /*
770 * Get timeout if any.
771 */
772 if (uap->tv != NULL) {
773 error = copyin(uap->tv, &ktv, sizeof (ktv));
774 if (error)
775 return (error);
776 error = itimerfix(&ktv);
777 if (error)
778 return (error);
779 ktvp = &ktv;
780 } else {
781 ktvp = NULL;
782 }
783
784 /*
785 * Do real work.
786 */
787 error = doselect(uap->nd, uap->in, uap->ou, uap->ex, ktvp,
788 &uap->sysmsg_result);
789
790 return (error);
791}
792
793
794/*
795 * Pselect system call.
796 */
797int
798sys_pselect(struct pselect_args *uap)
799{
800 struct thread *td = curthread;
801 struct lwp *lp = td->td_lwp;
802 struct timespec kts;
803 struct timeval ktv;
804 struct timeval *ktvp;
805 sigset_t sigmask;
806 int error;
807
808 /*
809 * Get timeout if any and convert it.
810 * Round up during conversion to avoid timeout going off early.
811 */
812 if (uap->ts != NULL) {
813 error = copyin(uap->ts, &kts, sizeof (kts));
814 if (error)
815 return (error);
816 ktv.tv_sec = kts.tv_sec;
817 ktv.tv_usec = (kts.tv_nsec + 999) / 1000;
818 error = itimerfix(&ktv);
819 if (error)
820 return (error);
821 ktvp = &ktv;
822 } else {
823 ktvp = NULL;
824 }
825
826 /*
827 * Install temporary signal mask if any provided.
828 */
829 if (uap->sigmask != NULL) {
830 error = copyin(uap->sigmask, &sigmask, sizeof(sigmask));
831 if (error)
832 return (error);
833 lp->lwp_oldsigmask = lp->lwp_sigmask;
834 SIG_CANTMASK(sigmask);
835 lp->lwp_sigmask = sigmask;
836 }
837
838 /*
839 * Do real job.
840 */
841 error = doselect(uap->nd, uap->in, uap->ou, uap->ex, ktvp,
842 &uap->sysmsg_result);
843
844 if (uap->sigmask != NULL) {
845 /* doselect() responsible for turning ERESTART into EINTR */
846 KKASSERT(error != ERESTART);
847 if (error == EINTR) {
848 /*
849 * We can't restore the previous signal mask now
850 * because it could block the signal that interrupted
851 * us. So make a note to restore it after executing
852 * the handler.
853 */
854 lp->lwp_flag |= LWP_OLDMASK;
855 } else {
856 /*
857 * No handler to run. Restore previous mask immediately.
858 */
859 lp->lwp_sigmask = lp->lwp_oldsigmask;
860 }
861 }
862
863 return (error);
864}
865
866/*
867 * Common code for sys_select() and sys_pselect().
868 *
869 * in, out and ex are userland pointers. tv must point to validated
870 * kernel-side timeout value or NULL for infinite timeout. res must
871 * point to syscall return value.
872 */
873static int
874doselect(int nd, fd_set *in, fd_set *ou, fd_set *ex, struct timeval *tv,
875 int *res)
984263bc 876{
8067b633 877 struct lwp *lp = curthread->td_lwp;
41c20dac
MD
878 struct proc *p = curproc;
879
984263bc
MD
880 /*
881 * The magic 2048 here is chosen to be just enough for FD_SETSIZE
882 * infds with the new FD_SETSIZE of 1024, and more than enough for
883 * FD_SETSIZE infds, outfds and exceptfds with the old FD_SETSIZE
884 * of 256.
885 */
886 fd_mask s_selbits[howmany(2048, NFDBITS)];
887 fd_mask *ibits[3], *obits[3], *selbits, *sbp;
888 struct timeval atv, rtv, ttv;
e43a034f 889 int ncoll, error, timo;
984263bc
MD
890 u_int nbufbytes, ncpbytes, nfdbits;
891
ae7cb1b5 892 if (nd < 0)
984263bc 893 return (EINVAL);
ae7cb1b5
NT
894 if (nd > p->p_fd->fd_nfiles)
895 nd = p->p_fd->fd_nfiles; /* forgiving; slightly wrong */
984263bc
MD
896
897 /*
898 * Allocate just enough bits for the non-null fd_sets. Use the
899 * preallocated auto buffer if possible.
900 */
ae7cb1b5 901 nfdbits = roundup(nd, NFDBITS);
984263bc
MD
902 ncpbytes = nfdbits / NBBY;
903 nbufbytes = 0;
ae7cb1b5 904 if (in != NULL)
984263bc 905 nbufbytes += 2 * ncpbytes;
ae7cb1b5 906 if (ou != NULL)
984263bc 907 nbufbytes += 2 * ncpbytes;
ae7cb1b5 908 if (ex != NULL)
984263bc
MD
909 nbufbytes += 2 * ncpbytes;
910 if (nbufbytes <= sizeof s_selbits)
911 selbits = &s_selbits[0];
912 else
efda3bd0 913 selbits = kmalloc(nbufbytes, M_SELECT, M_WAITOK);
984263bc
MD
914
915 /*
916 * Assign pointers into the bit buffers and fetch the input bits.
917 * Put the output buffers together so that they can be bzeroed
918 * together.
919 */
920 sbp = selbits;
921#define getbits(name, x) \
922 do { \
ae7cb1b5 923 if (name == NULL) \
984263bc
MD
924 ibits[x] = NULL; \
925 else { \
926 ibits[x] = sbp + nbufbytes / 2 / sizeof *sbp; \
927 obits[x] = sbp; \
928 sbp += ncpbytes / sizeof *sbp; \
ae7cb1b5 929 error = copyin(name, ibits[x], ncpbytes); \
984263bc
MD
930 if (error != 0) \
931 goto done; \
932 } \
933 } while (0)
934 getbits(in, 0);
935 getbits(ou, 1);
936 getbits(ex, 2);
937#undef getbits
938 if (nbufbytes != 0)
939 bzero(selbits, nbufbytes / 2);
940
ae7cb1b5
NT
941 if (tv != NULL) {
942 atv = *tv;
984263bc
MD
943 getmicrouptime(&rtv);
944 timevaladd(&atv, &rtv);
945 } else {
946 atv.tv_sec = 0;
947 atv.tv_usec = 0;
948 }
949 timo = 0;
950retry:
951 ncoll = nselcoll;
8067b633 952 lp->lwp_flag |= LWP_SELECT;
ae7cb1b5
NT
953 error = selscan(p, ibits, obits, nd, res);
954 if (error || *res)
984263bc
MD
955 goto done;
956 if (atv.tv_sec || atv.tv_usec) {
957 getmicrouptime(&rtv);
ae7cb1b5 958 if (timevalcmp(&rtv, &atv, >=))
984263bc
MD
959 goto done;
960 ttv = atv;
961 timevalsub(&ttv, &rtv);
962 timo = ttv.tv_sec > 24 * 60 * 60 ?
a94976ad 963 24 * 60 * 60 * hz : tvtohz_high(&ttv);
984263bc 964 }
e43a034f 965 crit_enter();
8067b633 966 if ((lp->lwp_flag & LWP_SELECT) == 0 || nselcoll != ncoll) {
e43a034f 967 crit_exit();
984263bc
MD
968 goto retry;
969 }
8067b633 970 lp->lwp_flag &= ~LWP_SELECT;
984263bc 971
377d4740 972 error = tsleep((caddr_t)&selwait, PCATCH, "select", timo);
984263bc 973
e43a034f 974 crit_exit();
984263bc
MD
975 if (error == 0)
976 goto retry;
977done:
8067b633 978 lp->lwp_flag &= ~LWP_SELECT;
984263bc
MD
979 /* select is not restarted after signals... */
980 if (error == ERESTART)
981 error = EINTR;
982 if (error == EWOULDBLOCK)
983 error = 0;
984#define putbits(name, x) \
ae7cb1b5 985 if (name && (error2 = copyout(obits[x], name, ncpbytes))) \
984263bc
MD
986 error = error2;
987 if (error == 0) {
988 int error2;
989
990 putbits(in, 0);
991 putbits(ou, 1);
992 putbits(ex, 2);
993#undef putbits
994 }
995 if (selbits != &s_selbits[0])
efda3bd0 996 kfree(selbits, M_SELECT);
984263bc
MD
997 return (error);
998}
999
1000static int
90b9818c 1001selscan(struct proc *p, fd_mask **ibits, fd_mask **obits, int nfd, int *res)
984263bc 1002{
984263bc
MD
1003 int msk, i, fd;
1004 fd_mask bits;
1005 struct file *fp;
1006 int n = 0;
1007 /* Note: backend also returns POLLHUP/POLLERR if appropriate. */
1008 static int flag[3] = { POLLRDNORM, POLLWRNORM, POLLRDBAND };
1009
1010 for (msk = 0; msk < 3; msk++) {
1011 if (ibits[msk] == NULL)
1012 continue;
1013 for (i = 0; i < nfd; i += NFDBITS) {
1014 bits = ibits[msk][i/NFDBITS];
1015 /* ffs(int mask) not portable, fd_mask is long */
1016 for (fd = i; bits && fd < nfd; fd++, bits >>= 1) {
1017 if (!(bits & 1))
1018 continue;
228b401d 1019 fp = holdfp(p->p_fd, fd, -1);
984263bc
MD
1020 if (fp == NULL)
1021 return (EBADF);
87de5057 1022 if (fo_poll(fp, flag[msk], fp->f_cred)) {
984263bc
MD
1023 obits[msk][(fd)/NFDBITS] |=
1024 ((fd_mask)1 << ((fd) % NFDBITS));
1025 n++;
1026 }
228b401d 1027 fdrop(fp);
984263bc
MD
1028 }
1029 }
1030 }
90b9818c 1031 *res = n;
984263bc
MD
1032 return (0);
1033}
1034
1035/*
1036 * Poll system call.
1037 */
984263bc 1038int
753fd850 1039sys_poll(struct poll_args *uap)
984263bc 1040{
b525b7ed
DR
1041 struct pollfd *bits;
1042 struct pollfd smallbits[32];
984263bc 1043 struct timeval atv, rtv, ttv;
e43a034f 1044 int ncoll, error = 0, timo;
984263bc
MD
1045 u_int nfds;
1046 size_t ni;
8067b633 1047 struct lwp *lp = curthread->td_lwp;
41c20dac 1048 struct proc *p = curproc;
984263bc 1049
ab2eb4eb 1050 nfds = uap->nfds;
984263bc
MD
1051 /*
1052 * This is kinda bogus. We have fd limits, but that is not
1053 * really related to the size of the pollfd array. Make sure
1054 * we let the process use at least FD_SETSIZE entries and at
1055 * least enough for the current limits. We want to be reasonably
1056 * safe, but not overly restrictive.
1057 */
1058 if (nfds > p->p_rlimit[RLIMIT_NOFILE].rlim_cur && nfds > FD_SETSIZE)
1059 return (EINVAL);
1060 ni = nfds * sizeof(struct pollfd);
1061 if (ni > sizeof(smallbits))
efda3bd0 1062 bits = kmalloc(ni, M_TEMP, M_WAITOK);
984263bc
MD
1063 else
1064 bits = smallbits;
ab2eb4eb 1065 error = copyin(uap->fds, bits, ni);
984263bc
MD
1066 if (error)
1067 goto done;
ab2eb4eb
DR
1068 if (uap->timeout != INFTIM) {
1069 atv.tv_sec = uap->timeout / 1000;
1070 atv.tv_usec = (uap->timeout % 1000) * 1000;
984263bc
MD
1071 if (itimerfix(&atv)) {
1072 error = EINVAL;
1073 goto done;
1074 }
1075 getmicrouptime(&rtv);
1076 timevaladd(&atv, &rtv);
1077 } else {
1078 atv.tv_sec = 0;
1079 atv.tv_usec = 0;
1080 }
1081 timo = 0;
1082retry:
1083 ncoll = nselcoll;
8067b633 1084 lp->lwp_flag |= LWP_SELECT;
b525b7ed 1085 error = pollscan(p, bits, nfds, &uap->sysmsg_result);
c7114eea 1086 if (error || uap->sysmsg_result)
984263bc
MD
1087 goto done;
1088 if (atv.tv_sec || atv.tv_usec) {
1089 getmicrouptime(&rtv);
1090 if (timevalcmp(&rtv, &atv, >=))
1091 goto done;
1092 ttv = atv;
1093 timevalsub(&ttv, &rtv);
1094 timo = ttv.tv_sec > 24 * 60 * 60 ?
a94976ad 1095 24 * 60 * 60 * hz : tvtohz_high(&ttv);
984263bc 1096 }
e43a034f 1097 crit_enter();
8067b633 1098 if ((lp->lwp_flag & LWP_SELECT) == 0 || nselcoll != ncoll) {
e43a034f 1099 crit_exit();
984263bc
MD
1100 goto retry;
1101 }
8067b633 1102 lp->lwp_flag &= ~LWP_SELECT;
377d4740 1103 error = tsleep((caddr_t)&selwait, PCATCH, "poll", timo);
e43a034f 1104 crit_exit();
984263bc
MD
1105 if (error == 0)
1106 goto retry;
1107done:
8067b633 1108 lp->lwp_flag &= ~LWP_SELECT;
984263bc
MD
1109 /* poll is not restarted after signals... */
1110 if (error == ERESTART)
1111 error = EINTR;
1112 if (error == EWOULDBLOCK)
1113 error = 0;
1114 if (error == 0) {
ab2eb4eb 1115 error = copyout(bits, uap->fds, ni);
984263bc
MD
1116 if (error)
1117 goto out;
1118 }
1119out:
1120 if (ni > sizeof(smallbits))
efda3bd0 1121 kfree(bits, M_TEMP);
984263bc
MD
1122 return (error);
1123}
1124
1125static int
90b9818c 1126pollscan(struct proc *p, struct pollfd *fds, u_int nfd, int *res)
984263bc 1127{
984263bc
MD
1128 int i;
1129 struct file *fp;
1130 int n = 0;
1131
1132 for (i = 0; i < nfd; i++, fds++) {
228b401d 1133 if (fds->fd >= p->p_fd->fd_nfiles) {
984263bc
MD
1134 fds->revents = POLLNVAL;
1135 n++;
1136 } else if (fds->fd < 0) {
1137 fds->revents = 0;
1138 } else {
228b401d 1139 fp = holdfp(p->p_fd, fds->fd, -1);
984263bc
MD
1140 if (fp == NULL) {
1141 fds->revents = POLLNVAL;
1142 n++;
1143 } else {
1144 /*
1145 * Note: backend also returns POLLHUP and
1146 * POLLERR if appropriate.
1147 */
1148 fds->revents = fo_poll(fp, fds->events,
87de5057 1149 fp->f_cred);
984263bc
MD
1150 if (fds->revents != 0)
1151 n++;
228b401d 1152 fdrop(fp);
984263bc
MD
1153 }
1154 }
1155 }
90b9818c 1156 *res = n;
984263bc
MD
1157 return (0);
1158}
1159
1160/*
1161 * OpenBSD poll system call.
1162 * XXX this isn't quite a true representation.. OpenBSD uses select ops.
1163 */
984263bc 1164int
753fd850 1165sys_openbsd_poll(struct openbsd_poll_args *uap)
984263bc 1166{
753fd850 1167 return (sys_poll((struct poll_args *)uap));
984263bc
MD
1168}
1169
1170/*ARGSUSED*/
1171int
b13267a5 1172seltrue(cdev_t dev, int events)
984263bc 1173{
984263bc
MD
1174 return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
1175}
1176
1177/*
41c20dac
MD
1178 * Record a select request. A global wait must be used since a process/thread
1179 * might go away after recording its request.
984263bc
MD
1180 */
1181void
41c20dac 1182selrecord(struct thread *selector, struct selinfo *sip)
984263bc
MD
1183{
1184 struct proc *p;
8067b633 1185 struct lwp *lp = NULL;
984263bc 1186
8067b633 1187 if (selector->td_lwp == NULL)
41c20dac
MD
1188 panic("selrecord: thread needs a process");
1189
8067b633
SS
1190 if (sip->si_pid == selector->td_proc->p_pid &&
1191 sip->si_tid == selector->td_lwp->lwp_tid)
984263bc 1192 return;
3e291793
MD
1193 if (sip->si_pid && (p = pfind(sip->si_pid)))
1194 lp = lwp_rb_tree_RB_LOOKUP(&p->p_lwp_tree, sip->si_tid);
8067b633 1195 if (lp != NULL && lp->lwp_wchan == (caddr_t)&selwait) {
984263bc 1196 sip->si_flags |= SI_COLL;
41c20dac 1197 } else {
8067b633 1198 sip->si_pid = selector->td_proc->p_pid;
acb157c2 1199 sip->si_tid = selector->td_lwp->lwp_tid;
41c20dac 1200 }
984263bc
MD
1201}
1202
1203/*
1204 * Do a wakeup when a selectable event occurs.
1205 */
1206void
41c20dac 1207selwakeup(struct selinfo *sip)
984263bc 1208{
41c20dac 1209 struct proc *p;
8067b633 1210 struct lwp *lp = NULL;
984263bc
MD
1211
1212 if (sip->si_pid == 0)
1213 return;
1214 if (sip->si_flags & SI_COLL) {
1215 nselcoll++;
1216 sip->si_flags &= ~SI_COLL;
41c20dac 1217 wakeup((caddr_t)&selwait); /* YYY fixable */
984263bc
MD
1218 }
1219 p = pfind(sip->si_pid);
1220 sip->si_pid = 0;
8067b633
SS
1221 if (p == NULL)
1222 return;
3e291793 1223 lp = lwp_rb_tree_RB_LOOKUP(&p->p_lwp_tree, sip->si_tid);
8067b633
SS
1224 if (lp == NULL)
1225 return;
1226
1227 crit_enter();
1228 if (lp->lwp_wchan == (caddr_t)&selwait) {
1229 /*
1230 * Flag the process to break the tsleep when
1231 * setrunnable is called, but only call setrunnable
1232 * here if the process is not in a stopped state.
1233 */
1234 lp->lwp_flag |= LWP_BREAKTSLEEP;
1235 if (p->p_stat != SSTOP)
1236 setrunnable(lp);
1237 } else if (lp->lwp_flag & LWP_SELECT) {
1238 lp->lwp_flag &= ~LWP_SELECT;
1239 }
1240 crit_exit();
984263bc 1241}
41c20dac 1242