This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: malloc using mprotect
Hello,
> No, that will actually take one VMA too, provided it is anonymous private
> mapping. mmap does some minimal merging
> /* Can we just expand an old anonymous mapping? */
Ok, how about the appended simple patch then? Behaviour should then
be the same as with sbrk().
Regards,
Wolfram.
2001-08-10 Wolfram Gloger <wg@malloc.de>
* malloc/malloc.c (grow_heap): Use mmap() rather than mprotect()
to allocate new memory, for better performance with Linux-2.4.x.
Index: malloc.c
===================================================================
RCS file: /cvs/glibc/libc/malloc/malloc.c,v
retrieving revision 1.83
diff -u -r1.83 malloc.c
--- malloc.c 2001/07/18 20:33:54 1.83
+++ malloc.c 2001/08/10 12:25:08
@@ -2078,7 +2078,8 @@
new_size = (long)h->size + diff;
if(new_size > HEAP_MAX_SIZE)
return -1;
- if(mprotect((char *)h + h->size, diff, PROT_READ|PROT_WRITE) != 0)
+ if((char *)MMAP((char *)h + h->size, diff, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_FIXED) == (char *) MAP_FAILED)
return -2;
} else {
new_size = (long)h->size + diff;