Changeset 2572 for trunk/src


Ignore:
Timestamp:
Jan 30, 2000, 3:48:52 PM (26 years ago)
Author:
sandervl
Message:

fixed error messages for images without fixups

Location:
trunk/src/peldr
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/peldr/makefile

    r1720 r2572  
    1 # $Id: makefile,v 1.11 1999-11-13 15:40:51 sandervl Exp $
     1# $Id: makefile,v 1.12 2000-01-30 14:48:51 sandervl Exp $
    22
    33#
     
    1414!include $(PDWIN32_INCLUDE)/pdwin32.mk
    1515
    16 
    17 CFLAGS = $(CFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
    18 CXXFLAGS = $(CXXFLAGS) /Ge+ -I$(PDWIN32_INCLUDE)
    19 LDFLAGSEXE = $(LDFLAGS) /Ge+ /B"/pmtype:pm /stack:0x100000 /NOBASE /Map" \
    20              $(PDWIN32_LIB)\peldr.lib os2386.lib $(PDWIN32_LIB)\odincrt.lib $(RTLLIB_O)
     16CFLAGS   = $(CFLAGS) /Ge+ -I$(PDWIN32_INCLUDE) -Gn-
     17CXXFLAGS = $(CXXFLAGS) /Ge+ -I$(PDWIN32_INCLUDE) -Gn-
     18LDFLAGS  = $(LDFLAGS_ODINCRT) /Ge+ /B"/pmtype:pm /stack:0x100000 /NOBASE /Map" \
     19             os2386.lib
    2120
    2221
    2322TARGET = pe
    24 TARGETDLL = peldr
    2523
    2624OBJS =  pe.obj
    27 OBJSDLL =  initterm.obj
    2825
    29 all: $(TARGETDLL).dll $(TARGETDLL).lib $(TARGET).exe
     26all: $(TARGET).exe
    3027
    3128
    3229$(TARGET).exe: $(OBJS) makefile
    33         $(LD) $(LDFLAGSEXE) -Fe$@ $(OBJS)
     30        $(LD) $(LDFLAGS) -Fe$@ $(OBJS)
    3431        $(CP) $(TARGET).exe $(PDWIN32_BIN)
    3532        $(CP) $@ $(PDWIN32_BIN)
    3633
    37 $(TARGETDLL).dll: $(OBJSDLL) $(TARGETDLL).def
    38         $(LD) $(LDFLAGS) -Fe$@ $(OBJSDLL) sbsstub.obj $(TARGETDLL).def OS2386.LIB $(RTLLIB)
    39         $(CP) $@ $(PDWIN32_BIN)
    4034
    41 $(TARGETDLL).lib: $(TARGETDLL).dll
    42         $(IMPLIB) $(IMPLIBFLAGS) $@ $(TARGETDLL).dll
    43         $(CP) $@ $(PDWIN32_LIB)
    44 
    45 
    46 initterm.obj: initterm.cpp
    47 misc.obj: misc.cpp
    48 pe.obj: pe.cpp pe.h $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\winexebase.h $(PDWIN32_INCLUDE)\exceptions.h ..\kernel32\exceptutil.h
     35pe.obj: pe.cpp pe.h $(PDWIN32_INCLUDE)\winimagebase.h $(PDWIN32_INCLUDE)\winexebase.h
    4936
    5037clean:
    5138        $(RM) *.obj *.lib *.dll *.map *.pch *.exe
    5239        $(RM) $(PDWIN32_BIN)\$(TARGET).exe
    53         $(RM) $(PDWIN32_BIN)\$(TARGETDLL).dll
    54         $(RM) $(PDWIN32_LIB)\$(TARGETDLL).lib
  • trunk/src/peldr/pe.cpp

    r1832 r2572  
    1 /* $Id: pe.cpp,v 1.12 1999-11-24 19:33:04 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.13 2000-01-30 14:48:51 sandervl Exp $ */
    22
    33/*
     
    6363WIN32CTOR              CreateWin32Exe       = 0;
    6464
     65ULONG                  reservedMemory       = 0;
     66
     67void AllocateExeMem(char *filename);
     68
     69//******************************************************************************
     70//******************************************************************************
    6571int main(int argc, char *argv[])
    6672{
     
    7177 HMODULE hmodPMWin = 0, hmodKernel32 = 0;
    7278
     79  if(argc >= 2) {
     80        strcpy(exeName, argv[1]);
     81        strupr(exeName);
     82        AllocateExeMem(exeName);
     83  }
     84
    7385  rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
    7486  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize);
     
    97109  strcpy(exeName, argv[1]);
    98110  strupr(exeName);
    99   if(CreateWin32Exe(exeName, ReserveMem()) == FALSE) {
     111  if(CreateWin32Exe(exeName, reservedMemory) == FALSE) {
    100112        goto fail;
    101113  }
     
    117129}
    118130//******************************************************************************
    119 //******************************************************************************
     131//SvL: Reserve memory for win32 exes without fixups
     132//     This is done before any Odin or PMWIN dll is loaded, so we'll get
     133//     a very low virtual address. (which is exactly what we want)
     134//******************************************************************************
     135void AllocateExeMem(char *filename)
     136{
     137 HFILE  dllfile = 0;
     138 char   szFileName[CCHMAXPATH], *tmp;
     139 ULONG  action, ulRead, signature;
     140 APIRET rc;
     141 IMAGE_DOS_HEADER doshdr;
     142 IMAGE_OPTIONAL_HEADER oh;
     143 IMAGE_FILE_HEADER     fh;
     144 ULONG  address = 0;
     145 ULONG  *memallocs;
     146 ULONG  alloccnt = 0;
     147 ULONG  diff, i, baseAddress;
     148 ULONG  ulSysinfo, flAllocMem = 0;
     149
     150  strcpy(szFileName, filename);
     151  tmp = szFileName;
     152  while(*tmp != ' ' && *tmp != 0)
     153        tmp++;
     154  *tmp = 0;
     155
     156  if(!strchr(szFileName, '.')) {
     157        strcat(szFileName,".EXE");
     158  }
     159  rc = DosOpen(szFileName, &dllfile, &action, 0, FILE_READONLY, OPEN_ACTION_OPEN_IF_EXISTS|OPEN_ACTION_FAIL_IF_NEW, OPEN_SHARE_DENYNONE|OPEN_ACCESS_READONLY, NULL);
     160  if(rc != 0) {
     161        if(!strstr(szFileName, ".EXE")) {
     162                strcat(szFileName,".EXE");
     163        }
     164  }
     165  else  DosClose(dllfile);
     166
     167  rc = DosOpen(szFileName, &dllfile, &action, 0, FILE_READONLY, OPEN_ACTION_OPEN_IF_EXISTS|OPEN_ACTION_FAIL_IF_NEW, OPEN_SHARE_DENYNONE|OPEN_ACCESS_READONLY, NULL);
     168  if(rc) {
     169        goto end; //oops
     170  }
     171
     172  //read dos header
     173  if(DosRead(dllfile, (LPVOID)&doshdr, sizeof(doshdr), &ulRead)) {
     174        goto end;
     175  }
     176  if(DosSetFilePtr(dllfile, doshdr.e_lfanew, FILE_BEGIN, &ulRead)) {
     177        goto end;
     178  }
     179  //read signature dword
     180  if(DosRead(dllfile, (LPVOID)&signature, sizeof(signature), &ulRead)) {
     181        goto end;
     182  }
     183  //read pe header
     184  if(DosRead(dllfile, (LPVOID)&fh, sizeof(fh), &ulRead)) {
     185        goto end;
     186  }
     187  //read optional header
     188  if(DosRead(dllfile, (LPVOID)&oh, sizeof(oh), &ulRead)) {
     189        goto end;
     190  }
     191  if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) {
     192        goto end;
     193  }
     194  if(!(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)) {
     195        goto end; //no need to allocate anything now
     196  }
     197
     198  // check for high memory support
     199  rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
     200  if (rc == 0 && ulSysinfo > 512)   //VirtualAddresslimit is in MB
     201  {
     202        flAllocMem = PAG_ANY;      // high memory support. Let's use it!
     203  }
     204
     205  //Reserve enough space to store 4096 pointers to 1MB memory chunks
     206  memallocs = (ULONG *)alloca(4096*sizeof(ULONG *));
     207  if(memallocs == NULL) {
     208        goto end; //oops
     209  }
     210
     211  if(oh.ImageBase < 512*1024*1024) {
     212        flAllocMem = 0;
     213  }
     214  else {
     215        if(flAllocMem == 0) {
     216                goto end; //no support for > 512 MB
     217        }
     218  }
     219  while(TRUE) {
     220        rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ | flAllocMem);
     221        if(rc) break;
     222
     223        if(address + FALLOC_SIZE >= oh.ImageBase) {
     224                if(address > oh.ImageBase) {//we've passed it!
     225                        DosFreeMem((PVOID)address);
     226                        break;
     227                }
     228                //found the right address
     229                DosFreeMem((PVOID)address);
     230
     231                diff = oh.ImageBase - address;
     232                if(diff) {
     233                        rc = DosAllocMem((PPVOID)&address, diff, PAG_READ | flAllocMem);
     234                        if(rc) break;
     235                }
     236                rc = DosAllocMem((PPVOID)&baseAddress, oh.SizeOfImage, PAG_READ | PAG_WRITE | flAllocMem);
     237                if(rc) break;
     238
     239                if(diff) DosFreeMem((PVOID)address);
     240
     241                reservedMemory = baseAddress;
     242                break;
     243        }
     244        memallocs[alloccnt++] = address;
     245  }
     246  for(i=0;i<alloccnt;i++) {
     247        DosFreeMem((PVOID)memallocs[i]);
     248  }
     249end:
     250  if(dllfile) DosClose(dllfile);
     251  return;
     252}
     253//******************************************************************************
     254//******************************************************************************
  • trunk/src/peldr/pe.h

    r506 r2572  
    1 /* $Id: pe.h,v 1.4 1999-08-16 13:54:07 sandervl Exp $ */
     1/* $Id: pe.h,v 1.5 2000-01-30 14:48:51 sandervl Exp $ */
    22
    33/*
     
    1515#define __PE_H__
    1616
     17#ifndef PAG_ANY
     18    #define PAG_ANY    0x00000400
     19#endif
     20
     21#ifndef QSV_VIRTUALADDRESSLIMIT
     22    #define QSV_VIRTUALADDRESSLIMIT 30
     23#endif
     24
     25#define FALLOC_SIZE (1024*1024)
     26
    1727extern char szErrorTitle[];
    1828extern char szMemErrorMsg[];
     
    2333extern char szInteralErrorMsg[];
    2434
    25 ULONG SYSTEM ReserveMem();
    26 
    2735#endif // NOIMAGE
    2836
Note: See TracChangeset for help on using the changeset viewer.