]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/bigalloc.c
Opt: fixed nothing-supplied detection
[libucw.git] / ucw / bigalloc.c
index 7532a446239bb11b320455a7059f63053c8be306..0044846d5d541fb06a03c56f90df8715a0898e2b 100644 (file)
@@ -8,7 +8,7 @@
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
+#include <ucw/lib.h>
 
 #include <sys/mman.h>
 #include <string.h>
@@ -17,6 +17,8 @@
 void *
 page_alloc(u64 len)
 {
+  if (!len)
+    return NULL;
   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)));
@@ -63,11 +65,11 @@ big_alloc(u64 len)
   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
+#ifdef CONFIG_UCW_DEBUG
   l += 2*CPU_PAGE_SIZE;
 #endif
   byte *p = page_alloc(l);
-#ifdef CONFIG_DEBUG
+#ifdef CONFIG_UCW_DEBUG
   *(u64*)p = len;
   mprotect(p, CPU_PAGE_SIZE, PROT_NONE);
   mprotect(p+l-CPU_PAGE_SIZE, CPU_PAGE_SIZE, PROT_NONE);
@@ -89,7 +91,7 @@ big_free(void *start, u64 len)
 {
   byte *p = start;
   u64 l = big_round(len);
-#ifdef CONFIG_DEBUG
+#ifdef CONFIG_UCW_DEBUG
   p -= CPU_PAGE_SIZE;
   mprotect(p, CPU_PAGE_SIZE, PROT_READ);
   ASSERT(*(u64*)p == len);