VirtualBox

Changeset 7279 in vbox


Ignore:
Timestamp:
Mar 4, 2008 3:37:58 PM (17 years ago)
Author:
vboxsync
Message:

Runtime function to load a shared library from the application directories.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/ldr.h

    r5999 r7279  
    5656 */
    5757RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
     58
     59/**
     60 * Loads a dynamic load library (/shared object) image file using native
     61 * OS facilities.
     62 *
     63 * If the path is specified in the filename, only this path is used.
     64 * If only the image file name is specified, then try to load it from:
     65 *   - RTPathAppPrivateArch
     66 *   - RTPathSharedLibs (legacy)
     67 *
     68 * @returns iprt status code.
     69 * @param   pszFilename Image filename.
     70 * @param   phLdrMod    Where to store the handle to the loaded module.
     71 */
     72RTDECL(int) RTLdrLoadAppSharedLib(const char *pszFilename, PRTLDRMOD phLdrMod);
    5873
    5974/**
  • trunk/src/VBox/Runtime/common/ldr/ldrNative.cpp

    r5999 r7279  
    3434#include <iprt/assert.h>
    3535#include <iprt/log.h>
     36#include <iprt/param.h>
     37#include <iprt/path.h>
    3638#include <iprt/string.h>
    3739#include <iprt/err.h>
     
    129131}
    130132
     133
     134/**
     135 * Loads a dynamic load library (/shared object) image file using native
     136 * OS facilities.
     137 *
     138 * If the path is specified in the filename, only this path is used.
     139 * If only the image file name is specified, then try to load it from:
     140 *   - RTPathAppPrivateArch
     141 *   - RTPathSharedLibs (legacy)
     142 *
     143 * @returns iprt status code.
     144 * @param   pszFilename Image filename.
     145 * @param   phLdrMod    Where to store the handle to the loaded module.
     146 */
     147RTDECL(int) RTLdrLoadAppSharedLib(const char *pszFilename, PRTLDRMOD phLdrMod)
     148{
     149    LogFlow(("RTLdrLoadAppSharedLib: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
     150
     151    /*
     152     * Validate input.
     153     */
     154    AssertMsgReturn(VALID_PTR(pszFilename), ("pszFilename=%p\n", pszFilename), VERR_INVALID_PARAMETER);
     155    AssertMsgReturn(VALID_PTR(phLdrMod), ("phLdrMod=%p\n", phLdrMod), VERR_INVALID_PARAMETER);
     156
     157    /*
     158     * If a path is specified, just load the file.
     159     */
     160    if (RTPathHavePath(pszFilename))
     161        return RTLdrLoad(pszFilename, phLdrMod);
     162
     163    /*
     164     * By default nothing is found.
     165     */
     166    int rc = VERR_FILE_NOT_FOUND;
     167    *phLdrMod = NIL_RTLDRMOD;
     168
     169    /*
     170     * Try default locations.
     171     */
     172    int i;
     173    for (i = 0;; i++)
     174    {
     175        /*
     176         * Get the appropriate base path.
     177         */
     178        char szBase[RTPATH_MAX];
     179        if (i == 0)
     180            rc = RTPathAppPrivateArch(szBase, sizeof (szBase));
     181        else if (i == 1)
     182            rc = RTPathSharedLibs(szBase, sizeof (szBase));
     183        else
     184            break;
     185
     186        if (RT_SUCCESS(rc))
     187        {
     188            /*
     189             * Got the base path. Construct szPath = pszBase + pszFilename
     190             */
     191            char szPath[RTPATH_MAX];
     192            rc = RTPathAbsEx(szBase, pszFilename, szPath, sizeof (szPath));
     193            if (RT_SUCCESS(rc))
     194            {
     195                /*
     196                 * Finally try to load the image file.
     197                 */
     198                rc = RTLdrLoad(szPath, phLdrMod);
     199                if (RT_SUCCESS(rc))
     200                {
     201                    /*
     202                     * Successfully loaded the image file.
     203                     */
     204                    LogFlow(("Library loaded: [%s]\n", szPath));
     205                    break;
     206                }
     207            }
     208        }
     209    }
     210    LogFlow(("RTLdrLoadAppSharedLib: returns %Rrc\n", rc));
     211    return rc;
     212}
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