Changeset 274


Ignore:
Timestamp:
Mar 9, 2011, 9:38:55 PM (14 years ago)
Author:
dmik
Message:

jdk: Provide common DllMain() code that calls static destructors when the DLL is detached from the process at termination and use it in JAWTOS2.DLL and JSOUND*.DLL. This fixes crashes in WGSS50.DLL and KERNEL32.DLL during Java process termination when running some applications (e.g. any application using sound, see #78 for details).

Location:
trunk/openjdk/jdk
Files:
1 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/openjdk/jdk/make/common/Library.gmk

    r245 r274  
    340340OTHER_INCLUDES += -I$(PLATFORM_SRC_OS2)/native/common
    341341OTHER_INCLUDES += -I$(PLATFORM_SRC_OS2)/native/$(PKGDIR)
     342# path to common code used by many DLLs
     343vpath %.cpp $(PLATFORM_SRC_OS2)/native/common
    342344endif
    343345
  • trunk/openjdk/jdk/make/javax/sound/FILES_c.gmk

    r255 r274  
    3333        PLATFORM_API_SolarisOS_PCM.c
    3434
    35 FILES_linux = 
     35FILES_linux =
    3636
    3737FILES_windows = \
     
    4646        PLATFORM_API_WinOS_Util.c \
    4747        PLATFORM_API_WinOS_Ports.c
    48        
     48
     49ifeq ($(PLATFORM), os2)
     50FILES_cpp += \
     51        jdk_DllMain.cpp
     52endif
     53
    4954FILES_export = \
    5055        com/sun/media/sound/Platform.java
  • trunk/openjdk/jdk/make/javax/sound/jsoundds/Makefile

    r255 r274  
    4747        PLATFORM_API_WinOS_DirectSound.cpp
    4848
     49ifeq ($(PLATFORM), os2)
     50FILES_cpp += \
     51        jdk_DllMain.cpp
     52endif
     53
    4954FILES_export = \
    5055        $(DAUDIOFILES_export)
  • trunk/openjdk/jdk/make/sun/awt/Makefile

    r263 r274  
    9494include FILES_export_windows.gmk
    9595
    96 FILES_c += awt_init.c
     96FILES_cpp += jdk_DllMain.cpp
    9797
    9898#
  • trunk/openjdk/jdk/src/os2/native/common/jdk_DllMain.cpp

    r272 r274  
    33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    44 *
    5  * Copyright 2010 netlabs.org. OS/2 Parts.
     5 * Copyright 2010-2011 netlabs.org. OS/2 Parts.
    66 *
    77 * This code is free software; you can redistribute it and/or modify it
     
    2626 */
    2727
    28 // This code performs C++ runtime initialization and registers the DLL
    29 // with Odin
     28// This code performs C++ runtime termination to make sure that the
     29// destructors of static objects are destroyed before Odin unloads itself
     30// at program termination. This is achieved by registering the DLL with Odin
     31// which makes sure it calls the supplied DllMain() routine at the right
     32// time. Note that using DosExitList() for this purpose is not a good idea
     33// because some Odin services still needed by the destructor code of some JDK
     34// classes may already be down when exit list routines are run.
    3035
    3136#define INCL_DOSPROCESS
     
    3338#include <odinlx.h>
    3439#include <misc.h>
    35 #include <exitlist.h>
    36 
    37 //#include <types.h>
    38 //#include <stdio.h>
    3940
    4041#include <emx/startup.h>
    4142
    42 static void APIENTRY cleanup(ULONG reason);
     43static HMODULE dllHandle = 0;
    4344
    44 static HMODULE dllHandle = 0;
     45BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
     46{
     47    // call destructors when detaching the DLL from the process
     48    if (reason == 0)
     49        __ctordtorTerm();
     50
     51    return TRUE;
     52}
    4553
    4654unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long ulFlag)
    4755{
    48     APIRET rc;
    49 
    5056    // If ulFlag is zero then the DLL is being loaded so initialization should
    5157    // be performed.  If ulFlag is 1 then the DLL is being freed so termination
     
    5359
    5460    // Note that we don't perform CRT initialization and things because this
    55     // is done in os_os2_init.cpp of JVM.DLL that is already loaded
     61    // is done in os_os2_init.cpp of JVM.DLL that is always loaded first
    5662
    5763    switch (ulFlag) {
    5864        case 0 :
    59             dllHandle = RegisterLxDll(hModule, NULL, NULL,
     65            dllHandle = RegisterLxDll(hModule, DllMain, NULL,
    6066                                      ODINNT_MAJOR_VERSION,
    6167                                      ODINNT_MINOR_VERSION,
     
    6672            __ctordtorInit();
    6773
    68             rc = DosExitList(EXITLIST_APPDLL|EXLST_ADD, cleanup);
    69             if (rc)
    70                 break;
    71 
    7274            return 1;
    7375
    7476        case 1 :
    75             if (dllHandle) {
     77            if (dllHandle)
    7678                UnregisterLxDll(dllHandle);
    77             }
    7879            return 1;
    7980
     
    8586    return 0;
    8687}
    87 
    88 static void APIENTRY cleanup(ULONG /*ulReason*/)
    89 {
    90    __ctordtorTerm();
    91    DosExitList(EXLST_EXIT, cleanup);
    92    return ;
    93 }
    94 
Note: See TracChangeset for help on using the changeset viewer.