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

Stefan Farfeleder stefan at fafoe.narf.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
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 18 09:20:17 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Stefan Farfeleder
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD frog.fafoe.narf.at 5.1-CURRENT FreeBSD 5.1-CURRENT #1: Sat Oct 18 17:37:40 CEST 2003 freebsd at frog.fafoe.narf.at:/freebsd/testing/obj/freebsd/testing/src/sys/TESTING i386

>Description:
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.

>How-To-Repeat:
>Fix:
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:
 	mtx_unlock_spin(&sched_lock);
 	mtx_unlock(&sellock);
 
-	error = pollscan(td, (struct pollfd *)bits, nfds);
+	error = pollscan(td, bits, nfds);
 	mtx_lock(&sellock);
 	if (error || td->td_retval[0])
 		goto done;
--- poll.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list