Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsGlueLinkingDlopen.cpp File Reference
#include "nsGlueLinking.h"
#include "nsXPCOMGlue.h"
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  DependentLib

Defines

#define LEADING_UNDERSCORE

Functions

static void AppendDependentLib (void *libHandle)
static void ReadDependentCB (const char *aDependentLib)
GetFrozenFunctionsFunc XPCOMGlueLoad (const char *xpcomFile)
void XPCOMGlueUnload ()
nsresult XPCOMGlueLoadXULFunctions (const nsDynamicFunctionLoad *symbols)

Variables

static DependentLibsTop
static voidsXULLibHandle

Class Documentation

struct DependentLib

Definition at line 54 of file nsGlueLinkingDlopen.cpp.

Collaboration diagram for DependentLib:
Class Members
HINSTANCE libHandle
HMODULE libHandle
void * libHandle
DependentLib * next

Define Documentation

Definition at line 51 of file nsGlueLinkingDlopen.cpp.


Function Documentation

static void AppendDependentLib ( void libHandle) [static]

Definition at line 64 of file nsGlueLinkingDlopen.cpp.

{
    DependentLib *d = new DependentLib;
    if (!d)
        return;

    d->next = sTop;
    d->libHandle = libHandle;

    sTop = d;
}

Here is the caller graph for this function:

static void ReadDependentCB ( const char *  aDependentLib) [static]

Definition at line 77 of file nsGlueLinkingDlopen.cpp.

{
    void *libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY);
    if (!libHandle)
        return;

    AppendDependentLib(libHandle);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 87 of file nsGlueLinkingDlopen.cpp.

{
    char xpcomDir[MAXPATHLEN];
    if (realpath(xpcomFile, xpcomDir)) {
        char *lastSlash = strrchr(xpcomDir, '/');
        if (lastSlash) {
            *lastSlash = '\0';

            XPCOMGlueLoadDependentLibs(xpcomDir, ReadDependentCB);

            snprintf(lastSlash, MAXPATHLEN - strlen(xpcomDir), "/" XUL_DLL);

            sXULLibHandle = dlopen(xpcomDir, RTLD_GLOBAL | RTLD_LAZY);
        }
    }

    // RTLD_DEFAULT is not defined in non-GNU toolchains, and it is
    // (void*) 0 in any case.

    void *libHandle = nsnull;

    if (xpcomFile[0] != '.' || xpcomFile[1] != '\0') {
        libHandle = dlopen(xpcomFile, RTLD_GLOBAL | RTLD_LAZY);
        if (libHandle) {
            AppendDependentLib(libHandle);
        }
    }

    GetFrozenFunctionsFunc sym =
        (GetFrozenFunctionsFunc) dlsym(libHandle,
                                       LEADING_UNDERSCORE "NS_GetFrozenFunctions");

    if (!sym)
        XPCOMGlueUnload();

    return sym;
}

Here is the call graph for this function:

nsresult XPCOMGlueLoadXULFunctions ( const nsDynamicFunctionLoad *  symbols)

Definition at line 144 of file nsGlueLinkingDlopen.cpp.

{
    // We don't null-check sXULLibHandle because this might work even
    // if it is null (same as RTLD_DEFAULT)

    nsresult rv = NS_OK;
    while (symbols->functionName) {
        char buffer[512];
        snprintf(buffer, sizeof(buffer),
                 LEADING_UNDERSCORE "%s", symbols->functionName);

        *symbols->function = (NSFuncPtr) dlsym(sXULLibHandle, buffer);
        if (!*symbols->function)
            rv = NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;

        ++symbols;
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 126 of file nsGlueLinkingDlopen.cpp.

{
    while (sTop) {
        dlclose(sTop->libHandle);

        DependentLib *temp = sTop;
        sTop = sTop->next;

        delete temp;
    }

    if (sXULLibHandle) {
        dlclose(sXULLibHandle);
        sXULLibHandle = nsnull;
    }
}

Variable Documentation

DependentLib* sTop [static]

Definition at line 60 of file nsGlueLinkingDlopen.cpp.

void* sXULLibHandle [static]

Definition at line 61 of file nsGlueLinkingDlopen.cpp.