gfx/gl/GLLibraryLoader.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 #include "GLLibraryLoader.h"
     7 #include "nsDebug.h"
     9 namespace mozilla {
    10 namespace gl {
    12 bool
    13 GLLibraryLoader::OpenLibrary(const char *library)
    14 {
    15     PRLibSpec lspec;
    16     lspec.type = PR_LibSpec_Pathname;
    17     lspec.value.pathname = library;
    19     mLibrary = PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
    20     if (!mLibrary)
    21         return false;
    23     return true;
    24 }
    26 bool
    27 GLLibraryLoader::LoadSymbols(SymLoadStruct *firstStruct,
    28                              bool tryplatform,
    29                              const char *prefix,
    30                              bool warnOnFailure)
    31 {
    32     return LoadSymbols(mLibrary,
    33                        firstStruct,
    34                        tryplatform ? mLookupFunc : nullptr,
    35                        prefix,
    36                        warnOnFailure);
    37 }
    39 PRFuncPtr
    40 GLLibraryLoader::LookupSymbol(PRLibrary *lib,
    41                               const char *sym,
    42                               PlatformLookupFunction lookupFunction)
    43 {
    44     PRFuncPtr res = 0;
    46     // try finding it in the library directly, if we have one
    47     if (lib) {
    48         res = PR_FindFunctionSymbol(lib, sym);
    49     }
    51     // then try looking it up via the lookup symbol
    52     if (!res && lookupFunction) {
    53         res = lookupFunction(sym);
    54     }
    56     // finally just try finding it in the process
    57     if (!res) {
    58         PRLibrary *leakedLibRef;
    59         res = PR_FindFunctionSymbolAndLibrary(sym, &leakedLibRef);
    60     }
    62     return res;
    63 }
    65 bool
    66 GLLibraryLoader::LoadSymbols(PRLibrary *lib,
    67                              SymLoadStruct *firstStruct,
    68                              PlatformLookupFunction lookupFunction,
    69                              const char *prefix,
    70                              bool warnOnFailure)
    71 {
    72     char sbuf[MAX_SYMBOL_LENGTH * 2];
    73     int failCount = 0;
    75     SymLoadStruct *ss = firstStruct;
    76     while (ss->symPointer) {
    77         *ss->symPointer = 0;
    79         for (int i = 0; i < MAX_SYMBOL_NAMES; i++) {
    80             if (ss->symNames[i] == nullptr)
    81                 break;
    83             const char *s = ss->symNames[i];
    84             if (prefix && *prefix != 0) {
    85                 strcpy(sbuf, prefix);
    86                 strcat(sbuf, ss->symNames[i]);
    87                 s = sbuf;
    88             }
    90             PRFuncPtr p = LookupSymbol(lib, s, lookupFunction);
    91             if (p) {
    92                 *ss->symPointer = p;
    93                 break;
    94             }
    95         }
    97         if (*ss->symPointer == 0) {
    98             if (warnOnFailure)
    99                 printf_stderr("Can't find symbol '%s'.\n", ss->symNames[0]);
   101             failCount++;
   102         }
   104         ss++;
   105     }
   107     return failCount == 0 ? true : false;
   108 }
   110 } /* namespace gl */
   111 } /* namespace mozilla */

mercurial