Changeset 395


Ignore:
Timestamp:
Jul 18, 2012, 9:37:38 PM (13 years ago)
Author:
dmik
Message:

Make sure BEGINLIBPATH is not necessary when loading JVM.

BEGINLIBPATH is not necessary at all now: neither when loading the JVM
with standard launchers (like java.exe) nor when doing JVM.DLL directly.

Location:
trunk/openjdk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/openjdk/hotspot/src/os/os2/vm/os_os2_init.cpp

    r346 r395  
    2828// the Windows DllMain() and registers the DLL with Odin
    2929
     30#define INCL_DOS
     31#define INCL_ERRORS
    3032#include <os2wrap.h> // Odin32 OS/2 api wrappers
    3133#include <odinlx.h>
     
    3638#include <emx/startup.h>
    3739#endif
     40
     41#include <string.h>
    3842
    3943extern "C" BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved);
     
    7276        CheckVersionFromHMOD(PE2LX_VERSION, hModule);
    7377
     78        // Assuming that JVM.DLL is stored in a bin/<type>/ subdirectory (where
     79        // type is e.g. "client"), we add this directory, as well as its parent
     80        // (which contains all other Java DLLs), to BEGINLIBPATH so that the OS2
     81        // DLL loader can satisfy DLL dependencies (i.e. find DLLs referred to
     82        // by other DLLs through their import module table) when some Java DLLs
     83        // (e.g. JAVA.DLL, JZIP.DLL) are dynamically loaded later by JVM.DLL.
     84        // Note that despite the fact that JVM.DLL is already loaded at this
     85        // point, we still need to add its directory to BEGINLIBPATH. This is
     86        // bcause most likely it's been loaded by full path which does NOT make
     87        // it locatable by the loader when referred to by name from the import
     88        // table of some other DLL (like JAVA.DLL).
     89
     90        char dllpath[CCHMAXPATH + 16 /* ";%BEGINLIBPATH%" */];
     91        if (DosQueryModuleName(hModule, sizeof(dllpath), dllpath) == NO_ERROR)
     92        {
     93            char *end = strrchr(dllpath, '\\');
     94            if (end)
     95            {
     96                strcpy(end, ";%BEGINLIBPATH%");
     97                DosSetExtLIBPATH(dllpath, BEGIN_LIBPATH);
     98                end = strrchr(dllpath, '\\');
     99                if (end)
     100                {
     101                    strcpy(end, ";%BEGINLIBPATH%");
     102                    DosSetExtLIBPATH(dllpath, BEGIN_LIBPATH);
     103                }
     104            }
     105        }
     106
    74107#ifdef ODIN_FORCE_WIN32_TIB
    75108        // enable __try/__except support
  • trunk/openjdk/jdk/src/windows/bin/java_md.c

    r390 r395  
    234234#ifdef __WIN32OS2__
    235235    /*
    236      * Native OS/2 LX DLLs support importing functions from other DLLs using
    237      * relocation fixup records which differs from the Win32 PE format that does
    238      * this through the IAT (import address table - a table of function
    239      * pointers). As a result, if DLL_A imports something from DLL_B, then when
    240      * DLL_A is loaded by a process, it will load a particular version of DLL_B
     236     * Native OS/2 LX DLLs import functions from other DLLs using relocation
     237     * fixup records which differs from the Win32 PE format that does this
     238     * through the IAT (import address table - a table of function pointers).
     239     * As a result, if DLL_A imports something from DLL_B then when DLL_A is
     240     * loaded by a process, it will load a particular version of DLL_B
    241241     * to call its functions and all other processes that load DLL_A will get
    242      * the same calls to that particular version of DLL_B (from within DLL_A)
    243      * even though they supply their own version of DLL_B. In case of Java this
    244      * means that if there is a Java process using e.g. server/JVM.DLL and
    245      * another process is requesting client/JVM.DLL, this second process will
    246      * eventually crash because all Java DLLs statically linked to JVM.DLL (e.g.
     242     * the same calls to that particular version of DLL_B even though they
     243     * supply their own version of DLL_B (because relocation only happens once
     244     * and it is system-wide, as opposed to Win32 where IAT tables are per-
     245     * process). In case of Java this means that if there is a Java process
     246     * using e.g. server/JVM.DLL and another process is requesting
     247     * client/JVM.DLL, this second process will eventually crash because all
     248     * Java DLLs statically linked to JVM.DLL through the import table (e.g.
    247249     * JVERIFY.DLL, JZIP.DLL) which it loads later will be calling functions
    248250     * from server/JVM.DLL but that DLL is *not* initialized within this process
    249      * (no surprise, it loaded and initialized client/JVM.DLL instead). In order
    250      * to avoid such crashes we have to give a corresponding error message and
    251      * terminate, there is no other solution so far.
     251     * (no surprise, the process has loaded and initialized client/JVM.DLL
     252     * instead). In order to avoid such crashes we have to give a corresponding
     253     * error message and terminate, there is no other solution so far.
    252254     */
    253255    {
     
    281283            return JNI_FALSE;
    282284    }
    283 
    284     /*
    285      * Add the JRE bin path to BEGINLIBPATH to make sure that other DLLs
    286      * statically linked to the various JRE DLLs (so that they refer to them by
    287      * name in the import tables) are able to find it. This is necessary because
    288      * on OS/2, loading a DLL by full path does NOT make it available to other
    289      * DLLs by name -- a normal procedure of searching it in LIBPATH and
    290      * BEGINLIBPATH/ENDLIBPATH is always performed in this case.
    291      */
    292     if (GetJREPath(crtpath, MAXPATHLEN)) {
    293         char *dir = (char *)malloc(strlen(crtpath) + 4 + 32);
    294         strcpy(dir, crtpath);
    295         strcat(dir, "\\bin;%BEGINLIBPATH%");
    296         if (_launcher_debug) {
    297              printf("Adding %s to BEGINLIBPATH\n", dir);
    298         }
    299         DosSetExtLIBPATH(dir, BEGIN_LIBPATH);
    300         free(dir);
    301     }
    302 
    303     /*
    304      * Do the same for the Java VM DLL which is located in a separate directory.
    305      */
    306     char *jvmdir = (char *)malloc(strlen(jvmpath) + 1 + 32);
    307     strcpy(jvmdir, jvmpath);
    308     char *sep = strrchr(jvmdir, '\\');
    309     if (sep) {
    310         strcpy(sep, ";%BEGINLIBPATH%");
    311         if (_launcher_debug) {
    312              printf("Adding %s to BEGINLIBPATH\n", jvmdir);
    313         }
    314         DosSetExtLIBPATH(jvmdir, BEGIN_LIBPATH);
    315     }
    316     free(jvmdir);
    317285#endif
    318286
Note: See TracChangeset for help on using the changeset viewer.