GLLibraryLoader.cpp (1606B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "GLLibraryLoader.h" 6 7 #include <regex> 8 9 #include "mozilla/gfx/Logging.h" 10 #include "nsDebug.h" 11 12 #ifdef WIN32 13 # include <windows.h> 14 #endif 15 16 namespace mozilla { 17 namespace gl { 18 19 void ClearSymbols(const SymLoadStruct* const firstStruct) { 20 for (auto itr = firstStruct; itr->symPointer; ++itr) { 21 *itr->symPointer = nullptr; 22 } 23 } 24 25 bool SymbolLoader::LoadSymbols(const SymLoadStruct* const firstStruct, 26 const bool warnOnFailures) const { 27 bool ok = true; 28 29 for (auto itr = firstStruct; itr->symPointer; ++itr) { 30 *itr->symPointer = nullptr; 31 32 for (const auto& s : itr->symNames) { 33 if (!s) break; 34 35 const auto p = GetProcAddress(s); 36 if (p) { 37 *itr->symPointer = p; 38 break; 39 } 40 } 41 42 if (!*itr->symPointer) { 43 if (warnOnFailures) { 44 printf_stderr("Can't find symbol '%s'.\n", itr->symNames[0]); 45 } 46 ok = false; 47 } 48 } 49 50 return ok; 51 } 52 53 // - 54 55 PRFuncPtr SymbolLoader::GetProcAddress(const char* const name) const { 56 #ifdef DEBUG 57 static const std::regex kRESymbol("[a-z].*"); 58 if (!std::regex_match(name, kRESymbol)) { 59 gfxCriticalError() << "Bad symbol name : " << name; 60 } 61 #endif 62 63 PRFuncPtr ret = nullptr; 64 if (!ret && mLib) { 65 ret = PR_FindFunctionSymbol(mLib, name); 66 } 67 if (!ret && mPfn) { 68 ret = mPfn(name); 69 } 70 return ret; 71 } 72 73 } // namespace gl 74 } // namespace mozilla