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
18 #include "llvm/System/IncludeFile.h"
23 /// This class encapsulates the notion of a memory block which has an address
24 /// and a size. It is used by the Memory class (a friend) as the result of
25 /// various memory allocation operations.
27 /// @brief Memory block abstraction.
30 void *base() const { return Address; }
31 unsigned size() const { return Size; }
33 void *Address; ///< Address of first byte of memory area
34 unsigned Size; ///< Size, in bytes of the memory area
38 /// This class provides various memory handling functions that manipulate
39 /// MemoryBlock instances.
41 /// @brief An abstraction for memory operations.
46 /// This method allocates a block of Read/Write/Execute memory that is
47 /// suitable for executing dynamically generated code (e.g. JIT). An
48 /// attempt to allocate \p NumBytes bytes of virtual memory is made.
49 /// \p NearBlock may point to an existing allocation in which case
50 /// an attempt is made to allocate more memory near the existing block.
52 /// On success, this returns a non-null memory block, otherwise it returns
53 /// a null memory block and fills in *ErrMsg.
55 /// @brief Allocate Read/Write/Execute memory.
56 static MemoryBlock AllocateRWX(unsigned NumBytes,
57 const MemoryBlock *NearBlock,
58 std::string *ErrMsg = 0);
60 /// This method releases a block of Read/Write/Execute memory that was
61 /// allocated with the AllocateRWX method. It should not be used to
62 /// release any memory block allocated any other way.
64 /// On success, this returns false, otherwise it returns true and fills
66 /// @throws std::string if an error occurred.
67 /// @brief Release Read/Write/Execute memory.
68 static bool ReleaseRWX(MemoryBlock &block, std::string *ErrMsg = 0);
74 FORCE_DEFINING_FILE_TO_BE_LINKED(SystemMemory)