At 11:44 AM 4/29/00 -0400, you wrote:
>Try reverting the CVS commit and trying the original patch I sent - the original
>patch checks to ensure that the pe section offsets are on pagesize bounds, and
>if not avoids the FILE_dommap call and just copies the section instead.
<snip>
Err, I had just deleted all these megabytes of attachments last week :-(
I had to get the patch from integrita and find a program to decode the mime b64
encoding :-(
This done, I have just taken a bit of your original code :
--- pe_image.c.orig Sat Apr 29 09:33:46 2000
+++ pe_image.c Sat Apr 29 21:31:20 2000
@@ -472,7 +472,7 @@
{
HMODULE hModule;
HANDLE mapping;
-
+ BOOL bCopyDll = FALSE;
IMAGE_NT_HEADERS *nt;
IMAGE_SECTION_HEADER *pe_sec;
IMAGE_DATA_DIRECTORY *dir;
@@ -655,10 +655,15 @@
server_call_fd( REQ_GET_READ_FD, -1, &unix_handle );
if (unix_handle == -1) goto error;
+ if ( nt->OptionalHeader.FileAlignment % VIRTUAL_GetPageSize() )
+ {
+ TRACE("Module %s is not aligned on page boundary. Reverting to old copy
+method\n", filename);
+ bCopyDll = TRUE;
+ }
/* Map the header */
if (FILE_dommap( unix_handle, (void *)load_addr, 0,
nt->OptionalHeader.SizeOfHeaders,
- 0, 0, PROT_EXEC | PROT_WRITE | PROT_READ,
- MAP_PRIVATE | MAP_FIXED ) != load_addr)
+ 0, 0, PROT_EXEC | PROT_WRITE | PROT_READ,
+ MAP_PRIVATE | MAP_FIXED ) != load_addr)
{
ERR_(win32)( "Critical Error: failed to map PE header to necessary
address.\n");
goto error;
@@ -668,18 +673,28 @@
pe_sec = PE_SECTIONS( hModule );
for (i = 0; i < nt->FileHeader.NumberOfSections; i++, pe_sec++)
{
- if (!pe_sec->SizeOfRawData) continue;
- TRACE("%s: mmaping section %s at %p off %lx\n",
+ if (!bCopyDll)
+ {
+ if (!pe_sec->SizeOfRawData) continue;
+ TRACE("%s: mmaping section %s at %p off %lx\n",
filename, pe_sec->Name, (void*)RVA(pe_sec->VirtualAddress),
pe_sec->PointerToRawData);
- if (FILE_dommap( unix_handle, (void*)RVA(pe_sec->VirtualAddress),
+ if (FILE_dommap( unix_handle, (void*)RVA(pe_sec->VirtualAddress),
0, min(pe_sec->Misc.VirtualSize, pe_sec->SizeOfRawData),
0, pe_sec->PointerToRawData, PROT_EXEC | PROT_WRITE |
PROT_READ,
MAP_PRIVATE | MAP_FIXED ) !=
(void*)RVA(pe_sec->VirtualAddress))
+ {
+ /* We failed to map to the right place (huh?) */
+ ERR_(win32)( "Critical Error: failed to map PE section to necessary
+address.\n");
+ goto error;
+ }
+ }
+ else
{
- /* We failed to map to the right place (huh?) */
- ERR_(win32)( "Critical Error: failed to map PE section to necessary
address.\n");
- goto error;
+ /* Just copy the non-BSS segments */
+ if(!(pe_sec->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA))
+ memcpy((char*)RVA(pe_sec->VirtualAddress),
+ (char*)(hModule + pe_sec->PointerToRawData), pe_sec->SizeOfRawData);
}
}
This is enough to fix the problem. So obviously your idea is correct.
I have just seen Alexandre Julliard's patch, I have not yet tested it
BTW, I am sorry to say that I have done a big mistake in my previous post;
in fact you are completely right, Wordviewer 97 can no longer find files selected
in the open file dialog. I suspect that this is Juergen's work (what a bunch of
Microsoft
haters ;-))
Gerard