2012-03-17 02:24:12 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "GLLibraryLoader.h"
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
#include <regex>
|
|
|
|
|
2020-04-05 06:50:33 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2012-12-19 11:16:02 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
|
2016-07-14 21:54:48 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 02:24:12 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
void ClearSymbols(const SymLoadStruct* const firstStruct) {
|
|
|
|
for (auto itr = firstStruct; itr->symPointer; ++itr) {
|
|
|
|
*itr->symPointer = nullptr;
|
|
|
|
}
|
2016-12-21 07:22:04 +03:00
|
|
|
}
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
bool SymbolLoader::LoadSymbols(const SymLoadStruct* const firstStruct,
|
|
|
|
const bool warnOnFailures) const {
|
|
|
|
bool ok = true;
|
2019-02-20 18:46:03 +03:00
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
for (auto itr = firstStruct; itr->symPointer; ++itr) {
|
|
|
|
*itr->symPointer = nullptr;
|
|
|
|
|
|
|
|
for (const auto& s : itr->symNames) {
|
|
|
|
if (!s) break;
|
|
|
|
|
|
|
|
const auto p = GetProcAddress(s);
|
2012-03-17 02:24:12 +04:00
|
|
|
if (p) {
|
2019-02-23 00:17:28 +03:00
|
|
|
*itr->symPointer = p;
|
2012-03-17 02:24:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
if (!*itr->symPointer) {
|
|
|
|
if (warnOnFailures) {
|
|
|
|
printf_stderr("Can't find symbol '%s'.\n", itr->symNames[0]);
|
2012-03-17 02:24:12 +04:00
|
|
|
}
|
2019-02-23 00:17:28 +03:00
|
|
|
ok = false;
|
2017-03-04 03:49:49 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
return ok;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
PRFuncPtr SymbolLoader::GetProcAddress(const char* const name) const {
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const std::regex kRESymbol("[a-z].*");
|
|
|
|
if (!std::regex_match(name, kRESymbol)) {
|
|
|
|
gfxCriticalError() << "Bad symbol name : " << name;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRFuncPtr ret = nullptr;
|
|
|
|
if (!ret && mLib) {
|
|
|
|
ret = PR_FindFunctionSymbol(mLib, name);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-02-27 18:08:59 +03:00
|
|
|
if (!ret && mPfn) {
|
|
|
|
ret = mPfn(name);
|
|
|
|
}
|
2019-02-23 00:17:28 +03:00
|
|
|
return ret;
|
2017-03-04 03:49:49 +03:00
|
|
|
}
|
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|