michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * michael@0: * ***** BEGIN LICENSE BLOCK ***** michael@0: * Copyright (C) 2010 Apple Inc. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * 1. Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * 2. Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' michael@0: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, michael@0: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR michael@0: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS michael@0: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF michael@0: * THE POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: * ***** END LICENSE BLOCK ***** */ michael@0: michael@0: #include "assembler/wtf/Platform.h" michael@0: michael@0: #if ENABLE_ASSEMBLER && WTF_OS_WINDOWS michael@0: michael@0: #include michael@0: #include "assembler/wtf/Assertions.h" michael@0: michael@0: #include "yarr/OSAllocator.h" michael@0: michael@0: namespace WTF { michael@0: michael@0: static inline DWORD protection(bool writable, bool executable) michael@0: { michael@0: return executable ? michael@0: (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) : michael@0: (writable ? PAGE_READWRITE : PAGE_READONLY); michael@0: } michael@0: michael@0: void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable) michael@0: { michael@0: void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable)); michael@0: if (!result) michael@0: CRASH(); michael@0: return result; michael@0: } michael@0: michael@0: void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable) michael@0: { michael@0: void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable)); michael@0: if (!result) michael@0: CRASH(); michael@0: return result; michael@0: } michael@0: michael@0: void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable) michael@0: { michael@0: void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable)); michael@0: if (!result) michael@0: CRASH(); michael@0: } michael@0: michael@0: void OSAllocator::decommit(void* address, size_t bytes) michael@0: { michael@0: bool result = VirtualFree(address, bytes, MEM_DECOMMIT); michael@0: if (!result) michael@0: CRASH(); michael@0: } michael@0: michael@0: void OSAllocator::releaseDecommitted(void* address, size_t bytes) michael@0: { michael@0: // According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx, michael@0: // dwSize must be 0 if dwFreeType is MEM_RELEASE. michael@0: bool result = VirtualFree(address, 0, MEM_RELEASE); michael@0: if (!result) michael@0: CRASH(); michael@0: } michael@0: michael@0: } // namespace WTF michael@0: michael@0: #endif