LLVM API Documentation
00001 //===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file provides the Win32 specific implementation of various Memory 00011 // management utilities 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #include "Win32.h" 00016 #include "llvm/System/Process.h" 00017 00018 namespace llvm { 00019 using namespace sys; 00020 00021 //===----------------------------------------------------------------------===// 00022 //=== WARNING: Implementation here must contain only Win32 specific code 00023 //=== and must not be UNIX code 00024 //===----------------------------------------------------------------------===// 00025 00026 MemoryBlock Memory::AllocateRWX(unsigned NumBytes, 00027 const MemoryBlock *NearBlock, 00028 std::string *ErrMsg) { 00029 if (NumBytes == 0) return MemoryBlock(); 00030 00031 static const long pageSize = Process::GetPageSize(); 00032 unsigned NumPages = (NumBytes+pageSize-1)/pageSize; 00033 00034 //FIXME: support NearBlock if ever needed on Win64. 00035 00036 void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT, 00037 PAGE_EXECUTE_READWRITE); 00038 if (pa == NULL) { 00039 MakeErrMsg(ErrMsg, "Can't allocate RWX Memory: "); 00040 return MemoryBlock(); 00041 } 00042 00043 MemoryBlock result; 00044 result.Address = pa; 00045 result.Size = NumPages*pageSize; 00046 return result; 00047 } 00048 00049 bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) { 00050 if (M.Address == 0 || M.Size == 0) return false; 00051 if (!VirtualFree(M.Address, 0, MEM_RELEASE)) 00052 return MakeErrMsg(ErrMsg, "Can't release RWX Memory: "); 00053 return false; 00054 } 00055 00056 bool Memory::setWritable(MemoryBlock &M, std::string *ErrMsg) { 00057 return true; 00058 } 00059 00060 bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) { 00061 return false; 00062 } 00063 00064 bool Memory::setRangeWritable(const void *Addr, size_t Size) { 00065 return true; 00066 } 00067 00068 bool Memory::setRangeExecutable(const void *Addr, size_t Size) { 00069 return false; 00070 } 00071 00072 }