- Timestamp:
- Oct 22, 2012, 3:50:20 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/peldr/pe.c
r22028 r22029 405 405 ULONG ulSysinfo, flAllocMem = 0; 406 406 BOOL ret = FALSE; 407 408 //Reserve enough space to store 4096 pointers to 1MB memory chunks 409 static ULONG memallocs[4096]; 407 ULONG allocSize = FALLOC_SIZE; 408 409 // Reserve enough space to store 4096 pointers to 1MB memory chunks + 410 // 16 pointers to 64K memory chunks (1MB) for the extra loop (see below) 411 static ULONG memallocs[4096 + 16]; 410 412 411 413 *fNEExe = FALSE; … … 445 447 DBG(("PE: AllocateExeMem: oh.Subsystem: %d\n", oh.Subsystem)); 446 448 DBG(("PE: AllocateExeMem: oh.ImageBase: 0x%08X\n", oh.ImageBase)); 449 DBG(("PE: AllocateExeMem: oh.SizeOfImage: 0x%08X\n", oh.SizeOfImage)); 447 450 448 451 // check for high memory support … … 464 467 } 465 468 while(TRUE) { 466 rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ | flAllocMem);469 rc = DosAllocMem((PPVOID)&address, allocSize, PAG_READ | flAllocMem); 467 470 if(rc) break; 468 471 469 if(address + FALLOC_SIZE>= oh.ImageBase) {472 if(address + allocSize >= oh.ImageBase) { 470 473 if(address > oh.ImageBase) {//we've passed it! 471 474 DosFreeMem((PVOID)address); … … 483 486 if(rc) break; 484 487 488 // Sometimes it's possible that a smaller block of memory enough to 489 // fit SizeOfImage is available below the target base address which 490 // will be skipped by the loop allocating memory in FALLOC_SIZE 491 // chunks when FALLOC_SIZE is greater than SizeOfImage. Continue 492 // allocation in smaller chunks in this case to get a perfect match. 493 if (baseAddress != oh.ImageBase) { 494 // save already allocated blocks for further release 495 memallocs[alloccnt++] = diff; 496 memallocs[alloccnt++] = baseAddress; 497 // set the exact chunk size 498 allocSize = oh.SizeOfImage; 499 continue; 500 } 501 485 502 if(diff) DosFreeMem((PVOID)address); 486 503 … … 493 510 DosFreeMem((PVOID)memallocs[i]); 494 511 } 495 DBG(("PE: AllocateExeMem: reservedMemory: 0x%08X\n", reservedMemory)); 496 ret = TRUE; 512 ret = rc == 0; 497 513 end: 498 514 if(dllfile) DosClose(dllfile); 515 DBG(("PE: AllocateExeMem: reservedMemory: 0x%08X\n", reservedMemory)); 499 516 DBG(("PE: AllocateExeMem: returning %d\n", ret)); 500 517 return ret;
Note:
See TracChangeset
for help on using the changeset viewer.