js/src/yarr/OSAllocator.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 #ifndef yarr_OSAllocator_h
michael@0 31 #define yarr_OSAllocator_h
michael@0 32
michael@0 33 #include <stdlib.h>
michael@0 34 #include "yarr/wtfbridge.h"
michael@0 35 #include "assembler/wtf/VMTags.h"
michael@0 36 #include "assembler/wtf/Assertions.h"
michael@0 37
michael@0 38 namespace WTF {
michael@0 39
michael@0 40 class OSAllocator {
michael@0 41 public:
michael@0 42 enum Usage {
michael@0 43 UnknownUsage = -1,
michael@0 44 FastMallocPages = VM_TAG_FOR_TCMALLOC_MEMORY,
michael@0 45 JSGCHeapPages = VM_TAG_FOR_COLLECTOR_MEMORY,
michael@0 46 JSVMStackPages = VM_TAG_FOR_REGISTERFILE_MEMORY,
michael@0 47 JSJITCodePages = VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY
michael@0 48 };
michael@0 49
michael@0 50 // These methods are symmetric; reserveUncommitted allocates VM in an uncommitted state,
michael@0 51 // releaseDecommitted should be called on a region of VM allocated by a single reservation,
michael@0 52 // the memory must all currently be in a decommitted state.
michael@0 53 static void* reserveUncommitted(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
michael@0 54 static void releaseDecommitted(void*, size_t);
michael@0 55
michael@0 56 // These methods are symmetric; they commit or decommit a region of VM (uncommitted VM should
michael@0 57 // never be accessed, since the OS may not have attached physical memory for these regions).
michael@0 58 // Clients should only call commit on uncommitted regions and decommit on committed regions.
michael@0 59 static void commit(void*, size_t, bool writable, bool executable);
michael@0 60 static void decommit(void*, size_t);
michael@0 61
michael@0 62 // These methods are symmetric; reserveAndCommit allocates VM in an committed state,
michael@0 63 // decommitAndRelease should be called on a region of VM allocated by a single reservation,
michael@0 64 // the memory must all currently be in a committed state.
michael@0 65 static void* reserveAndCommit(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
michael@0 66 static void decommitAndRelease(void* base, size_t size);
michael@0 67
michael@0 68 // These methods are akin to reserveAndCommit/decommitAndRelease, above - however rather than
michael@0 69 // committing/decommitting the entire region additional parameters allow a subregion to be
michael@0 70 // specified.
michael@0 71 static void* reserveAndCommit(size_t reserveSize, size_t commitSize, Usage = UnknownUsage, bool writable = true, bool executable = false);
michael@0 72 static void decommitAndRelease(void* releaseBase, size_t releaseSize, void* decommitBase, size_t decommitSize);
michael@0 73 };
michael@0 74
michael@0 75 inline void* OSAllocator::reserveAndCommit(size_t reserveSize, size_t commitSize, Usage usage, bool writable, bool executable)
michael@0 76 {
michael@0 77 void* base = reserveUncommitted(reserveSize, usage, writable, executable);
michael@0 78 commit(base, commitSize, writable, executable);
michael@0 79 return base;
michael@0 80 }
michael@0 81
michael@0 82 inline void OSAllocator::decommitAndRelease(void* releaseBase, size_t releaseSize, void* decommitBase, size_t decommitSize)
michael@0 83 {
michael@0 84 ASSERT(decommitBase >= releaseBase && (static_cast<char*>(decommitBase) + decommitSize) <= (static_cast<char*>(releaseBase) + releaseSize));
michael@0 85 #if WTF_OS_WINCE || WTF_OS_SYMBIAN
michael@0 86 // On most platforms we can actually skip this final decommit; releasing the VM will
michael@0 87 // implicitly decommit any physical memory in the region. This is not true on WINCE.
michael@0 88 // On Symbian, this makes implementation simpler and better aligned with the RChunk API
michael@0 89 decommit(decommitBase, decommitSize);
michael@0 90 #endif
michael@0 91 releaseDecommitted(releaseBase, releaseSize);
michael@0 92 }
michael@0 93
michael@0 94 inline void OSAllocator::decommitAndRelease(void* base, size_t size)
michael@0 95 {
michael@0 96 decommitAndRelease(base, size, base, size);
michael@0 97 }
michael@0 98
michael@0 99 } // namespace WTF
michael@0 100
michael@0 101 using WTF::OSAllocator;
michael@0 102
michael@0 103 #endif /* yarr_OSAllocator_h */

mercurial