| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" // NOLINT | 5 #include "platform/globals.h" // NOLINT |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "vm/os_thread.h" | 8 #include "vm/os_thread.h" |
| 9 | 9 |
| 10 #include <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 #pragma comment(linker, "/INCLUDE:p_thread_callback_dart") | 511 #pragma comment(linker, "/INCLUDE:p_thread_callback_dart") |
| 512 | 512 |
| 513 #else // _WIN64 | 513 #else // _WIN64 |
| 514 | 514 |
| 515 #pragma comment(linker, "/INCLUDE:__tls_used") | 515 #pragma comment(linker, "/INCLUDE:__tls_used") |
| 516 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") | 516 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") |
| 517 | 517 |
| 518 #endif // _WIN64 | 518 #endif // _WIN64 |
| 519 | 519 |
| 520 // Static callback function to call with each thread termination. | 520 // Static callback function to call with each thread termination. |
| 521 void NTAPI OnThreadExit(PVOID module, DWORD reason, PVOID reserved) { | 521 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) { |
| 522 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ | 522 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ |
| 523 // and on W2K and W2K3. So don't assume it is sent. | 523 // and on W2K and W2K3. So don't assume it is sent. |
| 524 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { | 524 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { |
| 525 dart::ThreadCleanupOnExit(); | 525 dart::ThreadCleanupOnExit(); |
| 526 dart::MonitorWaitData::ThreadExit(); | 526 dart::MonitorWaitData::ThreadExit(); |
| 527 } | 527 } |
| 528 } | 528 } |
| 529 | 529 |
| 530 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are | 530 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are |
| 531 // called automatically by the OS loader code (not the CRT) when the module is | 531 // called automatically by the OS loader code (not the CRT) when the module is |
| 532 // loaded and on thread creation. They are NOT called if the module has been | 532 // loaded and on thread creation. They are NOT called if the module has been |
| 533 // loaded by a LoadLibrary() call. It must have implicitly been loaded at | 533 // loaded by a LoadLibrary() call. It must have implicitly been loaded at |
| 534 // process startup. | 534 // process startup. |
| 535 // By implicitly loaded, I mean that it is directly referenced by the main EXE | 535 // By implicitly loaded, I mean that it is directly referenced by the main EXE |
| 536 // or by one of its dependent DLLs. Delay-loaded DLL doesn't count as being | 536 // or by one of its dependent DLLs. Delay-loaded DLL doesn't count as being |
| 537 // implicitly loaded. | 537 // implicitly loaded. |
| 538 // | 538 // |
| 539 // See VC\crt\src\tlssup.c for reference. | 539 // See VC\crt\src\tlssup.c for reference. |
| 540 | 540 |
| 541 // extern "C" suppresses C++ name mangling so we know the symbol name for the | 541 // extern "C" suppresses C++ name mangling so we know the symbol name for the |
| 542 // linker /INCLUDE:symbol pragma above. | 542 // linker /INCLUDE:symbol pragma above. |
| 543 extern "C" { | 543 extern "C" { |
| 544 // The linker must not discard p_thread_callback_dart. (We force a reference | 544 // The linker must not discard p_thread_callback_dart. (We force a reference |
| 545 // to this variable with a linker /INCLUDE:symbol pragma to ensure that.) If | 545 // to this variable with a linker /INCLUDE:symbol pragma to ensure that.) If |
| 546 // this variable is discarded, the OnThreadExit function will never be called. | 546 // this variable is discarded, the OnDartThreadExit function will never be |
| 547 // called. |
| 547 #ifdef _WIN64 | 548 #ifdef _WIN64 |
| 548 | 549 |
| 549 // .CRT section is merged with .rdata on x64 so it must be constant data. | 550 // .CRT section is merged with .rdata on x64 so it must be constant data. |
| 550 #pragma const_seg(".CRT$XLB") | 551 #pragma const_seg(".CRT$XLB") |
| 551 // When defining a const variable, it must have external linkage to be sure the | 552 // When defining a const variable, it must have external linkage to be sure the |
| 552 // linker doesn't discard it. | 553 // linker doesn't discard it. |
| 553 extern const PIMAGE_TLS_CALLBACK p_thread_callback_dart; | 554 extern const PIMAGE_TLS_CALLBACK p_thread_callback_dart; |
| 554 const PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnThreadExit; | 555 const PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; |
| 555 | 556 |
| 556 // Reset the default section. | 557 // Reset the default section. |
| 557 #pragma const_seg() | 558 #pragma const_seg() |
| 558 | 559 |
| 559 #else // _WIN64 | 560 #else // _WIN64 |
| 560 | 561 |
| 561 #pragma data_seg(".CRT$XLB") | 562 #pragma data_seg(".CRT$XLB") |
| 562 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnThreadExit; | 563 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; |
| 563 | 564 |
| 564 // Reset the default section. | 565 // Reset the default section. |
| 565 #pragma data_seg() | 566 #pragma data_seg() |
| 566 | 567 |
| 567 #endif // _WIN64 | 568 #endif // _WIN64 |
| 568 } // extern "C" | 569 } // extern "C" |
| 569 | 570 |
| 570 #endif // defined(TARGET_OS_WINDOWS) | 571 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |