bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: libio/libioP.h:ALLOC_BUF() unconditionally uses mmap()


From: Wayne Whitney
Subject: Re: libio/libioP.h:ALLOC_BUF() unconditionally uses mmap()
Date: Fri, 14 Dec 2001 00:25:03 -0800 (PST)

On 13 Dec 2001, Wolfram Gloger wrote:

> Ugh, is that absolutely necessary?  You really need 3GB _contiguous_
> memory?

Well, the program as written just calls sbrk() when it needs more memory;  
if sbrk() fails, it assumes it is out of memory.  Then it has its own
allocator on top of sbrk().

So I'm trying to figure which would be easiest to modify--the kernel,
glibc, or the program.  Of course, whenever I ask the maintainer of one of
these, they say I should go change one of the other two.  :-)

> IIRC, mmap() was used precisely to make it possible for user
> applications to override malloc and friends.  This is because eg. the
> buffer for stdin can be allocated very early, even before main() has
> started.  If 'malloc' was used, the hook pointers for overriding might
> still point to the system allocations, and then later the user-defined
> routine for free() might be used on the I/O buffer with disastrous
> consequences.

Speaking as a complete glibc novice, isn't there something like __malloc()
and __free() in glibc, internal routines around which malloc() and free()  
are simple wrappers?  Then even if malloc() and free() are redefined, the
internal routines __malloc() and __free() would be available, so the stdio
routines could use them.

The argument for not using mmap() explicitly here is that it seems that it
is the only place that does not obey the malloc() tuning environment
variables.  For example, it is the only mmap() in the way of this program
sbrk()'ing to the top of the user address space.

> I'd suggest that you reconfigure the kernel to map at something like
> 0xA0000000 or something.  I believe there are patches around to make
> this runtime-configurable via a /proc setting.

If you have a reference for this, that would be very helpful, as it is
something I did not think existed and have considered implementing myself.  
Although I do not yet understand how to do this, the best solution that
has been suggested to me is to set a value in the binary (an ELF section
attribute?) that would tell Linux where to start mmap() allocations for
that particular process.

Cheers, Wayne







reply via email to

[Prev in Thread] Current Thread [Next in Thread]