gfx/skia/trunk/src/ports/SkTLS_win.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 "SkTLS.h"
michael@0 9 #include "SkThread.h"
michael@0 10
michael@0 11 static bool gOnce = false;
michael@0 12 static DWORD gTlsIndex;
michael@0 13 SK_DECLARE_STATIC_MUTEX(gMutex);
michael@0 14
michael@0 15 void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) {
michael@0 16 if (!forceCreateTheSlot && !gOnce) {
michael@0 17 return NULL;
michael@0 18 }
michael@0 19
michael@0 20 if (!gOnce) {
michael@0 21 SkAutoMutexAcquire tmp(gMutex);
michael@0 22 if (!gOnce) {
michael@0 23 gTlsIndex = TlsAlloc();
michael@0 24 gOnce = true;
michael@0 25 }
michael@0 26 }
michael@0 27 return TlsGetValue(gTlsIndex);
michael@0 28 }
michael@0 29
michael@0 30 void SkTLS::PlatformSetSpecific(void* ptr) {
michael@0 31 SkASSERT(gOnce);
michael@0 32 (void)TlsSetValue(gTlsIndex, ptr);
michael@0 33 }
michael@0 34
michael@0 35 // Call TLS destructors on thread exit. Code based on Chromium's
michael@0 36 // base/threading/thread_local_storage_win.cc
michael@0 37 #ifdef _WIN64
michael@0 38
michael@0 39 #pragma comment(linker, "/INCLUDE:_tls_used")
michael@0 40 #pragma comment(linker, "/INCLUDE:skia_tls_callback")
michael@0 41
michael@0 42 #else
michael@0 43
michael@0 44 #pragma comment(linker, "/INCLUDE:__tls_used")
michael@0 45 #pragma comment(linker, "/INCLUDE:_skia_tls_callback")
michael@0 46
michael@0 47 #endif
michael@0 48
michael@0 49 void NTAPI onTLSCallback(PVOID unused, DWORD reason, PVOID unused2) {
michael@0 50 if ((DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) && gOnce) {
michael@0 51 void* ptr = TlsGetValue(gTlsIndex);
michael@0 52 if (ptr != NULL) {
michael@0 53 SkTLS::Destructor(ptr);
michael@0 54 TlsSetValue(gTlsIndex, NULL);
michael@0 55 }
michael@0 56 }
michael@0 57 }
michael@0 58
michael@0 59 extern "C" {
michael@0 60
michael@0 61 #ifdef _WIN64
michael@0 62
michael@0 63 #pragma const_seg(".CRT$XLB")
michael@0 64 extern const PIMAGE_TLS_CALLBACK skia_tls_callback;
michael@0 65 const PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
michael@0 66 #pragma const_seg()
michael@0 67
michael@0 68 #else
michael@0 69
michael@0 70 #pragma data_seg(".CRT$XLB")
michael@0 71 PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
michael@0 72 #pragma data_seg()
michael@0 73
michael@0 74 #endif
michael@0 75 }

mercurial