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
|
|
|
|
2006-07-07 17:32:37 +00:00
|
|
|
#include <string>
|
2006-07-26 16:18:00 +00:00
|
|
|
#include "llvm/System/IncludeFile.h"
|
2006-07-07 17:32:37 +00:00
|
|
|
|
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:
|
2006-07-07 17:32:37 +00:00
|
|
|
void *base() const { return Address; }
|
2004-09-13 22:38:11 +00:00
|
|
|
unsigned size() const { return Size; }
|
|
|
|
private:
|
2006-07-07 17:32:37 +00:00
|
|
|
void *Address; ///< Address of first byte of memory area
|
2004-09-13 22:38:11 +00:00
|
|
|
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.
|
2006-07-07 17:32:37 +00:00
|
|
|
///
|
|
|
|
/// On success, this returns a non-null memory block, otherwise it returns
|
|
|
|
/// a null memory block and fills in *ErrMsg.
|
|
|
|
///
|
2004-09-13 22:38:11 +00:00
|
|
|
/// @brief Allocate Read/Write/Execute memory.
|
2006-07-07 17:32:37 +00:00
|
|
|
static MemoryBlock AllocateRWX(unsigned NumBytes,
|
|
|
|
const MemoryBlock *NearBlock,
|
|
|
|
std::string *ErrMsg = 0);
|
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.
|
2006-07-07 17:32:37 +00:00
|
|
|
///
|
|
|
|
/// On success, this returns false, otherwise it returns true and fills
|
|
|
|
/// in *ErrMsg.
|
2004-09-13 22:38:11 +00:00
|
|
|
/// @throws std::string if an error occurred.
|
|
|
|
/// @brief Release Read/Write/Execute memory.
|
2006-07-07 17:32:37 +00:00
|
|
|
static bool ReleaseRWX(MemoryBlock &block, std::string *ErrMsg = 0);
|
2004-09-11 04:20:58 +00:00
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 16:18:00 +00:00
|
|
|
FORCE_DEFINING_FILE_TO_BE_LINKED(SystemMemory)
|
|
|
|
|
2004-09-11 04:20:58 +00:00
|
|
|
#endif
|