VirtualBox

Changeset 101944 in vbox


Ignore:
Timestamp:
Nov 7, 2023 2:37:39 PM (13 months ago)
Author:
vboxsync
Message:

libs/xpcom: Convert xcDll.{cpp,h} and nsLocalFileUnix.cpp to use our RTLdr* API directly instead of going through the API defined in prlink.h (which is also just using RTLdr* internally), bugref:10545

Location:
trunk/src/libs/xpcom18a4/xpcom
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/build/nsXPComInit.cpp

    r101920 r101944  
    3939#include "nsXPCOMPrivate.h"
    4040#include "nscore.h"
    41 #include "prlink.h"
    4241#include "nsCOMPtr.h"
    4342#include "nsObserverList.h"
  • trunk/src/libs/xpcom18a4/xpcom/components/xcDll.cpp

    r101942 r101944  
    7171nsDll::nsDll(nsIFile *dllSpec, nsNativeComponentLoader *loader)
    7272    : m_dllSpec(do_QueryInterface(dllSpec)),
    73       m_instance(NULL),
     73      m_hMod(NIL_RTLDRMOD),
    7474      m_moduleObject(NULL),
    7575      m_loader(loader),
     
    8181nsDll::~nsDll(void)
    8282{
     83    /** @todo r=aeichner Does this need fixing at all? */
    8384    //#if DEBUG_dougt
    8485    // The dll gets deleted when the dllStore is destroyed. This happens on
     
    120121PRBool nsDll::Load(void)
    121122{
    122         if (m_instance != NULL)
    123         {
    124                 // Already loaded
    125                 return (PR_TRUE);
    126         }
     123    /* Already loaded? Nothing to do. */
     124    if (m_hMod != NIL_RTLDRMOD)
     125        return PR_TRUE;
    127126
    128127    if (m_dllSpec)
     
    132131#endif
    133132
    134     // Load any library dependencies
    135     //   The Component Loader Manager may hold onto some extra data
    136     //   set by either the native component loader or the native
    137     //   component.  We assume that this data is a space delimited
    138     //   listing of dependent libraries which are required to be
    139     //   loaded prior to us loading the given component.  Once, the
    140     //   component is loaded into memory, we can release our hold
    141     //   on the dependent libraries with the assumption that the
    142     //   component library holds a reference via the OS so loader.
    143     nsCOMPtr<nsIComponentLoaderManager> manager = do_QueryInterface(m_loader->mCompMgr);
    144     if (!manager)
    145         return PR_TRUE;
    146 
    147     nsXPIDLCString extraData;
    148     manager->GetOptionalData(m_dllSpec, nsnull, getter_Copies(extraData));
    149 
    150     nsVoidArray dependentLibArray;
    151 
    152     // if there was any extra data, treat it as a listing of dependent libs
    153     if (extraData != nsnull)
    154     {
    155         // all dependent libraries are suppose to be in the "gre" directory.
    156         // note that the gre directory is the same as the "bin" directory,
    157         // when there isn't a real "gre" found.
    158 
    159         nsXPIDLCString path;
    160         nsCOMPtr<nsIFile> file;
    161         NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
    162 
    163         if (!file)
    164             return NS_ERROR_FAILURE;
    165 
    166         // we are talking about a file in the GRE dir.  Lets append something
    167         // stupid right now, so that later we can just set the leaf name.
    168         file->AppendNative(NS_LITERAL_CSTRING("dummy"));
    169 
    170         char *buffer = (char *)nsMemory::Clone(extraData, strlen(extraData) + 1);
    171         if (!buffer)
    172             return NS_ERROR_OUT_OF_MEMORY;
    173 
    174         char* newStr;
    175         char *token = nsCRT::strtok(buffer, " ", &newStr);
    176         while (token!=nsnull)
     133        // Load any library dependencies
     134        //   The Component Loader Manager may hold onto some extra data
     135        //   set by either the native component loader or the native
     136        //   component.  We assume that this data is a space delimited
     137        //   listing of dependent libraries which are required to be
     138        //   loaded prior to us loading the given component.  Once, the
     139        //   component is loaded into memory, we can release our hold
     140        //   on the dependent libraries with the assumption that the
     141        //   component library holds a reference via the OS so loader.
     142        nsCOMPtr<nsIComponentLoaderManager> manager = do_QueryInterface(m_loader->mCompMgr);
     143        if (!manager)
     144            return PR_TRUE;
     145
     146        nsXPIDLCString extraData;
     147        manager->GetOptionalData(m_dllSpec, nsnull, getter_Copies(extraData));
     148
     149        nsVoidArray dependentLibArray;
     150
     151        // if there was any extra data, treat it as a listing of dependent libs
     152        if (extraData != nsnull)
    177153        {
    178             nsCStringKey key(token);
    179             if (m_loader->mLoadedDependentLibs.Get(&key)) {
     154            // all dependent libraries are suppose to be in the "gre" directory.
     155            // note that the gre directory is the same as the "bin" directory,
     156            // when there isn't a real "gre" found.
     157
     158            nsXPIDLCString path;
     159            nsCOMPtr<nsIFile> file;
     160            NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
     161
     162            if (!file)
     163                return NS_ERROR_FAILURE;
     164
     165            // we are talking about a file in the GRE dir.  Lets append something
     166            // stupid right now, so that later we can just set the leaf name.
     167            file->AppendNative(NS_LITERAL_CSTRING("dummy"));
     168
     169            char *buffer = (char *)nsMemory::Clone(extraData, strlen(extraData) + 1);
     170            if (!buffer)
     171                return NS_ERROR_OUT_OF_MEMORY;
     172
     173            char* newStr;
     174            char *token = nsCRT::strtok(buffer, " ", &newStr);
     175            while (token!=nsnull)
     176            {
     177                nsCStringKey key(token);
     178                if (m_loader->mLoadedDependentLibs.Get(&key)) {
     179                    token = nsCRT::strtok(newStr, " ", &newStr);
     180                    continue;
     181                }
     182
     183                m_loader->mLoadedDependentLibs.Put(&key, (void*)1);
     184
     185                nsXPIDLCString libpath;
     186                file->SetNativeLeafName(nsDependentCString(token));
     187                file->GetNativePath(path);
     188                if (!path)
     189                    return NS_ERROR_FAILURE;
     190
     191                // Load this dependent library with the global flag and stash
     192                // the result for later so that we can unload it.
     193                const char *pszFilename = NULL;
     194
     195                // if the depend library path starts with a / we are
     196                // going to assume that it is a full path and should
     197                // be loaded without prepending the gre diretory
     198                // location.  We could have short circuited the
     199                // SetNativeLeafName above, but this is clearer and
     200                // the common case is a relative path.
     201                if (token[0] == '/')
     202                    pszFilename = token;
     203                else
     204                    pszFilename = path;
     205
     206                RTLDRMOD hMod = NIL_RTLDRMOD;
     207                RTERRINFOSTATIC ErrInfo;
     208                RTErrInfoInitStatic(&ErrInfo);
     209
     210                int vrc = RTLdrLoadEx(pszFilename, &hMod, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
     211                // if we couldn't load the dependent library.  We did the best we
     212                // can.  Now just let us fail later if this really was a required
     213                // dependency.
     214                if (RT_SUCCESS(vrc))
     215                    dependentLibArray.AppendElement((void*)hMod);
     216
    180217                token = nsCRT::strtok(newStr, " ", &newStr);
    181                 continue;
    182218            }
    183 
    184             m_loader->mLoadedDependentLibs.Put(&key, (void*)1);
    185 
    186             nsXPIDLCString libpath;
    187             file->SetNativeLeafName(nsDependentCString(token));
    188             file->GetNativePath(path);
    189             if (!path)
    190                 return NS_ERROR_FAILURE;
    191 
    192             // Load this dependent library with the global flag and stash
    193             // the result for later so that we can unload it.
    194             PRLibSpec libSpec;
    195             libSpec.type = PR_LibSpec_Pathname;
    196 
    197             // if the depend library path starts with a / we are
    198             // going to assume that it is a full path and should
    199             // be loaded without prepending the gre diretory
    200             // location.  We could have short circuited the
    201             // SetNativeLeafName above, but this is clearer and
    202             // the common case is a relative path.
    203 
    204             if (token[0] == '/')
    205                 libSpec.value.pathname = token;
    206             else
    207                 libSpec.value.pathname = path;
    208 
    209             PRLibrary* lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL);
    210             // if we couldn't load the dependent library.  We did the best we
    211             // can.  Now just let us fail later if this really was a required
    212             // dependency.
    213             if (lib)
    214                 dependentLibArray.AppendElement((void*)lib);
    215 
    216             token = nsCRT::strtok(newStr, " ", &newStr);
     219            nsMemory::Free(buffer);
    217220        }
    218         nsMemory::Free(buffer);
    219     }
    220 
    221     // load the component
    222     nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec));
    223     NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile");
    224     lf->Load(&m_instance);
    225 
    226     // Unload any of library dependencies we loaded earlier. The assumption
    227     // here is that the component will have a "internal" reference count to
    228     // the dependency library we just loaded.
    229     // XXX should we unload later - or even at all?
    230     if (extraData != nsnull)
    231     {
    232         PRInt32 arrayCount = dependentLibArray.Count();
    233         for (PRInt32 index = 0; index < arrayCount; index++)
    234             PR_UnloadLibrary((PRLibrary*)dependentLibArray.ElementAt(index));
    235     }
     221
     222        // load the component
     223        nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec));
     224        NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile");
     225        lf->Load(&m_hMod);
     226
     227        // Unload any of library dependencies we loaded earlier. The assumption
     228        // here is that the component will have a "internal" reference count to
     229        // the dependency library we just loaded.
     230        // XXX should we unload later - or even at all?
     231        if (extraData != nsnull)
     232        {
     233            PRInt32 arrayCount = dependentLibArray.Count();
     234            for (PRInt32 index = 0; index < arrayCount; index++)
     235                RTLdrClose((RTLDRMOD)dependentLibArray.ElementAt(index));
     236        }
    236237
    237238#ifdef NS_BUILD_REFCNT_LOGGING
    238239        nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
    239         if (m_instance) {
     240        if (m_hMod != NIL_RTLDRMOD)
     241        {
    240242            // Inform refcnt tracer of new library so that calls through the
    241243            // new library can be traced.
    242244            nsXPIDLCString displayPath;
    243245            GetDisplayPath(displayPath);
    244             nsTraceRefcntImpl::LoadLibrarySymbols(displayPath.get(), m_instance);
     246            nsTraceRefcntImpl::LoadLibrarySymbols(displayPath.get(), m_hMod);
    245247        }
    246248#endif
    247249    }
    248250
    249     return ((m_instance == NULL) ? PR_FALSE : PR_TRUE);
     251    return ((m_hMod == NIL_RTLDRMOD) ? PR_FALSE : PR_TRUE);
    250252}
    251253
    252254PRBool nsDll::Unload(void)
    253255{
    254         if (m_instance == NULL)
    255                 return (PR_FALSE);
     256    if (m_hMod == NULL)
     257        return PR_FALSE;
    256258
    257259    // Shutdown the dll
     
    261263    nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
    262264#endif
    263         PRStatus ret = PR_UnloadLibrary(m_instance);
     265    int vrc = RTLdrClose(m_hMod);
    264266#ifdef NS_BUILD_REFCNT_LOGGING
    265267    nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
    266268#endif
    267269
    268         if (ret == PR_SUCCESS)
    269         {
    270                 m_instance = NULL;
    271                 return (PR_TRUE);
    272         }
    273         else
    274                 return (PR_FALSE);
     270    if (RT_SUCCESS(vrc))
     271    {
     272        m_hMod = NIL_RTLDRMOD;
     273        return PR_TRUE;
     274    }
     275
     276    return PR_FALSE;
    275277}
    276278
    277279void * nsDll::FindSymbol(const char *symbol)
    278280{
    279         if (symbol == NULL)
    280                 return (NULL);
    281 
    282         // If not already loaded, load it now.
    283         if (Load() != PR_TRUE)
    284                 return (NULL);
    285 
    286     return(PR_FindSymbol(m_instance, symbol));
     281    if (symbol == NULL)
     282        return NULL;
     283
     284    // If not already loaded, load it now.
     285    if (Load() != PR_TRUE)
     286        return NULL;
     287
     288    void *pvSym = NULL;
     289    int vrc = RTLdrGetSymbol(m_hMod, symbol, &pvSym);
     290    RT_NOREF(vrc);
     291
     292    return pvSym;
    287293}
    288294
     
    315321    }
    316322
    317         // If not already loaded, load it now.
    318         if (Load() != PR_TRUE) return NS_ERROR_FAILURE;
     323    // If not already loaded, load it now.
     324    if (Load() != PR_TRUE) return NS_ERROR_FAILURE;
    319325
    320326    // We need a nsIFile for location
  • trunk/src/libs/xpcom18a4/xpcom/components/xcDll.h

    r101942 r101944  
    4747#define xcDll_h__
    4848
    49 #include "prio.h"
    50 #include "prlink.h"
    5149#include "nsISupports.h"
    5250#include "nsILocalFile.h"
    5351#include "nsCOMPtr.h"
    5452#include "nsString.h"
     53
     54#include <iprt/errcore.h>
     55#include <iprt/ldr.h>
    5556
    5657class nsNativeComponentLoader;
     
    7172{
    7273private:
    73     nsCOMPtr<nsIFile>         m_dllSpec; 
    74     PRLibrary                *m_instance;       
     74    nsCOMPtr<nsIFile>         m_dllSpec;
     75    RTLDRMOD                  m_hMod;
    7576    nsIModule                *m_moduleObject;
    7677    nsNativeComponentLoader  *m_loader;
     
    8081
    8182public:
    82  
    83         nsDll(nsIFile *dllSpec, nsNativeComponentLoader* loader);
    84         ~nsDll(void);
    8583
    86         // Dll Loading
    87         PRBool Load(void);
    88         PRBool Unload(void);
    89         PRBool IsLoaded(void)
    90         {
    91                 return ((m_instance != 0) ? PR_TRUE : PR_FALSE);
    92         }
     84    nsDll(nsIFile *dllSpec, nsNativeComponentLoader* loader);
     85    ~nsDll(void);
     86
     87    // Dll Loading
     88    PRBool Load(void);
     89    PRBool Unload(void);
     90    PRBool IsLoaded(void) { return ((m_hMod != NIL_RTLDRMOD) ? PR_TRUE : PR_FALSE); }
     91
    9392    void MarkForUnload(PRBool mark) { m_markForUnload = mark; }
    9493    PRBool IsMarkedForUnload(void) { return m_markForUnload; }
     
    9897    nsresult Shutdown(void);
    9998
    100         void *FindSymbol(const char *symbol);
    101        
     99    void *FindSymbol(const char *symbol);
     100
    102101    PRBool HasChanged(void);
    103102
    104103    void GetDisplayPath(nsACString& string);
    105104
    106         PRLibrary *GetInstance(void) { return (m_instance); }
     105#if 0
     106    PRLibrary *GetInstance(void) { return (m_instance); }
     107#endif
    107108
    108109    // NS_RELEASE() is required to be done on objects returned
  • trunk/src/libs/xpcom18a4/xpcom/io/nsILocalFile.idl

    r1 r101944  
    4343%{C++
    4444#include "prio.h"
    45 #include "prlink.h"
    4645#include <stdio.h>
     46
     47#include <iprt/ldr.h>
    4748%}
    4849
    4950[ptr] native PRFileDescStar(PRFileDesc);
    50 [ptr] native PRLibraryStar(PRLibrary);
     51[ptr] native RTLDRMOD(RTLDRMODINTERNAL);
    5152[ptr] native FILE(FILE);
    5253
     
    105106    [noscript] FILE           openANSIFileDesc(in string mode);
    106107
    107     [noscript] PRLibraryStar  load();
     108    [noscript] RTLDRMOD       load();
    108109   
    109110    readonly attribute PRInt64 diskSpaceAvailable;
  • trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.cpp

    r101803 r101944  
    5858#include <ctype.h>
    5959#include <locale.h>
    60 #ifdef XP_BEOS
    61     #include <Path.h>
    62     #include <Entry.h>
    63     #include <Roster.h>
    64 #endif
    65 #if defined(VMS)
    66     #include <fabdef.h>
    67 #endif
    6860
    6961#include "nsDirectoryServiceDefs.h"
     
    8274#include "nsNativeCharsetUtils.h"
    8375
    84 // On some platforms file/directory name comparisons need to
    85 // be case-blind.
    86 #if defined(VMS)
    87     #define FILE_STRCMP strcasecmp
    88     #define FILE_STRNCMP strncasecmp
    89 #else
    90     #define FILE_STRCMP strcmp
    91     #define FILE_STRNCMP strncmp
    92 #endif
     76#include <iprt/errcore.h>
     77
     78#define FILE_STRCMP strcmp
     79#define FILE_STRNCMP strncmp
    9380
    9481#define VALIDATE_STAT_CACHE()                   \
     
    15321519
    15331520NS_IMETHODIMP
    1534 nsLocalFile::Load(PRLibrary **_retval)
    1535 {
    1536     CHECK_mPath();
    1537     NS_ENSURE_ARG_POINTER(_retval);
    1538 
    1539     *_retval = PR_LoadLibrary(mPath.get());
    1540 
    1541     if (!*_retval)
     1521nsLocalFile::Load(RTLDRMOD *phMod)
     1522{
     1523    CHECK_mPath();
     1524    NS_ENSURE_ARG_POINTER(phMod);
     1525
     1526    RTLDRMOD hMod = NIL_RTLDRMOD;
     1527    int vrc = RTLdrLoad(mPath.get(), &hMod);
     1528    if (RT_FAILURE(vrc))
    15421529        return NS_ERROR_FAILURE;
     1530
     1531    *phMod = hMod;
    15431532    return NS_OK;
    15441533}
  • trunk/src/libs/xpcom18a4/xpcom/tests/RegFactory.cpp

    r1 r101944  
    3838#include <iostream.h>
    3939#include "plstr.h"
    40 #include "prlink.h"
    4140#include "nsIComponentRegistrar.h"
    4241#include "nsIComponentManager.h"
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