Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * |
michael@0 | 4 | * ***** BEGIN LICENSE BLOCK ***** |
michael@0 | 5 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
michael@0 | 6 | * |
michael@0 | 7 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 8 | * modification, are permitted provided that the following conditions |
michael@0 | 9 | * are met: |
michael@0 | 10 | * 1. Redistributions of source code must retain the above copyright |
michael@0 | 11 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 14 | * documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * |
michael@0 | 16 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
michael@0 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 18 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
michael@0 | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
michael@0 | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
michael@0 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
michael@0 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
michael@0 | 26 | * THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 27 | * |
michael@0 | 28 | * ***** END LICENSE BLOCK ***** */ |
michael@0 | 29 | |
michael@0 | 30 | #include "assembler/wtf/Platform.h" |
michael@0 | 31 | |
michael@0 | 32 | #if ENABLE_ASSEMBLER && WTF_OS_WINDOWS |
michael@0 | 33 | |
michael@0 | 34 | #include <windows.h> |
michael@0 | 35 | #include "assembler/wtf/Assertions.h" |
michael@0 | 36 | |
michael@0 | 37 | #include "yarr/OSAllocator.h" |
michael@0 | 38 | |
michael@0 | 39 | namespace WTF { |
michael@0 | 40 | |
michael@0 | 41 | static inline DWORD protection(bool writable, bool executable) |
michael@0 | 42 | { |
michael@0 | 43 | return executable ? |
michael@0 | 44 | (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) : |
michael@0 | 45 | (writable ? PAGE_READWRITE : PAGE_READONLY); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable) |
michael@0 | 49 | { |
michael@0 | 50 | void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable)); |
michael@0 | 51 | if (!result) |
michael@0 | 52 | CRASH(); |
michael@0 | 53 | return result; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable) |
michael@0 | 57 | { |
michael@0 | 58 | void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable)); |
michael@0 | 59 | if (!result) |
michael@0 | 60 | CRASH(); |
michael@0 | 61 | return result; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable) |
michael@0 | 65 | { |
michael@0 | 66 | void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable)); |
michael@0 | 67 | if (!result) |
michael@0 | 68 | CRASH(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | void OSAllocator::decommit(void* address, size_t bytes) |
michael@0 | 72 | { |
michael@0 | 73 | bool result = VirtualFree(address, bytes, MEM_DECOMMIT); |
michael@0 | 74 | if (!result) |
michael@0 | 75 | CRASH(); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | void OSAllocator::releaseDecommitted(void* address, size_t bytes) |
michael@0 | 79 | { |
michael@0 | 80 | // According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx, |
michael@0 | 81 | // dwSize must be 0 if dwFreeType is MEM_RELEASE. |
michael@0 | 82 | bool result = VirtualFree(address, 0, MEM_RELEASE); |
michael@0 | 83 | if (!result) |
michael@0 | 84 | CRASH(); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | } // namespace WTF |
michael@0 | 88 | |
michael@0 | 89 | #endif |