|
14 | 14 |
|
15 | 15 | #include "swift/Basic/Assertions.h"
|
16 | 16 | #include "swift/Basic/Defer.h"
|
| 17 | +#include "swift/Basic/LoadDynamicLibrary.h" |
17 | 18 | #include "swift/Basic/LLVM.h"
|
18 | 19 | #include "swift/Basic/Program.h"
|
19 | 20 | #include "swift/Basic/Sandbox.h"
|
|
25 | 26 |
|
26 | 27 | #include <signal.h>
|
27 | 28 |
|
28 |
| -#if defined(_WIN32) |
29 |
| -#define WIN32_LEAN_AND_MEAN |
30 |
| -#define NOMINMAX |
31 |
| -#include "llvm/Support/ConvertUTF.h" |
32 |
| -#include "llvm/Support/Windows/WindowsSupport.h" |
33 |
| -#include <windows.h> |
34 |
| -#else |
35 |
| -#include <dlfcn.h> |
36 |
| -#endif |
37 |
| - |
38 | 29 | #if HAVE_UNISTD_H
|
39 | 30 | #include <unistd.h>
|
40 | 31 | #elif defined(_WIN32)
|
|
43 | 34 |
|
44 | 35 | using namespace swift;
|
45 | 36 |
|
46 |
| -namespace { |
47 |
| -void *loadLibrary(const char *path, std::string *err); |
48 |
| -void *getAddressOfSymbol(void *handle, const char *symbol); |
49 |
| - |
50 |
| -#if defined(_WIN32) |
51 |
| -void *loadLibrary(const char *path, std::string *err) { |
52 |
| - SmallVector<wchar_t, MAX_PATH> pathUnicode; |
53 |
| - if (std::error_code ec = llvm::sys::windows::UTF8ToUTF16(path, pathUnicode)) { |
54 |
| - SetLastError(ec.value()); |
55 |
| - llvm::MakeErrMsg(err, std::string(path) + ": Can't convert to UTF-16"); |
56 |
| - return nullptr; |
57 |
| - } |
58 |
| - |
59 |
| - HMODULE handle = LoadLibraryW(pathUnicode.data()); |
60 |
| - if (handle == NULL) { |
61 |
| - llvm::MakeErrMsg(err, std::string(path) + ": Can't open"); |
62 |
| - return nullptr; |
63 |
| - } |
64 |
| - return (void *)handle; |
65 |
| -} |
66 |
| - |
67 |
| -void *getAddressOfSymbol(void *handle, const char *symbol) { |
68 |
| - return (void *)uintptr_t(GetProcAddress((HMODULE)handle, symbol)); |
69 |
| -} |
70 |
| - |
71 |
| -#else |
72 |
| -void *loadLibrary(const char *path, std::string *err) { |
73 |
| - void *handle = ::dlopen(path, RTLD_LAZY | RTLD_LOCAL); |
74 |
| - if (!handle) |
75 |
| - *err = ::dlerror(); |
76 |
| - return handle; |
77 |
| -} |
78 |
| - |
79 |
| -void *getAddressOfSymbol(void *handle, const char *symbol) { |
80 |
| - return ::dlsym(handle, symbol); |
81 |
| -} |
82 |
| - |
83 |
| -#endif |
84 |
| -} // namespace |
85 |
| - |
86 | 37 | PluginRegistry::PluginRegistry() {
|
87 | 38 | dumpMessaging = ::getenv("SWIFT_DUMP_PLUGIN_MESSAGING") != nullptr;
|
88 | 39 | }
|
|
0 commit comments