| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | DllMain.cpp |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | This file contains the entrypoint for libwsl. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #include "precomp.h" |
| 16 | |
| 17 | static HINSTANCE g_dllInstance; |
| 18 | |
| 19 | EXTERN_C BOOL STDAPICALLTYPE DllMain(_In_ HINSTANCE Instance, _In_ DWORD Reason, _In_opt_ LPVOID Reserved) |
| 20 | { |
| 21 | wil::DLLMain(Instance, Reason, Reserved); |
| 22 | |
| 23 | switch (Reason) |
| 24 | { |
| 25 | case DLL_PROCESS_ATTACH: |
| 26 | g_dllInstance = Instance; |
| 27 | WslTraceLoggingInitialize(LxssTelemetryProvider, TRUE, nullptr); |
| 28 | |
| 29 | // Accidentally including a Module<OutOfProc> can result in lifetime issues because it will call |
| 30 | // CoAddRefServerProcess/CoReleaseServerProcess outside of any WRL::Module<> that may be in use in the caller, |
| 31 | // which means the global counter is getting updated without the Module<> specific checks (e.g. last reference |
| 32 | // has been released). |
| 33 | FAIL_FAST_HR_IF_MSG( |
| 34 | HRESULT_FROM_WIN32(ERROR_INVALID_STATE), |
| 35 | Microsoft::WRL::GetModuleBase() != nullptr, |
| 36 | "A WRL::Module has been included"); |
| 37 | |
| 38 | break; |
| 39 | |
| 40 | case DLL_PROCESS_DETACH: |
| 41 | WslTraceLoggingUninitialize(); |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | return TRUE; |
| 46 | } |