|
33 | 33 | #define HAS_OS_FEATURE 1
|
34 | 34 | #endif
|
35 | 35 |
|
| 36 | +#if defined(_WIN32) |
| 37 | +#define WIN32_LEAN_AND_MEAN |
| 38 | +#define NOMINMAX |
| 39 | +#include <ShlWapi.h> |
| 40 | +#include <Windows.h> |
| 41 | +#endif |
| 42 | + |
36 | 43 | using namespace swift;
|
37 | 44 |
|
38 | 45 | static bool prespecializedLoggingEnabled = false;
|
@@ -67,10 +74,42 @@ static bool environmentProcessListContainsProcess(const char *list,
|
67 | 74 | }
|
68 | 75 |
|
69 | 76 | static bool isThisProcessEnabled(const LibPrespecializedData<InProcess> *data) {
|
| 77 | +#if defined(_WIN32) |
| 78 | + DWORD dwSize = MAX_PATH; |
| 79 | + DWORD dwResult; |
| 80 | + std::unique_ptr<WCHAR[]> pwszBuffer(new WCHAR[dwSize]); |
| 81 | + while (true) { |
| 82 | + dwResult = GetModuleFileNameW(nullptr, pwszBuffer.get(), dwSize); |
| 83 | + if (dwResult == 0) |
| 84 | + return true; |
| 85 | + if (dwResult < dwSize) |
| 86 | + break; |
| 87 | + if (dwResult == dwSize && GetLastError() == ERROR_INSUFFICIENT_BUFFER) |
| 88 | + pwszBuffer.reset(new WCHAR[dwSize <<= 1]); |
| 89 | + } |
| 90 | + |
| 91 | + PCWSTR pwszBaseName = PathFindFileNameW(pwszBuffer.get()); |
| 92 | + |
| 93 | + DWORD cchLength = |
| 94 | + WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS | WC_NO_BEST_FIT_CHARS, |
| 95 | + pwszBaseName, -1, nullptr, 0, nullptr, nullptr); |
| 96 | + if (cchLength == 0) |
| 97 | + return true; |
| 98 | + |
| 99 | + std::unique_ptr<char[]> pszBaseName{new char[cchLength]}; |
| 100 | + cchLength = WideCharToMultiByte( |
| 101 | + CP_UTF8, WC_ERR_INVALID_CHARS | WC_NO_BEST_FIT_CHARS, pwszBaseName, -1, |
| 102 | + pszBaseName.get(), cchLength, nullptr, nullptr); |
| 103 | + if (cchLength == 0) |
| 104 | + return true; |
| 105 | + |
| 106 | + const char *__progname = pszBaseName.get(); |
| 107 | +#else |
70 | 108 | extern const char *__progname;
|
71 | 109 |
|
72 | 110 | if (!__progname)
|
73 | 111 | return true;
|
| 112 | +#endif |
74 | 113 |
|
75 | 114 | auto envEnabledProcesses =
|
76 | 115 | runtime::environment::SWIFT_DEBUG_LIB_PRESPECIALIZED_ENABLED_PROCESSES();
|
|
0 commit comments