VirtualBox

Changeset 16390 in vbox


Ignore:
Timestamp:
Jan 29, 2009 10:19:49 PM (16 years ago)
Author:
vboxsync
Message:

XPCOM-darwin/amd64: Adopted prlink.c to IPRT (VBOX_USE_MORE_IPRT_IN_NSPR) and will use that on 64-bit darwin (more reusable effort).

Location:
trunk/src/libs/xpcom18a4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/Makefile.kmk

    r16389 r16390  
    706706VBox-xpcom-nspr_DEFS      += \
    707707        VBOX_USE_IPRT_IN_NSPR
     708VBox-xpcom-nspr_DEFS.darwin.amd64 = \
     709        VBOX_USE_MORE_IPRT_IN_NSPR
    708710VBox-xpcom-nspr_DEFS.darwin = \
    709711        HAVE_BSD_FLOCK=1 \
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c

    r11551 r16390  
    11/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    2 /* 
     2/*
    33 * The contents of this file are subject to the Mozilla Public
    44 * License Version 1.1 (the "License"); you may not use this file
    55 * except in compliance with the License. You may obtain a copy of
    66 * the License at http://www.mozilla.org/MPL/
    7  * 
     7 *
    88 * Software distributed under the License is distributed on an "AS
    99 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
    1010 * implied. See the License for the specific language governing
    1111 * rights and limitations under the License.
    12  * 
     12 *
    1313 * The Original Code is the Netscape Portable Runtime (NSPR).
    14  * 
     14 *
    1515 * The Initial Developer of the Original Code is Netscape
    16  * Communications Corporation.  Portions created by Netscape are 
     16 * Communications Corporation.  Portions created by Netscape are
    1717 * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
    1818 * Rights Reserved.
    19  * 
     19 *
    2020 * Contributor(s): Steve Streeter (Hewlett-Packard Company)
    21  * 
     21 *
    2222 * Alternatively, the contents of this file may be used under the
    2323 * terms of the GNU General Public License Version 2 or later (the
    24  * "GPL"), in which case the provisions of the GPL are applicable 
    25  * instead of those above.  If you wish to allow use of your 
     24 * "GPL"), in which case the provisions of the GPL are applicable
     25 * instead of those above.  If you wish to allow use of your
    2626 * version of this file only under the terms of the GPL and not to
    2727 * allow others to use your version of this file under the MPL,
     
    4141#include <string.h>
    4242
     43#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     44# include <iprt/ldr.h>
     45# include <iprt/path.h>
     46# include <iprt/err.h>
     47
     48# if defined(XP_MACOSX) /** @todo Add some equivalent to PR_GetLibraryFilePathname. */
     49#  include <mach-o/dyld.h>
     50# endif
     51
     52# ifdef XP_MAC
     53#  error "Misconfiguration: XP_MAC && VBOX_USE_MORE_IPRT_IN_NSPR are not intended to work together"
     54# endif
     55
     56#else /* ! VBOX_USE_MORE_IPRT_IN_NSPR */
     57
    4358#ifdef XP_BEOS
    4459#include <image.h>
     
    96111#endif
    97112#endif /* XP_UNIX */
     113
     114#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    98115
    99116#define _PR_DEFAULT_LD_FLAGS PR_LD_LAZY
     
    111128#include <unixlib.h>
    112129
    113 #pragma __nostandard 
     130#pragma __nostandard
    114131#pragma __member_alignment __save
    115132#pragma __nomember_alignment
    116133#ifdef __INITIAL_POINTER_SIZE
    117 #pragma __required_pointer_size __save 
     134#pragma __required_pointer_size __save
    118135#pragma __required_pointer_size __short
    119136#endif
    120  
     137
    121138typedef struct _imcb {
    122     struct _imcb *imcb$l_flink;         
    123     struct _imcb *imcb$l_blink;         
    124     unsigned short int imcb$w_size;     
    125     unsigned char imcb$b_type;         
    126     char imcb$b_resv_1;                 
    127     unsigned char imcb$b_access_mode;   
    128     unsigned char imcb$b_act_code;     
    129     unsigned short int imcb$w_chan;     
    130     unsigned int imcb$l_flags;         
    131     char imcb$t_image_name [40];       
    132     unsigned int imcb$l_symvec_size; 
     139    struct _imcb *imcb$l_flink;
     140    struct _imcb *imcb$l_blink;
     141    unsigned short int imcb$w_size;
     142    unsigned char imcb$b_type;
     143    char imcb$b_resv_1;
     144    unsigned char imcb$b_access_mode;
     145    unsigned char imcb$b_act_code;
     146    unsigned short int imcb$w_chan;
     147    unsigned int imcb$l_flags;
     148    char imcb$t_image_name [40];
     149    unsigned int imcb$l_symvec_size;
    133150    unsigned __int64 imcb$q_ident;
    134151    void *imcb$l_starting_address;
    135152    void *imcb$l_end_address;
    136153} IMCB;
    137  
     154
    138155#pragma __member_alignment __restore
    139 #ifdef __INITIAL_POINTER_SIZE 
     156#ifdef __INITIAL_POINTER_SIZE
    140157#pragma __required_pointer_size __restore
    141158#endif
    142159#pragma __standard
    143  
     160
    144161typedef struct {
    145162    short   buflen;
     
    166183 * On these platforms, symbols have a leading '_'.
    167184 */
     185#ifndef VBOX_USE_MORE_IPRT_IN_NSPR /* RTLdr hides this. */
    168186#if defined(SUNOS4) || defined(DARWIN) || defined(NEXTSTEP) \
    169187    || defined(WIN16) || defined(XP_OS2) \
     
    171189#define NEED_LEADING_UNDERSCORE
    172190#endif
     191#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    173192
    174193#ifdef XP_PC
     
    184203    const PRStaticLinkTable*    staticTable;
    185204
     205#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     206    RTLDRMOD                    dlh;
     207#else  /* !VBOX_USE_MORE_IPRT_IN_NSPR */
     208
    186209#ifdef XP_PC
    187210#ifdef XP_OS2
     
    214237#else
    215238    void*                       dlh;
    216 #endif 
    217 #endif 
     239#endif
     240#endif
    218241
    219242#ifdef XP_BEOS
     
    221244    void*                       stub_dlh;
    222245#endif
     246#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    223247};
    224248
     
    238262/************************************************************************/
    239263
    240 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
     264#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) && !defined(VBOX_USE_MORE_IPRT_IN_NSPR)
    241265static char* errStrBuf = NULL;
    242266#define ERR_STR_BUF_LENGTH    20
     
    271295void _PR_InitLinker(void)
    272296{
    273 #if !defined(XP_MAC) && !defined(XP_BEOS)
     297#if (!defined(XP_MAC) && !defined(XP_BEOS)) || defined(VBOX_USE_MORE_IPRT_IN_NSPR)
    274298    PRLibrary *lm;
    275299#endif
     
    283307    PR_EnterMonitor(pr_linker_lock);
    284308
    285 #if defined(XP_PC)
     309#if defined(XP_PC) || defined(VBOX_USE_MORE_IPRT_IN_NSPR)
    286310    lm = PR_NEWZAP(PRLibrary);
    287311    lm->name = strdup("Executable");
    288         /*
     312#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     313    lm->dlh = NIL_RTLDRMOD;
     314#else  /* !VBOX_USE_MORE_IPRT_IN_NSPR */
     315        /*
    289316        ** In WIN32, GetProcAddress(...) expects a module handle in order to
    290317        ** get exported symbols from the executable...
    291318        **
    292         ** However, in WIN16 this is accomplished by passing NULL to 
     319        ** However, in WIN16 this is accomplished by passing NULL to
    293320        ** GetProcAddress(...)
    294321        */
     
    298325        lm->dlh = (HINSTANCE)NULL;
    299326#endif /* ! _WIN32 */
     327#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    300328
    301329    lm->refCount    = 1;
     
    310338    if (!h) {
    311339        char *error;
    312        
     340
    313341        DLLErrorInternal(_MD_ERRNO());
    314342        error = (char*)PR_MALLOC(PR_GetErrorTextLength());
     
    340368#endif /* XP_UNIX */
    341369
    342 #if !defined(XP_MAC) && !defined(XP_BEOS)
     370#if !defined(XP_MAC) && !defined(XP_BEOS) || defined(VBOX_USE_MORE_IPRT_IN_NSPR)
    343371    PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (init)", lm?lm->name:"NULL"));
    344372#endif
     
    366394    PR_UnloadLibrary(pr_loadmap);
    367395    }
    368    
     396
    369397    PR_ExitMonitor(pr_linker_lock);
    370398
     
    385413{
    386414    /* FIXME: pr_exe_loadmap should be destroyed. */
    387    
     415
    388416    PR_DestroyMonitor(pr_linker_lock);
    389417    pr_linker_lock = NULL;
     
    394422    }
    395423
    396 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
     424#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR) && !defined(VBOX_USE_MORE_IPRT_IN_NSPR)
    397425    PR_DELETE(errStrBuf);
    398426#endif
     
    427455** Return the library path for finding shared libraries.
    428456*/
    429 PR_IMPLEMENT(char *) 
     457PR_IMPLEMENT(char *)
    430458PR_GetLibraryPath(void)
    431459{
     
    455483
    456484    ev = getenv("LD_LIBRARY_PATH");
    457    
     485
    458486    if (!ev)
    459487        ev = "";
    460    
     488
    461489    len = strlen(ev) + 1;        /* +1 for the null */
    462490    p = (char*) malloc(len);
     
    480508    }
    481509#else
     510# if defined(VBOX) && defined(XP_MACOSX)
     511    ev = getenv("DYLD_LIBRARY_PATH");
     512# else
    482513    ev = getenv("LD_LIBRARY_PATH");
     514# endif
    483515    if (!ev) {
    484516        ev = "/usr/lib:/lib";
     
    520552** Build library name from path, lib and extensions
    521553*/
    522 PR_IMPLEMENT(char*) 
     554PR_IMPLEMENT(char*)
    523555PR_GetLibraryName(const char *path, const char *lib)
    524556{
     
    570602** Free the memory allocated, for the caller, by PR_GetLibraryName
    571603*/
    572 PR_IMPLEMENT(void) 
     604PR_IMPLEMENT(void)
    573605PR_FreeLibraryName(char *mem)
    574606{
     
    576608}
    577609
    578 static PRLibrary* 
     610static PRLibrary*
    579611pr_UnlockedFindLibrary(const char *name)
    580612{
     
    587619#ifdef WIN32
    588620        /* Windows DLL names are case insensitive... */
    589     if (strcmpi(np, cp) == 0) 
     621    if (strcmpi(np, cp) == 0)
    590622#elif defined(XP_OS2)
    591623    if (stricmp(np, cp) == 0)
    592624#else
    593     if (strcmp(np, cp)  == 0) 
     625    if (strcmp(np, cp)  == 0)
    594626#endif
    595627    {
     
    630662    }
    631663}
    632            
    633 PR_IMPLEMENT(PRLibrary*) 
     664
     665PR_IMPLEMENT(PRLibrary*)
    634666PR_LoadLibrary(const char *name)
    635667{
     
    641673}
    642674
     675#ifndef VBOX_USE_MORE_IPRT_IN_NSPR /* exclude big chunk */
    643676#if defined(USE_MACH_DYLD)
    644677static NSModule
     
    699732        }
    700733    }
    701    
     734
    702735    return newGlue;
    703736}
     
    720753    char cName[64];
    721754    Str255 errName;
    722    
     755
    723756#if !defined(XP_MACOSX)
    724757    Str255 pName;
     
    845878    CFURLRef bundleURL;
    846879    CFBundleRef bundle = NULL;
    847    
     880
    848881#ifdef XP_MACOSX
    849882    char pathBuf[PATH_MAX];
     
    855888    if (!resolvedPath)
    856889        return PR_FAILURE;
    857        
     890
    858891    pathRef = CFStringCreateWithCString(NULL, pathBuf, kCFStringEncodingUTF8);
    859892    if (pathRef) {
     
    911944
    912945#endif /* defined(XP_MAC) || defined(XP_MACOSX) */
     946#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    913947
    914948/*
     
    938972    lm->staticTable = NULL;
    939973
     974#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     975    oserr = RTLdrOpen(name, &lm->dlh);
     976    if (RT_FAILURE(oserr))
     977        goto unlock;
     978    lm->name = strdup(name);
     979    lm->refCount = 1;
     980    lm->next = pr_loadmap;
     981    pr_loadmap = lm;
     982
     983#else  /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    940984#ifdef XP_OS2  /* Why isn't all this stuff in MD code?! */
    941985    {
     
    10061050        oserr = cfragNoLibraryErr;
    10071051        PR_DELETE(lm);
    1008         goto unlock;       
     1052        goto unlock;
    10091053    }
    10101054    lm->name = strdup(name);
     
    11141158               mozilla components), but allows 256M to be used by
    11151159               shared libraries.
    1116                
     1160
    11171161               unfortunately, mozilla is too large to fit into the
    11181162               "add-on" space, so we must trick the loader into
     
    11391183                    const char *endOfSystemName = strrchr(info.name, '/');
    11401184                    const char *endOfPassedName = strrchr(name, '/');
    1141                     if( 0 == endOfSystemName ) 
     1185                    if( 0 == endOfSystemName )
    11421186                        endOfSystemName = info.name;
    11431187                    else
     
    11741218    }
    11751219#endif
     1220#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    11761221
    11771222    result = lm;    /* success */
     
    11871232}
    11881233
    1189 PR_IMPLEMENT(PRLibrary*) 
     1234PR_IMPLEMENT(PRLibrary*)
    11901235PR_FindLibrary(const char *name)
    11911236{
     
    12111256        Boolean                                                 isFolder, wasAlias;
    12121257        OSErr                                                           err = noErr;
    1213        
     1258
    12141259        if (!_pr_initialized) _PR_ImplicitInitialization();
    12151260
    12161261        /* See if library is already loaded */
    12171262        PR_EnterMonitor(pr_linker_lock);
    1218  
     1263
    12191264        result = pr_UnlockedFindLibrary(fragmentName);
    12201265        if (result != NULL) goto unlock;
     
    12351280        goto unlock;
    12361281  }
    1237    
     1282
    12381283        /* Finally, try to load the library */
    12391284        err = NSLoadNamedFragment(&resolvedSpec, fragmentName, &connectionID);
     
    12681313        FSSpec                                                  resolvedSpec = *fileSpec;
    12691314        char*                                                           fragmentName = NULL;
    1270         UInt32              fragOffset, fragLength;               
     1315        UInt32              fragOffset, fragLength;
    12711316        CFragConnectionID               connectionID = 0;
    12721317        Boolean                                                 isFolder, wasAlias;
     
    12901335    err = GetIndexedFragmentOffsets(&resolvedSpec, fragIndex, &fragOffset, &fragLength, &fragmentName);
    12911336  if (err != noErr) goto unlock;
    1292  
     1337
    12931338        result = pr_UnlockedFindLibrary(fragmentName);
    12941339        free(fragmentName);
     
    12991344        if (newLib == NULL) goto unlock;
    13001345        newLib->staticTable = NULL;
    1301    
     1346
    13021347        /* Finally, try to load the library */
    13031348        err = NSLoadIndexedFragment(&resolvedSpec, fragIndex, &fragmentName, &connectionID);
     
    13321377** Unload a shared library which was loaded via PR_LoadLibrary
    13331378*/
    1334 PR_IMPLEMENT(PRStatus) 
     1379PR_IMPLEMENT(PRStatus)
    13351380PR_UnloadLibrary(PRLibrary *lib)
    13361381{
     
    13511396    }
    13521397
     1398#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     1399    result = RTLdrClose(lib->dlh);
     1400    lib->dlh = NIL_RTLDRMOD;
     1401
     1402#else  /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    13531403#ifdef XP_BEOS
    13541404    if(((image_id)lib->stub_dlh) == B_ERROR)
     
    13921442#endif
    13931443#endif
     1444#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    13941445
    13951446    /* unlink from library search list */
     
    14381489}
    14391490
    1440 static void* 
     1491static void*
    14411492pr_FindSymbolInLib(PRLibrary *lm, const char *name)
    14421493{
     
    14531504            }
    14541505        }
    1455         /* 
     1506        /*
    14561507        ** If the symbol was not found in the static table then check if
    14571508        ** the symbol was exported in the DLL... Win16 only!!
     
    14621513#endif
    14631514    }
    1464    
     1515
     1516#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
     1517    if (RT_FAILURE(RTLdrGetSymbol(lm->dlh, name, &f)))
     1518        f = NULL;
     1519
     1520#else  /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    14651521#ifdef XP_OS2
    14661522    rc = DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
     
    15001556        CFragSymbolClass    symClass;
    15011557        Str255              pName;
    1502        
     1558
    15031559        PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Looking up symbol: %s", name + SYM_OFFSET));
    1504        
     1560
    15051561        PStrFromCStr(name + SYM_OFFSET, pName);
    1506        
     1562
    15071563#if defined(XP_MACOSX)
    15081564        f = (FindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL;
     
    15101566        f = (NSFindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL;
    15111567#endif
    1512        
     1568
    15131569#if defined(XP_MACOSX)
    15141570        /* callers expect mach-o function pointers, so must wrap tvectors with glue. */
     
    15171573        }
    15181574#endif
    1519        
     1575
    15201576        if (f == NULL && strcmp(name + SYM_OFFSET, "main") == 0) f = lm->main;
    15211577    }
     
    15611617#endif /* HAVE_DLL */
    15621618#endif /* XP_UNIX */
     1619#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
    15631620    if (f == NULL) {
    15641621        PR_SetError(PR_FIND_SYMBOL_ERROR, _MD_ERRNO());
     
    15711628** Called by class loader to resolve missing native's
    15721629*/
    1573 PR_IMPLEMENT(void*) 
     1630PR_IMPLEMENT(void*)
    15741631PR_FindSymbol(PRLibrary *lib, const char *raw_name)
    15751632{
     
    16121669** Return the address of the function 'raw_name' in the library 'lib'
    16131670*/
    1614 PR_IMPLEMENT(PRFuncPtr) 
     1671PR_IMPLEMENT(PRFuncPtr)
    16151672PR_FindFunctionSymbol(PRLibrary *lib, const char *raw_name)
    16161673{
     
    16181675}
    16191676
    1620 PR_IMPLEMENT(void*) 
     1677PR_IMPLEMENT(void*)
    16211678PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
    16221679{
     
    16691726}
    16701727
    1671 PR_IMPLEMENT(PRFuncPtr) 
     1728PR_IMPLEMENT(PRFuncPtr)
    16721729PR_FindFunctionSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
    16731730{
     
    16791736** is called with the name then we will pretend it was already loaded
    16801737*/
    1681 PR_IMPLEMENT(PRLibrary*) 
     1738PR_IMPLEMENT(PRLibrary*)
    16821739PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt)
    16831740{
     
    17041761    lm->name = strdup(name);
    17051762    lm->refCount    = 1;
    1706 #if defined(XP_MAC)
     1763#if defined(XP_MAC) && !defined(VBOX_USE_MORE_IPRT_IN_NSPR)
    17071764    lm->connection  = pr_exe_loadmap ? pr_exe_loadmap->connection : 0;
    17081765#else
     
    17401797#elif defined(USE_MACH_DYLD)
    17411798    char *result;
    1742     char *image_name;
     1799    char const *image_name;
    17431800    int i, count = _dyld_image_count();
    17441801
     
    18751932    $DESCRIPTOR         (device_name_desc, device_name);
    18761933    struct fibdef       fib;
    1877     struct dsc$descriptor_s fib_desc = 
     1934    struct dsc$descriptor_s fib_desc =
    18781935        { sizeof(struct fibdef), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *)&fib } ;
    18791936    IOSB                iosb;
     
    18841941    char                file_name[MAX_FILNAM+1];
    18851942    char                *result = NULL;
    1886     struct dsc$descriptor_s file_name_desc = 
     1943    struct dsc$descriptor_s file_name_desc =
    18871944        { MAX_FILNAM, DSC$K_DTYPE_T, DSC$K_CLASS_S, (char *) &file_name[0] } ;
    18881945
     
    19041961         icb != IAC$GL_IMAGE_LIST;
    19051962         icb = icb->imcb$l_flink) {
    1906         if (((void *)addr >= icb->imcb$l_starting_address) && 
     1963        if (((void *)addr >= icb->imcb$l_starting_address) &&
    19071964            ((void *)addr <= icb->imcb$l_end_address)) {
    19081965            /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette