From 4adf195fb2f36dfbd054745469fa1c580de2f61b Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Fri, 18 May 2007 16:48:34 +0200 Subject: [PATCH] fixed support for 64bit big allocations --- lib/bigalloc.c | 17 +++++++++-------- lib/lib.h | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/bigalloc.c b/lib/bigalloc.c index e4b9faf1..a1060e60 100644 --- a/lib/bigalloc.c +++ b/lib/bigalloc.c @@ -12,19 +12,22 @@ #include #include +#include void * -page_alloc(unsigned int len) +page_alloc(u64 len) { + if (len > SIZE_MAX) + die("page_alloc: Size %llu is too large for the current architecture", (long long) len); ASSERT(!(len & (CPU_PAGE_SIZE-1))); byte *p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (p == (byte*) MAP_FAILED) - die("Cannot mmap %d bytes of memory: %m", len); + die("Cannot mmap %llu bytes of memory: %m", (long long)len); return p; } void -page_free(void *start, unsigned int len) +page_free(void *start, u64 len) { ASSERT(!(len & (CPU_PAGE_SIZE-1))); ASSERT(!((uintptr_t) start & (CPU_PAGE_SIZE-1))); @@ -32,7 +35,7 @@ page_free(void *start, unsigned int len) } void * -page_realloc(void *start, unsigned int old_len, unsigned int new_len) +page_realloc(void *start, u64 old_len, u64 new_len) { void *p = page_alloc(new_len); memcpy(p, start, MIN(old_len, new_len)); @@ -50,10 +53,8 @@ void * big_alloc(u64 len) { len = big_round(len); -#ifndef CPU_64BIT_POINTERS - if (len > 0xff000000) - die("big_alloc: Size %ju is too large for a 32-bit machine", (uintmax_t) len); -#endif + if (len > 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; #endif diff --git a/lib/lib.h b/lib/lib.h index 41a6283a..7e0e7f09 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -268,9 +268,9 @@ byte *str_format_flags(byte *dest, const byte *fmt, uns flags); /* bigalloc.c */ -void *page_alloc(unsigned int len) LIKE_MALLOC; // allocates a multiple of CPU_PAGE_SIZE bytes with mmap -void page_free(void *start, unsigned int len); -void *page_realloc(void *start, unsigned int old_len, unsigned int new_len); +void *page_alloc(u64 len) LIKE_MALLOC; // allocates a multiple of CPU_PAGE_SIZE bytes with mmap +void page_free(void *start, u64 len); +void *page_realloc(void *start, u64 old_len, u64 new_len); void *big_alloc(u64 len) LIKE_MALLOC; // allocate a large memory block in the most efficient way available void big_free(void *start, u64 len); -- 2.39.2