Only include funccheck() if we're not compiling for the kernel; the kernel
does not have stdarg.h.
Have the poolcheck routines use functions provided by the pool allocator
for memory allocation and failure reporting.  These operations depend upon
the environment in which the poolchecks are running.
Removed unnecessary header files from poolcheck code.

llvm-svn: 87285
diff --git a/safecode/runtime/KernelSafePoolAllocator/PoolAllocatorBitMask.cpp b/safecode/runtime/KernelSafePoolAllocator/PoolAllocatorBitMask.cpp
index 0c214aa..b1663c2 100755
--- a/safecode/runtime/KernelSafePoolAllocator/PoolAllocatorBitMask.cpp
+++ b/safecode/runtime/KernelSafePoolAllocator/PoolAllocatorBitMask.cpp
@@ -1158,3 +1158,13 @@
   Splay *poolchecksplay(void *Pool) {
     return ((PoolTy *)Pool)->splay;
   }
+
+  void poolcheckfail (const char * msg) {
+    fprintf (stderr, msg);
+    fflush (stderr);
+    exit (-1);
+  }
+
+  void * poolcheckmalloc (unsigned int size) {
+    return malloc (size);
+  }
diff --git a/safecode/runtime/KernelSafePoolAllocator/PoolCheck.cpp b/safecode/runtime/KernelSafePoolAllocator/PoolCheck.cpp
index ca6ce9a..60fe708 100755
--- a/safecode/runtime/KernelSafePoolAllocator/PoolCheck.cpp
+++ b/safecode/runtime/KernelSafePoolAllocator/PoolCheck.cpp
@@ -18,11 +18,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "PoolCheck.h"
-#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
+#ifdef LLVA_KERNEL
 #include <stdarg.h>
+#endif
 #define DEBUG(x) 
 
 //===----------------------------------------------------------------------===//
@@ -47,7 +45,7 @@
   if (MetaPool) {
     MetaPool = MetaPool->next;
   } else {
-    *MP = (MetaPoolTy *) malloc(sizeof(MetaPoolTy));
+    *MP = (MetaPoolTy *) poolcheckmalloc (sizeof(MetaPoolTy));
     (*MP)->Pool = P;
     (*MP)->next = 0;
     return;
@@ -57,7 +55,7 @@
     MetaPoolPrev = MetaPool;
   }
   //MetaPool is null;
-  MetaPoolPrev->next = (MetaPoolTy *) malloc(sizeof(MetaPoolTy));
+  MetaPoolPrev->next = (MetaPoolTy *) poolcheckmalloc (sizeof(MetaPoolTy));
   MetaPoolPrev->next->Pool = P;
   MetaPoolPrev->next->next = 0;
 }
@@ -104,8 +102,7 @@
 void poolcheckarray(MetaPoolTy **MP, void *NodeSrc, void *NodeResult) {
   MetaPoolTy *MetaPool = *MP;
   if (!MetaPool) {
-    printf("Empty meta pool? \n");
-    exit(-1);
+    poolcheckfail ("Empty meta pool? \n");
   }
   //iteratively search through the list
   //Check if there are other efficient data structures.
@@ -114,15 +111,13 @@
     if (poolcheckarrayoptim(Pool, NodeSrc, NodeResult)) return ;
     MetaPool = MetaPool->next;
   }
-  printf("poolcheck failure \n");
-  exit(-1);
+  poolcheckfail ("poolcheck failure \n");
 }
 
 void poolcheck(MetaPoolTy **MP, void *Node) {
   MetaPoolTy *MetaPool = *MP;
   if (!MetaPool) {
-    printf("Empty meta pool? \n");
-    exit(-1);
+    poolcheckfail ("Empty meta pool? \n");
   }
   //    iteratively search through the list
   //Check if there are other efficient data structures.
@@ -132,8 +127,7 @@
     if (poolcheckoptim(Pool, Node))   return;
     MetaPool = MetaPool->next;
   }
-  printf("poolcheck failure \n");
-  exit(-1);
+  poolcheckfail ("poolcheck failure \n");
 }
 
 
@@ -143,7 +137,7 @@
   if (PCS) {
     PCS = PCS->nextSlab;
   } else {
-    *PCSPtr = (PoolCheckSlab *) malloc(sizeof(PoolCheckSlab));
+    *PCSPtr = (PoolCheckSlab *) poolcheckmalloc (sizeof(PoolCheckSlab));
     (*PCSPtr)->Slab = Slab;
     (*PCSPtr)->nextSlab = 0;
     return;
@@ -153,7 +147,7 @@
     PCSPrev = PCS;
   }
   //PCS is null;
-  PCSPrev->nextSlab = (PoolCheckSlab *) malloc(sizeof(PoolCheckSlab));
+  PCSPrev->nextSlab = (PoolCheckSlab *) poolcheckmalloc (sizeof(PoolCheckSlab));
   PCSPrev->nextSlab->Slab = Slab;
   PCSPrev->nextSlab->nextSlab = 0;
 }
@@ -161,11 +155,15 @@
 
   void exactcheck(int a, int b) {
     if ((0 > a) || (a >= b)) {
-      fprintf(stderr, "exact check failed\n");
-      exit(-1);
+      poolcheckfail ("exact check failed\n");
     }
   }
 
+  //
+  // Disable this for kernel code.  I'm not sure how kernel code handles
+  // va_list type functions.
+  //
+#ifdef LLVA_KERNEL
   void funccheck(unsigned num, void *f, void *g, ...) {
     va_list ap;
     unsigned i = 0;
@@ -180,6 +178,7 @@
     }
     abort();
   }
+#endif
 
   void poolcheckregister(Splay *splay, void * allocaptr, unsigned NumBytes) {
     splay_insert_ptr(splay, (unsigned long)(allocaptr), NumBytes);
diff --git a/safecode/runtime/KernelSafePoolAllocator/PoolCheck.h b/safecode/runtime/KernelSafePoolAllocator/PoolCheck.h
index 687bb8d..a193502 100755
--- a/safecode/runtime/KernelSafePoolAllocator/PoolCheck.h
+++ b/safecode/runtime/KernelSafePoolAllocator/PoolCheck.h
@@ -46,6 +46,8 @@
   // Functions that need to be provided by the pool allocation run-time
   PoolCheckSlab *poolcheckslab(void *Pool);
   Splay *poolchecksplay(void *Pool);
+  void poolcheckfail (const char * msg);
+  void * poolcheckmalloc (unsigned int size);
 #ifdef __cpluscplus
 }
 #endif