gfx/skia/trunk/src/ports/SkPurgeableMemoryBlock_mac.cpp

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 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkPurgeableMemoryBlock.h"
michael@0 9
michael@0 10 #include <mach/mach.h>
michael@0 11
michael@0 12 bool SkPurgeableMemoryBlock::IsSupported() {
michael@0 13 return true;
michael@0 14 }
michael@0 15
michael@0 16 #ifdef SK_DEBUG
michael@0 17 bool SkPurgeableMemoryBlock::PlatformSupportsPurgingAllUnpinnedBlocks() {
michael@0 18 return true;
michael@0 19 }
michael@0 20
michael@0 21 bool SkPurgeableMemoryBlock::PurgeAllUnpinnedBlocks() {
michael@0 22 // Unused.
michael@0 23 int state = 0;
michael@0 24 kern_return_t ret = vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state);
michael@0 25 return ret == KERN_SUCCESS;
michael@0 26 }
michael@0 27
michael@0 28 bool SkPurgeableMemoryBlock::purge() {
michael@0 29 return false;
michael@0 30 }
michael@0 31 #endif
michael@0 32
michael@0 33 static size_t round_to_page_size(size_t size) {
michael@0 34 const size_t mask = 4096 - 1;
michael@0 35 return (size + mask) & ~mask;
michael@0 36 }
michael@0 37
michael@0 38 SkPurgeableMemoryBlock::SkPurgeableMemoryBlock(size_t size)
michael@0 39 : fAddr(NULL)
michael@0 40 , fSize(round_to_page_size(size))
michael@0 41 , fPinned(false) {
michael@0 42 }
michael@0 43
michael@0 44 SkPurgeableMemoryBlock::~SkPurgeableMemoryBlock() {
michael@0 45 SkDEBUGCODE(kern_return_t ret =) vm_deallocate(mach_task_self(),
michael@0 46 reinterpret_cast<vm_address_t>(fAddr),
michael@0 47 static_cast<vm_size_t>(fSize));
michael@0 48 #ifdef SK_DEBUG
michael@0 49 if (ret != KERN_SUCCESS) {
michael@0 50 SkDebugf("SkPurgeableMemoryBlock destructor failed to deallocate.\n");
michael@0 51 }
michael@0 52 #endif
michael@0 53 }
michael@0 54
michael@0 55 void* SkPurgeableMemoryBlock::pin(SkPurgeableMemoryBlock::PinResult* pinResult) {
michael@0 56 SkASSERT(!fPinned);
michael@0 57 SkASSERT(pinResult != NULL);
michael@0 58 if (NULL == fAddr) {
michael@0 59 vm_address_t addr = 0;
michael@0 60 kern_return_t ret = vm_allocate(mach_task_self(), &addr, static_cast<vm_size_t>(fSize),
michael@0 61 VM_FLAGS_PURGABLE | VM_FLAGS_ANYWHERE);
michael@0 62 if (KERN_SUCCESS == ret) {
michael@0 63 fAddr = reinterpret_cast<void*>(addr);
michael@0 64 *pinResult = kUninitialized_PinResult;
michael@0 65 fPinned = true;
michael@0 66 } else {
michael@0 67 fAddr = NULL;
michael@0 68 }
michael@0 69 } else {
michael@0 70 int state = VM_PURGABLE_NONVOLATILE;
michael@0 71 kern_return_t ret = vm_purgable_control(mach_task_self(),
michael@0 72 reinterpret_cast<vm_address_t>(fAddr),
michael@0 73 VM_PURGABLE_SET_STATE, &state);
michael@0 74 if (ret != KERN_SUCCESS) {
michael@0 75 fAddr = NULL;
michael@0 76 fPinned = false;
michael@0 77 return NULL;
michael@0 78 }
michael@0 79
michael@0 80 fPinned = true;
michael@0 81
michael@0 82 if (state & VM_PURGABLE_EMPTY) {
michael@0 83 *pinResult = kUninitialized_PinResult;
michael@0 84 } else {
michael@0 85 *pinResult = kRetained_PinResult;
michael@0 86 }
michael@0 87 }
michael@0 88 return fAddr;
michael@0 89 }
michael@0 90
michael@0 91 void SkPurgeableMemoryBlock::unpin() {
michael@0 92 SkASSERT(fPinned);
michael@0 93 int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT;
michael@0 94 SkDEBUGCODE(kern_return_t ret =) vm_purgable_control(mach_task_self(),
michael@0 95 reinterpret_cast<vm_address_t>(fAddr),
michael@0 96 VM_PURGABLE_SET_STATE, &state);
michael@0 97 fPinned = false;
michael@0 98
michael@0 99 #ifdef SK_DEBUG
michael@0 100 if (ret != KERN_SUCCESS) {
michael@0 101 SkDebugf("SkPurgeableMemoryBlock::unpin() failed.\n");
michael@0 102 }
michael@0 103 #endif
michael@0 104 }

mercurial