1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/yarr/OSAllocatorWin.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,89 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * 1.7 + * ***** BEGIN LICENSE BLOCK ***** 1.8 + * Copyright (C) 2010 Apple Inc. All rights reserved. 1.9 + * 1.10 + * Redistribution and use in source and binary forms, with or without 1.11 + * modification, are permitted provided that the following conditions 1.12 + * are met: 1.13 + * 1. Redistributions of source code must retain the above copyright 1.14 + * notice, this list of conditions and the following disclaimer. 1.15 + * 2. Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 1.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 1.21 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.22 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 1.23 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 1.29 + * THE POSSIBILITY OF SUCH DAMAGE. 1.30 + * 1.31 + * ***** END LICENSE BLOCK ***** */ 1.32 + 1.33 +#include "assembler/wtf/Platform.h" 1.34 + 1.35 +#if ENABLE_ASSEMBLER && WTF_OS_WINDOWS 1.36 + 1.37 +#include <windows.h> 1.38 +#include "assembler/wtf/Assertions.h" 1.39 + 1.40 +#include "yarr/OSAllocator.h" 1.41 + 1.42 +namespace WTF { 1.43 + 1.44 +static inline DWORD protection(bool writable, bool executable) 1.45 +{ 1.46 + return executable ? 1.47 + (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) : 1.48 + (writable ? PAGE_READWRITE : PAGE_READONLY); 1.49 +} 1.50 + 1.51 +void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable) 1.52 +{ 1.53 + void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable)); 1.54 + if (!result) 1.55 + CRASH(); 1.56 + return result; 1.57 +} 1.58 + 1.59 +void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable) 1.60 +{ 1.61 + void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable)); 1.62 + if (!result) 1.63 + CRASH(); 1.64 + return result; 1.65 +} 1.66 + 1.67 +void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable) 1.68 +{ 1.69 + void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable)); 1.70 + if (!result) 1.71 + CRASH(); 1.72 +} 1.73 + 1.74 +void OSAllocator::decommit(void* address, size_t bytes) 1.75 +{ 1.76 + bool result = VirtualFree(address, bytes, MEM_DECOMMIT); 1.77 + if (!result) 1.78 + CRASH(); 1.79 +} 1.80 + 1.81 +void OSAllocator::releaseDecommitted(void* address, size_t bytes) 1.82 +{ 1.83 + // According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx, 1.84 + // dwSize must be 0 if dwFreeType is MEM_RELEASE. 1.85 + bool result = VirtualFree(address, 0, MEM_RELEASE); 1.86 + if (!result) 1.87 + CRASH(); 1.88 +} 1.89 + 1.90 +} // namespace WTF 1.91 + 1.92 +#endif