LLVM API Documentation
00001 //===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Reid Spencer and is distributed under the 00006 // University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the llvm::sys::Memory class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SYSTEM_MEMORY_H 00015 #define LLVM_SYSTEM_MEMORY_H 00016 00017 namespace llvm { 00018 namespace sys { 00019 00020 /// This class encapsulates the notion of a memory block which has an address 00021 /// and a size. It is used by the Memory class (a friend) as the result of 00022 /// various memory allocation operations. 00023 /// @see Memory 00024 /// @brief Memory block abstraction. 00025 class MemoryBlock { 00026 public: 00027 void* base() const { return Address; } 00028 unsigned size() const { return Size; } 00029 private: 00030 void * Address; ///< Address of first byte of memory area 00031 unsigned Size; ///< Size, in bytes of the memory area 00032 friend class Memory; 00033 }; 00034 00035 /// This class provides various memory handling functions that manipulate 00036 /// MemoryBlock instances. 00037 /// @since 1.4 00038 /// @brief An abstraction for memory operations. 00039 class Memory { 00040 /// @name Functions 00041 /// @{ 00042 public: 00043 /// This method allocates a block of Read/Write/Execute memory that is 00044 /// suitable for executing dynamically generated code (e.g. JIT). An 00045 /// attempt to allocate \p NumBytes bytes of virtual memory is made. 00046 /// @throws std::string if an error occurred. 00047 /// @brief Allocate Read/Write/Execute memory. 00048 static MemoryBlock AllocateRWX(unsigned NumBytes); 00049 00050 /// This method releases a block of Read/Write/Execute memory that was 00051 /// allocated with the AllocateRWX method. It should not be used to release 00052 /// any memory block allocated any other way. 00053 /// @throws std::string if an error occurred. 00054 /// @brief Release Read/Write/Execute memory. 00055 static void ReleaseRWX(MemoryBlock& block); 00056 /// @} 00057 }; 00058 } 00059 } 00060 00061 // vim: sw=2 00062 00063 #endif