VirtualBox

Changeset 98694 in vbox


Ignore:
Timestamp:
Feb 22, 2023 11:08:43 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155994
Message:

Main/cbindings,/Config.kmk: Added VBoxCAPI-x86.dll/so/dylib for 32-bit apps. bugref:7675

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Config.kmk

    r98663 r98694  
    68816881endif
    68826882
     6883# x86 version of VBoxR3TstExe
     6884TEMPLATE_VBoxR3TstExe-x86              := 32-bit VBox Ring 3 Testcase Exe
     6885TEMPLATE_VBoxR3TstExe-x86_EXTENDS      := VBoxR3TstExe
     6886TEMPLATE_VBoxR3TstExe-x86_BLD_TRG_ARCH := x86
     6887TEMPLATE_VBoxR3TstExe-x86_LIBS          = $(LIB_RUNTIME_X86) $(TEMPLATE_VBoxR3Exe_LIBS)
    68836888
    68846889#
     
    73897394TEMPLATE_VBoxMainClientDll_LDFLAGS.darwin = $(filter-out -bind_at_load,$(TEMPLATE_VBoxMainClientExe_LDFLAGS.darwin))
    73907395
     7396# x86 version of VBoxMainClientDll
     7397TEMPLATE_VBoxMainClientDll-x86              := 32-bit VBox MAIN Client (shared library)
     7398TEMPLATE_VBoxMainClientDll-x86_EXTENDS      := VBoxMainClientDll
     7399TEMPLATE_VBoxMainClientDll-x86_BLD_TRG_ARCH := x86
     7400TEMPLATE_VBoxMainClientDll-x86_INST.win      = $(INST_DLL)x86/
     7401TEMPLATE_VBoxMainClientDll-x86_DEFS          = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBoxMainClientDll_DEFS)) \
     7402        HC_ARCH_BIT=32 ARCH_BITS=32 VBOX_IN_32_ON_64_MAIN_API
     7403TEMPLATE_VBoxMainClientDll-x86_LIBS = \
     7404        $(subst $(PATH_STAGE_LIB)/VBoxCOM$(VBOX_SUFF_LIB),$(PATH_STAGE_LIB)/VBoxCOM-x86$(VBOX_SUFF_LIB), \
     7405        $(subst $(LIB_RUNTIME),$(VBOX_LIB_RUNTIME_X86), \
     7406        $(subst $(LIB_XPCOM),$(VBOX_LIB_XPCOM_X86), \
     7407        $(TEMPLATE_VBoxMainClientDll_LIBS))))
     7408
    73917409#
    73927410# Template for building testcases which are API clients.
  • trunk/src/VBox/Main/cbinding/Makefile.kmk

    r98431 r98694  
    104104
    105105 #
     106 # The C API binding utility DLL, 32-bit variant for 64-bit hosts.
     107 #
     108 ifdef VBOX_WITH_32_ON_64_MAIN_API
     109  DLLS += VBoxCAPI-x86
     110  VBoxCAPI-x86_EXTENDS  := VBoxCAPI
     111  VBoxCAPI-x86_TEMPLATE := VBoxMainClientDll-x86
     112  ifdef VBOX_WITH_XPCOM
     113   VBoxCAPI-x86_INST    := $(INST_BIN)VBoxCAPI-x86$(VBOX_SUFF_DLL)
     114  endif
     115 endif
     116
     117 #
    106118 # The C glue library.
    107119 #
     
    124136        $(VBOX_PATH_SDK)/bindings/c/glue/VBoxCAPIGlue.h \
    125137        $(VBOX_PATH_SDK)/bindings/c/include/VBoxCAPI_v$(VBOX_API_VERSION).h
     138
     139
     140 ifdef VBOX_WITH_32_ON_64_MAIN_API
     141 # Same as above, but 32-bit version.
     142  LIBRARIES += VBoxCAPIGlue-x86
     143  VBoxCAPIGlue-x86_EXTENDS      := VBoxCAPIGlue
     144  VBoxCAPIGlue-x86_BLD_TRG_ARCH := x86
     145 endif
     146
    126147
    127148 if defined(VBOX_WITH_TESTCASES) && "$(KBUILD_TARGET)" != "darwin"
     
    150171  tstCAPIGlue_LIBS = \
    151172        $(VBoxCAPIGlue_1_TARGET)
     173
     174  ifdef VBOX_WITH_32_ON_64_MAIN_API
     175   # Same as above, but 32-bit version.
     176   PROGRAMS += tstCAPIGlue-x86
     177   tstCAPIGlue-x86_EXTENDS      := tstCAPIGlue
     178   tstCAPIGlue-x86_TEMPLATE     := VBoxR3TstExe-x86
     179   tstCAPIGlue-x86_BLD_TRG_ARCH := x86
     180   tstCAPIGlue-x86_LIBS          = $(VBoxCAPIGlue-x86_1_TARGET)
     181  endif
    152182 endif
    153183
  • trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp

    r98297 r98694  
    776776     * initialize it properly. The limited initialization in VBoxC is not
    777777     * sufficient, and causes trouble with com::Initialize() misbehaving. */
    778     RTR3InitDll(0);
     778    RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
    779779
    780780    /*
  • trunk/src/VBox/Main/cbinding/VBoxCAPIGlue.c

    r98103 r98694  
    4949# include <dlfcn.h>
    5050# include <pthread.h>
    51 #else /* WIN32 */
     51#else  /* WIN32 */
    5252# include <Windows.h>
    5353#endif /* WIN32 */
     
    5757*   Defined Constants And Macros                                                                                                 *
    5858*********************************************************************************************************************************/
     59#if defined(__i386__) || defined(_M_IX86) || defined(__X86__)
     60/** This is a 32-bit process running against a 64-bit VBox installation.
     61 * Since there are only 64-bit VBox now, we don't need any runtime checks.  */
     62# define IS_32_ON_64
     63#endif
     64
    5965#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || defined(__FreeBSD__)
    60 # define DYNLIB_NAME        "VBoxXPCOMC.so"
     66# ifndef IS_32_ON_64
     67#  define DYNLIB_NAME           "VBoxXPCOMC.so"
     68# else
     69#  define DYNLIB_NAME           "VBoxCAPI-x86.so"
     70# endif
    6171#elif defined(__APPLE__)
    62 # define DYNLIB_NAME        "VBoxXPCOMC.dylib"
    63 #elif defined(__OS2__)
    64 # define DYNLIB_NAME        "VBoxXPCOMC.dll"
     72# ifndef IS_32_ON_64
     73#  define DYNLIB_NAME           "VBoxXPCOMC.dylib"
     74# else
     75#  define DYNLIB_NAME           "VBoxCAPI-x86.dylib"
     76# endif
    6577#elif defined(WIN32)
    66 # define DYNLIB_NAME        "VBoxCAPI.dll"
     78# ifndef IS_32_ON_64
     79#  define DYNLIB_NAME           "VBoxCAPI.dll"
     80# else
     81#  define DYNLIB_NAME           "VBoxCAPI-x86.dll"
     82#  define DYNLIB_SUBDIR         "x86"
     83#  define SLASH_DYNLIB_SUBDIR   "\\" DYNLIB_SUBDIR
     84# endif
    6785#else
    6886# error "Port me"
     87#endif
     88#ifndef DYNLIB_SUBDIR
     89# define DYNLIB_SUBDIR          ""
     90# define SLASH_DYNLIB_SUBDIR    ""
     91#endif
     92
     93#ifdef WIN32
     94# define DIR_SLASH_CH           '\\'
     95#else
     96# define DIR_SLASH_CH           '/'
    6997#endif
    7098
     
    131159 *                          (boolean).
    132160 */
    133 static int tryLoadLibrary(const char *pszHome, int fSetAppHome)
    134 {
    135     size_t      cchHome = pszHome ? strlen(pszHome) : 0;
    136     size_t      cbBufNeeded;
    137     char        szName[4096];
     161static int tryLoadLibrary(const char *pszHome, const char *pszSub, int fSetAppHome)
     162{
     163    size_t const cchHome = pszHome ? strlen(pszHome) : 0;
     164    size_t const cchSub  = pszSub  ? strlen(pszSub)  : 0;
     165    size_t       cbBufNeeded;
     166    size_t       offName;
     167    char         szName[4096];
    138168
    139169    /*
    140170     * Construct the full name.
    141171     */
    142     cbBufNeeded = cchHome + sizeof("/" DYNLIB_NAME);
     172    cbBufNeeded = cchHome + !!cchHome + cchSub + !!cchSub + sizeof(DYNLIB_NAME);
    143173    if (cbBufNeeded > sizeof(szName))
    144174    {
     
    147177        return -1;
    148178    }
     179    offName = 0;
    149180    if (cchHome)
    150181    {
    151         memcpy(szName, pszHome, cchHome);
    152         szName[cchHome] = '/';
    153         cchHome++;
    154     }
    155     memcpy(&szName[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME));
     182        memcpy(&szName[offName], pszHome, cchHome);
     183        offName += cchHome;
     184        szName[offName++] = DIR_SLASH_CH;
     185    }
     186    if (cchSub)
     187    {
     188        memcpy(&szName[offName], pszSub, cchSub);
     189        offName += cchSub;
     190        szName[offName++] = DIR_SLASH_CH;
     191    }
     192    memcpy(&szName[offName], DYNLIB_NAME, sizeof(DYNLIB_NAME));
    156193
    157194    /*
     
    172209    g_hVBoxCAPI = dlopen(szName, RTLD_NOW | RTLD_LOCAL);
    173210#else /* WIN32 */
    174     g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */);
     211    g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */,
     212                                 cchHome ? LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 : 0 /* dwFlags */);
     213    if (!g_hVBoxCAPI && GetLastError() == ERROR_INVALID_PARAMETER)
     214        g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */);
    175215#endif /* WIN32 */
    176216    if (g_hVBoxCAPI)
     
    194234            if (g_pVBoxFuncs)
    195235            {
    196                 if (   (   VBOX_CAPI_MAJOR(g_pVBoxFuncs->uVersion)
    197                         == VBOX_CAPI_MAJOR(VBOX_CAPI_VERSION))
    198                     && (   VBOX_CAPI_MINOR(g_pVBoxFuncs->uVersion)
    199                         >= VBOX_CAPI_MINOR(VBOX_CAPI_VERSION)))
     236                if (      VBOX_CAPI_MAJOR(g_pVBoxFuncs->uVersion)
     237                       == VBOX_CAPI_MAJOR(VBOX_CAPI_VERSION)
     238                    &&    VBOX_CAPI_MINOR(g_pVBoxFuncs->uVersion)
     239                       >= VBOX_CAPI_MINOR(VBOX_CAPI_VERSION))
    200240                {
    201241                    g_pfnGetFunctions = pfnGetFunctions;
     
    266306    pszHome = getenv("VBOX_APP_HOME");
    267307    if (pszHome)
    268         return tryLoadLibrary(pszHome, 0);
     308        return tryLoadLibrary(pszHome, DYNLIB_SUBDIR, 0);
    269309
    270310    /*
     
    272312     */
    273313#if defined(__gnu__linux__) || defined(__linux__)
    274     if (tryLoadLibrary("/opt/VirtualBox", 1) == 0)
    275         return 0;
    276     if (tryLoadLibrary("/usr/lib/virtualbox", 1) == 0)
     314    if (tryLoadLibrary("/opt/VirtualBox", DYNLIB_SUBDIR, 1) == 0)
     315        return 0;
     316    if (tryLoadLibrary("/usr/lib/virtualbox", DYNLIB_SUBDIR, 1) == 0)
    277317        return 0;
    278318#elif defined(__sun__)
    279     if (tryLoadLibrary("/opt/VirtualBox/amd64", 1) == 0)
    280         return 0;
    281     if (tryLoadLibrary("/opt/VirtualBox/i386", 1) == 0)
     319    if (tryLoadLibrary("/opt/VirtualBox/amd64", NULL, 1) == 0)
     320        return 0;
     321    if (tryLoadLibrary("/opt/VirtualBox/i386", NULL, 1) == 0)
    282322        return 0;
    283323#elif defined(__APPLE__)
    284     if (tryLoadLibrary("/Applications/VirtualBox.app/Contents/MacOS", 1) == 0)
     324    if (tryLoadLibrary("/Applications/VirtualBox.app/Contents/MacOS", DYNLIB_SUBDIR, 1) == 0)
    285325        return 0;
    286326#elif defined(__FreeBSD__)
    287     if (tryLoadLibrary("/usr/local/lib/virtualbox", 1) == 0)
    288         return 0;
    289 #elif defined(__OS2__)
    290     if (tryLoadLibrary("C:/Apps/VirtualBox", 1) == 0)
     327    if (tryLoadLibrary("/usr/local/lib/virtualbox", DYNLIB_SUBDIR, 1) == 0)
    291328        return 0;
    292329#elif defined(WIN32)
     330# ifdef IS_32_ON_64
     331    pszHome = getenv("ProgramW6432");
     332    if (pszHome && tryLoadLibrary(pszHome, "\\Oracle\\VirtualBox" SLASH_DYNLIB_SUBDIR, 1) == 0)
     333        return 0;
     334# endif
    293335    pszHome = getenv("ProgramFiles");
    294     if (pszHome)
    295     {
    296         char szPath[4096];
    297         size_t cb = sizeof(szPath);
    298         char *tmp = szPath;
    299         strncpy(tmp, pszHome, cb);
    300         tmp[cb - 1] = '\0';
    301         cb -= strlen(tmp);
    302         tmp += strlen(tmp);
    303         strncpy(tmp, "/Oracle/VirtualBox", cb);
    304         tmp[cb - 1] = '\0';
    305         if (tryLoadLibrary(szPath, 1) == 0)
    306             return 0;
    307     }
    308     if (tryLoadLibrary("C:/Program Files/Oracle/VirtualBox", 1) == 0)
     336    if (pszHome && tryLoadLibrary(pszHome, "\\Oracle\\VirtualBox" SLASH_DYNLIB_SUBDIR, 1) == 0)
     337        return 0;
     338    if (tryLoadLibrary("C:\\Program Files\\Oracle\\VirtualBox", DYNLIB_SUBDIR, 1) == 0)
    309339        return 0;
    310340#else
     
    315345     * Finally try the dynamic linker search path.
    316346     */
    317     if (tryLoadLibrary(NULL, 1) == 0)
     347    if (tryLoadLibrary(NULL, NULL, 1) == 0)
    318348        return 0;
    319349
Note: See TracChangeset for help on using the changeset viewer.

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