Changeset 544 for trunk/src


Ignore:
Timestamp:
Aug 18, 1999, 2:24:53 PM (26 years ago)
Author:
sandervl
Message:

PE loader changes (exes without fixups + TLS support)

Location:
trunk/src
Files:
5 edited

Legend:

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

    r282 r544  
    1 /* $Id: windll.cpp,v 1.8 1999-07-07 08:42:48 sandervl Exp $ */
     1/* $Id: windll.cpp,v 1.9 1999-08-18 12:24:16 sandervl Exp $ */
    22
    33/*
     
    154154//******************************************************************************
    155155//******************************************************************************
    156 BOOL Win32Dll::init()
     156BOOL Win32Dll::init(ULONG reservedMem)
    157157{
    158158 char  *syspath;
     
    177177        else    fclose(dllfile);
    178178        if(isPEImage(szFileName) == TRUE) {
    179                 fRet = Win32Image::init();
     179                fRet = Win32Image::init(0);
    180180                dllEntryPoint = (WIN32DLLENTRY)entryPoint;
    181181                return fRet;
  • trunk/src/kernel32/winimage.cpp

    r532 r544  
    1 /* $Id: winimage.cpp,v 1.9 1999-08-17 17:04:52 sandervl Exp $ */
     1/* $Id: winimage.cpp,v 1.10 1999-08-18 12:24:16 sandervl Exp $ */
    22
    33/*
    44 * Win32 PE Image class
    55 *
    6  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
    77 * Copyright 1998 Knut St. Osmundsen
    88 *
     
    2525#include <stdlib.h>
    2626
    27 //#include <iostream.h>
    28 //#include <fstream.h>
    2927#include <assert.h>
    3028#include "misc.h"
     
    136134
    137135  if(NameTable)
    138     DosFreeResource((PVOID)NameTable);
     136        DosFreeResource((PVOID)NameTable);
    139137
    140138  if(Win32Table)
    141     DosFreeResource((PVOID)Win32Table);
     139        DosFreeResource((PVOID)Win32Table);
    142140
    143141  while(winres)
    144142  {
    145     res    = winres->next;
    146     delete(winres);
    147     winres = res;
     143        res    = winres->next;
     144        delete(winres);
     145        winres = res;
    148146  }
    149147  if(realBaseAddress)
    150     DosFreeMem((PVOID)realBaseAddress);
     148        DosFreeMem((PVOID)realBaseAddress);
    151149
    152150  if(nameexports)
    153     free(nameexports);
     151        free(nameexports);
    154152
    155153  if(ordexports)
    156     free(ordexports);
     154        free(ordexports);
    157155  if(fullpath)
    158     free(fullpath);
    159 }
    160 //******************************************************************************
    161 //******************************************************************************
    162 BOOL Win32Image::init()
     156        free(fullpath);
     157}
     158//******************************************************************************
     159//******************************************************************************
     160BOOL Win32Image::init(ULONG reservedMem)
    163161{
    164162 HFILE  win32handle;
     
    170168 ULONG  filesize, ulRead;
    171169 PIMAGE_SECTION_HEADER psh;
     170 IMAGE_TLS_DIRECTORY *tlsDir = NULL;
    172171 int    nSections, i;
    173172
     
    185184
    186185  if (rc != NO_ERROR) {
    187     sprintf(szErrorMsg, "Unable to open %32s\n", szFileName);
     186        sprintf(szErrorMsg, "Unable to open %32s\n", szFileName);
    188187        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    189     errorState = ERROR_INTERNAL;
     188        errorState = ERROR_INTERNAL;
    190189        return(FALSE);
    191190  }
     
    198197  win32file = malloc(filesize);
    199198  if(win32file == NULL) {
    200     fout << "Error allocating memory" << endl;
     199        fout << "Error allocating memory" << endl;
    201200        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    202     DosClose(win32handle);                /* Close the file */
    203     errorState = ERROR_INTERNAL;
    204     return(FALSE);
     201        DosClose(win32handle);                /* Close the file */
     202        errorState = ERROR_INTERNAL;
     203        return(FALSE);
    205204  }
    206205  rc = DosRead(win32handle, win32file, filesize, &ulRead);
    207206  if(rc != NO_ERROR) {
    208     fout << "DosRead returned " << rc << endl;
     207        fout << "DosRead returned " << rc << endl;
    209208        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szFileErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    210     DosClose(win32handle);                /* Close the file */
    211     errorState = ERROR_INTERNAL;
    212     return(FALSE);
     209        DosClose(win32handle);                /* Close the file */
     210        errorState = ERROR_INTERNAL;
     211        return(FALSE);
    213212  }
    214213
    215214  if(GetPEFileHeader (win32file, &fh) == FALSE) {
    216     fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl;
     215        fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl;
    217216        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    218     DosClose(win32handle);                /* Close the file */
    219     errorState = ERROR_INTERNAL;
    220     return(FALSE);
     217        DosClose(win32handle);                /* Close the file */
     218        errorState = ERROR_INTERNAL;
     219        return(FALSE);
    221220  }
    222221
    223222  if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid
    224     fout << "Not a valid PE file!" << endl;
     223        fout << "Not a valid PE file!" << endl;
    225224        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    226     DosClose(win32handle);                /* Close the file */
    227     errorState = ERROR_INTERNAL;
    228     return(FALSE);
     225        DosClose(win32handle);                /* Close the file */
     226        errorState = ERROR_INTERNAL;
     227        return(FALSE);
    229228  }
    230229  if(fh.Machine != IMAGE_FILE_MACHINE_I386) {
    231     fout << "You need a REAL CPU to run this code" << endl;
     230        fout << "You need a REAL CPU to run this code" << endl;
    232231        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    233     DosClose(win32handle);                /* Close the file */
    234     errorState = ERROR_INTERNAL;
    235     return(FALSE);
     232        DosClose(win32handle);                /* Close the file */
     233        errorState = ERROR_INTERNAL;
     234        return(FALSE);
    236235  }
    237236  //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)?
    238237  if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
    239     fout << "Can't convert system files" << endl;
     238        fout << "Can't convert system files" << endl;
    240239        WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    241     DosClose(win32handle);                /* Close the file */
    242     errorState = ERROR_INTERNAL;
    243     return(FALSE);
     240        DosClose(win32handle);                /* Close the file */
     241        errorState = ERROR_INTERNAL;
     242        return(FALSE);
    244243  }
    245244
    246245  if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) {
    247     fout << "No fixups, might not run!" << endl;
     246        fout << "No fixups, might not run!" << endl;
    248247  }
    249248
     
    270269    fout << endl << "*************************PE SECTIONS START**************************" << endl;
    271270    for (i=0; i<nSections; i++) {
    272         fout << "Raw data size:       " << psh[i].SizeOfRawData << endl;
    273         fout << "Virtual Address:     " << psh[i].VirtualAddress << endl;
    274         fout << "Virtual Size:        " << psh[i].Misc.VirtualSize << endl;
    275         fout << "Pointer to raw data: " << psh[i].PointerToRawData << endl;
    276         fout.setf(ios::hex, ios::basefield);
    277         fout << "Section flags:       " << psh[i].Characteristics << endl << endl;
    278         fout.setf(ios::dec, ios::basefield);
     271        fout << "Raw data size:       " << hex(psh[i].SizeOfRawData) << endl;
     272        fout << "Virtual Address:     " << hex(psh[i].VirtualAddress) << endl;
     273        fout << "Virtual Size:        " << hex(psh[i].Misc.VirtualSize) << endl;
     274        fout << "Pointer to raw data: " << hex(psh[i].PointerToRawData) << endl;
     275        fout << "Section flags:       " << hex(psh[i].Characteristics) << endl << endl;
    279276        if(strcmp(psh[i].Name, ".reloc") == 0) {
    280277            fout << ".reloc" << endl << endl;
     
    298295            continue;
    299296        }
     297        if(strcmp(psh[i].Name, ".tls") == 0)
     298        {
     299                tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS);
     300                if(tlsDir) {
     301                        fout << "TLS Directory" << endl;
     302                        fout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
     303                        fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
     304                        fout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
     305                        fout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
     306                        addSection(SECTION_TLS, (char *)win32file+psh[i].PointerToRawData,
     307                                   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
     308                                   psh[i].Misc.VirtualSize);
     309                }
     310                continue;
     311        }
     312
    300313        if(strcmp(psh[i].Name, ".debug") == 0) {
    301314            fout << ".rdebug" << endl << endl;
     
    371384
    372385  if(imageSize != imageVirtEnd - oh.ImageBase) {
    373     fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
    374     imageSize = imageVirtEnd - oh.ImageBase;
    375   }
    376   if(allocSections() == FALSE) {
    377     fout << "Failed to allocate image memory, rc " << errorState << endl;
    378     return(FALSE);
     386        fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
     387        imageSize = imageVirtEnd - oh.ImageBase;
     388  }
     389  if(allocSections(reservedMem) == FALSE) {
     390        fout << "Failed to allocate image memory, rc " << errorState << endl;
     391        return(FALSE);
    379392  }
    380393  fout << "OS/2 base address " << baseAddress << endl;
    381394  if(storeSections() == FALSE) {
    382     fout << "Failed to store sections, rc " << errorState << endl;
    383     return(FALSE);
     395        fout << "Failed to store sections, rc " << errorState << endl;
     396        return(FALSE);
    384397  }
    385398  entryPoint = baseAddress + oh.AddressOfEntryPoint;
    386399
    387   if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) {
    388     fout << "Failed to set fixups" << endl;
    389     return(FALSE);
    390   }
     400  if(tlsDir != NULL) {
     401   Section *sect = findSection(SECTION_TLS);
     402
     403        if(sect == NULL) {
     404                fout << "Couldn't find TLS section!!" << endl;
     405                return(FALSE);
     406        }
     407        setTLSAddress((char *)(sect->realvirtaddr + (tlsDir->StartAddressOfRawData - sect->virtaddr)));
     408        setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData);
     409        setTLSTotalSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData + tlsDir->SizeOfZeroFill);
     410
     411        sect = findSectionByAddr((ULONG)tlsDir->AddressOfIndex);
     412        if(sect == NULL) {
     413                fout << "Couldn't find TLS AddressOfIndex section!!" << endl;
     414                return(FALSE);
     415        }
     416        setTLSIndexAddr((LPDWORD)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfIndex - sect->virtaddr)));
     417
     418        sect = findSectionByAddr((ULONG)tlsDir->AddressOfCallBacks);
     419        if(sect == NULL) {
     420                fout << "Couldn't find TLS AddressOfCallBacks section!!" << endl;
     421                return(FALSE);
     422        }
     423        setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr)));
     424  }
     425
     426  if(realBaseAddress != oh.ImageBase) {
     427        if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) {
     428                fout << "Failed to set fixups" << endl;
     429                return(FALSE);
     430        }
     431  }
     432
    391433  if(processImports((char *)win32file) == FALSE) {
    392     fout << "Failed to process imports!" << endl;
    393     return(FALSE);
     434        fout << "Failed to process imports!" << endl;
     435        return(FALSE);
    394436  }
    395437
    396438  if(fh.Characteristics & IMAGE_FILE_DLL) {
    397     if(processExports((char *)win32file) == FALSE) {
    398         fout << "Failed to process exported apis" << endl;
    399         return(FALSE);
    400     }
     439        if(processExports((char *)win32file) == FALSE) {
     440                fout << "Failed to process exported apis" << endl;
     441                return(FALSE);
     442        }
    401443  }
    402444  IMAGE_SECTION_HEADER sh;
    403445  if(GetSectionHdrByName (win32file, &sh, ".rsrc")) {
    404     //get offset in resource object of directory entry
    405     pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE);
     446        //get offset in resource object of directory entry
     447        pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE);
    406448  }
    407449  //set final memory protection flags (storeSections sets them to read/write)
    408450  if(setMemFlags() == FALSE) {
    409     fout << "Failed to set memory protection" << endl;
    410     return(FALSE);
     451        fout << "Failed to set memory protection" << endl;
     452        return(FALSE);
    411453  }
    412454
     
    428470
    429471  if(type == SECTION_RESOURCE) {
    430     pResSection = &section[nrsections];
     472        pResSection = &section[nrsections];
    431473  }
    432474  virtsize   = ((virtsize - 1) & ~0xFFF) + PAGE_SIZE;
     
    435477
    436478  if(virtaddress < imageVirtBase)
    437     imageVirtBase = virtaddress;
     479        imageVirtBase = virtaddress;
    438480  if(virtaddress + virtsize > imageVirtEnd)
    439     imageVirtEnd = virtaddress + virtsize;
     481        imageVirtEnd = virtaddress + virtsize;
    440482
    441483  nrsections++;
     
    443485//******************************************************************************
    444486//******************************************************************************
    445 BOOL Win32Image::allocSections()
     487BOOL Win32Image::allocSections(ULONG reservedMem)
    446488{
    447489 APIRET rc;
    448490
    449491  if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) {
    450     fout << "No fixups, might not run!" << endl;
    451     return allocFixedMem();
     492        fout << "No fixups, might not run!" << endl;
     493        return allocFixedMem(reservedMem);
    452494  }
    453495  rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);
    454496  if(rc) {
    455     errorState = rc;
    456     return(FALSE);
     497        errorState = rc;
     498        return(FALSE);
    457499  }
    458500  realBaseAddress = baseAddress;
     
    460502}
    461503//******************************************************************************
     504//******************************************************************************
     505Section *Win32Image::findSection(ULONG type)
     506{
     507  for(int i=0;i<nrsections;i++) {
     508        if(section[i].type == type) {
     509                return &section[i];
     510        }
     511  }
     512  return NULL;
     513}
     514//******************************************************************************
     515//******************************************************************************
     516Section *Win32Image::findSectionByAddr(ULONG addr)
     517{
     518  for(int i=0;i<nrsections;i++) {
     519        if(section[i].virtaddr <= addr && section[i].virtaddr + section[i].virtualsize > addr) {
     520                return &section[i];
     521        }
     522  }
     523  return NULL;
     524}
     525//******************************************************************************
    462526#define FALLOC_SIZE (1024*1024)
    463527//******************************************************************************
    464 BOOL Win32Image::allocFixedMem()
     528BOOL Win32Image::allocFixedMem(ULONG reservedMem)
    465529{
    466530 ULONG  address = 0;
     
    471535
    472536  baseAddress = realBaseAddress = 0;
     537 
     538  if(reservedMem && reservedMem <= oh.ImageBase &&
     539     ((oh.ImageBase - reservedMem) + imageSize < PELDR_RESERVEDMEMSIZE))
     540  {
     541        //ok, it fits perfectly
     542        realBaseAddress = oh.ImageBase;
     543        baseAddress = oh.ImageBase;
     544        return TRUE;
     545  }
    473546
    474547  while(TRUE) {
    475     rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ);
    476     if(rc) break;
    477 
    478     if(firstaddress == 0)
    479         firstaddress = address;
    480 
    481     fout << "DosAllocMem returned " << address << endl;
    482     if(address + FALLOC_SIZE >= oh.ImageBase) {
    483         if(address > oh.ImageBase) {//we've passed it!
    484             DosFreeMem((PVOID)address);
    485             return(FALSE);
    486         }
    487         //found the right address
    488         DosFreeMem((PVOID)address);
    489         //align at 64 kb boundary
    490         realBaseAddress = oh.ImageBase & 0xFFFF0000;
    491         diff = realBaseAddress - address;
    492         if(diff) {
    493             rc = DosAllocMem((PPVOID)&address, diff, PAG_READ);
    494             if(rc) break;
    495         }
    496         rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);
    497         if(rc) break;
    498 
    499         if(baseAddress != realBaseAddress) {
    500             fout << "baseAddress != realBaseAddress!!" << endl;
    501             break;
    502         }
    503         if(diff) DosFreeMem((PVOID)address);
    504 
    505         address = realBaseAddress;
    506         realBaseAddress = baseAddress;
    507         baseAddress = oh.ImageBase;
    508         break;
    509     }
    510     lastaddress = address;
     548        rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ);
     549        if(rc) break;
     550
     551        if(firstaddress == 0)
     552                firstaddress = address;
     553
     554        fout << "DosAllocMem returned " << address << endl;
     555        if(address + FALLOC_SIZE >= oh.ImageBase) {
     556                if(address > oh.ImageBase) {//we've passed it!
     557                        DosFreeMem((PVOID)address);
     558                        return(FALSE);
     559                }
     560                //found the right address
     561                DosFreeMem((PVOID)address);
     562                //align at 64 kb boundary
     563                realBaseAddress = oh.ImageBase & 0xFFFF0000;
     564                diff = realBaseAddress - address;
     565                if(diff) {
     566                        rc = DosAllocMem((PPVOID)&address, diff, PAG_READ);
     567                        if(rc) break;
     568                }
     569                rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);
     570                if(rc) break;
     571
     572                if(baseAddress != realBaseAddress) {
     573                        fout << "baseAddress != realBaseAddress!!" << endl;
     574                        break;
     575                }
     576                if(diff) DosFreeMem((PVOID)address);
     577
     578                address = realBaseAddress;
     579                realBaseAddress = baseAddress;
     580                baseAddress = oh.ImageBase;
     581                break;
     582        }
     583        lastaddress = address;
    511584  }
    512585  while(firstaddress <= lastaddress) {
    513     DosFreeMem((PVOID)firstaddress);
    514     firstaddress += FALLOC_SIZE;
     586        DosFreeMem((PVOID)firstaddress);
     587        firstaddress += FALLOC_SIZE;
    515588  }
    516589  if(baseAddress == 0) //Let me guess.. MS Office app?
    517     return(FALSE);
     590        return(FALSE);
     591
    518592  return(TRUE);
    519593}
     
    527601
    528602  for(i=0;i<nrsections;i++) {
    529     section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase);
     603        section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase);
    530604  }
    531605  for(i=0;i<nrsections;i++) {
    532     pagFlags = PAG_COMMIT;
    533     switch(section[i].type) {
     606        pagFlags = PAG_COMMIT;
     607        switch(section[i].type) {
    534608        case SECTION_CODE:
    535609        case (SECTION_CODE | SECTION_IMPORT):
     
    539613        case SECTION_READONLYDATA:
    540614        case SECTION_RESOURCE:
    541             pagFlags |= PAG_WRITE | PAG_READ;
    542             break;
     615        case SECTION_TLS:
     616                pagFlags |= PAG_WRITE | PAG_READ;
     617                break;
    543618        case SECTION_EXPORT:
    544619        case SECTION_DEBUG:
    545620        case SECTION_RELOC:
    546             pagFlags = 0;   //don't commit
    547             break;
    548     }
    549     if(pagFlags == 0)   continue;   //debug or export section
    550 
    551     rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
    552     if(rc) {
    553         errorState = rc;
    554         return(FALSE);
    555     }
    556     if(section[i].type != SECTION_UNINITDATA) {
    557         assert(section[i].rawdata);
    558         memcpy((char *)section[i].realvirtaddr, section[i].rawdata, section[i].rawsize);
    559     }
     621                pagFlags = 0;   //don't commit
     622                break;
     623        }
     624        if(pagFlags == 0)   continue;   //debug or export section
     625
     626        rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
     627        if(rc) {
     628                errorState = rc;
     629                return(FALSE);
     630        }
     631        if(section[i].type != SECTION_UNINITDATA) {
     632                assert(section[i].rawdata);
     633                memcpy((char *)section[i].realvirtaddr, section[i].rawdata, section[i].rawsize);
     634        }
    560635  }
    561636  return(TRUE);
     
    570645
    571646  for(i=0;i<nrsections;i++) {
    572     pagFlags = 0;
    573     switch(section[i].type) {
     647        pagFlags = 0;
     648        switch(section[i].type) {
    574649        case SECTION_CODE:
    575650        case (SECTION_CODE | SECTION_IMPORT):
    576             pagFlags |= PAG_EXECUTE | PAG_READ;
    577             break;
     651                pagFlags |= PAG_EXECUTE | PAG_READ;
     652                break;
    578653        case SECTION_INITDATA:
    579654        case SECTION_UNINITDATA:
    580655        case SECTION_IMPORT: //TODO: read only?
    581             pagFlags |= PAG_WRITE | PAG_READ;
    582             break;
     656                pagFlags |= PAG_WRITE | PAG_READ;
     657                break;
    583658        case SECTION_READONLYDATA:
    584659        case SECTION_RESOURCE:
    585             pagFlags |= PAG_READ;
    586             break;
     660        case SECTION_TLS:
     661                pagFlags |= PAG_READ;
     662                break;
    587663        default:
    588             continue;
    589     }
    590     rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
    591     if(rc) {
    592         errorState = rc;
    593         return(FALSE);
    594     }
     664                continue;
     665        }
     666        rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
     667        if(rc) {
     668                errorState = rc;
     669                return(FALSE);
     670        }
    595671  }
    596672  return(TRUE);
     
    804880
    805881  if(nameexports == NULL) {
    806     nameExportSize= 4096;
    807     nameexports   = (NameExport *)malloc(nameExportSize);
    808     curnameexport = nameexports;
     882        nameExportSize= 4096;
     883        nameexports   = (NameExport *)malloc(nameExportSize);
     884        curnameexport = nameexports;
    809885  }
    810886  nsize = (ULONG)curnameexport - (ULONG)nameexports;
    811887  if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) {
    812     nameExportSize += 4096;
    813     char *tmp = (char *)nameexports;
    814     nameexports = (NameExport *)malloc(nameExportSize);
    815     memcpy(nameexports, tmp, nsize);
    816     curnameexport = (NameExport *)((ULONG)nameexports + nsize);
    817     free(tmp);
     888        nameExportSize += 4096;
     889        char *tmp = (char *)nameexports;
     890        nameexports = (NameExport *)malloc(nameExportSize);
     891        memcpy(nameexports, tmp, nsize);
     892        curnameexport = (NameExport *)((ULONG)nameexports + nsize);
     893        free(tmp);
    818894  }
    819895  curnameexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase);
     
    824900  curnameexport->nlength = strlen(apiname) + 1;
    825901  if(curnameexport->nlength < sizeof(curnameexport->name))
    826     curnameexport->nlength = sizeof(curnameexport->name);
     902        curnameexport->nlength = sizeof(curnameexport->name);
     903
    827904  curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength);
    828905}
     
    832909{
    833910  if(ordexports == NULL) {
    834     ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
    835     curordexport = ordexports;
     911        ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
     912        curordexport = ordexports;
    836913  }
    837914  curordexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase);
     
    9801057    WinDll = Win32Dll::findModule(pszCurModule);
    9811058    if(WinDll == NULL)
    982      {  //not found, so load it
     1059    {  //not found, so load it
    9831060        WinDll = new Win32Dll(pszCurModule);
    9841061
     
    9921069        fout << "**********************     Loading Module        *********************" << endl;
    9931070        fout << "**********************************************************************" << endl;
    994         if(WinDll->init() == FALSE) {
     1071        if(WinDll->init(0) == FALSE) {
    9951072            fout << "Internal WinDll error " << WinDll->getError() << endl;
    9961073            return(FALSE);
     
    10761153  if (rc != NO_ERROR)
    10771154  {
    1078     dprintf(("KERNEL32:Win32Image::isPEImage(%s) failed with %u\n",
    1079              szFileName,
    1080              rc));
    1081     return(FALSE);
     1155        dprintf(("KERNEL32:Win32Image::isPEImage(%s) failed with %u\n",
     1156                  szFileName, rc));
     1157        return(FALSE);
    10821158  }
    10831159
     
    10871163  IMAGE_DOS_HEADER *pdoshdr = (IMAGE_DOS_HEADER *)malloc(sizeof(IMAGE_DOS_HEADER));
    10881164  if(pdoshdr == NULL)   {
    1089     DosClose(win32handle);                /* Close the file */
    1090     return(FALSE);
     1165        DosClose(win32handle);                /* Close the file */
     1166        return(FALSE);
    10911167  }
    10921168  rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead);
    10931169  if(rc != NO_ERROR) {
    1094     DosClose(win32handle);                /* Close the file */
    1095     return(FALSE);
     1170        DosClose(win32handle);                /* Close the file */
     1171        return(FALSE);
    10961172  }
    10971173  ULONG hdrsize = pdoshdr->e_lfanew + SIZE_OF_NT_SIGNATURE + sizeof(IMAGE_FILE_HEADER);
     
    11031179  win32file = malloc(hdrsize);
    11041180  if(win32file == NULL) {
    1105     DosClose(win32handle);                /* Close the file */
    1106     return(FALSE);
     1181        DosClose(win32handle);                /* Close the file */
     1182        return(FALSE);
    11071183  }
    11081184  rc = DosRead(win32handle, win32file, hdrsize, &ulRead);
    11091185  if(rc != NO_ERROR) {
    1110     goto failure;
     1186        goto failure;
    11111187  }
    11121188
    11131189  if(GetPEFileHeader (win32file, &fh) == FALSE) {
    1114     goto failure;
     1190        goto failure;
    11151191  }
    11161192
    11171193  if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid
    1118     goto failure;
     1194        goto failure;
    11191195  }
    11201196  if(fh.Machine != IMAGE_FILE_MACHINE_I386) {
    1121     goto failure;
     1197        goto failure;
    11221198  }
    11231199  //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)?
    11241200  if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
    1125     goto failure;
     1201        goto failure;
    11261202  }
    11271203  DosClose(win32handle);
  • trunk/src/kernel32/wprocess.cpp

    r532 r544  
    1 /* $Id: wprocess.cpp,v 1.20 1999-08-17 17:04:52 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.21 1999-08-18 12:24:17 sandervl Exp $ */
    22
    33/*
     
    395395        return(0);
    396396
    397     module->init();
     397    module->init(0);
    398398    if(module->getError() != NO_ERROR) {
    399399        dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
     
    467467        return(0);
    468468
    469     module->init();
     469    module->init(0);
    470470    if(module->getError() != NO_ERROR) {
    471471        dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
  • trunk/src/peldr/initterm.cpp

    r506 r544  
    1 /* $Id: initterm.cpp,v 1.1 1999-08-16 13:54:06 sandervl Exp $ */
     1/* $Id: initterm.cpp,v 1.2 1999-08-18 12:24:32 sandervl Exp $ */
    22
    33/*
     
    3232#include <odin.h>
    3333#include <misc.h>       /*PLF Wed  98-03-18 23:18:15*/
     34#include <winimage.h>
    3435
    3536/*-------------------------------------------------------------------*/
     
    7576         //     This is done before any Odin or PMWIN dll is loaded, so we'll get
    7677         //     a very low virtual address. (which is exactly what we want)
    77          rc = DosAllocMem((PPVOID)&reservedMemory, 16*1024*1024, PAG_WRITE | PAG_READ);
     78         rc = DosAllocMem((PPVOID)&reservedMemory, PELDR_RESERVEDMEMSIZE, PAG_WRITE | PAG_READ);
    7879
    7980         /*******************************************************************/
  • trunk/src/peldr/pe.cpp

    r506 r544  
    1 /* $Id: pe.cpp,v 1.5 1999-08-16 13:54:07 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.6 1999-08-18 12:24:32 sandervl Exp $ */
    22
    33/*
     
    7272 HMODULE hmodPMWin, hmodKernel32;
    7373
    74   printf("memory allocated at %X\n", ReserveMem());
    75 
    7674  rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
    7775  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize);
     
    130128  WinExe->setCommandLine(szCmdLine);
    131129
    132   if(WinExe->init() == FALSE) {
     130  if(WinExe->init(ReserveMem()) == FALSE) {
    133131        delete WinExe;
    134132        return(1);
Note: See TracChangeset for help on using the changeset viewer.