2004-09-11 04:20:58 +00:00
|
|
|
//===- llvm/System/Memory.h - Memory Support --------------------*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-09-11 04:20:58 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-21 20:48:15 +00:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-09-11 04:20:58 +00:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-09-11 04:20:58 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the llvm::sys::Memory class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-13 22:38:11 +00:00
|
|
|
#ifndef LLVM_SYSTEM_MEMORY_H
|
|
|
|
#define LLVM_SYSTEM_MEMORY_H
|
2004-09-11 04:20:58 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
|
|
|
|
2004-09-13 22:38:11 +00:00
|
|
|
/// This class encapsulates the notion of a memory block which has an address
|
|
|
|
/// and a size. It is used by the Memory class (a friend) as the result of
|
|
|
|
/// various memory allocation operations.
|
|
|
|
/// @see Memory
|
|
|
|
/// @brief Memory block abstraction.
|
|
|
|
class MemoryBlock {
|
|
|
|
public:
|
|
|
|
void* base() const { return Address; }
|
|
|
|
unsigned size() const { return Size; }
|
|
|
|
private:
|
|
|
|
void * Address; ///< Address of first byte of memory area
|
|
|
|
unsigned Size; ///< Size, in bytes of the memory area
|
|
|
|
friend class Memory;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This class provides various memory handling functions that manipulate
|
|
|
|
/// MemoryBlock instances.
|
2004-09-11 04:20:58 +00:00
|
|
|
/// @since 1.4
|
2004-09-13 22:38:11 +00:00
|
|
|
/// @brief An abstraction for memory operations.
|
2004-09-11 04:20:58 +00:00
|
|
|
class Memory {
|
|
|
|
/// @name Functions
|
|
|
|
/// @{
|
|
|
|
public:
|
2004-09-13 22:38:11 +00:00
|
|
|
/// This method allocates a block of Read/Write/Execute memory that is
|
|
|
|
/// suitable for executing dynamically generated code (e.g. JIT). An
|
2005-04-21 20:48:15 +00:00
|
|
|
/// attempt to allocate \p NumBytes bytes of virtual memory is made.
|
2005-07-29 23:40:16 +00:00
|
|
|
/// \p NearBlock may point to an existing allocation in which case
|
|
|
|
/// an attempt is made to allocate more memory near the existing block.
|
2004-09-13 22:38:11 +00:00
|
|
|
/// @throws std::string if an error occurred.
|
|
|
|
/// @brief Allocate Read/Write/Execute memory.
|
2005-07-29 23:40:16 +00:00
|
|
|
static MemoryBlock AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock);
|
2004-09-13 22:38:11 +00:00
|
|
|
|
|
|
|
/// This method releases a block of Read/Write/Execute memory that was
|
2005-04-21 20:48:15 +00:00
|
|
|
/// allocated with the AllocateRWX method. It should not be used to
|
2004-12-20 00:58:41 +00:00
|
|
|
/// release any memory block allocated any other way.
|
2004-09-13 22:38:11 +00:00
|
|
|
/// @throws std::string if an error occurred.
|
|
|
|
/// @brief Release Read/Write/Execute memory.
|
|
|
|
static void ReleaseRWX(MemoryBlock& block);
|
2004-12-20 00:58:41 +00:00
|
|
|
|
2004-09-11 04:20:58 +00:00
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|