[dovecot-cvs] dovecot/src/lib mmap-anon.c,1.8,1.9
cras at procontrol.fi
cras at procontrol.fi
Sat Dec 28 09:04:04 EET 2002
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv1858/lib
Modified Files:
mmap-anon.c
Log Message:
Keep the mmap()ed area far from heap.
Index: mmap-anon.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mmap-anon.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mmap-anon.c 27 Dec 2002 15:39:10 -0000 1.8
+++ mmap-anon.c 28 Dec 2002 07:04:01 -0000 1.9
@@ -34,6 +34,7 @@
#ifndef HAVE_LINUX_MREMAP
+#include <stdlib.h>
#include <sys/mman.h>
/* MMAP_BASE_MOVE may be negative as well */
@@ -58,18 +59,28 @@
static int page_size = 0;
static int header_size = 0;
static void *movable_mmap_base = NULL;
-static void *mmap_top_limit = NULL;
+static void *mmap_top_limit, *mmap_heap_bottom, *mmap_heap_top;
static void movable_mmap_init(void)
{
+ ssize_t abs_base_move;
char x;
+ abs_base_move = MMAP_BASE_MOVE;
+ if (abs_base_move < 0)
+ abs_base_move = -abs_base_move;
+
page_size = getpagesize();
header_size = page_size;
/* keep our allocations far below stack. assumes the stack is
growing down. */
- mmap_top_limit = &x - (1024*1024*256);
+ mmap_top_limit = &x - abs_base_move*2;
+
+ /* keep our allocations far from heap */
+ mmap_heap_bottom = malloc(1);
+ mmap_heap_top = (char *) mmap_heap_bottom + abs_base_move*2;
+ free(mmap_heap_bottom);
}
static int anon_mmap_fixed(void *address, size_t length)
@@ -149,6 +160,12 @@
if ((char *) movable_mmap_base + length >=
(char *) mmap_top_limit) {
/* too high, stack could grow over it */
+ continue;
+ }
+
+ if ((char *) movable_mmap_base >= (char *) mmap_heap_bottom &&
+ (char *) movable_mmap_base < (char *) mmap_heap_top) {
+ /* too near heap */
continue;
}
More information about the dovecot-cvs
mailing list