diff options
-rw-r--r-- | Config.kmk | 18 | ||||
-rw-r--r-- | src/VBox/Main/cbinding/Makefile.kmk | 30 | ||||
-rw-r--r-- | src/VBox/Main/cbinding/VBoxCAPI.cpp | 2 | ||||
-rw-r--r-- | src/VBox/Main/cbinding/VBoxCAPIGlue.c | 122 |
4 files changed, 125 insertions, 47 deletions
diff --git a/Config.kmk b/Config.kmk index e94ca23b3b3..eedd8c31edc 100644 --- a/Config.kmk +++ b/Config.kmk @@ -6880,6 +6880,11 @@ if defined(VBOX_WITH_MORE_NT4_COMPAT_BINARIES) && "$(KBUILD_TARGET).$(KBUILD_TAR $(PATH_TOOL_$(TEMPLATE_VBoxR3Exe_TOOL.win.x86)_LIB)/oldnames.lib endif +# x86 version of VBoxR3TstExe +TEMPLATE_VBoxR3TstExe-x86 := 32-bit VBox Ring 3 Testcase Exe +TEMPLATE_VBoxR3TstExe-x86_EXTENDS := VBoxR3TstExe +TEMPLATE_VBoxR3TstExe-x86_BLD_TRG_ARCH := x86 +TEMPLATE_VBoxR3TstExe-x86_LIBS = $(LIB_RUNTIME_X86) $(TEMPLATE_VBoxR3Exe_LIBS) # # Ring-3 testcase DLL. @@ -7388,6 +7393,19 @@ ifn1of ($(KBUILD_TARGET), darwin os2 win) endif TEMPLATE_VBoxMainClientDll_LDFLAGS.darwin = $(filter-out -bind_at_load,$(TEMPLATE_VBoxMainClientExe_LDFLAGS.darwin)) +# x86 version of VBoxMainClientDll +TEMPLATE_VBoxMainClientDll-x86 := 32-bit VBox MAIN Client (shared library) +TEMPLATE_VBoxMainClientDll-x86_EXTENDS := VBoxMainClientDll +TEMPLATE_VBoxMainClientDll-x86_BLD_TRG_ARCH := x86 +TEMPLATE_VBoxMainClientDll-x86_INST.win = $(INST_DLL)x86/ +TEMPLATE_VBoxMainClientDll-x86_DEFS = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VBoxMainClientDll_DEFS)) \ + HC_ARCH_BIT=32 ARCH_BITS=32 VBOX_IN_32_ON_64_MAIN_API +TEMPLATE_VBoxMainClientDll-x86_LIBS = \ + $(subst $(PATH_STAGE_LIB)/VBoxCOM$(VBOX_SUFF_LIB),$(PATH_STAGE_LIB)/VBoxCOM-x86$(VBOX_SUFF_LIB), \ + $(subst $(LIB_RUNTIME),$(VBOX_LIB_RUNTIME_X86), \ + $(subst $(LIB_XPCOM),$(VBOX_LIB_XPCOM_X86), \ + $(TEMPLATE_VBoxMainClientDll_LIBS)))) + # # Template for building testcases which are API clients. # diff --git a/src/VBox/Main/cbinding/Makefile.kmk b/src/VBox/Main/cbinding/Makefile.kmk index eda3f10eb60..228e09381eb 100644 --- a/src/VBox/Main/cbinding/Makefile.kmk +++ b/src/VBox/Main/cbinding/Makefile.kmk @@ -103,6 +103,18 @@ if !defined(VBOX_ONLY_SDK) $(CAPIHeaders_0_OUTDIR)/VBoxCAPI.h # + # The C API binding utility DLL, 32-bit variant for 64-bit hosts. + # + ifdef VBOX_WITH_32_ON_64_MAIN_API + DLLS += VBoxCAPI-x86 + VBoxCAPI-x86_EXTENDS := VBoxCAPI + VBoxCAPI-x86_TEMPLATE := VBoxMainClientDll-x86 + ifdef VBOX_WITH_XPCOM + VBoxCAPI-x86_INST := $(INST_BIN)VBoxCAPI-x86$(VBOX_SUFF_DLL) + endif + endif + + # # The C glue library. # LIBRARIES += VBoxCAPIGlue @@ -124,6 +136,15 @@ if !defined(VBOX_ONLY_SDK) $(VBOX_PATH_SDK)/bindings/c/glue/VBoxCAPIGlue.h \ $(VBOX_PATH_SDK)/bindings/c/include/VBoxCAPI_v$(VBOX_API_VERSION).h + + ifdef VBOX_WITH_32_ON_64_MAIN_API + # Same as above, but 32-bit version. + LIBRARIES += VBoxCAPIGlue-x86 + VBoxCAPIGlue-x86_EXTENDS := VBoxCAPIGlue + VBoxCAPIGlue-x86_BLD_TRG_ARCH := x86 + endif + + if defined(VBOX_WITH_TESTCASES) && "$(KBUILD_TARGET)" != "darwin" # # The testcase (also in samples). @@ -149,6 +170,15 @@ if !defined(VBOX_ONLY_SDK) tstCAPIGlue.c tstCAPIGlue_LIBS = \ $(VBoxCAPIGlue_1_TARGET) + + ifdef VBOX_WITH_32_ON_64_MAIN_API + # Same as above, but 32-bit version. + PROGRAMS += tstCAPIGlue-x86 + tstCAPIGlue-x86_EXTENDS := tstCAPIGlue + tstCAPIGlue-x86_TEMPLATE := VBoxR3TstExe-x86 + tstCAPIGlue-x86_BLD_TRG_ARCH := x86 + tstCAPIGlue-x86_LIBS = $(VBoxCAPIGlue-x86_1_TARGET) + endif endif endif # ! VBOX_ONLY_SDK diff --git a/src/VBox/Main/cbinding/VBoxCAPI.cpp b/src/VBox/Main/cbinding/VBoxCAPI.cpp index 66b36dc1885..a7240e35a5e 100644 --- a/src/VBox/Main/cbinding/VBoxCAPI.cpp +++ b/src/VBox/Main/cbinding/VBoxCAPI.cpp @@ -775,7 +775,7 @@ VBoxGetCAPIFunctions(unsigned uVersion) /* This is the first piece of code which knows that IPRT exists, so * initialize it properly. The limited initialization in VBoxC is not * sufficient, and causes trouble with com::Initialize() misbehaving. */ - RTR3InitDll(0); + RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); /* * The current interface version. diff --git a/src/VBox/Main/cbinding/VBoxCAPIGlue.c b/src/VBox/Main/cbinding/VBoxCAPIGlue.c index e906083dc31..9577fb540d6 100644 --- a/src/VBox/Main/cbinding/VBoxCAPIGlue.c +++ b/src/VBox/Main/cbinding/VBoxCAPIGlue.c @@ -48,7 +48,7 @@ #ifndef WIN32 # include <dlfcn.h> # include <pthread.h> -#else /* WIN32 */ +#else /* WIN32 */ # include <Windows.h> #endif /* WIN32 */ @@ -56,17 +56,45 @@ /********************************************************************************************************************************* * Defined Constants And Macros * *********************************************************************************************************************************/ +#if defined(__i386__) || defined(_M_IX86) || defined(__X86__) +/** This is a 32-bit process running against a 64-bit VBox installation. + * Since there are only 64-bit VBox now, we don't need any runtime checks. */ +# define IS_32_ON_64 +#endif + #if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || defined(__FreeBSD__) -# define DYNLIB_NAME "VBoxXPCOMC.so" +# ifndef IS_32_ON_64 +# define DYNLIB_NAME "VBoxXPCOMC.so" +# else +# define DYNLIB_NAME "VBoxCAPI-x86.so" +# endif #elif defined(__APPLE__) -# define DYNLIB_NAME "VBoxXPCOMC.dylib" -#elif defined(__OS2__) -# define DYNLIB_NAME "VBoxXPCOMC.dll" +# ifndef IS_32_ON_64 +# define DYNLIB_NAME "VBoxXPCOMC.dylib" +# else +# define DYNLIB_NAME "VBoxCAPI-x86.dylib" +# endif #elif defined(WIN32) -# define DYNLIB_NAME "VBoxCAPI.dll" +# ifndef IS_32_ON_64 +# define DYNLIB_NAME "VBoxCAPI.dll" +# else +# define DYNLIB_NAME "VBoxCAPI-x86.dll" +# define DYNLIB_SUBDIR "x86" +# define SLASH_DYNLIB_SUBDIR "\\" DYNLIB_SUBDIR +# endif #else # error "Port me" #endif +#ifndef DYNLIB_SUBDIR +# define DYNLIB_SUBDIR "" +# define SLASH_DYNLIB_SUBDIR "" +#endif + +#ifdef WIN32 +# define DIR_SLASH_CH '\\' +#else +# define DIR_SLASH_CH '/' +#endif /********************************************************************************************************************************* @@ -130,29 +158,38 @@ static void setErrMsg(int fAlways, const char *pszFormat, ...) * @param fSetAppHome Whether to set the VBOX_APP_HOME env.var. or not * (boolean). */ -static int tryLoadLibrary(const char *pszHome, int fSetAppHome) +static int tryLoadLibrary(const char *pszHome, const char *pszSub, int fSetAppHome) { - size_t cchHome = pszHome ? strlen(pszHome) : 0; - size_t cbBufNeeded; - char szName[4096]; + size_t const cchHome = pszHome ? strlen(pszHome) : 0; + size_t const cchSub = pszSub ? strlen(pszSub) : 0; + size_t cbBufNeeded; + size_t offName; + char szName[4096]; /* * Construct the full name. */ - cbBufNeeded = cchHome + sizeof("/" DYNLIB_NAME); + cbBufNeeded = cchHome + !!cchHome + cchSub + !!cchSub + sizeof(DYNLIB_NAME); if (cbBufNeeded > sizeof(szName)) { setErrMsg(1, "path buffer too small: %u bytes needed", (unsigned)cbBufNeeded); return -1; } + offName = 0; if (cchHome) { - memcpy(szName, pszHome, cchHome); - szName[cchHome] = '/'; - cchHome++; + memcpy(&szName[offName], pszHome, cchHome); + offName += cchHome; + szName[offName++] = DIR_SLASH_CH; } - memcpy(&szName[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME)); + if (cchSub) + { + memcpy(&szName[offName], pszSub, cchSub); + offName += cchSub; + szName[offName++] = DIR_SLASH_CH; + } + memcpy(&szName[offName], DYNLIB_NAME, sizeof(DYNLIB_NAME)); /* * Try load it by that name, setting the VBOX_APP_HOME first (for now). @@ -171,7 +208,10 @@ static int tryLoadLibrary(const char *pszHome, int fSetAppHome) #ifndef WIN32 g_hVBoxCAPI = dlopen(szName, RTLD_NOW | RTLD_LOCAL); #else /* WIN32 */ - g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */); + g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, + cchHome ? LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 : 0 /* dwFlags */); + if (!g_hVBoxCAPI && GetLastError() == ERROR_INVALID_PARAMETER) + g_hVBoxCAPI = LoadLibraryExA(szName, NULL /* hFile */, 0 /* dwFlags */); #endif /* WIN32 */ if (g_hVBoxCAPI) { @@ -193,10 +233,10 @@ static int tryLoadLibrary(const char *pszHome, int fSetAppHome) g_pVBoxFuncs = pfnGetFunctions(VBOX_CAPI_VERSION); if (g_pVBoxFuncs) { - if ( ( VBOX_CAPI_MAJOR(g_pVBoxFuncs->uVersion) - == VBOX_CAPI_MAJOR(VBOX_CAPI_VERSION)) - && ( VBOX_CAPI_MINOR(g_pVBoxFuncs->uVersion) - >= VBOX_CAPI_MINOR(VBOX_CAPI_VERSION))) + if ( VBOX_CAPI_MAJOR(g_pVBoxFuncs->uVersion) + == VBOX_CAPI_MAJOR(VBOX_CAPI_VERSION) + && VBOX_CAPI_MINOR(g_pVBoxFuncs->uVersion) + >= VBOX_CAPI_MINOR(VBOX_CAPI_VERSION)) { g_pfnGetFunctions = pfnGetFunctions; return 0; @@ -265,47 +305,37 @@ int VBoxCGlueInit(void) */ pszHome = getenv("VBOX_APP_HOME"); if (pszHome) - return tryLoadLibrary(pszHome, 0); + return tryLoadLibrary(pszHome, DYNLIB_SUBDIR, 0); /* * Try the known standard locations. */ #if defined(__gnu__linux__) || defined(__linux__) - if (tryLoadLibrary("/opt/VirtualBox", 1) == 0) + if (tryLoadLibrary("/opt/VirtualBox", DYNLIB_SUBDIR, 1) == 0) return 0; - if (tryLoadLibrary("/usr/lib/virtualbox", 1) == 0) + if (tryLoadLibrary("/usr/lib/virtualbox", DYNLIB_SUBDIR, 1) == 0) return 0; #elif defined(__sun__) - if (tryLoadLibrary("/opt/VirtualBox/amd64", 1) == 0) + if (tryLoadLibrary("/opt/VirtualBox/amd64", NULL, 1) == 0) return 0; - if (tryLoadLibrary("/opt/VirtualBox/i386", 1) == 0) + if (tryLoadLibrary("/opt/VirtualBox/i386", NULL, 1) == 0) return 0; #elif defined(__APPLE__) - if (tryLoadLibrary("/Applications/VirtualBox.app/Contents/MacOS", 1) == 0) + if (tryLoadLibrary("/Applications/VirtualBox.app/Contents/MacOS", DYNLIB_SUBDIR, 1) == 0) return 0; #elif defined(__FreeBSD__) - if (tryLoadLibrary("/usr/local/lib/virtualbox", 1) == 0) - return 0; -#elif defined(__OS2__) - if (tryLoadLibrary("C:/Apps/VirtualBox", 1) == 0) + if (tryLoadLibrary("/usr/local/lib/virtualbox", DYNLIB_SUBDIR, 1) == 0) return 0; #elif defined(WIN32) +# ifdef IS_32_ON_64 + pszHome = getenv("ProgramW6432"); + if (pszHome && tryLoadLibrary(pszHome, "\\Oracle\\VirtualBox" SLASH_DYNLIB_SUBDIR, 1) == 0) + return 0; +# endif pszHome = getenv("ProgramFiles"); - if (pszHome) - { - char szPath[4096]; - size_t cb = sizeof(szPath); - char *tmp = szPath; - strncpy(tmp, pszHome, cb); - tmp[cb - 1] = '\0'; - cb -= strlen(tmp); - tmp += strlen(tmp); - strncpy(tmp, "/Oracle/VirtualBox", cb); - tmp[cb - 1] = '\0'; - if (tryLoadLibrary(szPath, 1) == 0) - return 0; - } - if (tryLoadLibrary("C:/Program Files/Oracle/VirtualBox", 1) == 0) + if (pszHome && tryLoadLibrary(pszHome, "\\Oracle\\VirtualBox" SLASH_DYNLIB_SUBDIR, 1) == 0) + return 0; + if (tryLoadLibrary("C:\\Program Files\\Oracle\\VirtualBox", DYNLIB_SUBDIR, 1) == 0) return 0; #else # error "port me" @@ -314,7 +344,7 @@ int VBoxCGlueInit(void) /* * Finally try the dynamic linker search path. */ - if (tryLoadLibrary(NULL, 1) == 0) + if (tryLoadLibrary(NULL, NULL, 1) == 0) return 0; /* No luck, return failure. */ |