MCPcopy Create free account
hub / github.com/ROCm/clr / loadLibrary

Method loadLibrary

rocclr/os/os.cpp:51–117  ·  view source on GitHub ↗

================================================================================================

Source from the content-addressed store, hash-verified

49
50// ================================================================================================
51void* Os::loadLibrary(const char* libraryname) {
52 void* handle;
53
54 // Try with the system library prefix and extension instead.
55 std::string str = libraryname;
56
57 size_t namestart = str.rfind(fileSeparator());
58 namestart = (namestart != std::string::npos) ? namestart + 1 : 0;
59
60 if (namestart == 0) {
61#if IS_WINDOWS
62 // Try with the path of the current loaded dll(OCL runtime) first
63 HMODULE hm = NULL;
64 if (!GetModuleHandleExA(
65 GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
66 (LPCSTR)&loadLibrary, &hm))
67 return NULL;
68
69 char cszDllPath[1024] = {0};
70 if (!GetModuleFileNameA(hm, cszDllPath, sizeof(cszDllPath))) return NULL;
71
72 LPSTR cszFileName;
73 char buffer[1024] = {0};
74 if (!GetFullPathNameA(cszDllPath, sizeof(buffer), buffer, &cszFileName)) return NULL;
75
76 std::string newPath;
77 newPath = cszDllPath;
78 newPath.replace(newPath.find(cszFileName), strlen(libraryname), libraryname);
79
80 handle = Os::loadLibrary_(newPath.c_str());
81 if (handle != NULL) {
82 return handle;
83 }
84#endif
85 }
86
87 handle = Os::loadLibrary_(libraryname);
88 if (handle != NULL) {
89 return handle;
90 }
91
92 const char* prefix = Os::libraryPrefix();
93 if (prefix != NULL && str.compare(namestart, strlen(prefix), prefix) == 0) {
94 // It is alread present, not need to prepend it.
95 prefix = NULL;
96 }
97 size_t dot = str.rfind('.');
98 if (dot != std::string::npos) {
99 // check that the dot was on the filename not a dir name.
100 if (namestart < dot) {
101 // strip the previous extension.
102 str.resize(dot);
103 }
104 }
105 if (prefix != NULL && prefix[0] != '\0') {
106 str.insert(namestart, prefix);
107 }
108 str.append(Os::libraryExtension());

Callers

nothing calls this directly

Calls 2

stringFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected