From: Martin Mares Date: Fri, 2 Feb 2007 12:54:46 +0000 (+0100) Subject: big_alloc() now takes a 64-bit argument. X-Git-Tag: holmes-import~506^2~13^2~178 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=7442c1c86d2210ca3ef1538115f4a0423cd2f046;p=libucw.git big_alloc() now takes a 64-bit argument. We would like to allocate buffers larger than 4 GB on 64-bit machines. I've purposefully used u64 instead of size_t, because configuration variables for buffer sizes will be usually u64's and big_alloc() is the proper place to report buffer size errors. --- diff --git a/lib/bigalloc.c b/lib/bigalloc.c index ad6aeff0..2ed76df3 100644 --- a/lib/bigalloc.c +++ b/lib/bigalloc.c @@ -1,7 +1,7 @@ /* * UCW Library -- Allocation of Large Aligned Buffers * - * (c) 2006 Martin Mares + * (c) 2006--2007 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -11,16 +11,20 @@ #include -static unsigned int -big_round(unsigned int len) +static u64 +big_round(u64 len) { - return ALIGN_TO(len, CPU_PAGE_SIZE); + return ALIGN_TO(len, (u64)CPU_PAGE_SIZE); } void * -big_alloc(unsigned int len) +big_alloc(u64 len) { len = big_round(len); +#ifndef CPU_64BIT_POINTERS + if (len > 0xff000000) + die("big_alloc: Size %08Lx is too large for a 32-bit machine", (long long) len); +#endif #ifdef CONFIG_DEBUG len += 2*CPU_PAGE_SIZE; #endif @@ -36,7 +40,7 @@ big_alloc(unsigned int len) } void -big_free(void *start, unsigned int len) +big_free(void *start, u64 len) { byte *p = start; ASSERT(!((uintptr_t) p & (CPU_PAGE_SIZE-1))); diff --git a/lib/lib.h b/lib/lib.h index ea795c92..554d9ecb 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -265,7 +265,7 @@ byte *str_unesc(byte *dest, byte *src); /* bigalloc.c */ -void *big_alloc(unsigned int len); -void big_free(void *start, unsigned int len); +void *big_alloc(u64 len); +void big_free(void *start, u64 len); #endif