andre@0: Index: mozilla/nsprpub/pr/include/prtypes.h andre@0: =================================================================== andre@0: RCS file: /cvsroot/mozilla/nsprpub/pr/include/prtypes.h,v andre@0: retrieving revision 3.52 andre@0: diff -p -u -8 -r3.52 prtypes.h andre@0: --- mozilla/nsprpub/pr/include/prtypes.h 7 Dec 2012 21:13:41 -0000 3.52 andre@0: +++ mozilla/nsprpub/pr/include/prtypes.h 29 Jan 2013 01:15:02 -0000 andre@0: @@ -43,17 +43,33 @@ andre@0: ** Example: andre@0: ** in dowhim.h andre@0: ** PR_EXTERN( void ) DoWhatIMean( void ); andre@0: ** in dowhim.c andre@0: ** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; } andre@0: ** andre@0: ** andre@0: ***********************************************************************/ andre@0: -#if defined(WIN32) andre@0: +#if defined(NSPR_STATIC) andre@0: + andre@0: +#define PR_EXPORT(__type) extern __type andre@0: +#define PR_EXPORT_DATA(__type) extern __type andre@0: +#define PR_IMPORT(__type) extern __type andre@0: +#define PR_IMPORT_DATA(__type) extern __type andre@0: + andre@0: +#define PR_EXTERN(__type) extern __type andre@0: +#define PR_IMPLEMENT(__type) __type andre@0: +#define PR_EXTERN_DATA(__type) extern __type andre@0: +#define PR_IMPLEMENT_DATA(__type) __type andre@0: + andre@0: +#define PR_CALLBACK andre@0: +#define PR_CALLBACK_DECL andre@0: +#define PR_STATIC_CALLBACK(__x) static __x andre@0: + andre@0: +#elif defined(WIN32) andre@0: andre@0: #define PR_EXPORT(__type) extern __declspec(dllexport) __type andre@0: #define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type andre@0: #define PR_IMPORT(__type) __declspec(dllimport) __type andre@0: #define PR_IMPORT_DATA(__type) __declspec(dllimport) __type andre@0: andre@0: #define PR_EXTERN(__type) extern __declspec(dllexport) __type andre@0: #define PR_IMPLEMENT(__type) __declspec(dllexport) __type andre@0: Index: mozilla/nsprpub/pr/src/md/windows/w95dllmain.c andre@0: =================================================================== andre@0: RCS file: /cvsroot/mozilla/nsprpub/pr/src/md/windows/w95dllmain.c,v andre@0: retrieving revision 3.9 andre@0: diff -p -u -8 -r3.9 w95dllmain.c andre@0: --- mozilla/nsprpub/pr/src/md/windows/w95dllmain.c 6 Mar 2012 13:14:17 -0000 3.9 andre@0: +++ mozilla/nsprpub/pr/src/md/windows/w95dllmain.c 29 Jan 2013 01:15:02 -0000 andre@0: @@ -1,13 +1,15 @@ andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: +#ifndef NSPR_STATIC /* See the end of w95thred.c. */ andre@0: + andre@0: /* andre@0: * The DLL entry point (DllMain) for NSPR. andre@0: * andre@0: * This is used to detach threads that were automatically attached by andre@0: * nspr. andre@0: */ andre@0: andre@0: #include andre@0: @@ -32,8 +34,10 @@ PRThread *me; andre@0: _PRI_DetachThread(); andre@0: } andre@0: break; andre@0: case DLL_PROCESS_DETACH: andre@0: break; andre@0: } andre@0: return TRUE; andre@0: } andre@0: + andre@0: +#endif andre@0: Index: mozilla/nsprpub/pr/src/md/windows/w95thred.c andre@0: =================================================================== andre@0: RCS file: /cvsroot/mozilla/nsprpub/pr/src/md/windows/w95thred.c,v andre@0: retrieving revision 3.22 andre@0: diff -p -u -8 -r3.22 w95thred.c andre@0: --- mozilla/nsprpub/pr/src/md/windows/w95thred.c 13 Jun 2012 02:17:05 -0000 3.22 andre@0: +++ mozilla/nsprpub/pr/src/md/windows/w95thred.c 29 Jan 2013 01:15:02 -0000 andre@0: @@ -313,8 +313,125 @@ PRThread *thread; andre@0: andre@0: if (NULL == thread) { andre@0: thread = _PRI_AttachThread( andre@0: PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0); andre@0: } andre@0: PR_ASSERT(thread != NULL); andre@0: return thread; andre@0: } andre@0: + andre@0: +#ifdef NSPR_STATIC andre@0: + andre@0: +// The following code is from Chromium src/base/thread_local_storage_win.cc, andre@0: +// r11329. andre@0: + andre@0: +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. andre@0: +// andre@0: +// Redistribution and use in source and binary forms, with or without andre@0: +// modification, are permitted provided that the following conditions are andre@0: +// met: andre@0: +// andre@0: +// * Redistributions of source code must retain the above copyright andre@0: +// notice, this list of conditions and the following disclaimer. andre@0: +// * Redistributions in binary form must reproduce the above andre@0: +// copyright notice, this list of conditions and the following disclaimer andre@0: +// in the documentation and/or other materials provided with the andre@0: +// distribution. andre@0: +// * Neither the name of Google Inc. nor the names of its andre@0: +// contributors may be used to endorse or promote products derived from andre@0: +// this software without specific prior written permission. andre@0: +// andre@0: +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS andre@0: +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT andre@0: +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR andre@0: +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT andre@0: +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, andre@0: +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT andre@0: +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, andre@0: +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY andre@0: +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT andre@0: +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE andre@0: +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. andre@0: + andre@0: +// Thread Termination Callbacks. andre@0: +// Windows doesn't support a per-thread destructor with its andre@0: +// TLS primitives. So, we build it manually by inserting a andre@0: +// function to be called on each thread's exit. andre@0: +// This magic is from http://www.codeproject.com/threads/tls.asp andre@0: +// and it works for VC++ 7.0 and later. andre@0: + andre@0: +// Force a reference to _tls_used to make the linker create the TLS directory andre@0: +// if it's not already there. (e.g. if __declspec(thread) is not used). andre@0: +// Force a reference to p_thread_callback_nspr to prevent whole program andre@0: +// optimization from discarding the variable. andre@0: +#ifdef _WIN64 andre@0: + andre@0: +#pragma comment(linker, "/INCLUDE:_tls_used") andre@0: +#pragma comment(linker, "/INCLUDE:p_thread_callback_nspr") andre@0: + andre@0: +#else // _WIN64 andre@0: + andre@0: +#pragma comment(linker, "/INCLUDE:__tls_used") andre@0: +#pragma comment(linker, "/INCLUDE:_p_thread_callback_nspr") andre@0: + andre@0: +#endif // _WIN64 andre@0: + andre@0: +// Static callback function to call with each thread termination. andre@0: +static void NTAPI PR_OnThreadExit(PVOID module, DWORD reason, PVOID reserved) andre@0: +{ andre@0: +PRThread *me; andre@0: + andre@0: + switch (reason) { andre@0: + case DLL_PROCESS_ATTACH: andre@0: + break; andre@0: + case DLL_THREAD_ATTACH: andre@0: + break; andre@0: + case DLL_THREAD_DETACH: andre@0: + if (_pr_initialized) { andre@0: + me = _MD_GET_ATTACHED_THREAD(); andre@0: + if ((me != NULL) && (me->flags & _PR_ATTACHED)) andre@0: + _PRI_DetachThread(); andre@0: + } andre@0: + break; andre@0: + case DLL_PROCESS_DETACH: andre@0: + break; andre@0: + } andre@0: +} andre@0: + andre@0: +// .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are andre@0: +// called automatically by the OS loader code (not the CRT) when the module is andre@0: +// loaded and on thread creation. They are NOT called if the module has been andre@0: +// loaded by a LoadLibrary() call. It must have implicitly been loaded at andre@0: +// process startup. andre@0: +// By implicitly loaded, I mean that it is directly referenced by the main EXE andre@0: +// or by one of its dependent DLLs. Delay-loaded DLL doesn't count as being andre@0: +// implicitly loaded. andre@0: +// andre@0: +// See VC\crt\src\tlssup.c for reference. andre@0: + andre@0: +// The linker must not discard p_thread_callback_nspr. (We force a reference andre@0: +// to this variable with a linker /INCLUDE:symbol pragma to ensure that.) If andre@0: +// this variable is discarded, the PR_OnThreadExit function will never be andre@0: +// called. andre@0: +#ifdef _WIN64 andre@0: + andre@0: +// .CRT section is merged with .rdata on x64 so it must be constant data. andre@0: +#pragma const_seg(".CRT$XLB") andre@0: +// When defining a const variable, it must have external linkage to be sure the andre@0: +// linker doesn't discard it. andre@0: +extern const PIMAGE_TLS_CALLBACK p_thread_callback_nspr; andre@0: +const PIMAGE_TLS_CALLBACK p_thread_callback_nspr = PR_OnThreadExit; andre@0: + andre@0: +// Reset the default section. andre@0: +#pragma const_seg() andre@0: + andre@0: +#else // _WIN64 andre@0: + andre@0: +#pragma data_seg(".CRT$XLB") andre@0: +PIMAGE_TLS_CALLBACK p_thread_callback_nspr = PR_OnThreadExit; andre@0: + andre@0: +// Reset the default section. andre@0: +#pragma data_seg() andre@0: + andre@0: +#endif // _WIN64 andre@0: + andre@0: +#endif // NSPR_STATIC