X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fbigalloc.c;h=9581188cc046f8171241ef5bfde20e64a44e5a0c;hb=5a78c3505ae7fa76a061e26676450049ec5946d5;hp=a1060e60be7d3cb7185bfff87b4f4c92aa33083f;hpb=4adf195fb2f36dfbd054745469fa1c580de2f61b;p=libucw.git diff --git a/lib/bigalloc.c b/lib/bigalloc.c index a1060e60..9581188c 100644 --- a/lib/bigalloc.c +++ b/lib/bigalloc.c @@ -26,6 +26,14 @@ page_alloc(u64 len) return p; } +void * +page_alloc_zero(u64 len) +{ + void *p = page_alloc(len); + bzero(p, len); + return p; +} + void page_free(void *start, u64 len) { @@ -52,31 +60,42 @@ 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; } +void * +big_alloc_zero(u64 len) +{ + void *p = big_alloc(len); + bzero(p, big_round(len)); + return p; +} + 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