1 //===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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
22 /// This class encapsulates the notion of a memory block which has an address
23 /// and a size. It is used by the Memory class (a friend) as the result of
24 /// various memory allocation operations.
26 /// @brief Memory block abstraction.
29 void *base() const { return Address; }
30 unsigned size() const { return Size; }
32 void *Address; ///< Address of first byte of memory area
33 unsigned Size; ///< Size, in bytes of the memory area
37 /// This class provides various memory handling functions that manipulate
38 /// MemoryBlock instances.
40 /// @brief An abstraction for memory operations.
45 /// This method allocates a block of Read/Write/Execute memory that is
46 /// suitable for executing dynamically generated code (e.g. JIT). An
47 /// attempt to allocate \p NumBytes bytes of virtual memory is made.
48 /// \p NearBlock may point to an existing allocation in which case
49 /// an attempt is made to allocate more memory near the existing block.
51 /// On success, this returns a non-null memory block, otherwise it returns
52 /// a null memory block and fills in *ErrMsg.
54 /// @brief Allocate Read/Write/Execute memory.
55 static MemoryBlock AllocateRWX(unsigned NumBytes,
56 const MemoryBlock *NearBlock,
57 std::string *ErrMsg = 0);
59 /// This method releases a block of Read/Write/Execute memory that was
60 /// allocated with the AllocateRWX method. It should not be used to
61 /// release any memory block allocated any other way.
63 /// On success, this returns false, otherwise it returns true and fills
65 /// @throws std::string if an error occurred.
66 /// @brief Release Read/Write/Execute memory.
67 static bool ReleaseRWX(MemoryBlock &block, std::string *ErrMsg = 0);