2012-03-16 22:24:12 +00: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"
|
|
|
|
|
2012-12-19 07:16:02 +00:00
|
|
|
#include "nsDebug.h"
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLLibraryLoader::OpenLibrary(const char *library)
|
|
|
|
{
|
|
|
|
PRLibSpec lspec;
|
|
|
|
lspec.type = PR_LibSpec_Pathname;
|
|
|
|
lspec.value.pathname = library;
|
|
|
|
|
|
|
|
mLibrary = PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
|
|
|
|
if (!mLibrary)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-12-19 07:16:02 +00:00
|
|
|
GLLibraryLoader::LoadSymbols(SymLoadStruct *firstStruct,
|
|
|
|
bool tryplatform,
|
|
|
|
const char *prefix,
|
|
|
|
bool warnOnFailure)
|
2012-03-16 22:24:12 +00:00
|
|
|
{
|
2012-12-19 07:16:02 +00:00
|
|
|
return LoadSymbols(mLibrary,
|
|
|
|
firstStruct,
|
|
|
|
tryplatform ? mLookupFunc : nullptr,
|
|
|
|
prefix,
|
|
|
|
warnOnFailure);
|
2012-03-16 22:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRFuncPtr
|
|
|
|
GLLibraryLoader::LookupSymbol(PRLibrary *lib,
|
2012-12-19 07:16:02 +00:00
|
|
|
const char *sym,
|
|
|
|
PlatformLookupFunction lookupFunction)
|
2012-03-16 22:24:12 +00:00
|
|
|
{
|
|
|
|
PRFuncPtr res = 0;
|
|
|
|
|
|
|
|
// try finding it in the library directly, if we have one
|
|
|
|
if (lib) {
|
|
|
|
res = PR_FindFunctionSymbol(lib, sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
// then try looking it up via the lookup symbol
|
|
|
|
if (!res && lookupFunction) {
|
|
|
|
res = lookupFunction(sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally just try finding it in the process
|
|
|
|
if (!res) {
|
|
|
|
PRLibrary *leakedLibRef;
|
|
|
|
res = PR_FindFunctionSymbolAndLibrary(sym, &leakedLibRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLLibraryLoader::LoadSymbols(PRLibrary *lib,
|
2012-12-19 07:16:02 +00:00
|
|
|
SymLoadStruct *firstStruct,
|
|
|
|
PlatformLookupFunction lookupFunction,
|
|
|
|
const char *prefix,
|
|
|
|
bool warnOnFailure)
|
2012-03-16 22:24:12 +00:00
|
|
|
{
|
|
|
|
char sbuf[MAX_SYMBOL_LENGTH * 2];
|
|
|
|
int failCount = 0;
|
|
|
|
|
|
|
|
SymLoadStruct *ss = firstStruct;
|
|
|
|
while (ss->symPointer) {
|
|
|
|
*ss->symPointer = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_SYMBOL_NAMES; i++) {
|
2012-07-30 14:20:58 +00:00
|
|
|
if (ss->symNames[i] == nullptr)
|
2012-03-16 22:24:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
const char *s = ss->symNames[i];
|
|
|
|
if (prefix && *prefix != 0) {
|
|
|
|
strcpy(sbuf, prefix);
|
|
|
|
strcat(sbuf, ss->symNames[i]);
|
|
|
|
s = sbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRFuncPtr p = LookupSymbol(lib, s, lookupFunction);
|
|
|
|
if (p) {
|
|
|
|
*ss->symPointer = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ss->symPointer == 0) {
|
2012-12-19 07:16:02 +00:00
|
|
|
if (warnOnFailure)
|
|
|
|
printf_stderr("Can't find symbol '%s'.\n", ss->symNames[0]);
|
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
failCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ss++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return failCount == 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|