js/src/yarr/OSAllocatorWin.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial