Changeset 21649 for trunk/src


Ignore:
Timestamp:
Jun 23, 2011, 2:02:58 PM (14 years ago)
Author:
dmik
Message:

general: Exit gracefully instead of crashing if KERNEL32.DLL initialization fails. Note that "gracefully" means "silently" in this case since it seems that the only way how the OS/2 loader reports a failure to initialize a required DLL for a started EXE is by returning a non-zero exit code.

Location:
trunk/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/NTDLL/initntdll.c

    r21584 r21649  
    5454
    5555         //Initialize kernel32 first (circular dependency between kernel32 & ntdll)
    56          InitializeKernel32();
     56         if (InitializeKernel32() == 0)
     57             return 0;
    5758
    5859         CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
  • trunk/src/crypt32/initcrypt32.cpp

    r21311 r21649  
    8888      case 0 :
    8989
    90          InitializeKernel32();
     90         if (InitializeKernel32() == 0)
     91             return 0;
     92
    9193         //CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    9294         dllHandle = RegisterLxDll(hModule, OdinLibMain, (PVOID)&crypt32_PEResTab);
  • trunk/src/gdi32/initgdi32.cpp

    r21304 r21649  
    9999         ParseLogStatusGDI32();
    100100
    101          InitializeKernel32();
     101         if (InitializeKernel32() == 0)
     102             return 0;
     103
    102104         CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    103105         if(InitRegionSpace() == FALSE) {
  • trunk/src/kernel32/initkernel32.cpp

    r21626 r21649  
    112112    /*-------------------------------------------------------------------------*/
    113113
    114     if(fInit == TRUE && ulFlag == 0) {
    115         return 1; //already initialized
    116     }
    117     fInit = TRUE;
    118 
    119114    switch (ulFlag)
    120115    {
    121         case 0 :
     116        case 0:
    122117        {
     118            if (fInit)
     119                return 1; // already initialized
     120
    123121            // This always must be the first thing to do.
    124122            RasInitialize (hModule);
     
    257255            RasEntry (RAS_EVENT_Kernel32InitComplete, &dllHandle, sizeof (dllHandle));
    258256
     257            fInit = TRUE;
     258
    259259            break;
    260260        }
    261261
    262         case 1 :
     262        case 1:
    263263            if (dllHandle)
    264264            {
     
    267267            break;
    268268
    269         default  :
    270             return 0UL;
     269        default:
     270            return 0;
    271271    }
    272272
     
    280280void APIENTRY cleanupKernel32(ULONG ulReason)
    281281{
    282     dprintf(("kernel32 exit %d\n", ulReason));
     282    if (!fInit)
     283    {
     284        // The initialization sequence was not complete; attempting to
     285        // uninitialize some things may crash (yeah, dirty code that doesn't
     286        // analyze its own state)
     287        return;
     288    }
     289
     290    dprintf(("kernel32 exit %d", ulReason));
    283291
    284292    TEB *teb = GetThreadTEB();
  • trunk/src/kernel32/initterm.cpp

    r21426 r21649  
    9595    /*-------------------------------------------------------------------------*/
    9696
    97     if(fInit == TRUE && ulFlag == 0) {
    98         return 1; //already initialized
    99     }
    100 
    10197    switch (ulFlag)
    10298    {
    103         case 0 :
     99        case 0:
    104100        {
     101            if (fInit)
     102                return 1; // already initialized
     103
    105104            ctordtorInit();
    106105
     
    112111            rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup);
    113112            if (rc)
    114                 return 0UL;
     113                return 0;
    115114
    116             rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
    117             if(rc == 0){
    118                 if(version[0] >= 20 && version[1] <= 30) {
     115            rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR,
     116                                 version, sizeof(version));
     117            if (rc == 0)
     118                if(version[0] >= 20 && version[1] <= 30)
    119119                    fVersionWarp3 = TRUE;
    120                 }
    121             }
    122120
    123121            rc = inittermKernel32(hModule, ulFlag);
     
    125123        }
    126124
    127         case 1 :
     125        case 1:
    128126            rc = inittermKernel32(hModule, ulFlag);
    129127            break;
    130128
    131         default  :
    132             return 0UL;
     129        default:
     130            return 0;
    133131    }
    134132
     
    156154    HMODULE hModule;
    157155
    158     if(!fInit) {
     156    if (!fInit)
    159157        loadNr = globLoadNr++;
    160     }
    161     DosQueryModuleHandleStrict("WGSS50", &hModule);
    162     _O32__DLL_InitTerm(hModule, 0);
    163     DosQueryModuleHandleStrict("KERNEL32", &hModule);
    164     return DLLENTRYPOINT_NAME(hModule, 0);
     158
     159    if (DosQueryModuleHandleStrict("WGSS50", &hModule) == NO_ERROR)
     160        if (_O32__DLL_InitTerm(hModule, 0) != 0)
     161            if (DosQueryModuleHandleStrict("KERNEL32", &hModule) == NO_ERROR)
     162                return DLLENTRYPOINT_NAME(hModule, 0);
     163
     164    return 0; // failure
    165165}
    166166//******************************************************************************
  • trunk/src/mscms/initmscms.cpp

    r21311 r21649  
    8888      case 0 :
    8989
    90          InitializeKernel32();
     90         if (InitializeKernel32() == 0)
     91             return 0;
     92
    9193         //CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    9294         dllHandle = RegisterLxDll(hModule, OdinLibMain, NULL);
  • trunk/src/oleacc/initoleacc.cpp

    r21313 r21649  
    8888      case 0 :
    8989
    90          InitializeKernel32();
     90         if (InitializeKernel32() == 0)
     91             return 0;
     92
    9193         CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    9294         dllHandle = RegisterLxDll(hModule, OdinLibMain, (PVOID)&oleacc_PEResTab);
  • trunk/src/rsaenh/initrsaenh.cpp

    r21363 r21649  
    8888      case 0 :
    8989
    90          InitializeKernel32();
     90         if (InitializeKernel32() == 0)
     91             return 0;
     92
    9193         //CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    9294         dllHandle = RegisterLxDll(hModule, OdinLibMain, NULL);
  • trunk/src/schannel/initschannel.cpp

    r21373 r21649  
    8888      case 0 :
    8989
    90          InitializeKernel32();
     90         if (InitializeKernel32() == 0)
     91             return 0;
     92
    9193         //CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    9294         dllHandle = RegisterLxDll(hModule, OdinLibMain, NULL);
  • trunk/src/secur32/initsecur32.cpp

    r21364 r21649  
    8888      case 0 :
    8989
    90          InitializeKernel32();
     90         if (InitializeKernel32() == 0)
     91             return 0;
     92
    9193         //CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    9294         dllHandle = RegisterLxDll(hModule, OdinLibMain, NULL);
  • trunk/src/user32/controls/initodinctrl.cpp

    r8543 r21649  
    6767         ParseLogStatusOdinCtrl();
    6868
    69          InitializeKernel32();
     69         if (InitializeKernel32() == 0)
     70             return 0;
     71
    7072         CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    7173         break;
    72      
     74
    7375      case 1 :
    7476         break;
  • trunk/src/user32/inituser32.cpp

    r21595 r21649  
    174174         ParseLogStatusUSER32();
    175175
    176          InitializeKernel32();
     176         if (InitializeKernel32() == 0)
     177             return 0;
     178
    177179         CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
    178180
Note: See TracChangeset for help on using the changeset viewer.