1 //===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the llvm::sys::Memory class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SYSTEM_MEMORY_H
15 #define LLVM_SYSTEM_MEMORY_H
20 /// This class encapsulates the notion of a memory block which has an address
21 /// and a size. It is used by the Memory class (a friend) as the result of
22 /// various memory allocation operations.
24 /// @brief Memory block abstraction.
27 void* base() const { return Address; }
28 unsigned size() const { return Size; }
30 void * Address; ///< Address of first byte of memory area
31 unsigned Size; ///< Size, in bytes of the memory area
35 /// This class provides various memory handling functions that manipulate
36 /// MemoryBlock instances.
38 /// @brief An abstraction for memory operations.
43 /// This method allocates a block of Read/Write/Execute memory that is
44 /// suitable for executing dynamically generated code (e.g. JIT). An
45 /// attempt to allocate \p NumBytes bytes of virtual memory is made.
46 /// @throws std::string if an error occurred.
47 /// @brief Allocate Read/Write/Execute memory.
48 static MemoryBlock AllocateRWX(unsigned NumBytes);
50 /// This method releases a block of Read/Write/Execute memory that was
51 /// allocated with the AllocateRWX method. It should not be used to release
52 /// any memory block allocated any other way.
53 /// @throws std::string if an error occurred.
54 /// @brief Release Read/Write/Execute memory.
55 static void ReleaseRWX(MemoryBlock& block);