MemoryManager.cpp

Go to the documentation of this file.
00001 //===-- MemoryManager.cpp -------------------------------------------------===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "Common.h"
00011 
00012 #include "CoreStats.h"
00013 #include "Memory.h"
00014 #include "MemoryManager.h"
00015 
00016 #include "klee/ExecutionState.h"
00017 #include "klee/Expr.h"
00018 #include "klee/Solver.h"
00019 
00020 #include "llvm/Support/CommandLine.h"
00021 
00022 using namespace klee;
00023 
00024 /***/
00025 
00026 MemoryManager::~MemoryManager() { 
00027   while (!objects.empty()) {
00028     MemoryObject *mo = objects.back();
00029     objects.pop_back();
00030     delete mo;
00031   }
00032 }
00033 
00034 MemoryObject *MemoryManager::allocate(uint64_t size, bool isLocal, bool isGlobal,
00035                                       const llvm::Value *allocSite) {
00036   if (size>10*1024*1024) {
00037     klee_warning_once(0, "failing large alloc: %u bytes", (unsigned) size);
00038     return 0;
00039   }
00040   uint64_t address = (uint64_t) (unsigned long) malloc((unsigned) size);
00041   if (!address)
00042     return 0;
00043   
00044   ++stats::allocations;
00045   MemoryObject *res = new MemoryObject(address, size, isLocal, isGlobal, false,
00046                                        allocSite);
00047   objects.push_back(res);
00048   return res;
00049 }
00050 
00051 MemoryObject *MemoryManager::allocateFixed(uint64_t address, uint64_t size,
00052                                            const llvm::Value *allocSite) {
00053 #ifndef NDEBUG
00054   for (objects_ty::iterator it = objects.begin(), ie = objects.end();
00055        it != ie; ++it) {
00056     MemoryObject *mo = *it;
00057     assert(!(address+size > mo->address && address < mo->address+mo->size) &&
00058            "allocated an overlapping object");
00059   }
00060 #endif
00061 
00062   ++stats::allocations;
00063   MemoryObject *res = new MemoryObject(address, size, false, true, true,
00064                                        allocSite);
00065   objects.push_back(res);
00066   return res;
00067 }
00068 
00069 void MemoryManager::deallocate(const MemoryObject *mo) {
00070   assert(0);
00071 }

Generated on Fri Jun 5 03:31:31 2009 for klee by  doxygen 1.5.8