From owner-svn-src-head@freebsd.org Sun Dec 27 23:04:13 2015 Return-Path: Delivered-To: svn-src-head@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 3520BA53FB4; Sun, 27 Dec 2015 23:04:13 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E2D011A29; Sun, 27 Dec 2015 23:04:12 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBRN4C5Q034465; Sun, 27 Dec 2015 23:04:12 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBRN4C5D034464; Sun, 27 Dec 2015 23:04:12 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201512272304.tBRN4C5D034464@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Sun, 27 Dec 2015 23:04:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292809 - head/lib/libc/stdio X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Dec 2015 23:04:13 -0000 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); g->next = NULL; g->niobs = n; g->iobs = p;