Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "SyncProfile.h" |
michael@0 | 8 | #include "UnwinderThread2.h" |
michael@0 | 9 | |
michael@0 | 10 | SyncProfile::SyncProfile(const char* aName, int aEntrySize, PseudoStack *aStack, |
michael@0 | 11 | Thread::tid_t aThreadId, bool aIsMainThread) |
michael@0 | 12 | : ThreadProfile(aName, aEntrySize, aStack, aThreadId, |
michael@0 | 13 | Sampler::AllocPlatformData(aThreadId), aIsMainThread, |
michael@0 | 14 | tlsStackTop.get()), |
michael@0 | 15 | mOwnerState(REFERENCED), |
michael@0 | 16 | mUtb(nullptr) |
michael@0 | 17 | { |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | SyncProfile::~SyncProfile() |
michael@0 | 21 | { |
michael@0 | 22 | if (mUtb) { |
michael@0 | 23 | utb__release_sync_buffer(mUtb); |
michael@0 | 24 | } |
michael@0 | 25 | Sampler::FreePlatformData(GetPlatformData()); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | bool |
michael@0 | 29 | SyncProfile::SetUWTBuffer(LinkedUWTBuffer* aBuff) |
michael@0 | 30 | { |
michael@0 | 31 | MOZ_ASSERT(aBuff); |
michael@0 | 32 | mUtb = aBuff; |
michael@0 | 33 | return true; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | bool |
michael@0 | 37 | SyncProfile::ShouldDestroy() |
michael@0 | 38 | { |
michael@0 | 39 | GetMutex()->AssertNotCurrentThreadOwns(); |
michael@0 | 40 | mozilla::MutexAutoLock lock(*GetMutex()); |
michael@0 | 41 | if (mOwnerState == OWNED) { |
michael@0 | 42 | mOwnerState = OWNER_DESTROYING; |
michael@0 | 43 | return true; |
michael@0 | 44 | } |
michael@0 | 45 | mOwnerState = ORPHANED; |
michael@0 | 46 | return false; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | void |
michael@0 | 50 | SyncProfile::EndUnwind() |
michael@0 | 51 | { |
michael@0 | 52 | // Mutex must be held when this is called |
michael@0 | 53 | GetMutex()->AssertCurrentThreadOwns(); |
michael@0 | 54 | if (mOwnerState != ORPHANED) { |
michael@0 | 55 | flush(); |
michael@0 | 56 | mOwnerState = OWNED; |
michael@0 | 57 | } |
michael@0 | 58 | // Save mOwnerState before we release the mutex |
michael@0 | 59 | OwnerState ownerState = mOwnerState; |
michael@0 | 60 | ThreadProfile::EndUnwind(); |
michael@0 | 61 | if (ownerState == ORPHANED) { |
michael@0 | 62 | delete this; |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 |