2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)sys_generic.c 8.9 (Berkeley) 2/14/95
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/filedesc.h>
66 #include <sys/ioctl.h>
69 #include <sys/socketvar.h>
71 #include <sys/kernel.h>
73 #include <sys/malloc.h>
75 #include <sys/mount.h>
76 #include <sys/protosw.h>
79 #include <sys/kdebug.h>
80 #include <kern/assert.h>
81 #include <kern/thread_act.h>
84 #include <sys/socket.h>
85 #include <sys/socketvar.h>
86 #include <sys/errno.h>
87 #include <sys/syscall.h>
89 #include <bsm/audit_kernel.h>
92 #include <net/route.h>
94 #include <netinet/in.h>
95 #include <netinet/in_systm.h>
96 #include <netinet/ip.h>
97 #include <netinet/in_pcb.h>
98 #include <netinet/ip_var.h>
99 #include <netinet/ip6.h>
100 #include <netinet/tcp.h>
101 #include <netinet/tcp_fsm.h>
102 #include <netinet/tcp_seq.h>
103 #include <netinet/tcp_timer.h>
104 #include <netinet/tcp_var.h>
105 #include <netinet/tcpip.h>
106 #include <netinet/tcp_debug.h>
107 /* for wait queue based select */
108 #include <kern/wait_queue.h>
110 #include <sys/ktrace.h>
112 #include <sys/vnode.h>
115 __private_extern__
struct file
*
116 holdfp(fdp
, fd
, flag
)
117 struct filedesc
* fdp
;
122 if (((u_int
)fd
) >= fdp
->fd_nfiles
||
123 (fp
= fdp
->fd_ofiles
[fd
]) == NULL
||
124 (fp
->f_flag
& flag
) == 0) {
135 #ifndef _SYS_SYSPROTO_H_
145 register struct read_args
*uap
;
148 register struct file
*fp
;
151 if ((fp
= holdfp(p
->p_fd
, uap
->fd
, FREAD
)) == NULL
)
153 error
= dofileread(p
, fp
, uap
->fd
, uap
->cbuf
, uap
->nbyte
,
154 (off_t
)-1, 0, retval
);
162 #ifndef _SYS_SYSPROTO_H_
167 #ifdef DOUBLE_ALIGN_PARAMS
174 pread(p
, uap
, retval
)
176 register struct pread_args
*uap
;
179 register struct file
*fp
;
182 if ((fp
= holdfp(p
->p_fd
, uap
->fd
, FREAD
)) == NULL
)
184 if (fp
->f_type
!= DTYPE_VNODE
) {
187 error
= dofileread(p
, fp
, uap
->fd
, uap
->buf
, uap
->nbyte
,
188 uap
->offset
, FOF_OFFSET
, retval
);
193 KERNEL_DEBUG_CONSTANT((BSDDBG_CODE(DBG_BSD_SC_EXTENDED_INFO
, SYS_pread
) | DBG_FUNC_NONE
),
194 uap
->fd
, uap
->nbyte
, (unsigned int)((uap
->offset
>> 32)), (unsigned int)(uap
->offset
), 0);
200 * Code common for read and pread
202 __private_extern__
int
203 dofileread(p
, fp
, fd
, buf
, nbyte
, offset
, flags
, retval
)
221 aiov
.iov_base
= (caddr_t
)buf
;
222 aiov
.iov_len
= nbyte
;
223 auio
.uio_iov
= &aiov
;
225 auio
.uio_offset
= offset
;
228 auio
.uio_resid
= nbyte
;
229 auio
.uio_rw
= UIO_READ
;
230 auio
.uio_segflg
= UIO_USERSPACE
;
234 * if tracing, save a copy of iovec
236 if (KTRPOINT(p
, KTR_GENIO
)) {
244 if ((error
= fo_read(fp
, &auio
, fp
->f_cred
, flags
, p
))) {
245 if (auio
.uio_resid
!= cnt
&& (error
== ERESTART
||
246 error
== EINTR
|| error
== EWOULDBLOCK
))
249 cnt
-= auio
.uio_resid
;
251 if (didktr
&& error
== 0) {
252 ktruio
.uio_iov
= &ktriov
;
253 ktruio
.uio_resid
= cnt
;
254 ktrgenio(p
->p_tracep
, fd
, UIO_READ
, &ktruio
, error
,
263 * Scatter read system call.
265 #ifndef _SYS_SYSPROTO_H_
273 readv(p
, uap
, retval
)
275 register struct readv_args
*uap
;
279 register struct iovec
*iov
;
281 struct iovec aiov
[UIO_SMALLIOV
];
283 if (uap
->iovcnt
> UIO_SMALLIOV
) {
284 if (uap
->iovcnt
> UIO_MAXIOV
)
286 if ((iov
= (struct iovec
*)
287 kalloc(sizeof(struct iovec
) * (uap
->iovcnt
))) == 0)
292 auio
.uio_iovcnt
= uap
->iovcnt
;
293 auio
.uio_rw
= UIO_READ
;
294 error
= copyin((caddr_t
)uap
->iovp
, (caddr_t
)iov
,
295 uap
->iovcnt
* sizeof (struct iovec
));
297 error
= rwuio(p
, uap
->fd
, &auio
, UIO_READ
, retval
);
298 if (uap
->iovcnt
> UIO_SMALLIOV
)
299 kfree(iov
, sizeof(struct iovec
)*uap
->iovcnt
);
306 #ifndef _SYS_SYSPROTO_H_
314 write(p
, uap
, retval
)
316 register struct write_args
*uap
;
319 register struct file
*fp
;
322 if ((fp
= holdfp(p
->p_fd
, uap
->fd
, FWRITE
)) == NULL
)
324 error
= dofilewrite(p
, fp
, uap
->fd
, uap
->cbuf
, uap
->nbyte
,
325 (off_t
)-1, 0, retval
);
333 #ifndef _SYS_SYSPROTO_H_
338 #ifdef DOUBLE_ALIGN_PARAMS
345 pwrite(p
, uap
, retval
)
347 register struct pwrite_args
*uap
;
350 register struct file
*fp
;
353 if ((fp
= holdfp(p
->p_fd
, uap
->fd
, FWRITE
)) == NULL
)
355 if (fp
->f_type
!= DTYPE_VNODE
) {
358 error
= dofilewrite(p
, fp
, uap
->fd
, uap
->buf
, uap
->nbyte
,
359 uap
->offset
, FOF_OFFSET
, retval
);
364 KERNEL_DEBUG_CONSTANT((BSDDBG_CODE(DBG_BSD_SC_EXTENDED_INFO
, SYS_pwrite
) | DBG_FUNC_NONE
),
365 uap
->fd
, uap
->nbyte
, (unsigned int)((uap
->offset
>> 32)), (unsigned int)(uap
->offset
), 0);
370 __private_extern__
int
371 dofilewrite(p
, fp
, fd
, buf
, nbyte
, offset
, flags
, retval
)
389 aiov
.iov_base
= (void *)(uintptr_t)buf
;
390 aiov
.iov_len
= nbyte
;
391 auio
.uio_iov
= &aiov
;
393 auio
.uio_offset
= offset
;
396 auio
.uio_resid
= nbyte
;
397 auio
.uio_rw
= UIO_WRITE
;
398 auio
.uio_segflg
= UIO_USERSPACE
;
402 * if tracing, save a copy of iovec and uio
404 if (KTRPOINT(p
, KTR_GENIO
)) {
411 if (fp
->f_type
== DTYPE_VNODE
)
413 if ((error
= fo_write(fp
, &auio
, fp
->f_cred
, flags
, p
))) {
414 if (auio
.uio_resid
!= cnt
&& (error
== ERESTART
||
415 error
== EINTR
|| error
== EWOULDBLOCK
))
417 /* The socket layer handles SIGPIPE */
418 if (error
== EPIPE
&& fp
->f_type
!= DTYPE_SOCKET
)
421 cnt
-= auio
.uio_resid
;
423 if (didktr
&& error
== 0) {
424 ktruio
.uio_iov
= &ktriov
;
425 ktruio
.uio_resid
= cnt
;
426 ktrgenio(p
->p_tracep
, fd
, UIO_WRITE
, &ktruio
, error
,
435 * Gather write system call
437 #ifndef _SYS_SYSPROTO_H_
445 writev(p
, uap
, retval
)
447 register struct writev_args
*uap
;
451 register struct iovec
*iov
;
453 struct iovec aiov
[UIO_SMALLIOV
];
455 if (uap
->iovcnt
> UIO_SMALLIOV
) {
456 if (uap
->iovcnt
> UIO_MAXIOV
)
458 if ((iov
= (struct iovec
*)
459 kalloc(sizeof(struct iovec
) * (uap
->iovcnt
))) == 0)
464 auio
.uio_iovcnt
= uap
->iovcnt
;
465 auio
.uio_rw
= UIO_WRITE
;
466 error
= copyin((caddr_t
)uap
->iovp
, (caddr_t
)iov
,
467 uap
->iovcnt
* sizeof (struct iovec
));
469 error
= rwuio(p
, uap
->fd
, &auio
, UIO_WRITE
, retval
);
470 if (uap
->iovcnt
> UIO_SMALLIOV
)
471 kfree(iov
, sizeof(struct iovec
)*uap
->iovcnt
);
476 rwuio(p
, fdes
, uio
, rw
, retval
)
479 register struct uio
*uio
;
484 register struct iovec
*iov
;
485 int i
, count
, flag
, error
;
487 struct iovec
*ktriov
;
493 if (error
= fdgetf(p
, fdes
, &fp
))
496 if ((fp
->f_flag
&(rw
==UIO_READ
? FREAD
: FWRITE
)) == 0) {
500 uio
->uio_segflg
= UIO_USERSPACE
;
503 for (i
= 0; i
< uio
->uio_iovcnt
; i
++) {
504 if (iov
->iov_len
< 0) {
507 uio
->uio_resid
+= iov
->iov_len
;
508 if (uio
->uio_resid
< 0) {
513 count
= uio
->uio_resid
;
516 * if tracing, save a copy of iovec
518 if (KTRPOINT(p
, KTR_GENIO
)) {
519 iovlen
= uio
->uio_iovcnt
* sizeof (struct iovec
);
520 MALLOC(ktriov
, struct iovec
*, iovlen
, M_TEMP
, M_WAITOK
);
521 bcopy((caddr_t
)uio
->uio_iov
, (caddr_t
)ktriov
, iovlen
);
527 if (rw
== UIO_READ
) {
528 if (error
= fo_read(fp
, uio
, fp
->f_cred
, 0, p
))
529 if (uio
->uio_resid
!= count
&& (error
== ERESTART
||
530 error
== EINTR
|| error
== EWOULDBLOCK
))
533 if (fp
->f_type
== DTYPE_VNODE
)
535 if (error
= fo_write(fp
, uio
, fp
->f_cred
, 0, p
)) {
536 if (uio
->uio_resid
!= count
&& (error
== ERESTART
||
537 error
== EINTR
|| error
== EWOULDBLOCK
))
539 /* The socket layer handles SIGPIPE */
540 if (error
== EPIPE
&& fp
->f_type
!= DTYPE_SOCKET
)
545 *retval
= count
- uio
->uio_resid
;
550 ktruio
.uio_iov
= ktriov
;
551 ktruio
.uio_resid
= *retval
;
552 ktrgenio(p
->p_tracep
, fdes
, rw
, &ktruio
, error
,
555 FREE(ktriov
, M_TEMP
);
565 #ifndef _SYS_SYSPROTO_H_
573 ioctl(p
, uap
, retval
)
575 register struct ioctl_args
*uap
;
584 #define STK_PARAMS 128
585 char stkbuf
[STK_PARAMS
];
587 AUDIT_ARG(fd
, uap
->fd
);
588 AUDIT_ARG(cmd
, uap
->com
); /* XXX cmd is int, uap->com is long */
589 AUDIT_ARG(addr
, uap
->data
);
590 if (error
= fdgetf(p
, uap
->fd
, &fp
))
593 AUDIT_ARG(file
, p
, fp
);
594 if ((fp
->f_flag
& (FREAD
| FWRITE
)) == 0)
599 * ### LD 6/11/97 Hack Alert: this is to get AppleTalk to work
600 * while implementing an ATioctl system call
603 extern int appletalk_inited
;
605 if (appletalk_inited
&& ((uap
->com
& 0x0000FFFF) == 0xff99)) {
606 #ifdef APPLETALK_DEBUG
607 kprintf("ioctl: special AppleTalk \n");
609 error
= fo_ioctl(fp
, uap
->com
, uap
->data
, p
);
617 switch (com
= uap
->com
) {
619 *fdflags(p
, uap
->fd
) &= ~UF_EXCLOSE
;
622 *fdflags(p
, uap
->fd
) |= UF_EXCLOSE
;
627 * Interpret high order word to find amount of data to be
628 * copied to/from the user's address space.
630 size
= IOCPARM_LEN(com
);
631 if (size
> IOCPARM_MAX
)
634 if (size
> sizeof (stkbuf
)) {
635 if ((memp
= (caddr_t
)kalloc(size
)) == 0)
642 error
= copyin(uap
->data
, data
, (u_int
)size
);
649 *(caddr_t
*)data
= uap
->data
;
650 } else if ((com
&IOC_OUT
) && size
)
652 * Zero the buffer so the user always
653 * gets back something deterministic.
656 else if (com
&IOC_VOID
)
657 *(caddr_t
*)data
= uap
->data
;
662 if (tmp
= *(int *)data
)
663 fp
->f_flag
|= FNONBLOCK
;
665 fp
->f_flag
&= ~FNONBLOCK
;
666 error
= fo_ioctl(fp
, FIONBIO
, (caddr_t
)&tmp
, p
);
670 if (tmp
= *(int *)data
)
671 fp
->f_flag
|= FASYNC
;
673 fp
->f_flag
&= ~FASYNC
;
674 error
= fo_ioctl(fp
, FIOASYNC
, (caddr_t
)&tmp
, p
);
679 if (fp
->f_type
== DTYPE_SOCKET
) {
680 ((struct socket
*)fp
->f_data
)->so_pgid
= tmp
;
687 struct proc
*p1
= pfind(tmp
);
692 tmp
= p1
->p_pgrp
->pg_id
;
694 error
= fo_ioctl(fp
, (int)TIOCSPGRP
, (caddr_t
)&tmp
, p
);
698 if (fp
->f_type
== DTYPE_SOCKET
) {
700 *(int *)data
= ((struct socket
*)fp
->f_data
)->so_pgid
;
703 error
= fo_ioctl(fp
, TIOCGPGRP
, data
, p
);
704 *(int *)data
= -*(int *)data
;
708 error
= fo_ioctl(fp
, com
, data
, p
);
710 * Copy any data to user, size was
711 * already set and checked above.
713 if (error
== 0 && (com
&IOC_OUT
) && size
)
714 error
= copyout(data
, uap
->data
, (u_int
)size
);
722 int selwait
, nselcoll
;
723 #define SEL_FIRSTPASS 1
724 #define SEL_SECONDPASS 2
725 extern int selcontinue(int error
);
726 extern int selprocess(int error
, int sel_pass
);
727 static int selscan(struct proc
*p
, struct _select
* sel
,
728 int nfd
, register_t
*retval
, int sel_pass
);
729 static int selcount(struct proc
*p
, u_int32_t
*ibits
, u_int32_t
*obits
,
730 int nfd
, int * count
, int * nfcount
);
731 extern uint64_t tvtoabstime(struct timeval
*tvp
);
734 * Select system call.
736 #ifndef _SYS_SYSPROTO_H_
746 select(p
, uap
, retval
)
747 register struct proc
*p
;
748 register struct select_args
*uap
;
756 int needzerofill
= 1;
761 th_act
= current_act();
762 uth
= get_bsdthread_info(th_act
);
763 sel
= &uth
->uu_state
.ss_select
;
764 retval
= (int *)get_bsduthreadrval(th_act
);
771 if (uap
->nd
> p
->p_fd
->fd_nfiles
)
772 uap
->nd
= p
->p_fd
->fd_nfiles
; /* forgiving; slightly wrong */
774 nw
= howmany(uap
->nd
, NFDBITS
);
775 ni
= nw
* sizeof(fd_mask
);
778 * if this is the first select by the thread
779 * allocate the space for bits.
781 if (sel
->nbytes
== 0) {
782 sel
->nbytes
= 3 * ni
;
783 MALLOC(sel
->ibits
, u_int32_t
*, sel
->nbytes
, M_TEMP
, M_WAITOK
);
784 MALLOC(sel
->obits
, u_int32_t
*, sel
->nbytes
, M_TEMP
, M_WAITOK
);
785 bzero((caddr_t
)sel
->ibits
, sel
->nbytes
);
786 bzero((caddr_t
)sel
->obits
, sel
->nbytes
);
791 * if the previously allocated space for the bits
792 * is smaller than what is requested. Reallocate.
794 if (sel
->nbytes
< (3 * ni
)) {
795 sel
->nbytes
= (3 * ni
);
796 FREE(sel
->ibits
, M_TEMP
);
797 FREE(sel
->obits
, M_TEMP
);
798 MALLOC(sel
->ibits
, u_int32_t
*, sel
->nbytes
, M_TEMP
, M_WAITOK
);
799 MALLOC(sel
->obits
, u_int32_t
*, sel
->nbytes
, M_TEMP
, M_WAITOK
);
800 bzero((caddr_t
)sel
->ibits
, sel
->nbytes
);
801 bzero((caddr_t
)sel
->obits
, sel
->nbytes
);
806 bzero((caddr_t
)sel
->ibits
, sel
->nbytes
);
807 bzero((caddr_t
)sel
->obits
, sel
->nbytes
);
811 * get the bits from the user address space
813 #define getbits(name, x) \
815 if (uap->name && (error = copyin((caddr_t)uap->name, \
816 (caddr_t)&sel->ibits[(x) * nw], ni))) \
828 error
= copyin((caddr_t
)uap
->tv
, (caddr_t
)&atv
, sizeof (atv
));
831 if (itimerfix(&atv
)) {
836 clock_absolutetime_interval_to_deadline(
837 tvtoabstime(&atv
), &sel
->abstime
);
843 if (error
= selcount(p
, sel
->ibits
, sel
->obits
, uap
->nd
, &count
, &nfcount
)) {
847 sel
->nfcount
= nfcount
;
849 size
= SIZEOF_WAITQUEUE_SUB
+ (count
* SIZEOF_WAITQUEUE_LINK
);
850 if (sel
->allocsize
) {
851 if (uth
->uu_wqsub
== 0)
852 panic("select: wql memory smashed");
853 /* needed for the select now */
854 if (size
> sel
->allocsize
) {
855 kfree(uth
->uu_wqsub
, sel
->allocsize
);
856 sel
->allocsize
= size
;
857 uth
->uu_wqsub
= (wait_queue_sub_t
)kalloc(sel
->allocsize
);
858 if (uth
->uu_wqsub
== (wait_queue_sub_t
)NULL
)
859 panic("failed to allocate memory for waitqueue\n");
860 sel
->wql
= (char *)uth
->uu_wqsub
+ SIZEOF_WAITQUEUE_SUB
;
864 sel
->allocsize
= size
;
865 uth
->uu_wqsub
= (wait_queue_sub_t
)kalloc(sel
->allocsize
);
866 if (uth
->uu_wqsub
== (wait_queue_sub_t
)NULL
)
867 panic("failed to allocate memory for waitqueue\n");
868 sel
->wql
= (char *)uth
->uu_wqsub
+ SIZEOF_WAITQUEUE_SUB
;
870 bzero(uth
->uu_wqsub
, size
);
871 wait_queue_sub_init(uth
->uu_wqsub
, (SYNC_POLICY_FIFO
| SYNC_POLICY_PREPOST
));
874 return selprocess(error
, SEL_FIRSTPASS
);
878 selcontinue(int error
)
880 return selprocess(error
, SEL_SECONDPASS
);
884 selprocess(error
, sel_pass
)
891 struct select_args
*uap
;
898 wait_result_t wait_result
;
901 th_act
= current_act();
902 uap
= (struct select_args
*)get_bsduthreadarg(th_act
);
903 retval
= (int *)get_bsduthreadrval(th_act
);
904 uth
= get_bsdthread_info(th_act
);
905 sel
= &uth
->uu_state
.ss_select
;
907 /* if it is first pass wait queue is not setup yet */
908 if ((error
!= 0) && (sel_pass
== SEL_FIRSTPASS
))
918 p
->p_flag
|= P_SELECT
;
919 /* skip scans if the select is just for timeouts */
921 if (sel_pass
== SEL_FIRSTPASS
)
922 wait_queue_sub_clearrefs(uth
->uu_wqsub
);
924 error
= selscan(p
, sel
, uap
->nd
, retval
, sel_pass
);
925 if (error
|| *retval
) {
929 /* if the select of log, then we canwakeup and discover some one
930 * else already read the data; go toselct again if time permits
944 clock_get_uptime(&now
);
945 if (now
>= sel
->abstime
)
950 /* cleanup obits and try again */
952 sel_pass
= SEL_FIRSTPASS
;
957 * To effect a poll, the timeout argument should be
958 * non-nil, pointing to a zero-valued timeval structure.
960 if (uap
->tv
&& sel
->abstime
== 0) {
964 /* No spurious wakeups due to colls,no need to check for them */
965 if ((sel_pass
== SEL_SECONDPASS
) || ((p
->p_flag
& P_SELECT
) == 0)) {
966 sel_pass
= SEL_FIRSTPASS
;
970 p
->p_flag
&= ~P_SELECT
;
972 /* if the select is just for timeout skip check */
973 if (sel
->count
&&(sel_pass
== SEL_SECONDPASS
))
974 panic("selprocess: 2nd pass assertwaiting");
976 /* Wait Queue Subordinate has waitqueue as first element */
977 wait_result
= wait_queue_assert_wait((wait_queue_t
)uth
->uu_wqsub
,
978 &selwait
, THREAD_ABORTSAFE
);
979 if (wait_result
!= THREAD_AWAKENED
) {
980 /* there are no preposted events */
981 error
= tsleep1(NULL
, PSOCK
| PCATCH
,
982 "select", sel
->abstime
, selcontinue
);
988 sel_pass
= SEL_SECONDPASS
;
996 wait_subqueue_unlink_all(uth
->uu_wqsub
);
997 p
->p_flag
&= ~P_SELECT
;
998 /* select is not restarted after signals... */
999 if (error
== ERESTART
)
1001 if (error
== EWOULDBLOCK
)
1003 nw
= howmany(uap
->nd
, NFDBITS
);
1004 ni
= nw
* sizeof(fd_mask
);
1006 #define putbits(name, x) \
1008 if (uap->name && (error2 = copyout((caddr_t)&sel->obits[(x) * nw], \
1009 (caddr_t)uap->name, ni))) \
1025 selscan(p
, sel
, nfd
, retval
, sel_pass
)
1027 struct _select
*sel
;
1032 register struct filedesc
*fdp
= p
->p_fd
;
1033 register int msk
, i
, j
, fd
;
1034 register u_int32_t bits
;
1038 static int flag
[3] = { FREAD
, FWRITE
, 0 };
1039 u_int32_t
*iptr
, *optr
;
1041 u_int32_t
*ibits
, *obits
;
1049 * Problems when reboot; due to MacOSX signal probs
1050 * in Beaker1C ; verify that the p->p_fd is valid
1062 nfcount
= sel
->nfcount
;
1064 if (nfcount
> count
)
1065 panic("selcount count<nfcount");
1067 nw
= howmany(nfd
, NFDBITS
);
1070 if ( nfcount
< count
) {
1071 /* some or all in kernel funnel */
1072 for (msk
= 0; msk
< 3; msk
++) {
1073 iptr
= (u_int32_t
*)&ibits
[msk
* nw
];
1074 optr
= (u_int32_t
*)&obits
[msk
* nw
];
1075 for (i
= 0; i
< nfd
; i
+= NFDBITS
) {
1076 bits
= iptr
[i
/NFDBITS
];
1077 while ((j
= ffs(bits
)) && (fd
= i
+ --j
) < nfd
) {
1079 fp
= fdp
->fd_ofiles
[fd
];
1081 (fdp
->fd_ofileflags
[fd
] & UF_RESERVED
)) {
1084 if (sel_pass
== SEL_SECONDPASS
)
1085 wql_ptr
= (char *)0;
1087 wql_ptr
= (wql
+ nc
* SIZEOF_WAITQUEUE_LINK
);
1089 * Merlot: need to remove the bogus f_data check
1090 * from the following "if" statement. It's there
1091 * because of various problems stemming from
1092 * races due to the split-funnels and lack of real
1093 * referencing on sockets...
1095 if (fp
->f_ops
&& (fp
->f_type
!= DTYPE_SOCKET
)
1096 && (fp
->f_data
!= (caddr_t
)-1)
1097 && !(fp
->f_type
== DTYPE_VNODE
1098 && (vp
= (struct vnode
*)fp
->f_data
)
1099 && vp
->v_type
== VFIFO
)
1100 && fo_select(fp
, flag
[msk
], wql_ptr
, p
)) {
1101 optr
[fd
/NFDBITS
] |= (1 << (fd
% NFDBITS
));
1111 /* socket file descriptors for scan */
1112 thread_funnel_switch(KERNEL_FUNNEL
, NETWORK_FUNNEL
);
1115 for (msk
= 0; msk
< 3; msk
++) {
1116 iptr
= (u_int32_t
*)&ibits
[msk
* nw
];
1117 optr
= (u_int32_t
*)&obits
[msk
* nw
];
1118 for (i
= 0; i
< nfd
; i
+= NFDBITS
) {
1119 bits
= iptr
[i
/NFDBITS
];
1120 while ((j
= ffs(bits
)) && (fd
= i
+ --j
) < nfd
) {
1122 fp
= fdp
->fd_ofiles
[fd
];
1124 (fdp
->fd_ofileflags
[fd
] & UF_RESERVED
)) {
1125 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
1128 if (sel_pass
== SEL_SECONDPASS
)
1129 wql_ptr
= (char *)0;
1131 wql_ptr
= (wql
+ nc
* SIZEOF_WAITQUEUE_LINK
);
1133 && (fp
->f_type
== DTYPE_SOCKET
1134 || (fp
->f_type
== DTYPE_VNODE
1135 && (vp
= (struct vnode
*)fp
->f_data
)
1136 && vp
!= (struct vnode
*)-1
1137 && vp
->v_type
== VFIFO
))
1138 && fo_select(fp
, flag
[msk
], wql_ptr
, p
)) {
1139 optr
[fd
/NFDBITS
] |= (1 << (fd
% NFDBITS
));
1146 thread_funnel_switch(NETWORK_FUNNEL
, KERNEL_FUNNEL
);
1155 seltrue(dev
, flag
, p
)
1165 selcount(p
, ibits
, obits
, nfd
, count
, nfcount
)
1167 u_int32_t
*ibits
, *obits
;
1172 register struct filedesc
*fdp
= p
->p_fd
;
1173 register int msk
, i
, j
, fd
;
1174 register u_int32_t bits
;
1179 static int flag
[3] = { FREAD
, FWRITE
, 0 };
1180 u_int32_t
*iptr
, *fptr
, *fbits
;
1185 * Problems when reboot; due to MacOSX signal probs
1186 * in Beaker1C ; verify that the p->p_fd is valid
1194 nw
= howmany(nfd
, NFDBITS
);
1197 for (msk
= 0; msk
< 3; msk
++) {
1198 iptr
= (u_int32_t
*)&ibits
[msk
* nw
];
1199 for (i
= 0; i
< nfd
; i
+= NFDBITS
) {
1200 bits
= iptr
[i
/NFDBITS
];
1201 while ((j
= ffs(bits
)) && (fd
= i
+ --j
) < nfd
) {
1203 fp
= fdp
->fd_ofiles
[fd
];
1205 (fdp
->fd_ofileflags
[fd
] & UF_RESERVED
)) {
1210 if (fp
->f_type
== DTYPE_SOCKET
||
1211 (fp
->f_type
== DTYPE_VNODE
1212 && (vp
= (struct vnode
*)fp
->f_data
)
1213 && vp
->v_type
== VFIFO
))
1225 * Record a select request.
1228 selrecord(selector
, sip
, p_wql
)
1229 struct proc
*selector
;
1230 struct selinfo
*sip
;
1233 thread_act_t cur_act
= current_act();
1234 struct uthread
* ut
= get_bsdthread_info(cur_act
);
1236 /* need to look at collisions */
1238 if ((p_wql
== (void *)0) && ((sip
->si_flags
& SI_INITED
) == 0)) {
1242 /*do not record if this is second pass of select */
1243 if((p_wql
== (void *)0)) {
1247 if ((sip
->si_flags
& SI_INITED
) == 0) {
1248 wait_queue_init(&sip
->si_wait_queue
, SYNC_POLICY_FIFO
);
1249 sip
->si_flags
|= SI_INITED
;
1250 sip
->si_flags
&= ~SI_CLEAR
;
1253 if (sip
->si_flags
& SI_RECORDED
) {
1254 sip
->si_flags
|= SI_COLL
;
1256 sip
->si_flags
&= ~SI_COLL
;
1258 sip
->si_flags
|= SI_RECORDED
;
1259 if (!wait_queue_member(&sip
->si_wait_queue
, ut
->uu_wqsub
))
1260 wait_queue_link_noalloc(&sip
->si_wait_queue
, ut
->uu_wqsub
, (wait_queue_link_t
)p_wql
);
1267 register struct selinfo
*sip
;
1270 if ((sip
->si_flags
& SI_INITED
) == 0) {
1274 if (sip
->si_flags
& SI_COLL
) {
1276 sip
->si_flags
&= ~SI_COLL
;
1278 /* will not support */
1279 //wakeup((caddr_t)&selwait);
1283 if (sip
->si_flags
& SI_RECORDED
) {
1284 wait_queue_wakeup_all(&sip
->si_wait_queue
, &selwait
, THREAD_AWAKENED
);
1285 sip
->si_flags
&= ~SI_RECORDED
;
1292 register struct selinfo
*sip
;
1295 if ((sip
->si_flags
& SI_INITED
) == 0) {
1298 if (sip
->si_flags
& SI_RECORDED
) {
1300 sip
->si_flags
&= ~(SI_RECORDED
| SI_COLL
);
1302 sip
->si_flags
|= SI_CLEAR
;
1303 wait_queue_unlinkall_nofree(&sip
->si_wait_queue
);
1307 extern struct eventqelt
*evprocdeque(struct proc
*p
, struct eventqelt
*eqp
);
1310 * called upon socket close. deque and free all events for
1314 evsofree(struct socket
*sp
)
1316 struct eventqelt
*eqp
, *next
;
1318 if (sp
== NULL
) return;
1320 for (eqp
= sp
->so_evlist
.tqh_first
; eqp
!= NULL
; eqp
= next
) {
1321 next
= eqp
->ee_slist
.tqe_next
;
1322 evprocdeque(eqp
->ee_proc
, eqp
); // remove from proc q if there
1323 TAILQ_REMOVE(&sp
->so_evlist
, eqp
, ee_slist
); // remove from socket q
1329 #define DBG_EVENT 0x10
1331 #define DBG_POST 0x10
1332 #define DBG_WATCH 0x11
1333 #define DBG_WAIT 0x12
1334 #define DBG_MOD 0x13
1335 #define DBG_EWAKEUP 0x14
1336 #define DBG_ENQUEUE 0x15
1337 #define DBG_DEQUEUE 0x16
1339 #define DBG_MISC_POST MISCDBG_CODE(DBG_EVENT,DBG_POST)
1340 #define DBG_MISC_WATCH MISCDBG_CODE(DBG_EVENT,DBG_WATCH)
1341 #define DBG_MISC_WAIT MISCDBG_CODE(DBG_EVENT,DBG_WAIT)
1342 #define DBG_MISC_MOD MISCDBG_CODE(DBG_EVENT,DBG_MOD)
1343 #define DBG_MISC_EWAKEUP MISCDBG_CODE(DBG_EVENT,DBG_EWAKEUP)
1344 #define DBG_MISC_ENQUEUE MISCDBG_CODE(DBG_EVENT,DBG_ENQUEUE)
1345 #define DBG_MISC_DEQUEUE MISCDBG_CODE(DBG_EVENT,DBG_DEQUEUE)
1349 * enque this event if it's not already queued. wakeup
1350 the proc if we do queue this event to it.
1353 evprocenque(struct eventqelt
*eqp
)
1358 KERNEL_DEBUG(DBG_MISC_ENQUEUE
|DBG_FUNC_START
, eqp
, eqp
->ee_flags
, eqp
->ee_eventmask
,0,0);
1359 if (eqp
->ee_flags
& EV_QUEUED
) {
1360 KERNEL_DEBUG(DBG_MISC_ENQUEUE
|DBG_FUNC_END
, 0,0,0,0,0);
1363 eqp
->ee_flags
|= EV_QUEUED
;
1364 eqp
->ee_eventmask
= 0; // disarm
1366 TAILQ_INSERT_TAIL(&p
->p_evlist
, eqp
, ee_plist
);
1367 KERNEL_DEBUG(DBG_MISC_EWAKEUP
,0,0,0,eqp
,0);
1368 wakeup(&p
->p_evlist
);
1369 KERNEL_DEBUG(DBG_MISC_ENQUEUE
|DBG_FUNC_END
, 0,0,0,0,0);
1373 * given either a sockbuf or a socket run down the
1374 * event list and queue ready events found
1377 postevent(struct socket
*sp
, struct sockbuf
*sb
, int event
)
1380 struct eventqelt
*evq
;
1381 register struct tcpcb
*tp
;
1383 if (sb
) sp
= sb
->sb_so
;
1384 if (!sp
|| sp
->so_evlist
.tqh_first
== NULL
) return;
1386 KERNEL_DEBUG(DBG_MISC_POST
|DBG_FUNC_START
, event
,0,0,0,0);
1388 for (evq
= sp
->so_evlist
.tqh_first
;
1389 evq
!= NULL
; evq
= evq
->ee_slist
.tqe_next
) {
1393 /* ready for reading:
1394 - byte cnt >= receive low water mark
1395 - read-half of conn closed
1396 - conn pending for listening sock
1397 - socket error pending
1400 - byte cnt avail >= send low water mark
1401 - write half of conn closed
1402 - socket error pending
1403 - non-blocking conn completed successfully
1407 - sock at out of band mark
1410 switch (event
& EV_DMASK
) {
1414 case EV_RWBYTES
|EV_OOB
:
1415 if (event
& EV_OOB
) {
1416 if ((evq
->ee_eventmask
& EV_EX
)) {
1417 if (sp
->so_oobmark
|| ((sp
->so_state
& SS_RCVATMARK
))) {
1418 mask
|= EV_EX
|EV_OOB
;
1422 if (event
& EV_RWBYTES
) {
1423 if ((evq
->ee_eventmask
& EV_RE
) && soreadable(sp
)) {
1424 if ((sp
->so_type
== SOCK_STREAM
) && (sp
->so_error
== ECONNREFUSED
) ||
1425 (sp
->so_error
== ECONNRESET
)) {
1426 if ((sp
->so_pcb
== 0) ||
1427 !(tp
= sototcpcb(sp
)) ||
1428 (tp
->t_state
== TCPS_CLOSED
)) {
1429 mask
|= EV_RE
|EV_RESET
;
1433 if (sp
->so_state
& SS_CANTRCVMORE
) {
1434 mask
|= EV_RE
|EV_FIN
;
1435 evq
->ee_req
.er_rcnt
= sp
->so_rcv
.sb_cc
;
1439 evq
->ee_req
.er_rcnt
= sp
->so_rcv
.sb_cc
;
1442 if ((evq
->ee_eventmask
& EV_WR
) && sowriteable(sp
)) {
1443 if ((sp
->so_type
== SOCK_STREAM
) &&(sp
->so_error
== ECONNREFUSED
) ||
1444 (sp
->so_error
== ECONNRESET
)) {
1445 if ((sp
->so_pcb
== 0) ||
1446 !(tp
= sototcpcb(sp
)) ||
1447 (tp
->t_state
== TCPS_CLOSED
)) {
1448 mask
|= EV_WR
|EV_RESET
;
1453 evq
->ee_req
.er_wcnt
= sbspace(&sp
->so_snd
);
1459 if ((evq
->ee_eventmask
& EV_RE
)) {
1460 evq
->ee_req
.er_rcnt
= sp
->so_qlen
+ 1; // incl this one
1461 mask
|= EV_RE
|EV_RCONN
;
1466 if ((evq
->ee_eventmask
& EV_WR
)) {
1467 mask
|= EV_WR
|EV_WCONN
;
1472 if ((evq
->ee_eventmask
& EV_RE
)) {
1473 mask
|= EV_RE
|EV_RCLOSED
;
1478 if ((evq
->ee_eventmask
& EV_WR
)) {
1479 mask
|= EV_WR
|EV_WCLOSED
;
1484 if (evq
->ee_eventmask
& EV_RE
) {
1485 mask
|= EV_RE
|EV_FIN
;
1491 if (evq
->ee_eventmask
& EV_RE
) {
1492 mask
|= EV_RE
| event
;
1494 if (evq
->ee_eventmask
& EV_WR
) {
1495 mask
|= EV_WR
| event
;
1504 evq
->ee_req
.er_eventbits
|= mask
;
1505 KERNEL_DEBUG(DBG_MISC_POST
, evq
, evq
->ee_req
.er_eventbits
, mask
,0,0);
1509 KERNEL_DEBUG(DBG_MISC_POST
|DBG_FUNC_END
, 0,0,0,0,0);
1513 * remove and return the first event (eqp=NULL) or a specific
1514 * event, or return NULL if no events found
1517 evprocdeque(struct proc
*p
, struct eventqelt
*eqp
)
1520 KERNEL_DEBUG(DBG_MISC_DEQUEUE
|DBG_FUNC_START
,p
,eqp
,0,0,0);
1522 if (eqp
&& ((eqp
->ee_flags
& EV_QUEUED
) == NULL
)) {
1523 KERNEL_DEBUG(DBG_MISC_DEQUEUE
|DBG_FUNC_END
,0,0,0,0,0);
1526 if (p
->p_evlist
.tqh_first
== NULL
) {
1527 KERNEL_DEBUG(DBG_MISC_DEQUEUE
|DBG_FUNC_END
,0,0,0,0,0);
1530 if (eqp
== NULL
) { // remove first
1531 eqp
= p
->p_evlist
.tqh_first
;
1533 TAILQ_REMOVE(&p
->p_evlist
, eqp
, ee_plist
);
1534 eqp
->ee_flags
&= ~EV_QUEUED
;
1535 KERNEL_DEBUG(DBG_MISC_DEQUEUE
|DBG_FUNC_END
,eqp
,0,0,0,0);
1539 struct evwatch_args
{
1540 struct eventreq
*u_req
;
1546 * watchevent system call. user passes us an event to watch
1547 * for. we malloc an event object, initialize it, and queue
1548 * it to the open socket. when the event occurs, postevent()
1549 * will enque it back to our proc where we can retrieve it
1552 * should this prevent duplicate events on same socket?
1555 watchevent(p
, uap
, retval
)
1557 struct evwatch_args
*uap
;
1560 struct eventqelt
*eqp
= (struct eventqelt
*)0;
1561 struct eventqelt
*np
;
1562 struct eventreq
*erp
;
1567 KERNEL_DEBUG(DBG_MISC_WATCH
|DBG_FUNC_START
, 0,0,0,0,0);
1569 // get a qelt and fill with users req
1570 MALLOC(eqp
, struct eventqelt
*, sizeof(struct eventqelt
), M_TEMP
, M_WAITOK
);
1571 if (!eqp
) panic("can't MALLOC eqp");
1573 // get users request pkt
1574 if (error
= copyin((caddr_t
)uap
->u_req
, (caddr_t
)erp
,
1575 sizeof(struct eventreq
))) {
1577 KERNEL_DEBUG(DBG_MISC_WATCH
|DBG_FUNC_END
, error
,0,0,0,0);
1580 KERNEL_DEBUG(DBG_MISC_WATCH
, erp
->er_handle
,uap
->u_eventmask
,eqp
,0,0);
1581 // validate, freeing qelt if errors
1583 if (erp
->er_type
!= EV_FD
) {
1585 } else if (erp
->er_handle
< 0) {
1587 } else if (erp
->er_handle
> p
->p_fd
->fd_nfiles
) {
1589 } else if ((fp
= *fdfile(p
, erp
->er_handle
)) == NULL
) {
1591 } else if (fp
->f_type
!= DTYPE_SOCKET
) {
1596 KERNEL_DEBUG(DBG_MISC_WATCH
|DBG_FUNC_END
, error
,0,0,0,0);
1600 erp
->er_rcnt
= erp
->er_wcnt
= erp
->er_eventbits
= 0;
1602 eqp
->ee_eventmask
= uap
->u_eventmask
& EV_MASK
;
1605 sp
= (struct socket
*)fp
->f_data
;
1608 // only allow one watch per file per proc
1609 for (np
= sp
->so_evlist
.tqh_first
; np
!= NULL
; np
= np
->ee_slist
.tqe_next
) {
1610 if (np
->ee_proc
== p
) {
1612 KERNEL_DEBUG(DBG_MISC_WATCH
|DBG_FUNC_END
, EINVAL
,0,0,0,0);
1617 TAILQ_INSERT_TAIL(&sp
->so_evlist
, eqp
, ee_slist
);
1618 postevent(sp
, 0, EV_RWBYTES
); // catch existing events
1619 KERNEL_DEBUG(DBG_MISC_WATCH
|DBG_FUNC_END
, 0,0,0,0,0);
1623 struct evwait_args
{
1624 struct eventreq
*u_req
;
1629 * waitevent system call.
1630 * grabs the next waiting event for this proc and returns
1631 * it. if no events, user can request to sleep with timeout
1632 * or poll mode (tv=NULL);
1635 waitevent(p
, uap
, retval
)
1637 struct evwait_args
*uap
;
1641 struct eventqelt
*eqp
;
1642 uint64_t abstime
, interval
;
1647 error
= copyin((caddr_t
)uap
->tv
, (caddr_t
)&atv
, sizeof (atv
));
1650 if (itimerfix(&atv
)) {
1655 interval
= tvtoabstime(&atv
);
1658 abstime
= interval
= 0;
1660 KERNEL_DEBUG(DBG_MISC_WAIT
|DBG_FUNC_START
, 0,0,0,0,0);
1663 if ((eqp
= evprocdeque(p
,NULL
)) != NULL
) {
1664 error
= copyout((caddr_t
)&eqp
->ee_req
,
1665 (caddr_t
)uap
->u_req
, sizeof(struct eventreq
));
1666 KERNEL_DEBUG(DBG_MISC_WAIT
|DBG_FUNC_END
, error
,
1667 eqp
->ee_req
.er_handle
,eqp
->ee_req
.er_eventbits
,eqp
,0);
1672 if (uap
->tv
&& interval
== 0) {
1673 *retval
= 1; // poll failed
1674 KERNEL_DEBUG(DBG_MISC_WAIT
|DBG_FUNC_END
, error
,0,0,0,0);
1680 clock_absolutetime_interval_to_deadline(interval
, &abstime
);
1682 KERNEL_DEBUG(DBG_MISC_WAIT
, 1,&p
->p_evlist
,0,0,0);
1683 error
= tsleep1(&p
->p_evlist
, PSOCK
| PCATCH
,
1684 "waitevent", abstime
, (int (*)(int))0);
1685 KERNEL_DEBUG(DBG_MISC_WAIT
, 2,&p
->p_evlist
,0,0,0);
1688 if (error
== ERESTART
)
1690 if (error
== EWOULDBLOCK
) {
1696 KERNEL_DEBUG(DBG_MISC_WAIT
|DBG_FUNC_END
, 0,0,0,0,0);
1701 struct modwatch_args
{
1702 struct eventreq
*u_req
;
1707 * modwatch system call. user passes in event to modify.
1708 * if we find it we reset the event bits and que/deque event
1712 modwatch(p
, uap
, retval
)
1714 struct modwatch_args
*uap
;
1718 struct eventreq
*erp
= &er
;
1719 struct eventqelt
*evq
;
1725 KERNEL_DEBUG(DBG_MISC_MOD
|DBG_FUNC_START
, 0,0,0,0,0);
1727 // get users request pkt
1728 if (error
= copyin((caddr_t
)uap
->u_req
, (caddr_t
)erp
,
1729 sizeof(struct eventreq
))) return(error
);
1731 if (erp
->er_type
!= EV_FD
) return(EINVAL
);
1732 if (erp
->er_handle
< 0) return(EBADF
);
1733 if (erp
->er_handle
> p
->p_fd
->fd_nfiles
) return(EBADF
);
1734 if ((fp
= *fdfile(p
, erp
->er_handle
)) == NULL
)
1736 if (fp
->f_type
!= DTYPE_SOCKET
) return(EINVAL
); // for now must be sock
1737 sp
= (struct socket
*)fp
->f_data
;
1739 /* soo_close sets f_data to 0 before switching funnel */
1740 if (sp
== (struct socket
*)0)
1743 // locate event if possible
1744 for (evq
= sp
->so_evlist
.tqh_first
;
1745 evq
!= NULL
; evq
= evq
->ee_slist
.tqe_next
) {
1746 if (evq
->ee_proc
== p
) break;
1750 KERNEL_DEBUG(DBG_MISC_MOD
|DBG_FUNC_END
, EINVAL
,0,0,0,0);
1753 KERNEL_DEBUG(DBG_MISC_MOD
, erp
->er_handle
,uap
->u_eventmask
,evq
,0,0);
1755 if (uap
->u_eventmask
== EV_RM
) {
1756 evprocdeque(p
, evq
);
1757 TAILQ_REMOVE(&sp
->so_evlist
, evq
, ee_slist
);
1759 KERNEL_DEBUG(DBG_MISC_MOD
|DBG_FUNC_END
, 0,0,0,0,0);
1763 switch (uap
->u_eventmask
& EV_MASK
) {
1781 case EV_EX
|EV_RE
|EV_WR
:
1782 flag
= EV_OOB
|EV_RWBYTES
;
1789 evq
->ee_eventmask
= uap
->u_eventmask
& EV_MASK
;
1790 evprocdeque(p
, evq
);
1791 evq
->ee_req
.er_eventbits
= 0;
1792 postevent(sp
, 0, flag
);
1793 KERNEL_DEBUG(DBG_MISC_MOD
|DBG_FUNC_END
, evq
->ee_req
.er_handle
,evq
->ee_eventmask
,sp
,flag
,0);