From owner-svn-src-all@freebsd.org Mon Dec 28 19:42:41 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2E7F0A5416B; Mon, 28 Dec 2015 19:42:41 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0F46E1E3E; Mon, 28 Dec 2015 19:42:41 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 6922CB93E; Mon, 28 Dec 2015 14:42:39 -0500 (EST) From: John Baldwin To: Warner Losh Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r292809 - head/lib/libc/stdio Date: Mon, 28 Dec 2015 09:21:30 -0800 Message-ID: <41508412.yspAtSoPCD@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-STABLE; KDE/4.14.3; amd64; ; ) In-Reply-To: <201512272304.tBRN4C5D034464@repo.freebsd.org> References: <201512272304.tBRN4C5D034464@repo.freebsd.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 28 Dec 2015 14:42:39 -0500 (EST) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Dec 2015 19:42:41 -0000 On Sunday, December 27, 2015 11:04:12 PM Warner Losh wrote: > Author: imp > Date: Sun Dec 27 23:04:11 2015 > New Revision: 292809 > URL: https://svnweb.freebsd.org/changeset/base/292809 > > Log: > The FILE structure has a mbstate_t in it. This structure needs to be > aligned on a int64_t boundary. However, when we allocate the array of > these structures, we use ALIGNBYTES which defaults to sizeof(int) on > arm, i386 and others. The i386 stuff can handle unaligned accesses > seemlessly. However, arm cannot. Take this into account when creating > the array of FILEs, and add some comments about why. > > Differential Revision: https://reviews.freebsd.org/D4708 > > Modified: > head/lib/libc/stdio/findfp.c > > Modified: head/lib/libc/stdio/findfp.c > ============================================================================== > --- head/lib/libc/stdio/findfp.c Sun Dec 27 23:04:10 2015 (r292808) > +++ head/lib/libc/stdio/findfp.c Sun Dec 27 23:04:11 2015 (r292809) > @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > #include > > #include > @@ -96,11 +97,22 @@ moreglue(int n) > struct glue *g; > static FILE empty = { ._fl_mutex = PTHREAD_MUTEX_INITIALIZER }; > FILE *p; > + size_t align; > > - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); > + /* > + * FILE has a mbstate_t variable. This variable tries to be int64_t > + * aligned through its definition. int64_t may be larger than void *, > + * which is the size traditionally used for ALIGNBYTES. So, use our own > + * rounding instead of the MI ALIGN macros. If for some reason > + * ALIGNBYTES is larger than int64_t, respect that too. There appears to > + * be no portable way to ask for FILE's alignment requirements other > + * than just knowing here. > + */ > + align = MAX(ALIGNBYTES, sizeof(int64_t)); > + g = (struct glue *)malloc(sizeof(*g) + align + n * sizeof(FILE)); > if (g == NULL) > return (NULL); > - p = (FILE *)ALIGN(g + 1); > + p = (FILE *)roundup((uintptr_t)(g + 1), align); Can this use posix_memalign() rather than doing the alignment by hand? -- John Baldwin