]> mj.ucw.cz Git - libucw.git/commitdiff
big_alloc() now takes a 64-bit argument.
authorMartin Mares <mj@ucw.cz>
Fri, 2 Feb 2007 12:54:46 +0000 (13:54 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 2 Feb 2007 12:54:46 +0000 (13:54 +0100)
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.

lib/bigalloc.c
lib/lib.h

index ad6aeff0cd523e9acc97bcc53408e8367abb989d..2ed76df31502b24886a6925fd3ad22d1c24ebb63 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     UCW Library -- Allocation of Large Aligned Buffers
  *
- *     (c) 2006 Martin Mares <mj@ucw.cz>
+ *     (c) 2006--2007 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
 
 #include <sys/mman.h>
 
-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)));
index ea795c92d8f220a0c4ab405114301e2462c630a5..554d9ecbd5d7b1561a12408b39058f8886faf529 100644 (file)
--- 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