malloc(0) returns 0x800 on FreeBSD 6.2 ?

Andrew Reilly andrew at areilly.bpc-users.org
Mon Dec 11 17:47:58 PST 2006


On Mon, 11 Dec 2006 12:25:44 -0600
Dan Nelson <dnelson at allantgroup.com> wrote:

> The FreeBSD 6.x behaviour is slightly against POSIX rules that state
> all successful malloc calls must return unique pointers, so the 7.x
> malloc silently rounds zero-size mallocs to 1.  Ideally malloc would
> return unique pointers to blocks of memory set to MPROT_NONE via
> mprotect() (you could fit 8192 of these pointers in an 8k page), to

Could you, really?  I'm not a language lawyer, and this is a
language-lawyer question, but I would have expected that the
maximal alignment rule would prevent you from allocating more
than 512 or 1024 "unique, valid" pointers in a page.  Perhaps
there is no alignment requirement on a zero-byte object?

Just curious.  I don't care about the actual implementation, and
I thought that handing out a special MPROT_NONE page was a good
idea...

> prevent applications from using that byte of memory.

Cheers,

-- 
Andrew


More information about the freebsd-stable mailing list