diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index f5f0ab730f..b6e4ada312 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.107 2008/11/12 09:41:49 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.108 2008/11/13 07:38:45 otto Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> |
4 | * | 4 | * |
@@ -64,6 +64,13 @@ | |||
64 | #define MALLOC_MAXCHUNK (1 << (MALLOC_PAGESHIFT-1)) | 64 | #define MALLOC_MAXCHUNK (1 << (MALLOC_PAGESHIFT-1)) |
65 | #define MALLOC_MAXCACHE 256 | 65 | #define MALLOC_MAXCACHE 256 |
66 | #define MALLOC_DELAYED_CHUNKS 16 /* should be power of 2 */ | 66 | #define MALLOC_DELAYED_CHUNKS 16 /* should be power of 2 */ |
67 | /* | ||
68 | * When the P option is active, we move allocations between half a page | ||
69 | * and a whole page towards the end, subject to alignment constraints. | ||
70 | * This is the extra headroom we allow. Set to zero to be the most | ||
71 | * strict. | ||
72 | */ | ||
73 | #define MALLOC_LEEWAY 16 | ||
67 | 74 | ||
68 | #define PAGEROUND(x) (((x) + (MALLOC_PAGEMASK)) & ~MALLOC_PAGEMASK) | 75 | #define PAGEROUND(x) (((x) + (MALLOC_PAGEMASK)) & ~MALLOC_PAGEMASK) |
69 | 76 | ||
@@ -1081,12 +1088,12 @@ omalloc(size_t sz, int zero_fill) | |||
1081 | } | 1088 | } |
1082 | 1089 | ||
1083 | if (malloc_move && | 1090 | if (malloc_move && |
1084 | sz - malloc_guard < MALLOC_PAGESIZE - MALLOC_MINSIZE) { | 1091 | sz - malloc_guard < MALLOC_PAGESIZE - MALLOC_LEEWAY) { |
1085 | /* fill whole allocation */ | 1092 | /* fill whole allocation */ |
1086 | if (malloc_junk) | 1093 | if (malloc_junk) |
1087 | memset(p, SOME_JUNK, psz - malloc_guard); | 1094 | memset(p, SOME_JUNK, psz - malloc_guard); |
1088 | /* shift towards the end */ | 1095 | /* shift towards the end */ |
1089 | p = ((char *)p) + ((MALLOC_PAGESIZE - MALLOC_MINSIZE - | 1096 | p = ((char *)p) + ((MALLOC_PAGESIZE - MALLOC_LEEWAY - |
1090 | (sz - malloc_guard)) & ~(MALLOC_MINSIZE-1)); | 1097 | (sz - malloc_guard)) & ~(MALLOC_MINSIZE-1)); |
1091 | /* fill zeros if needed and overwritten above */ | 1098 | /* fill zeros if needed and overwritten above */ |
1092 | if (zero_fill && malloc_junk) | 1099 | if (zero_fill && malloc_junk) |
@@ -1177,9 +1184,11 @@ ofree(void *p) | |||
1177 | } | 1184 | } |
1178 | REALSIZE(sz, r); | 1185 | REALSIZE(sz, r); |
1179 | if (sz > MALLOC_MAXCHUNK) { | 1186 | if (sz > MALLOC_MAXCHUNK) { |
1180 | if (sz - malloc_guard >= MALLOC_PAGESIZE - MALLOC_MINSIZE) { | 1187 | if (sz - malloc_guard >= MALLOC_PAGESIZE - MALLOC_LEEWAY) { |
1181 | if (r->p != p) | 1188 | if (r->p != p) { |
1182 | wrterror("bogus pointer"); | 1189 | wrterror("bogus pointer"); |
1190 | return; | ||
1191 | } | ||
1183 | } else { | 1192 | } else { |
1184 | #if notyetbecause_of_realloc | 1193 | #if notyetbecause_of_realloc |
1185 | /* shifted towards the end */ | 1194 | /* shifted towards the end */ |