Changeset 2513 for trunk/src


Ignore:
Timestamp:
Jan 25, 2000, 9:27:58 PM (26 years ago)
Author:
sandervl
Message:

Allocate low memory at right address and with right size in peldr.dll (fixes install of Windows Media Player)

Location:
trunk/src
Files:
3 edited

Legend:

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

    r2253 r2513  
    1 /* $Id: initterm.cpp,v 1.32 1999-12-29 18:49:50 sandervl Exp $ */
     1/* $Id: initterm.cpp,v 1.33 2000-01-25 20:27:16 sandervl Exp $ */
    22
    33/*
     
    121121
    122122            PROFILE_LoadOdinIni();
    123 //            if(RegisterLxDll(hModule, 0, 0) == FALSE)
    124123            if(RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab) == FALSE)
    125124                return 0UL;
  • trunk/src/kernel32/winimagepeldr.cpp

    r2493 r2513  
    1 /* $Id: winimagepeldr.cpp,v 1.28 2000-01-21 22:38:53 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.29 2000-01-25 20:27:17 sandervl Exp $ */
    22
    33/*
     
    770770  realBaseAddress = 0;
    771771
     772#if 1
     773  //Allocated in peldr.dll
     774  if(reservedMem && reservedMem == oh.ImageBase) {
     775        realBaseAddress = oh.ImageBase;
     776        return TRUE;
     777  }
     778#else
    772779  if(reservedMem && reservedMem <= oh.ImageBase &&
    773780     ((oh.ImageBase - reservedMem) + imageSize < PELDR_RESERVEDMEMSIZE))
    774781  {
    775         //ok, it fits perfectly
    776         realBaseAddress = oh.ImageBase;
    777         return TRUE;
    778   }
     782        //ok, it fits perfectly; free it now and allocate it below
     783        DosFreeMem((PVOID)reservedMem);
     784//              realBaseAddress = oh.ImageBase;
     785//      return TRUE;
     786  }
     787#endif
    779788
    780789  //Reserve enough space to store 4096 pointers to 1MB memory chunks
  • trunk/src/peldr/initterm.cpp

    r951 r2513  
    1 /* $Id: initterm.cpp,v 1.3 1999-09-15 23:26:08 sandervl Exp $ */
     1/* $Id: initterm.cpp,v 1.4 2000-01-25 20:27:58 sandervl Exp $ */
    22
    33/*
     
    2626#define  INCL_DOSMODULEMGR
    2727#define  INCL_DOSPROCESS
     28#define  INCL_DOSMISC
    2829#include <os2.h>
    2930#include <stdlib.h>
     
    3435#include <winimagepeldr.h>
    3536
     37#ifndef PAG_ANY
     38    #define PAG_ANY    0x00000400
     39#endif
     40
     41#ifndef QSV_VIRTUALADDRESSLIMIT
     42    #define QSV_VIRTUALADDRESSLIMIT 30
     43#endif
     44
     45#define FALLOC_SIZE (1024*1024)
     46
    3647/*-------------------------------------------------------------------*/
    3748/* A clean up routine registered with DosExitList must be used if    */
     
    4354
    4455ULONG reservedMemory = 0;
     56
     57void AllocateExeMem(char *filename);
    4558
    4659/****************************************************************************/
     
    6578
    6679   switch (ulFlag) {
    67       case 0 :
     80   case 0 :
     81   {
     82        PTIB ptib;
     83        PPIB ppib;
     84        char *win32app;
    6885
    6986         /*******************************************************************/
     
    7390         /*******************************************************************/
    7491
    75          //SvL: Reserve memory for win32 exes without fixups
    76          //     This is done before any Odin or PMWIN dll is loaded, so we'll get
    77          //     a very low virtual address. (which is exactly what we want)
    78          rc = DosAllocMem((PPVOID)&reservedMemory, PELDR_RESERVEDMEMSIZE, PAG_WRITE | PAG_READ);
     92         DosGetInfoBlocks(&ptib, &ppib);
     93         win32app = ppib->pib_pchcmd + strlen(ppib->pib_pchcmd) + 1;
     94         AllocateExeMem(win32app);
    7995
    8096         /*******************************************************************/
     
    8399         /*******************************************************************/
    84100         break;
    85       case 1 :
     101   }
     102   case 1 :
    86103         break;
    87       default  :
     104   default  :
    88105         return 0UL;
    89106   }
     
    94111   return 1UL;
    95112}
    96 
     113//******************************************************************************
     114//******************************************************************************
    97115ULONG SYSTEM ReserveMem()
    98116{
    99117   return reservedMemory;
    100118}
     119//******************************************************************************
     120//SvL: Reserve memory for win32 exes without fixups
     121//     This is done before any Odin or PMWIN dll is loaded, so we'll get
     122//     a very low virtual address. (which is exactly what we want)
     123//******************************************************************************
     124void AllocateExeMem(char *filename)
     125{
     126 HFILE  dllfile;
     127 char   szFileName[CCHMAXPATH], *tmp;
     128 ULONG  action, ulRead, signature;
     129 APIRET rc;
     130 IMAGE_DOS_HEADER doshdr;
     131 IMAGE_OPTIONAL_HEADER oh;
     132 IMAGE_FILE_HEADER     fh;
     133 ULONG  address = 0;
     134 ULONG  *memallocs;
     135 ULONG  alloccnt = 0;
     136 ULONG  diff, i, baseAddress;
     137 ULONG  ulSysinfo, flAllocMem;
     138
     139  tmp = filename;
     140  while(*tmp != ' ' && *tmp != 0)
     141        tmp++;
     142  *tmp = 0;
     143
     144  strcpy(szFileName, filename);
     145  if(!strchr(szFileName, '.')) {
     146        strcat(szFileName,".EXE");
     147  }
     148  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);
     149  if(rc != 0) {
     150        if(!strstr(szFileName, ".EXE")) {
     151                strcat(szFileName,".EXE");
     152        }
     153  }
     154  else  DosClose(dllfile);
     155
     156  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);
     157  if(rc) {
     158        return; //oops
     159  }
     160
     161  //read dos header
     162  if(DosRead(dllfile, (LPVOID)&doshdr, sizeof(doshdr), &ulRead)) {
     163        goto end;
     164  }
     165  if(DosSetFilePtr(dllfile, doshdr.e_lfanew, FILE_BEGIN, &ulRead)) {
     166        goto end;
     167  }
     168  //read signature dword
     169  if(DosRead(dllfile, (LPVOID)&signature, sizeof(signature), &ulRead)) {
     170        goto end;
     171  }
     172  //read pe header
     173  if(DosRead(dllfile, (LPVOID)&fh, sizeof(fh), &ulRead)) {
     174        goto end;
     175  }
     176  //read optional header
     177  if(DosRead(dllfile, (LPVOID)&oh, sizeof(oh), &ulRead)) {
     178        goto end;
     179  }
     180  if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) {
     181        goto end;
     182  }
     183  if(!(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)) {
     184        goto end; //no need to allocate anything now
     185  }
     186
     187  // check for high memory support
     188  rc = DosQuerySysInfo(QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ulSysinfo, sizeof(ulSysinfo));
     189  if (rc == 0 && ulSysinfo > 512)   //VirtualAddresslimit is in MB
     190  {
     191        flAllocMem = PAG_ANY;      // high memory support. Let's use it!
     192  }
     193
     194  //Reserve enough space to store 4096 pointers to 1MB memory chunks
     195  memallocs = (ULONG *)alloca(4096*sizeof(ULONG *));
     196  if(memallocs == NULL) {
     197        goto end; //oops
     198  }
     199
     200  if(oh.ImageBase < 512*1024*124) {
     201        flAllocMem = 0;
     202  }
     203  while(TRUE) {
     204        rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ | flAllocMem);
     205        if(rc) break;
     206
     207        if(address + FALLOC_SIZE >= oh.ImageBase) {
     208                if(address > oh.ImageBase) {//we've passed it!
     209                        DosFreeMem((PVOID)address);
     210                        break;
     211                }
     212                //found the right address
     213                DosFreeMem((PVOID)address);
     214
     215                diff = oh.ImageBase - address;
     216                if(diff) {
     217                        rc = DosAllocMem((PPVOID)&address, diff, PAG_READ | flAllocMem);
     218                        if(rc) break;
     219                }
     220                rc = DosAllocMem((PPVOID)&baseAddress, oh.SizeOfImage, PAG_READ | PAG_WRITE | flAllocMem);
     221                if(rc) break;
     222
     223                if(diff) DosFreeMem((PVOID)address);
     224
     225                reservedMemory = baseAddress;
     226                break;
     227        }
     228        memallocs[alloccnt++] = address;
     229  }
     230  for(i=0;i<alloccnt;i++) {
     231        DosFreeMem((PVOID)memallocs[i]);
     232  }
     233
     234end:
     235  DosClose(dllfile);
     236  return;
     237}
     238//******************************************************************************
     239//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.