Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Dec 2015 13:01:26 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        src-committers <src-committers@freebsd.org>, svn-src-head@freebsd.org,  svn-src-all@freebsd.org, Warner Losh <imp@freebsd.org>
Subject:   Re: svn commit: r292809 - head/lib/libc/stdio
Message-ID:  <CANCZdfq4sMAEzJ-wxNnybJiiTnJV3k5NZgcQACnchHCgpKQxrQ@mail.gmail.com>
In-Reply-To: <41508412.yspAtSoPCD@ralph.baldwin.cx>
References:  <201512272304.tBRN4C5D034464@repo.freebsd.org> <41508412.yspAtSoPCD@ralph.baldwin.cx>

next in thread | previous in thread | raw e-mail | index | archive | help
I'll look at that, but I don't think posix_memalign is the right way to go.
The alignment of FILE is more strict than posix_memalign will return. Ian's
idea of __alignof__ is the way to go. We allocate them in one block on
purpose for performance, and posix_memalign would be a one at a time affair.

Warner
On Dec 28, 2015 12:42 PM, "John Baldwin" <jhb@freebsd.org> wrote:

> 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 <unistd.h>
> >  #include <stdio.h>
> >  #include <stdlib.h>
> > +#include <stdint.h>
> >  #include <string.h>
> >
> >  #include <spinlock.h>
> > @@ -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
>



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