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

kernel32: Check for failures during DLL initialization and return the corresponding code to OS/2. This causes the graceful (silent) process termination instead of a crash in cases like low memory conditions and other runtime errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/initkernel32.cpp

    r21649 r21650  
    144144                else fWin32k = TRUE;
    145145            }
    146             strcpy(kernel32Path, OSLibGetDllName(hModule));
     146
     147            char *kernel32Name = OSLibGetDllName(hModule);
     148            if (!kernel32Name)
     149                return 0; // failure
     150
     151            strcpy(kernel32Path, kernel32Name);
    147152            char *endofpath = strrchr(kernel32Path, '\\');
    148153            *(endofpath+1) = 0;
     
    167172            //SvL: Do it here instead of during the exe object creation
    168173            //(std handles can be used in win32 dll initialization routines
    169             HMInitialize();             /* store standard handles within HandleManager */
     174            if (HMInitialize() != NO_ERROR)
     175                return 0;
    170176
    171177            // VP: Shared heap should be initialized before call to PROFILE_*
    172178            // because they use a critical section which in turn uses smalloc
    173179            // in debug build
    174             if (InitializeSharedHeap() == FALSE)
    175                 return 0UL;
     180            if (!InitializeSharedHeap())
     181                return 0;
    176182
    177183            // VP: initialize profile internal data (critical section actually).
     
    188194            }
    189195
    190             if (InitializeCodeHeap() == FALSE)
    191                 return 0UL;
     196            if (!InitializeCodeHeap())
     197                return 0;
    192198
    193199            InitializeMemMaps();
     
    196202            dllHandle = RegisterLxDll(hModule, 0, (PVOID)&kernel32_PEResTab);
    197203            if (dllHandle == 0)
    198                 return 0UL;
     204                return 0;
    199205
    200206            //SvL: Kernel32 is a special case; pe.exe loads it, so increase
     
    209215            OSLibDosSetInitialMaxFileHandles(ODIN_DEFAULT_MAX_FILEHANDLES);
    210216
    211 
    212217#ifdef DEBUG
    213218            {
    214             LPSTR WIN32API GetEnvironmentStringsA();
    215 
    216             char *tmpenvnew = GetEnvironmentStringsA();
    217             dprintf(("Environment:"));
    218             while(*tmpenvnew) {
    219                 dprintf(("%s", tmpenvnew));
    220                 tmpenvnew += strlen(tmpenvnew)+1;
    221             }
    222             }
    223 #endif
    224 
    225             InitDirectories();          //Must be done before InitializeTIB (which loads NTDLL -> USER32)
    226             InitializeMainThread();     //Must be done after HMInitialize!
     219                LPSTR WIN32API GetEnvironmentStringsA();
     220
     221                char *tmpenvnew = GetEnvironmentStringsA();
     222                dprintf(("Environment:"));
     223                while(*tmpenvnew) {
     224                    dprintf(("%s", tmpenvnew));
     225                    tmpenvnew += strlen(tmpenvnew)+1;
     226                }
     227            }
     228#endif
     229
     230            // Must be done before InitializeTIB (which loads NTDLL -> USER32)
     231            InitDirectories();
     232
     233            // Must be done after HMInitialize!
     234            if (InitializeMainThread() == NULL)
     235                return 0;
     236
    227237            RegisterDevices();
    228238            Win32DllBase::setDefaultRenaming();
    229             rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &ulSysinfo, sizeof(ulSysinfo));
     239
     240            rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS,
     241                                 &ulSysinfo, sizeof(ulSysinfo));
    230242            if (rc != 0)
    231243                ulSysinfo = 1;
    232244
    233             /* Setup codepage info */
     245            // Setup codepage info
    234246            CODEPAGE_Init();
    235247
    236             if( IsDBCSEnv() && DosLoadModule( szModName, sizeof( szModName ), "OS2IM", &imHandle ) == 0 )
    237                 DosQueryProcAddr( imHandle, 140, NULL, &pfnImSetMsgQueueProperty );
     248            if (IsDBCSEnv() && DosLoadModule(szModName, sizeof( szModName ),
     249                                             "OS2IM", &imHandle) == 0)
     250                DosQueryProcAddr(imHandle, 140, NULL, &pfnImSetMsgQueueProperty);
    238251
    239252            InitSystemInfo(ulSysinfo);
    240             //Set up environment as found in NT
     253
     254            // Set up environment as found in NT
    241255            InitEnvironment(ulSysinfo);
    242256
    243             //InitDynamicRegistry creates/changes keys that may change (i.e. odin.ini
    244             //keys that affect windows version)
     257            // InitDynamicRegistry creates/changes keys that may change (i.e.
     258            // odin.ini keys that affect windows version)
    245259            InitDynamicRegistry();
    246260
    247             //Set the process affinity mask to the system affinity mask
     261            // Set the process affinity mask to the system affinity mask
    248262            DWORD dwProcessAffinityMask, dwSystemAffinityMask;
    249             GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);
     263            GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask,
     264                                   &dwSystemAffinityMask);
    250265            SetProcessAffinityMask(GetCurrentProcess(), dwSystemAffinityMask);
    251266
    252             //Set default paths for PE & NE loaders
    253             InitLoaders();
    254 
    255             RasEntry (RAS_EVENT_Kernel32InitComplete, &dllHandle, sizeof (dllHandle));
     267            // Set default paths for PE & NE loaders
     268            if (!InitLoaders())
     269                return 0;
     270
     271            RasEntry(RAS_EVENT_Kernel32InitComplete,
     272                     &dllHandle, sizeof (dllHandle));
    256273
    257274            fInit = TRUE;
     
    261278
    262279        case 1:
     280
    263281            if (dllHandle)
    264             {
    265282                UnregisterLxDll(dllHandle);
    266             }
     283
    267284            break;
    268285
     
    274291    /* A non-zero value must be returned to indicate success.  */
    275292    /***********************************************************/
    276     return 1UL;
     293    return 1;
    277294}
    278295//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.