1 //===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Jeff Cohen and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides the Win32 specific implementation of various Memory
11 // management utilities
13 //===----------------------------------------------------------------------===//
16 #include "llvm/System/Memory.h"
17 #include "llvm/System/Process.h"
22 //===----------------------------------------------------------------------===//
23 //=== WARNING: Implementation here must contain only Win32 specific code
24 //=== and must not be UNIX code
25 //===----------------------------------------------------------------------===//
27 MemoryBlock Memory::AllocateRWX(unsigned NumBytes) {
28 if (NumBytes == 0) return MemoryBlock();
30 static const long pageSize = Process::GetPageSize();
31 unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
33 void *pa = VirtualAlloc(NULL, NumPages*pageSize, MEM_COMMIT,
34 PAGE_EXECUTE_READWRITE);
36 ThrowError("Can't allocate RWX Memory: ");
41 result.Size = NumPages*pageSize;
45 void Memory::ReleaseRWX(MemoryBlock& M) {
46 if (M.Address == 0 || M.Size == 0) return;
47 if (!VirtualFree(M.Address, 0, MEM_RELEASE)) {
48 ThrowError("Can't release RWX Memory: ");
54 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab