xref: /titanic_52/usr/src/uts/common/sys/select.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifndef _SYS_SELECT_H
41*7c478bd9Sstevel@tonic-gate #define	_SYS_SELECT_H
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #ifndef _KERNEL
48*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
49*7c478bd9Sstevel@tonic-gate #include <sys/time_impl.h>
50*7c478bd9Sstevel@tonic-gate #endif
51*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
52*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
55*7c478bd9Sstevel@tonic-gate extern "C" {
56*7c478bd9Sstevel@tonic-gate #endif
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate  * The sigset_t type is defined in <sys/signal.h> and duplicated
62*7c478bd9Sstevel@tonic-gate  * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
63*7c478bd9Sstevel@tonic-gate  * now allows the visibility of signal.h in this header, however
64*7c478bd9Sstevel@tonic-gate  * an order of inclusion problem occurs as a result of inclusion
65*7c478bd9Sstevel@tonic-gate  * of <sys/select.h> in <signal.h> under certain conditions.
66*7c478bd9Sstevel@tonic-gate  * Rather than include <sys/signal.h> here, we've duplicated
67*7c478bd9Sstevel@tonic-gate  * the sigset_t type instead. This type is required for the XPG6
68*7c478bd9Sstevel@tonic-gate  * introduced pselect() function also declared in this header.
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate #ifndef	_SIGSET_T
71*7c478bd9Sstevel@tonic-gate #define	_SIGSET_T
72*7c478bd9Sstevel@tonic-gate typedef struct {		/* signal set type */
73*7c478bd9Sstevel@tonic-gate 	unsigned int	__sigbits[4];
74*7c478bd9Sstevel@tonic-gate } sigset_t;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate /* Kernel view of the ILP32 user sigset_t structure */
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate typedef struct {
81*7c478bd9Sstevel@tonic-gate 	uint32_t	__sigbits[4];
82*7c478bd9Sstevel@tonic-gate } sigset32_t;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate #endif  /* _SYSCALL32 */
85*7c478bd9Sstevel@tonic-gate #endif  /* _SIGSET_T */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  * Select uses bit masks of file descriptors in longs.
91*7c478bd9Sstevel@tonic-gate  * These macros manipulate such bit fields.
92*7c478bd9Sstevel@tonic-gate  * FD_SETSIZE may be defined by the user, but the default here
93*7c478bd9Sstevel@tonic-gate  * should be >= NOFILE (param.h).
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate #ifndef	FD_SETSIZE
96*7c478bd9Sstevel@tonic-gate #ifdef _LP64
97*7c478bd9Sstevel@tonic-gate #define	FD_SETSIZE	65536
98*7c478bd9Sstevel@tonic-gate #else
99*7c478bd9Sstevel@tonic-gate #define	FD_SETSIZE	1024
100*7c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
101*7c478bd9Sstevel@tonic-gate #elif FD_SETSIZE > 1024 && !defined(_LP64)
102*7c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
103*7c478bd9Sstevel@tonic-gate #pragma	redefine_extname	select	select_large_fdset
104*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
105*7c478bd9Sstevel@tonic-gate #pragma	redefine_extname	pselect	pselect_large_fdset
106*7c478bd9Sstevel@tonic-gate #endif
107*7c478bd9Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
108*7c478bd9Sstevel@tonic-gate #define	select	select_large_fdset
109*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
110*7c478bd9Sstevel@tonic-gate #define	pselect	pselect_large_fdset
111*7c478bd9Sstevel@tonic-gate #endif
112*7c478bd9Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
113*7c478bd9Sstevel@tonic-gate #endif	/* FD_SETSIZE */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
116*7c478bd9Sstevel@tonic-gate typedef	long	fd_mask;
117*7c478bd9Sstevel@tonic-gate #endif
118*7c478bd9Sstevel@tonic-gate typedef	long	fds_mask;
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate  *  The value of _NBBY needs to be consistant with the value
122*7c478bd9Sstevel@tonic-gate  *  of NBBY in <sys/param.h>.
123*7c478bd9Sstevel@tonic-gate  */
124*7c478bd9Sstevel@tonic-gate #define	_NBBY 8
125*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
126*7c478bd9Sstevel@tonic-gate #ifndef NBBY		/* number of bits per byte */
127*7c478bd9Sstevel@tonic-gate #define	NBBY _NBBY
128*7c478bd9Sstevel@tonic-gate #endif
129*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
132*7c478bd9Sstevel@tonic-gate #define	NFDBITS		(sizeof (fd_mask) * NBBY)	/* bits per mask */
133*7c478bd9Sstevel@tonic-gate #endif
134*7c478bd9Sstevel@tonic-gate #define	FD_NFDBITS	(sizeof (fds_mask) * _NBBY)	/* bits per mask */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #define	__howmany(__x, __y)	(((__x)+((__y)-1))/(__y))
137*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
138*7c478bd9Sstevel@tonic-gate #ifndef	howmany
139*7c478bd9Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
140*7c478bd9Sstevel@tonic-gate #endif
141*7c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
144*7c478bd9Sstevel@tonic-gate typedef	struct fd_set {
145*7c478bd9Sstevel@tonic-gate #else
146*7c478bd9Sstevel@tonic-gate typedef	struct __fd_set {
147*7c478bd9Sstevel@tonic-gate #endif
148*7c478bd9Sstevel@tonic-gate 	long	fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
149*7c478bd9Sstevel@tonic-gate } fd_set;
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate #define	FD_SET(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
152*7c478bd9Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS)))
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate #define	FD_CLR(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
155*7c478bd9Sstevel@tonic-gate 				    ~(1ul << ((__n) % FD_NFDBITS)))
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate #define	FD_ISSET(__n, __p)	(((__p)->fds_bits[(__n)/FD_NFDBITS] & \
158*7c478bd9Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS))) != 0l)
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
161*7c478bd9Sstevel@tonic-gate #define	FD_ZERO(p)	bzero((p), sizeof (*(p)))
162*7c478bd9Sstevel@tonic-gate #else
163*7c478bd9Sstevel@tonic-gate #define	FD_ZERO(__p)    (void) memset((__p), 0, sizeof (*(__p)))
164*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate #ifndef	_KERNEL
167*7c478bd9Sstevel@tonic-gate #ifdef	__STDC__
168*7c478bd9Sstevel@tonic-gate extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
169*7c478bd9Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD);
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
172*7c478bd9Sstevel@tonic-gate extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
173*7c478bd9Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD,
174*7c478bd9Sstevel@tonic-gate 	const sigset_t *_RESTRICT_KYWD);
175*7c478bd9Sstevel@tonic-gate #endif
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #else
178*7c478bd9Sstevel@tonic-gate extern int select();
179*7c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
180*7c478bd9Sstevel@tonic-gate extern int pselect();
181*7c478bd9Sstevel@tonic-gate #endif
182*7c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
183*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate #endif
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_SELECT_H */
190