diff options
author | otto <> | 2008-08-25 17:56:17 +0000 |
---|---|---|
committer | otto <> | 2008-08-25 17:56:17 +0000 |
commit | f1cdd30b5c0055da3d496515af889a0ba4fb6467 (patch) | |
tree | 2768f3befad9518143e4e0931d85d400344e1ee7 /src | |
parent | 2c1c90021954987a22bb7b30dc795b3f2dea16b1 (diff) | |
download | openbsd-f1cdd30b5c0055da3d496515af889a0ba4fb6467.tar.gz openbsd-f1cdd30b5c0055da3d496515af889a0ba4fb6467.tar.bz2 openbsd-f1cdd30b5c0055da3d496515af889a0ba4fb6467.zip |
Make all combinations of G, P, J and zero-fill work with as little
effort as possible in most cases; ok djm@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 1cbe7fa084..be80640e81 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.97 2008/08/23 07:49:38 djm Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.98 2008/08/25 17:56:17 otto Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> |
4 | * | 4 | * |
@@ -1078,8 +1078,6 @@ omalloc(size_t sz, int zero_fill) | |||
1078 | errno = ENOMEM; | 1078 | errno = ENOMEM; |
1079 | return NULL; | 1079 | return NULL; |
1080 | } | 1080 | } |
1081 | if (malloc_junk) | ||
1082 | memset(p + sz, SOME_JUNK, psz - sz); | ||
1083 | if (malloc_guard) { | 1081 | if (malloc_guard) { |
1084 | if (mprotect((char *)p + psz - malloc_guard, | 1082 | if (mprotect((char *)p + psz - malloc_guard, |
1085 | malloc_guard, PROT_NONE)) | 1083 | malloc_guard, PROT_NONE)) |
@@ -1087,11 +1085,28 @@ omalloc(size_t sz, int zero_fill) | |||
1087 | malloc_guarded += malloc_guard; | 1085 | malloc_guarded += malloc_guard; |
1088 | } | 1086 | } |
1089 | 1087 | ||
1090 | /* shift towards the end */ | ||
1091 | if (malloc_move && | 1088 | if (malloc_move && |
1092 | sz - malloc_guard < MALLOC_PAGESIZE - MALLOC_MINSIZE) | 1089 | sz - malloc_guard < MALLOC_PAGESIZE - MALLOC_MINSIZE) { |
1090 | /* fill whole allocation */ | ||
1091 | if (malloc_junk) | ||
1092 | memset(p, SOME_JUNK, psz - malloc_guard); | ||
1093 | /* shift towards the end */ | ||
1093 | p = ((char *)p) + ((MALLOC_PAGESIZE - MALLOC_MINSIZE - | 1094 | p = ((char *)p) + ((MALLOC_PAGESIZE - MALLOC_MINSIZE - |
1094 | (sz - malloc_guard)) & ~(MALLOC_MINSIZE-1)); | 1095 | (sz - malloc_guard)) & ~(MALLOC_MINSIZE-1)); |
1096 | /* fill zeros if needed and overwritten above */ | ||
1097 | if (zero_fill && malloc_junk) | ||
1098 | memset(p, 0, sz - malloc_guard); | ||
1099 | } else { | ||
1100 | if (malloc_junk) { | ||
1101 | if (zero_fill) | ||
1102 | memset(p + sz - malloc_guard, | ||
1103 | SOME_JUNK, psz - sz); | ||
1104 | else | ||
1105 | memset(p, | ||
1106 | SOME_JUNK, psz - malloc_guard); | ||
1107 | } | ||
1108 | } | ||
1109 | |||
1095 | } else { | 1110 | } else { |
1096 | /* takes care of SOME_JUNK */ | 1111 | /* takes care of SOME_JUNK */ |
1097 | p = malloc_bytes(&g_pool, sz); | 1112 | p = malloc_bytes(&g_pool, sz); |