Ignore:
Timestamp:
Jul 15, 2002, 4:28:53 PM (23 years ago)
Author:
sandervl
Message:

Rewrote algorithm for 64kb alignment in VirtualAlloc'ed memory; allocation changes for heap (in 64kb chunks) & PE image (align at 64kb)

File:
1 edited

Legend:

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

    r7797 r8877  
    1 /* $Id: winimagelx.cpp,v 1.14 2002-02-03 13:16:22 sandervl Exp $ */
     1/* $Id: winimagelx.cpp,v 1.15 2002-07-15 14:28:53 sandervl Exp $ */
    22
    33/*
     
    6666               : Win32ImageBase(hInstance), header(0)
    6767{
    68  APIRET rc;
    69  char  *name;
     68    APIRET rc;
     69    char  *name;
    7070
    71   szFileName[0] = 0;
     71    szFileName[0] = 0;
    7272
    73   if(lpszCustomDllName) {
     73    if(lpszCustomDllName) {
    7474       name = lpszCustomDllName;
    7575       this->dwOrdinalBase = ::dwOrdinalBase;
    76   }
    77   else {
     76    }
     77    else {
    7878       name = OSLibGetDllName(hinstance);
    7979       this->dwOrdinalBase = 0;
    80   }
     80    }
    8181
    82   strcpy(szFileName, name);
    83   strupr(szFileName);
     82    strcpy(szFileName, name);
     83    strupr(szFileName);
    8484
    85   setFullPath(szFileName);
     85    setFullPath(szFileName);
    8686
    87   //Pointer to PE resource tree generates by wrc (or NULL for system dlls)
    88   pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
     87    //Pointer to PE resource tree generates by wrc (or NULL for system dlls)
     88    pResRootDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
    8989
    90   //ulRVAResourceSection contains the virtual address of the imagebase in the PE header
    91   //for the resource section (images loaded by the pe.exe)
    92   //For LX images, this is 0 as OffsetToData contains a relative offset
    93   ulRVAResourceSection = 0;
     90    //ulRVAResourceSection contains the virtual address of the imagebase in the PE header
     91    //for the resource section (images loaded by the pe.exe)
     92    //For LX images, this is 0 as OffsetToData contains a relative offset
     93    ulRVAResourceSection = 0;
    9494}
    9595//******************************************************************************
     
    9797Win32LxImage::~Win32LxImage()
    9898{
    99   if(header) {
    100         DosFreeMem(header);
    101   }
     99    if(header) {
     100        DosFreeMem(header);
     101    }
    102102}
    103103//******************************************************************************
     
    105105ULONG Win32LxImage::getApi(char *name)
    106106{
    107   APIRET      rc;
    108   ULONG       apiaddr;
     107    APIRET      rc;
     108    ULONG       apiaddr;
    109109
    110   rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr);
    111   if(rc)
    112   {
    113         dprintf(("Win32LxImage::getApi %x %s -> rc = %d", hinstanceOS2, name, rc));
    114         return(0);
    115   }
    116   return(apiaddr);
     110    rc = DosQueryProcAddr(hinstanceOS2, 0, name, (PFN *)&apiaddr);
     111    if(rc)
     112    {
     113            dprintf(("Win32LxImage::getApi %x %s -> rc = %d", hinstanceOS2, name, rc));
     114            return(0);
     115    }
     116    return(apiaddr);
    117117}
    118118//******************************************************************************
     
    120120ULONG Win32LxImage::getApi(int ordinal)
    121121{
    122  APIRET      rc;
    123  ULONG       apiaddr;
     122    APIRET      rc;
     123    ULONG       apiaddr;
    124124
    125   rc = DosQueryProcAddr(hinstanceOS2, dwOrdinalBase+ordinal, NULL, (PFN *)&apiaddr);
    126   if(rc) {
    127         dprintf(("Win32LxImage::getApi %x %d -> rc = %d", hinstanceOS2, ordinal, rc));
    128         return(0);
    129   }
    130   return(apiaddr);
     125    rc = DosQueryProcAddr(hinstanceOS2, dwOrdinalBase+ordinal, NULL, (PFN *)&apiaddr);
     126    if(rc) {
     127        dprintf(("Win32LxImage::getApi %x %d -> rc = %d", hinstanceOS2, ordinal, rc));
     128        return(0);
     129    }
     130    return(apiaddr);
    131131}
    132132//******************************************************************************
     
    135135                                 DWORD Subsystem)
    136136{
    137  APIRET rc;
    138  IMAGE_DOS_HEADER *pdosheader;
    139  PIMAGE_OPTIONAL_HEADER poh;
    140  PIMAGE_FILE_HEADER     pfh;
    141  DWORD *ntsig;
     137    APIRET rc;
     138    IMAGE_DOS_HEADER *pdosheader;
     139    PIMAGE_OPTIONAL_HEADER poh;
     140    PIMAGE_FILE_HEADER     pfh;
     141    DWORD *ntsig;
    142142
    143   rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT);
    144   if(rc) {
    145         dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));
     143    rc = DosAllocMem(&header, 4096, PAG_READ | PAG_WRITE | PAG_COMMIT | flAllocMem);
     144    if(rc) {
     145        dprintf(("ERROR: buildHeader DosAllocMem failed!! (rc=%x)", rc));
    146146        DebugInt3();
    147         return NULL;
    148   }
    149   memcpy(header, dosHeader, sizeof(dosHeader));
    150   ntsig  = (DWORD *)((LPBYTE)header + sizeof(dosHeader));
    151   *ntsig = IMAGE_NT_SIGNATURE;
    152   pfh    = (PIMAGE_FILE_HEADER)(ntsig+1);
    153   pfh->Machine              = IMAGE_FILE_MACHINE_I386;
    154   pfh->NumberOfSections     = 0;
    155   pfh->TimeDateStamp        = 0x3794f60f;
    156   pfh->PointerToSymbolTable = 0;
    157   pfh->NumberOfSymbols      = 0;
    158   pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
    159   pfh->Characteristics      = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |
    160                               IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
    161                               IMAGE_FILE_RELOCS_STRIPPED;
    162   poh    = (PIMAGE_OPTIONAL_HEADER)(pfh+1);
    163   poh->Magic                       = IMAGE_NT_OPTIONAL_HDR_MAGIC;
    164   poh->MajorLinkerVersion          = 0x3;
    165   poh->MinorLinkerVersion          = 0xA;
    166   poh->SizeOfCode                  = 0;
    167   poh->SizeOfInitializedData       = 0;
    168   poh->SizeOfUninitializedData     = 0;
    169   poh->AddressOfEntryPoint         = 0;
    170   poh->BaseOfCode                  = 0;
    171   poh->BaseOfData                  = 0;
    172   poh->ImageBase                   = 0;
    173   poh->SectionAlignment            = 4096;
    174   poh->FileAlignment               = 512;
    175   poh->MajorOperatingSystemVersion = MajorImageVersion;
    176   poh->MinorOperatingSystemVersion = MinorImageVersion;
    177   poh->MajorImageVersion           = MajorImageVersion;
    178   poh->MinorImageVersion           = MinorImageVersion;
    179   poh->MajorSubsystemVersion       = ODINNT_MAJOR_VERSION;
    180   poh->MinorSubsystemVersion       = ODINNT_MINOR_VERSION;
    181   poh->Reserved1                   = 0;
    182   poh->SizeOfImage                 = 0;
    183   poh->SizeOfHeaders               = 1024;
    184   poh->CheckSum                    = 0;
    185   poh->Subsystem                   = Subsystem;
    186   poh->DllCharacteristics          = 0;
    187   poh->SizeOfStackReserve          = 1*1024*1024;
    188   poh->SizeOfStackCommit           = 4096;
    189   poh->SizeOfHeapReserve           = 1*1024*1024;
    190   poh->SizeOfHeapCommit            = 4096;
    191   poh->LoaderFlags                 = 0;
    192   poh->NumberOfRvaAndSizes         = 0;
     147            return NULL;
     148    }
     149    memcpy(header, dosHeader, sizeof(dosHeader));
     150    ntsig  = (DWORD *)((LPBYTE)header + sizeof(dosHeader));
     151    *ntsig = IMAGE_NT_SIGNATURE;
     152    pfh    = (PIMAGE_FILE_HEADER)(ntsig+1);
     153    pfh->Machine              = IMAGE_FILE_MACHINE_I386;
     154    pfh->NumberOfSections     = 0;
     155    pfh->TimeDateStamp        = 0x3794f60f;
     156    pfh->PointerToSymbolTable = 0;
     157    pfh->NumberOfSymbols      = 0;
     158    pfh->SizeOfOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER);
     159    pfh->Characteristics      = IMAGE_FILE_DLL | IMAGE_FILE_32BIT_MACHINE |
     160                                IMAGE_FILE_DEBUG_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE |
     161                                IMAGE_FILE_RELOCS_STRIPPED;
     162    poh    = (PIMAGE_OPTIONAL_HEADER)(pfh+1);
     163    poh->Magic                       = IMAGE_NT_OPTIONAL_HDR_MAGIC;
     164    poh->MajorLinkerVersion          = 0x3;
     165    poh->MinorLinkerVersion          = 0xA;
     166    poh->SizeOfCode                  = 0;
     167    poh->SizeOfInitializedData       = 0;
     168    poh->SizeOfUninitializedData     = 0;
     169    poh->AddressOfEntryPoint         = 0;
     170    poh->BaseOfCode                  = 0;
     171    poh->BaseOfData                  = 0;
     172    poh->ImageBase                   = 0;
     173    poh->SectionAlignment            = 4096;
     174    poh->FileAlignment               = 512;
     175    poh->MajorOperatingSystemVersion = MajorImageVersion;
     176    poh->MinorOperatingSystemVersion = MinorImageVersion;
     177    poh->MajorImageVersion           = MajorImageVersion;
     178    poh->MinorImageVersion           = MinorImageVersion;
     179    poh->MajorSubsystemVersion       = ODINNT_MAJOR_VERSION;
     180    poh->MinorSubsystemVersion       = ODINNT_MINOR_VERSION;
     181    poh->Reserved1                   = 0;
     182    poh->SizeOfImage                 = 0;
     183    poh->SizeOfHeaders               = 1024;
     184    poh->CheckSum                    = 0;
     185    poh->Subsystem                   = Subsystem;
     186    poh->DllCharacteristics          = 0;
     187    poh->SizeOfStackReserve          = 1*1024*1024;
     188    poh->SizeOfStackCommit           = 4096;
     189    poh->SizeOfHeapReserve           = 1*1024*1024;
     190    poh->SizeOfHeapCommit            = 4096;
     191    poh->LoaderFlags                 = 0;
     192    poh->NumberOfRvaAndSizes         = 0;
    193193//  poh->DataDirectory[0]
    194194
    195   return header;
     195    return header;
    196196}
    197197//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.