summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorotto <>2016-10-12 07:36:38 +0000
committerotto <>2016-10-12 07:36:38 +0000
commitf630946338f9031d4355cb3e6854cefc69ca7193 (patch)
treebfebf79858643b66ea357579415fc485c833e1a8 /src/lib
parentce6f98553e9389a9df158dab95df0a9eafe22d8f (diff)
downloadopenbsd-f630946338f9031d4355cb3e6854cefc69ca7193.tar.gz
openbsd-f630946338f9031d4355cb3e6854cefc69ca7193.tar.bz2
openbsd-f630946338f9031d4355cb3e6854cefc69ca7193.zip
optimize canary code a bit by storing offset of sizes table instead of
recomputing it all the time
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/stdlib/malloc.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index ba3124eac6..fe80af08c5 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.199 2016/10/07 05:55:37 otto Exp $ */ 1/* $OpenBSD: malloc.c,v 1.200 2016/10/12 07:36:38 otto Exp $ */
2/* 2/*
3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> 3 * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> 4 * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
@@ -165,6 +165,7 @@ struct chunk_info {
165 u_short shift; /* how far to shift for this size */ 165 u_short shift; /* how far to shift for this size */
166 u_short free; /* how many free chunks */ 166 u_short free; /* how many free chunks */
167 u_short total; /* how many chunks */ 167 u_short total; /* how many chunks */
168 u_short offset; /* requested size table offset */
168 /* which chunks are free */ 169 /* which chunks are free */
169 u_short bits[1]; 170 u_short bits[1];
170}; 171};
@@ -916,6 +917,7 @@ omalloc_make_chunks(struct dir_info *d, int bits, int listnum)
916 bp->size = 1U << bits; 917 bp->size = 1U << bits;
917 bp->shift = bits; 918 bp->shift = bits;
918 bp->total = bp->free = MALLOC_PAGESIZE >> bits; 919 bp->total = bp->free = MALLOC_PAGESIZE >> bits;
920 bp->offset = howmany(bp->total, MALLOC_BITS);
919 bp->page = pp; 921 bp->page = pp;
920 } 922 }
921 923
@@ -1025,7 +1027,7 @@ malloc_bytes(struct dir_info *d, size_t argsize, void *f)
1025 k += (lp - bp->bits) * MALLOC_BITS; 1027 k += (lp - bp->bits) * MALLOC_BITS;
1026 1028
1027 if (mopts.chunk_canaries) 1029 if (mopts.chunk_canaries)
1028 bp->bits[howmany(bp->total, MALLOC_BITS) + k] = argsize; 1030 bp->bits[bp->offset + k] = argsize;
1029 1031
1030 k <<= bp->shift; 1032 k <<= bp->shift;
1031 1033
@@ -1056,8 +1058,7 @@ find_chunknum(struct dir_info *d, struct region_info *r, void *ptr, int check)
1056 /* Find the chunk number on the page */ 1058 /* Find the chunk number on the page */
1057 chunknum = ((uintptr_t)ptr & MALLOC_PAGEMASK) >> info->shift; 1059 chunknum = ((uintptr_t)ptr & MALLOC_PAGEMASK) >> info->shift;
1058 if (check && mopts.chunk_canaries && info->size > 0) { 1060 if (check && mopts.chunk_canaries && info->size > 0) {
1059 size_t sz = info->bits[howmany(info->total, MALLOC_BITS) + 1061 size_t sz = info->bits[info->offset + chunknum];
1060 chunknum];
1061 size_t check_sz = info->size - sz; 1062 size_t check_sz = info->size - sz;
1062 u_char *p, *q; 1063 u_char *p, *q;
1063 1064
@@ -1280,7 +1281,8 @@ malloc(size_t size)
1280/*DEF_STRONG(malloc);*/ 1281/*DEF_STRONG(malloc);*/
1281 1282
1282static void 1283static void
1283validate_junk(struct dir_info *pool, void *p) { 1284validate_junk(struct dir_info *pool, void *p)
1285{
1284 struct region_info *r; 1286 struct region_info *r;
1285 size_t byte, sz; 1287 size_t byte, sz;
1286 1288