VirtualBox

Changeset 2247 in kBuild for trunk/src


Ignore:
Timestamp:
Jan 18, 2009 4:08:13 AM (16 years ago)
Author:
bird
Message:

kbuild.c/FreeBSD: Alternative method for obtaining the executable address.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kbuild.c

    r2243 r2247  
    4040#if defined(__APPLE__)
    4141# include <mach-o/dyld.h>
     42#endif
     43#if defined(__FreeBSD__)
     44# include <dlfcn.h>
     45# include <sys/link_elf.h>
    4246#endif
    4347
     
    133137    rc = readlink("/proc/curproc/file", szTmp, GET_PATH_MAX - 1);
    134138    if (rc < 0 || rc == GET_PATH_MAX - 1)
     139    {
     140        /* /proc is optional, try rtdl. */
     141        void *hExe = dlopen(NULL, 0);
    135142        rc = -1;
     143        if (hExe)
     144        {
     145            struct link_map const *pLinkMap = 0;
     146            if (dlinfo(hExe, RTLD_DI_LINKMAP, &pLinkMap) == 0)
     147            {
     148                const char *pszImageName = pLinkMap->l_name;
     149                size_t cchImageName = strlen(pszImageName);
     150                if (cchImageName < GET_PATH_MAX)
     151                {
     152                    memcpy(szTmp, pszImageName, cchImageName + 1);
     153                    rc = 0;
     154                }
     155            }   
     156        }
     157    }
    136158    else
    137159        szTmp[rc] = '\0';
    138160
    139 #elif defined(__gnu_linux__) /** @todo find proper define... */
     161#elif defined(__gnu_linux__) || defined(__linux__)
    140162    rc = readlink("/proc/self/exe", szTmp, GET_PATH_MAX - 1);
    141163    if (rc < 0 || rc == GET_PATH_MAX - 1)
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