2004-09-11 04:59:30 +00:00
|
|
|
//===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-09-11 04:59:30 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides the Win32 specific implementation of various Memory
|
|
|
|
// management utilities
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-15 05:49:50 +00:00
|
|
|
#include "Win32.h"
|
2009-07-23 21:46:56 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2004-09-15 05:49:50 +00:00
|
|
|
#include "llvm/System/Process.h"
|
2004-09-11 04:59:30 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
using namespace sys;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2004-09-15 05:49:50 +00:00
|
|
|
//=== WARNING: Implementation here must contain only Win32 specific code
|
|
|
|
//=== and must not be UNIX code
|
2004-09-11 04:59:30 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-23 21:46:56 +00:00
|
|
|
MemoryBlock Memory::AllocateRWX(size_t NumBytes,
|
2006-07-07 17:32:37 +00:00
|
|
|
const MemoryBlock *NearBlock,
|
|
|
|
std::string *ErrMsg) {
|
2004-09-13 22:38:11 +00:00
|
|
|
if (NumBytes == 0) return MemoryBlock();
|
2004-09-11 04:59:30 +00:00
|
|
|
|
2009-07-23 21:46:56 +00:00
|
|
|
static const size_t pageSize = Process::GetPageSize();
|
|
|
|
size_t NumPages = (NumBytes+pageSize-1)/pageSize;
|
2004-09-15 05:49:50 +00:00
|
|
|
|
2005-07-29 23:40:16 +00:00
|
|
|
//FIXME: support NearBlock if ever needed on Win64.
|
|
|
|
|
2004-09-15 05:49:50 +00:00
|
|
|
void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT,
|
|
|
|
PAGE_EXECUTE_READWRITE);
|
|
|
|
if (pa == NULL) {
|
2006-08-25 21:37:17 +00:00
|
|
|
MakeErrMsg(ErrMsg, "Can't allocate RWX Memory: ");
|
2006-07-07 17:32:37 +00:00
|
|
|
return MemoryBlock();
|
2004-09-11 04:59:30 +00:00
|
|
|
}
|
2004-09-15 05:49:50 +00:00
|
|
|
|
2004-09-13 22:38:11 +00:00
|
|
|
MemoryBlock result;
|
2004-09-15 05:49:50 +00:00
|
|
|
result.Address = pa;
|
|
|
|
result.Size = NumPages*pageSize;
|
2004-09-13 22:38:11 +00:00
|
|
|
return result;
|
2004-09-11 04:59:30 +00:00
|
|
|
}
|
|
|
|
|
2006-07-07 17:32:37 +00:00
|
|
|
bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
|
2006-07-26 20:37:11 +00:00
|
|
|
if (M.Address == 0 || M.Size == 0) return false;
|
2006-07-07 17:32:37 +00:00
|
|
|
if (!VirtualFree(M.Address, 0, MEM_RELEASE))
|
2006-08-25 21:37:17 +00:00
|
|
|
return MakeErrMsg(ErrMsg, "Can't release RWX Memory: ");
|
2006-07-26 20:37:11 +00:00
|
|
|
return false;
|
2004-09-11 04:59:30 +00:00
|
|
|
}
|
2004-09-15 05:49:50 +00:00
|
|
|
|
2008-10-20 21:39:23 +00:00
|
|
|
bool Memory::setWritable(MemoryBlock &M, std::string *ErrMsg) {
|
2008-10-04 08:15:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-20 21:39:23 +00:00
|
|
|
bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) {
|
2008-10-04 08:15:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-20 21:39:23 +00:00
|
|
|
bool Memory::setRangeWritable(const void *Addr, size_t Size) {
|
|
|
|
return true;
|
2004-09-15 05:49:50 +00:00
|
|
|
}
|
|
|
|
|
2008-10-20 21:39:23 +00:00
|
|
|
bool Memory::setRangeExecutable(const void *Addr, size_t Size) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|