ntdll/kernel32: #11

Eric Pouech pouech-eric at wanadoo.fr
Thu Mar 20 14:11:46 CST 2003


- rewrote mapping of module into memory using only NTDLL APIs

(NB: file searching and opening still needs to be addressed)

A+
-- 
Eric Pouech
-------------- next part --------------
Common subdirectories: dlls/ntdll10/CVS and dlls/ntdll/CVS
Common subdirectories: dlls/ntdll10/tests and dlls/ntdll/tests
Common subdirectories: include10/bitmaps and include/bitmaps
Common subdirectories: include10/CVS and include/CVS
Common subdirectories: include10/msvcrt and include/msvcrt
Common subdirectories: include10/wine and include/wine
Common subdirectories: loader10/CVS and loader/CVS
Common subdirectories: loader10/ne and loader/ne
diff -u -x '*~' -x '.#*' loader10/pe_image.c loader/pe_image.c
--- loader10/pe_image.c	2003-03-20 20:55:44.000000000 +0100
+++ loader/pe_image.c	2003-03-20 20:58:49.000000000 +0100
@@ -375,15 +375,34 @@
     IMAGE_NT_HEADERS *nt;
     HMODULE hModule;
     HANDLE mapping;
-    void *base;
+    void *base = NULL;
+    OBJECT_ATTRIBUTES attr;
+    LARGE_INTEGER lg_int;
+    DWORD len = 0;
+    NTSTATUS nts;
 
     TRACE_(module)( "loading %s\n", filename );
 
-    mapping = CreateFileMappingA( hFile, NULL, SEC_IMAGE, 0, 0, NULL );
-    if (!mapping) return 0;
-    base = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
-    CloseHandle( mapping );
-    if (!base) return 0;
+    attr.Length                   = sizeof(attr);
+    attr.RootDirectory            = 0;
+    attr.ObjectName               = NULL;
+    attr.Attributes               = 0;
+    attr.SecurityDescriptor       = NULL;
+    attr.SecurityQualityOfService = NULL;
+    
+    lg_int.QuadPart = 0;
+
+    if (NtCreateSection( &mapping, 
+                         STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ,
+                         &attr, &lg_int, 0, SEC_IMAGE, hFile ) != STATUS_SUCCESS)
+        return 0;
+
+    nts = NtMapViewOfSection( mapping, (HANDLE)0xffffffff /* current process */, 
+                              &base, 0, 0, &lg_int, &len, ViewShare, 0, 
+                              PAGE_READONLY );
+    
+    NtClose( mapping );
+    if (nts != STATUS_SUCCESS) return 0;
 
     /* virus check */
 
@@ -662,6 +681,7 @@
 		/* the address has been relocated already */
 		return addr;
 }
+
 void PE_InitTls( void )
 {
 	WINE_MODREF		*wm;
@@ -688,7 +708,9 @@
 		}
 		datasize= pdir->EndAddressOfRawData-pdir->StartAddressOfRawData;
 		size	= datasize + pdir->SizeOfZeroFill;
-		mem=VirtualAlloc(0,size,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
+                NtAllocateVirtualMemory( (HANDLE)0xffffffff /* current process */,
+                                         &mem, NULL, &size, 
+                                         MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE );
 		memcpy(mem,_fixup_address(&(peh->OptionalHeader),delta,(LPVOID)pdir->StartAddressOfRawData),datasize);
 		if (pdir->AddressOfCallBacks) {
 		     PIMAGE_TLS_CALLBACK *cbs;
Only in loader: pe_image.c.orig
Common subdirectories: misc10/CVS and misc/CVS
Common subdirectories: relay3210/CVS and relay32/CVS
Common subdirectories: scheduler10/CVS and scheduler/CVS


More information about the wine-patches mailing list