Don't bother checking canRead() before calling getMagicNumber();
[oota-llvm.git] / lib / System / Win32 / Memory.inc
index 9ebef6a71a39cb09741082a6b7484f3b2b86114f..19fccbddc26bd0e6501fea9d5649c456cf37d965 100644 (file)
@@ -2,8 +2,8 @@
 // 
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Jeff Cohen and is distributed under the 
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 // 
 //===----------------------------------------------------------------------===//
 //
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Win32.h"
+#include "llvm/System/DataTypes.h"
 #include "llvm/System/Process.h"
 
 namespace llvm {
@@ -23,16 +24,21 @@ using namespace sys;
 //===          and must not be UNIX code
 //===----------------------------------------------------------------------===//
 
-MemoryBlock Memory::AllocateRWX(unsigned NumBytes) {
+MemoryBlock Memory::AllocateRWX(size_t NumBytes,
+                                const MemoryBlock *NearBlock,
+                                std::string *ErrMsg) {
   if (NumBytes == 0) return MemoryBlock();
 
-  static const long pageSize = Process::GetPageSize();
-  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+  static const size_t pageSize = Process::GetPageSize();
+  size_t NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  //FIXME: support NearBlock if ever needed on Win64.
 
   void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT,
                   PAGE_EXECUTE_READWRITE);
   if (pa == NULL) {
-    ThrowError("Can't allocate RWX Memory: ");
+    MakeErrMsg(ErrMsg, "Can't allocate RWX Memory: ");
+    return MemoryBlock();
   }
 
   MemoryBlock result;
@@ -41,12 +47,27 @@ MemoryBlock Memory::AllocateRWX(unsigned NumBytes) {
   return result;
 }
 
-void Memory::ReleaseRWX(MemoryBlock& M) {
-  if (M.Address == 0 || M.Size == 0) return;
-  if (!VirtualFree(M.Address, 0, MEM_RELEASE)) {
-    ThrowError("Can't release RWX Memory: ");
-  }
+bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
+  if (M.Address == 0 || M.Size == 0) return false;
+  if (!VirtualFree(M.Address, 0, MEM_RELEASE))
+    return MakeErrMsg(ErrMsg, "Can't release RWX Memory: ");
+  return false;
 }
 
+bool Memory::setWritable(MemoryBlock &M, std::string *ErrMsg) {
+  return true;
 }
 
+bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) {
+  return false;
+}
+
+bool Memory::setRangeWritable(const void *Addr, size_t Size) {
+  return true;
+}
+
+bool Memory::setRangeExecutable(const void *Addr, size_t Size) {
+  return false;
+}
+
+}