Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Oct 2003 18:17:39 +0200 (CEST)
From:      Stefan Farfeleder <stefan@fafoe.narf.at>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        stefan@fafoe.narf.at
Subject:   kern/58214: [patch] Align smallbits properly in poll()
Message-ID:  <20031018161739.9D78C1FC@frog.fafoe.narf.at>
Resent-Message-ID: <200310181620.h9IGKIfl092420@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031018161739.9D78C1FC>