From: Pavel Charvat Date: Fri, 1 Jun 2007 13:45:48 +0000 (+0200) Subject: big_alloc: check if big_alloc and big_free sizes match X-Git-Tag: holmes-import~506^2~13^2~109 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=22e2db8b109438537f95e5841aff836d3ce9977d;p=libucw.git big_alloc: check if big_alloc and big_free sizes match --- diff --git a/lib/bigalloc.c b/lib/bigalloc.c index ee84b7b5..9581188c 100644 --- a/lib/bigalloc.c +++ b/lib/bigalloc.c @@ -60,16 +60,17 @@ big_round(u64 len) void * big_alloc(u64 len) { - len = big_round(len); - if (len > SIZE_MAX - 2*CPU_PAGE_SIZE) + u64 l = big_round(len); + if (l > SIZE_MAX - 2*CPU_PAGE_SIZE) die("big_alloc: Size %llu is too large for the current architecture", (long long) len); #ifdef CONFIG_DEBUG - len += 2*CPU_PAGE_SIZE; + l += 2*CPU_PAGE_SIZE; #endif - byte *p = page_alloc(len); + byte *p = page_alloc(l); #ifdef CONFIG_DEBUG + *(u64*)p = len; mprotect(p, CPU_PAGE_SIZE, PROT_NONE); - mprotect(p+len-CPU_PAGE_SIZE, CPU_PAGE_SIZE, PROT_NONE); + mprotect(p+l-CPU_PAGE_SIZE, CPU_PAGE_SIZE, PROT_NONE); p += CPU_PAGE_SIZE; #endif return p; @@ -87,12 +88,14 @@ void big_free(void *start, u64 len) { byte *p = start; - len = big_round(len); + u64 l = big_round(len); #ifdef CONFIG_DEBUG p -= CPU_PAGE_SIZE; - len += 2*CPU_PAGE_SIZE; + mprotect(p, CPU_PAGE_SIZE, PROT_READ); + ASSERT(*(u64*)p == len); + l += 2*CPU_PAGE_SIZE; #endif - page_free(p, len); + page_free(p, l); } #ifdef TEST