kern/58214: [patch] Align smallbits properly in poll()

Stefan Farfeleder stefan at
Sat Oct 18 09:20:20 PDT 2003

>Number:         58214
>Category:       kern
>Synopsis:       [patch] Align smallbits properly in poll()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 18 09:20:17 PDT 2003
>Originator:     Stefan Farfeleder
>Release:        FreeBSD 5.1-CURRENT i386
System: FreeBSD 5.1-CURRENT FreeBSD 5.1-CURRENT #1: Sat Oct 18 17:37:40 CEST 2003 freebsd at i386

Poll() uses the array smallbits that is big enough to hold 32 struct pollfd's
to avoid calling malloc() on small numbers of fds.  Because smalltype's members
have type char, its address might be misaligned for a struct pollfd.

Additionally, bits' type is changed to void * to avoid a cast and allows to get
rid of another one.

--- poll.diff begins here ---
Index: src/sys/kern/sys_generic.c
RCS file: /usr/home/ncvs/src/sys/kern/sys_generic.c,v
retrieving revision 1.125
diff -u -p -r1.125 sys_generic.c
--- src/sys/kern/sys_generic.c	27 Sep 2003 12:53:33 -0000	1.125
+++ src/sys/kern/sys_generic.c	18 Oct 2003 15:10:19 -0000
@@ -938,8 +938,8 @@ poll(td, uap)
 	struct thread *td;
 	struct poll_args *uap;
-	caddr_t bits;
-	char smallbits[32 * sizeof(struct pollfd)];
+	void *bits;
+	struct pollfd smallbits[32];
 	struct timeval atv, rtv, ttv;
 	int error = 0, timo;
 	u_int ncoll, nfds;
@@ -991,7 +991,7 @@ retry:
-	error = pollscan(td, (struct pollfd *)bits, nfds);
+	error = pollscan(td, bits, nfds);
 	if (error || td->td_retval[0])
 		goto done;
--- poll.diff ends here ---


More information about the freebsd-bugs mailing list