This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: malloc-based ggc-page
On Wed, Jan 19, 2000 at 01:06:35PM -0800, Geoff Keating wrote:
> > Date: Wed, 19 Jan 2000 18:41:33 +0100
> > From: Marc Espie <espie@quatramaran.ens.fr>
>
> > The valloc() function allocates size bytes aligned on a page
> > boundary. It is implemented by calling malloc(3) with a
> > slightly larger request, saving the true beginning of the block
> > allocated, and returning a proper- ly aligned pointer.
> ...
> > Coincidentally, on OpenBSD, valloc is currently just a wrapper around
> > malloc, that calls getpagesize, allocates almost one page more what's needed,
> > and aligns the resulting value on page sizes...
> >
> > ... which does mean that, apart from valloc(0), free will work on such
> > systems.
> I don't know about the BSDs, but if you tried to do that under glibc
> free() would crash (this is a feature). You have to pass the value
> you got from malloc(), not just some pointer in the allocated block.
Read carefully. valloc(size) is implemented by calling malloc after adding
pagesize-1 to size. So unless size == 0, malloc is called with something
larger than a page, so malloc's result is aligned on a page boundary.
Then valloc aligns the resulting pointer.... which is already aligned...
hence does not change... hence is the pointer returned by malloc... hence
can be passed to free.