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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.