Changeset 1325 for trunk/src/kernel32


Ignore:
Timestamp:
Oct 17, 1999, 3:49:09 AM (26 years ago)
Author:
bird
Message:

No exception throwing. Constructors is moved into an init method.
TLS is now implemented, but not tested.

Location:
trunk/src/kernel32
Files:
3 edited

Legend:

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

    r1274 r1325  
    1 /* $Id: windllpe2lx.cpp,v 1.2 1999-10-14 01:37:55 bird Exp $ */
     1/* $Id: windllpe2lx.cpp,v 1.3 1999-10-17 01:49:08 bird Exp $ */
    22
    33/*
     
    8888
    8989        /* Try create pe2lx dll object. */
    90         try
     90        pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
     91        if (pWinMod == NULL)
    9192        {
    92             pWinMod = new Win32Pe2LxDll(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
    93             if (pWinMod == NULL)
    94                 throw ((ULONG)ERROR_NOT_ENOUGH_MEMORY);
    95 
    96             /* @@@PH 1998/03/17 Console devices initialization */
    97             iConsoleDevicesRegister();
    98 
    99             /* Add reference and attach dll to process. */
    100             pWinMod->AddRef();
    101             pWinMod->attachProcess();
     93            eprintf(("RegisterPe2LxDll: new returned a NULL-pointer\n"));
     94            return 0;
    10295        }
    103         catch(ULONG ul)
     96        if (!pWinMod->init())
    10497        {
    105             eprintf(("RegisterPe2LxDLL: Failed to create module object, ul=%d\n", ul));
    106             DebugInt3();
    107             return 0;  /* fail dll load */
     98            eprintf(("RegisterPe2LxDll: init-method failed.\n"));
     99            delete pWinMod;
     100            return 0;
    108101        }
     102
     103        /* @@@PH 1998/03/17 Console devices initialization */
     104        iConsoleDevicesRegister();
     105
     106        /* Add reference and attach dll to process. */
     107        pWinMod->AddRef();
     108        pWinMod->attachProcess();
    109109    }
    110110    else
     
    112112        if (pWinMod != NULL && !fFreeLibrary)
    113113            return 0;   /* don't unload (OS/2 dll unload bug) - see OS2.bugs in root dir. */
    114 
    115         #if 0 /* Runtime environment could already be gone, so don't do this */
    116             dprintf(("KERNEL32: Dll Removed by FreeLibrary or ExitProcess\n"));
    117         #endif
    118114    }
    119115
     
    130126 * @author    Sander van Leeuwen, knut st. osmundsen
    131127 */
    132 Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k) throw(ULONG)
     128Win32Pe2LxDll::Win32Pe2LxDll(HINSTANCE hinstance, BOOL fWin32k)
    133129    : Win32ImageBase(hinstance),
    134130    Win32DllBase(hinstance, NULL),
     
    136132{
    137133    dprintf(("Win32Pe2LxDll::Win32Pe2LxDll %s", szModule));
    138     /* set entry point. */
    139     dllEntryPoint = (WIN32DLLENTRY)entryPoint;
    140134}
    141135
     
    151145}
    152146
     147
     148/**
     149 * Init object.
     150 * Must be called immedeately after objecte construction.
     151 * @returns   Success indicator. (TRUE == success)
     152 * @sketch    call init method of the parten class.
     153 *            set dllEntryPoint
     154 * @status    completely implemented.
     155 * @author    knut st. osmundsen
     156 */
     157BOOL Win32Pe2LxDll::init()
     158{
     159    if (Win32Pe2LxImage::init())
     160    {
     161        /* set entry point. */
     162        dllEntryPoint = (WIN32DLLENTRY)entryPoint;
     163    }
     164    else
     165        return FALSE;
     166    return TRUE;
     167}
    153168
    154169/**
  • trunk/src/kernel32/winexepe2lx.cpp

    r1274 r1325  
    1 /* $Id: winexepe2lx.cpp,v 1.2 1999-10-14 01:37:56 bird Exp $ */
     1/* $Id: winexepe2lx.cpp,v 1.3 1999-10-17 01:49:09 bird Exp $ */
    22
    33/*
     
    5252void WIN32API RegisterPe2LxExe(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulReserved)
    5353{
     54    Win32Pe2LxExe *pWinPe2LxExe;
     55
    5456    /* I/O init. */
    5557    if (getenv("WIN32_IOPL2"))
     
    7375
    7476    /* Create Pe2Lx Exe object. */
    75     try
     77    pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
     78    if (pWinPe2LxExe == NULL)
    7679    {
    77         Win32Pe2LxExe *pWinPe2LxExe;
    78         pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
    79         if (pWinPe2LxExe == NULL)
    80             throw ((ULONG)ERROR_NOT_ENOUGH_MEMORY);
    81 
    82         /* Call start (which calls the entry point). */
    83         /*DebugInt3();*/
    84         pWinPe2LxExe->start();
    85     }
    86     catch (ULONG ul)
    87     {
    88         eprintf(("Win32Pe2LxExe creation failed! ul=%d\n", ul));
    89         DebugInt3();
     80        eprintf(("RegisterPe2LxExe: new returned a NULL-pointer\n"));
    9081        return;
    9182    }
     83    if (!pWinPe2LxExe->init())
     84    {
     85        eprintf(("RegisterPe2LxExe: init-method failed.\n"));
     86        delete pWinPe2LxExe;
     87        return;
     88    }
     89
     90    /* Call start (which calls the entry point). */
     91    /*DebugInt3();*/
     92    pWinPe2LxExe->start();
    9293}
    9394
     
    102103 * @remark    Win32Pe2LxImage may throw an exception!
    103104 */
    104 Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k) throw(ULONG):
    105     Win32ImageBase(hinstance),
     105Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k)
     106    : Win32ImageBase(hinstance),
    106107    Win32ExeBase(hinstance),
    107108    Win32Pe2LxImage(hinstance, fWin32k)
    108109{
    109     fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
    110 
    111     /* console app? */
    112     if (fConsoleApp)
    113     {
    114         APIRET rc;
    115 
    116         dprintf(("Console application!\n"));
    117 
    118         rc = iConsoleInit();    /* initialize console subsystem */
    119         if (rc != NO_ERROR)     /* check for errors */
    120             dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
    121     }
    122110}
    123111
     
    130118Win32Pe2LxExe::~Win32Pe2LxExe()
    131119{
     120
    132121}
     122
     123
     124/**
     125 * Init object.
     126 * Must be called immedeately after the object construction.
     127 * @returns   Success indicator. (TRUE == success)
     128 * @sketch
     129 * @status    completely implemented.
     130 * @author    knut st. osmundsen
     131 */
     132BOOL Win32Pe2LxExe::init()
     133{
     134    if (Win32Pe2LxImage::init())
     135    {
     136        fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
     137
     138        /* console app? */
     139        if (fConsoleApp)
     140        {
     141            APIRET rc;
     142
     143            dprintf(("Console application!\n"));
     144
     145            rc = iConsoleInit();    /* initialize console subsystem */
     146            if (rc != NO_ERROR)     /* check for errors */
     147                dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
     148        }
     149    }
     150    else
     151        return FALSE;
     152    return TRUE;
     153}
     154
  • trunk/src/kernel32/winimagepe2lx.cpp

    r1274 r1325  
    1 /* $Id: winimagepe2lx.cpp,v 1.2 1999-10-14 01:37:56 bird Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.3 1999-10-17 01:49:09 bird Exp $ */
    22
    33/*
     
    118118 * @param     fWin32k     TRUE:  Win32k module.
    119119 *                        FALSE: Pe2Lx module.
     120 * @status    partially implemented.
     121 * @author    knut st. osmundsen, Sander van Leeuwen
     122 */
     123Win32Pe2LxImage::Win32Pe2LxImage(HINSTANCE hinstance, BOOL fWin32k)
     124    : Win32ImageBase(hinstance),
     125    paSections(NULL), cSections(0), pNtHdrs(NULL), fWin32k(fWin32k)
     126{
     127}
     128
     129
     130/**
     131 * Free memory associated with this object.
     132 * @status    completely implemented.
     133 * @author    knut st. osmundsen, Sander van Leeuwen
     134 */
     135Win32Pe2LxImage::~Win32Pe2LxImage()
     136{
     137    cleanup();
     138}
     139
     140
     141/**
     142 * Initiates the object.
     143 * Must be called immediately after the object construction.
     144 * @returns   Success indicator, TRUE == success; FALSE = failure.
    120145 * @sketch    Get section placement and sizes for this module. (paSections, cSections)
    121146 *            Verify that there is at least one section - the header section.
     
    127152 *            Locate the resource directory (if any). (pResDir, pResourceSectionStart)
    128153 *            TLS - FIXME!
    129  * @status    partially implmented.
    130  * @author    knut st. osmundsen, Sander van Leeuwen
    131  */
    132 Win32Pe2LxImage::Win32Pe2LxImage(HINSTANCE hinstance, BOOL fWin32k) throw(ULONG)
    133     : Win32ImageBase(hinstance),
    134     paSections(NULL), cSections(0), pNtHdrs(NULL), fWin32k(fWin32k)
     154 * @status    completely implemented.
     155 * @author    knut st. osmundsen
     156 * @remark    Object must be destroyed if failure!
     157 */
     158BOOL Win32Pe2LxImage::init()
    135159{
    136160    APIRET rc;
     
    142166        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: error - getSection failed with rc=%d\n",
    143167                 rc));
    144         Win32Pe2LxImage::~Win32Pe2LxImage();
    145         throw((ULONG)rc);
     168        return FALSE;
    146169    }
    147170
     
    150173    {
    151174        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: no header section, cSections is 0\n"));
    152         Win32Pe2LxImage::~Win32Pe2LxImage();
    153         throw((ULONG)ERROR_BAD_EXE_FORMAT);
     175        return FALSE;
    154176    }
    155177
     
    164186    {
    165187        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: Not a pe2lx image!(?)\n"));
    166         Win32Pe2LxImage::~Win32Pe2LxImage();
    167         throw((ULONG)ERROR_BAD_EXE_FORMAT);
     188        return FALSE;
    168189    }
    169190
     
    186207    {
    187208        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: Not a pe2lx image!(?)\n"));
    188         Win32Pe2LxImage::~Win32Pe2LxImage();
    189         throw((ULONG)ERROR_BAD_EXE_FORMAT);
     209        return FALSE;
    190210    }
    191211
     
    195215    {
    196216        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: setSectionRVAs failed with rc=%d\n", rc));
    197         Win32Pe2LxImage::~Win32Pe2LxImage();
    198         throw((ULONG)rc);
     217        return FALSE;
    199218    }
    200219
     
    208227        dprintf(("Win32Pe2LxImage::Win32Pe2LxImage: entrypoint is incorrect, AddrOfEP=0x%08x, entryPoint=0x%08x\n",
    209228                 pNtHdrs->OptionalHeader.AddressOfEntryPoint, entryPoint));
    210         Win32Pe2LxImage::~Win32Pe2LxImage();
    211         throw((ULONG)ERROR_INVALID_STARTING_CODESEG);
     229        return FALSE;
    212230    }
    213231
     
    220238    }
    221239
    222     /* TLS - FIXME! */
    223 }
    224 
    225 
    226 /**
    227  * Free memory associated with this object.
    228  * @status    completely implemented.
    229  * @author    knut st. osmundsen, Sander van Leeuwen
    230  */
    231 Win32Pe2LxImage::~Win32Pe2LxImage()
    232 {
    233     cleanup();
    234 }
     240    /* TLS - Thread Local Storage */
     241    if (pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress != 0UL
     242        && pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].Size != 0UL)
     243    {
     244        PIMAGE_TLS_DIRECTORY pTLSDir;
     245        pTLSDir = (PIMAGE_TLS_DIRECTORY)getPointerFromRVA(pNtHdrs->OptionalHeader.
     246                                                          DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].
     247                                                          VirtualAddress);
     248
     249        if (pTLSDir != NULL)
     250        {
     251            PVOID pv;
     252            pv = getPointerFromRVA(pTLSDir->StartAddressOfRawData);
     253            if (pv == NULL)
     254            {
     255                eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS StartAddressOfRawData - %#8x.\n",
     256                         pTLSDir->StartAddressOfRawData));
     257                return FALSE;
     258            }
     259            setTLSAddress(pv);
     260            setTLSInitSize(pTLSDir->EndAddressOfRawData - pTLSDir->StartAddressOfRawData);
     261            setTLSTotalSize(pTLSDir->EndAddressOfRawData - pTLSDir->StartAddressOfRawData + pTLSDir->SizeOfZeroFill);
     262            pv = getPointerFromRVA((ULONG)pTLSDir->AddressOfIndex);
     263            if (pv == NULL)
     264            {
     265                eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOffIndex - %#8x.\n",
     266                         pTLSDir->AddressOfIndex));
     267                return FALSE;
     268            }
     269            setTLSIndexAddr((LPDWORD)pv);
     270            pv = getPointerFromRVA((ULONG)pTLSDir->AddressOfCallBacks);
     271            if (pv == NULL)
     272            {
     273                eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOffIndex - %#8x.\n",
     274                         pTLSDir->AddressOfIndex));
     275                return FALSE;
     276            }
     277            setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv);
     278        }
     279        else
     280        {
     281            eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS Dir - %#8x. (getPointerFromRVA failed)\n",
     282                     pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress));
     283            return FALSE;
     284        }
     285    }
     286    return TRUE;
     287}
     288
    235289
    236290
Note: See TracChangeset for help on using the changeset viewer.