ntdll/kernel32: #8

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


move some fields (refCount, tls_index and module) from WINE_MODREF to 
LDR_MODULE
A+
-- 
Eric Pouech
-------------- next part --------------
Common subdirectories: dlls/ntdll7/CVS and dlls/ntdll/CVS
diff -u -x '*~' -x '.#*' dlls/ntdll7/loader.c dlls/ntdll/loader.c
--- dlls/ntdll7/loader.c	2003-03-20 19:35:42.000000000 +0100
+++ dlls/ntdll/loader.c	2003-03-20 20:21:54.000000000 +0100
@@ -71,7 +71,7 @@
 	return NULL;
     }
     for ( wm = MODULE_modref_list; wm; wm=wm->next )
-	if (wm->module == hmod)
+	if (wm->ldr.BaseAddress == hmod)
 	    return wm;
     return NULL;
 }
@@ -93,8 +93,8 @@
     if ((wm = RtlAllocateHeap( ntdll_get_process_heap(), HEAP_ZERO_MEMORY,
                                sizeof(*wm) + long_len + short_len + 1 )))
     {
-        wm->module = hModule;
-        wm->tlsindex = -1;
+        wm->ldr.BaseAddress = hModule;
+        wm->ldr.TlsIndex = -1;
 
         wm->filename = wm->data;
         memcpy( wm->filename, filename, long_len + 1 );
@@ -154,7 +154,7 @@
     TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );
 
     /* Call the initialization routine */
-    retv = PE_InitDLL( wm->module, type, lpReserved );
+    retv = PE_InitDLL( wm->ldr.BaseAddress, type, lpReserved );
 
     /* The state of the module list may have changed due to the call
        to PE_InitDLL. We cannot assume that this module has not been
@@ -272,7 +272,7 @@
             /* Check whether to detach this DLL */
             if ( !(wm->flags & WINE_MODREF_PROCESS_ATTACHED) )
                 continue;
-            if ( wm->refCount > 0 && !bForceDetach )
+            if ( wm->ldr.LoadCount > 0 && !bForceDetach )
                 continue;
 
             /* Call detach notification */
@@ -357,8 +357,8 @@
 
     for ( wm = MODULE_modref_list; wm; wm = wm->next )
     {
-        if ((const void *)wm->module <= addr &&
-            (char *)addr < (char*)wm->module + wm->ldr.SizeOfImage)
+        if ((const void *)wm->ldr.BaseAddress <= addr &&
+            (char *)addr < (char*)wm->ldr.BaseAddress + wm->ldr.SizeOfImage)
         {
             *mod = &wm->ldr;
             return STATUS_SUCCESS;
@@ -471,7 +471,7 @@
         return STATUS_DLL_NOT_FOUND;
     }
 
-    *base = wm->module;
+    *base = wm->ldr.BaseAddress;
     return STATUS_SUCCESS;
 }
 
@@ -632,7 +632,7 @@
     }
     if (*pwm)
     {
-        (*pwm)->refCount++;
+        (*pwm)->ldr.LoadCount++;
         
         if (((*pwm)->flags & WINE_MODREF_DONT_RESOLVE_REFS) &&
             !(flags & DONT_RESOLVE_DLL_REFERENCES))
@@ -640,7 +640,7 @@
             (*pwm)->flags &= ~WINE_MODREF_DONT_RESOLVE_REFS;
             PE_fixup_imports( *pwm );
         }
-        TRACE("Already loaded module '%s' at %p, count=%d\n", filename, (*pwm)->module, (*pwm)->refCount);
+        TRACE("Already loaded module '%s' at %p, count=%d\n", filename, (*pwm)->ldr.BaseAddress, (*pwm)->ldr.LoadCount);
         if (allocated_libdir)
         {
             RtlFreeHeap( ntdll_get_process_heap(), 0, (LPSTR)libdir );
@@ -679,12 +679,12 @@
         if (nts == STATUS_SUCCESS)
         {
             /* Initialize DLL just loaded */
-            TRACE("Loaded module '%s' at %p\n", filename, (*pwm)->module);
+            TRACE("Loaded module '%s' at %p\n", filename, (*pwm)->ldr.BaseAddress);
             if (!TRACE_ON(module))
                 TRACE_(loaddll)("Loaded module '%s' : %s\n", filename, filetype);
-            /* Set the refCount here so that an attach failure will */
+            /* Set the ldr.LoadCount here so that an attach failure will */
             /* decrement the dependencies through the MODULE_FreeLibrary call. */
-            (*pwm)->refCount = 1;
+            (*pwm)->ldr.LoadCount = 1;
             
             if (allocated_libdir)
             {
@@ -735,7 +735,7 @@
         if ( !MODULE_DllProcessAttach( wm, NULL ) )
         {
             WARN_(module)("Attach failed for module '%s'.\n", str.Buffer);
-            LdrUnloadDll(wm->module);
+            LdrUnloadDll(wm->ldr.BaseAddress);
             nts = STATUS_DLL_INIT_FAILED;
             wm = NULL;
         }
@@ -747,7 +747,7 @@
         break;
     }
 
-    *hModule = (wm) ? wm->module : NULL;
+    *hModule = (wm) ? wm->ldr.BaseAddress : NULL;
     
     RtlLeaveCriticalSection( &loader_section );
 
@@ -812,7 +812,7 @@
     {
         next = wm->next;
 
-        if (wm->refCount)
+        if (wm->ldr.LoadCount)
             continue;
 
         /* Unlink this modref from the chain */
@@ -830,13 +830,13 @@
 
         SERVER_START_REQ( unload_dll )
         {
-            req->base = (void *)wm->module;
+            req->base = (void *)wm->ldr.BaseAddress;
             wine_server_call( req );
         }
         SERVER_END_REQ;
 
         if (wm->dlhandle) wine_dll_unload( wm->dlhandle );
-        else UnmapViewOfFile( (LPVOID)wm->module );
+        else UnmapViewOfFile( (LPVOID)wm->ldr.BaseAddress );
         FreeLibrary16( wm->hDummyMod );
         RtlFreeHeap( ntdll_get_process_heap(), 0, wm->deps );
         RtlFreeHeap( ntdll_get_process_heap(), 0, wm );
@@ -855,13 +855,13 @@
     if ( wm->flags & WINE_MODREF_MARKER )
         return;
 
-    if ( wm->refCount <= 0 )
+    if ( wm->ldr.LoadCount <= 0 )
         return;
 
-    --wm->refCount;
-    TRACE("(%s) refCount: %d\n", wm->modname, wm->refCount );
+    --wm->ldr.LoadCount;
+    TRACE("(%s) ldr.LoadCount: %d\n", wm->modname, wm->ldr.LoadCount );
 
-    if ( wm->refCount == 0 )
+    if ( wm->ldr.LoadCount == 0 )
     {
         wm->flags |= WINE_MODREF_MARKER;
 
Only in dlls/ntdll: loader.c.orig
Only in dlls/ntdll: loader.c.rej
Common subdirectories: dlls/ntdll7/tests and dlls/ntdll/tests
Common subdirectories: include7/bitmaps and include/bitmaps
Common subdirectories: include7/CVS and include/CVS
diff -u -x '*~' -x '.#*' include7/module.h include/module.h
--- include7/module.h	2003-03-20 19:33:59.000000000 +0100
+++ include/module.h	2003-03-20 20:20:15.000000000 +0100
@@ -130,10 +130,8 @@
 {
 	struct _wine_modref *next;
 	struct _wine_modref *prev;
-	HMODULE              module;
 	HMODULE16            hDummyMod; /* Win16 dummy module */
 	void                *dlhandle;  /* handle returned by dlopen() */
-	int                  tlsindex;  /* TLS index or -1 if none */
         LDR_MODULE           ldr;
 	FARPROC            (*find_export)( struct _wine_modref *wm, LPCSTR func,
                                            int hint, BOOL snoop );
@@ -142,7 +140,6 @@
 	struct _wine_modref	**deps;
 
 	int			flags;
-	int			refCount;
 
 	char			*filename;
 	char			*modname;
Common subdirectories: include7/msvcrt and include/msvcrt
Common subdirectories: include7/wine and include/wine
Common subdirectories: loader7/CVS and loader/CVS
Common subdirectories: loader7/ne and loader/ne
diff -u -x '*~' -x '.#*' loader7/pe_image.c loader/pe_image.c
--- loader7/pe_image.c	2003-03-15 08:49:00.000000000 +0100
+++ loader/pe_image.c	2003-03-20 20:20:15.000000000 +0100
@@ -126,18 +126,18 @@
         IMAGE_EXPORT_DIRECTORY *exports;
         DWORD exp_size;
 
-        if (!(exports = RtlImageDirectoryEntryToData( wm->module, TRUE,
+        if (!(exports = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE,
                                                       IMAGE_DIRECTORY_ENTRY_EXPORT, &exp_size )))
             return NULL;
 
         if (HIWORD(funcName)) TRACE("(%s)\n",funcName);
         else TRACE("(%d)\n",LOWORD(funcName));
 
-	ordinals= get_rva(wm->module, exports->AddressOfNameOrdinals);
-	function= get_rva(wm->module, exports->AddressOfFunctions);
-	name    = get_rva(wm->module, exports->AddressOfNames);
+	ordinals= get_rva(wm->ldr.BaseAddress, exports->AddressOfNameOrdinals);
+	function= get_rva(wm->ldr.BaseAddress, exports->AddressOfFunctions);
+	name    = get_rva(wm->ldr.BaseAddress, exports->AddressOfNames);
 	forward = NULL;
-        rva_start = (char *)exports - (char *)wm->module;
+        rva_start = (char *)exports - (char *)wm->ldr.BaseAddress;
 
 	if (HIWORD(funcName))
         {
@@ -146,7 +146,7 @@
             /* first check the hint */
             if (hint >= 0 && hint <= max)
             {
-                ename = get_rva(wm->module, name[hint]);
+                ename = get_rva(wm->ldr.BaseAddress, name[hint]);
                 if (!strcmp( ename, funcName ))
                 {
                     ordinal = ordinals[hint];
@@ -158,7 +158,7 @@
             while (min <= max)
             {
                 int res, pos = (min + max) / 2;
-                ename = get_rva(wm->module, name[pos]);
+                ename = get_rva(wm->ldr.BaseAddress, name[pos]);
                 if (!(res = strcmp( ename, funcName )))
                 {
                     ordinal = ordinals[pos];
@@ -177,7 +177,7 @@
                 for (i = 0; i < exports->NumberOfNames; i++)
                     if (ordinals[i] == ordinal)
                     {
-                        ename = get_rva(wm->module, name[i]);
+                        ename = get_rva(wm->ldr.BaseAddress, name[i]);
                         break;
                     }
             }
@@ -192,13 +192,13 @@
         addr = function[ordinal];
         if (!addr) return NULL;
 
-        proc = get_rva(wm->module, addr);
+        proc = get_rva(wm->ldr.BaseAddress, addr);
         if (((char *)proc < (char *)exports) || ((char *)proc >= (char *)exports + exp_size))
         {
             if (snoop)
             {
                 if (!ename) ename = "@";
-                proc = SNOOP_GetProcAddress(wm->module,ename,ordinal,proc);
+                proc = SNOOP_GetProcAddress(wm->ldr.BaseAddress,ename,ordinal,proc);
             }
             return proc;
         }
@@ -218,7 +218,7 @@
                     ERR("module not found for forward '%s' used by '%s'\n", forward, wm->modname );
                     return NULL;
                 }
-		if (!(proc = MODULE_GetProcAddress( wm_fw->module, end + 1, -1, snoop )))
+		if (!(proc = MODULE_GetProcAddress( wm_fw->ldr.BaseAddress, end + 1, -1, snoop )))
                     ERR("function not found for forward '%s' used by '%s'. If you are using builtin '%s', try using the native one instead.\n", forward, wm->modname, wm->modname );
 		return proc;
 	}
@@ -233,7 +233,7 @@
     IMAGE_IMPORT_DESCRIPTOR *imports, *pe_imp;
     DWORD size;
 
-    imports = RtlImageDirectoryEntryToData( wm->module, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size );
+    imports = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size );
 
     /* first, count the number of imported non-internal modules */
     pe_imp = imports;
@@ -267,7 +267,7 @@
     	WINE_MODREF		*wmImp;
 	IMAGE_IMPORT_BY_NAME	*pe_name;
 	PIMAGE_THUNK_DATA	import_list,thunk_list;
- 	char			*name = get_rva(wm->module, pe_imp->Name);
+ 	char			*name = get_rva(wm->ldr.BaseAddress, pe_imp->Name);
         NTSTATUS                nts;
 
 	if (characteristics_detection && !pe_imp->u.Characteristics)
@@ -292,8 +292,8 @@
 
 	if (pe_imp->u.OriginalFirstThunk != 0) { /* original MS style */
 	    TRACE("Microsoft style imports used\n");
-	    import_list = get_rva(wm->module, (DWORD)pe_imp->u.OriginalFirstThunk);
-	    thunk_list = get_rva(wm->module, (DWORD)pe_imp->FirstThunk);
+	    import_list = get_rva(wm->ldr.BaseAddress, (DWORD)pe_imp->u.OriginalFirstThunk);
+	    thunk_list = get_rva(wm->ldr.BaseAddress, (DWORD)pe_imp->FirstThunk);
 
 	    while (import_list->u1.Ordinal) {
 		if (IMAGE_SNAP_BY_ORDINAL(import_list->u1.Ordinal)) {
@@ -301,7 +301,7 @@
 
 		    TRACE("--- Ordinal %s,%d\n", name, ordinal);
 		    thunk_list->u1.Function=(PDWORD)MODULE_GetProcAddress(
-                        wmImp->module, (LPCSTR)ordinal, -1, TRUE
+                        wmImp->ldr.BaseAddress, (LPCSTR)ordinal, -1, TRUE
 		    );
 		    if (!thunk_list->u1.Function) {
 			ERR("No implementation for %s.%d imported from %s, setting to 0xdeadbeef\n",
@@ -309,10 +309,10 @@
                         thunk_list->u1.Function = (PDWORD)0xdeadbeef;
 		    }
 		} else {		/* import by name */
-		    pe_name = get_rva(wm->module, (DWORD)import_list->u1.AddressOfData);
+		    pe_name = get_rva(wm->ldr.BaseAddress, (DWORD)import_list->u1.AddressOfData);
 		    TRACE("--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint);
 		    thunk_list->u1.Function=(PDWORD)MODULE_GetProcAddress(
-                        wmImp->module, pe_name->Name, pe_name->Hint, TRUE
+                        wmImp->ldr.BaseAddress, pe_name->Name, pe_name->Hint, TRUE
 		    );
 		    if (!thunk_list->u1.Function) {
 			ERR("No implementation for %s.%d(%s) imported from %s, setting to 0xdeadbeef\n",
@@ -325,7 +325,7 @@
 	    }
 	} else {	/* Borland style */
 	    TRACE("Borland style imports used\n");
-	    thunk_list = get_rva(wm->module, (DWORD)pe_imp->FirstThunk);
+	    thunk_list = get_rva(wm->ldr.BaseAddress, (DWORD)pe_imp->FirstThunk);
 	    while (thunk_list->u1.Ordinal) {
 		if (IMAGE_SNAP_BY_ORDINAL(thunk_list->u1.Ordinal)) {
 		    /* not sure about this branch, but it seems to work */
@@ -333,7 +333,7 @@
 
 		    TRACE("--- Ordinal %s.%d\n",name,ordinal);
 		    thunk_list->u1.Function=(PDWORD)MODULE_GetProcAddress(
-                        wmImp->module, (LPCSTR) ordinal, -1, TRUE
+                        wmImp->ldr.BaseAddress, (LPCSTR) ordinal, -1, TRUE
 		    );
 		    if (!thunk_list->u1.Function) {
 			ERR("No implementation for %s.%d imported from %s, setting to 0xdeadbeef\n",
@@ -341,11 +341,11 @@
                         thunk_list->u1.Function = (PDWORD)0xdeadbeef;
 		    }
 		} else {
-		    pe_name=get_rva(wm->module, (DWORD)thunk_list->u1.AddressOfData);
+		    pe_name=get_rva(wm->ldr.BaseAddress, (DWORD)thunk_list->u1.AddressOfData);
 		    TRACE("--- %s %s.%d\n",
 		   		  pe_name->Name,name,pe_name->Hint);
 		    thunk_list->u1.Function=(PDWORD)MODULE_GetProcAddress(
-                        wmImp->module, pe_name->Name, pe_name->Hint, TRUE
+                        wmImp->ldr.BaseAddress, pe_name->Name, pe_name->Hint, TRUE
 		    );
 		    if (!thunk_list->u1.Function) {
 		    	ERR("No implementation for %s.%d(%s) imported from %s, setting to 0xdeadbeef\n",
@@ -672,19 +672,19 @@
         int delta;
 
 	for (wm = MODULE_modref_list;wm;wm=wm->next) {
-                peh = RtlImageNtHeader(wm->module);
-                pdir = RtlImageDirectoryEntryToData( wm->module, TRUE,
+                peh = RtlImageNtHeader(wm->ldr.BaseAddress);
+                pdir = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE,
                                                      IMAGE_DIRECTORY_ENTRY_TLS, &dirsize );
                 if (!pdir) continue;
-                delta = (char *)wm->module - (char *)peh->OptionalHeader.ImageBase;
+                delta = (char *)wm->ldr.BaseAddress - (char *)peh->OptionalHeader.ImageBase;
 
-		if ( wm->tlsindex == -1 ) {
+		if ( wm->ldr.TlsIndex == -1 ) {
 			LPDWORD xaddr;
-			wm->tlsindex = TlsAlloc();
+			wm->ldr.TlsIndex = TlsAlloc();
 			xaddr = _fixup_address(&(peh->OptionalHeader),delta,
 					pdir->AddressOfIndex
 			);
-			*xaddr=wm->tlsindex;
+			*xaddr=wm->ldr.TlsIndex;
 		}
 		datasize= pdir->EndAddressOfRawData-pdir->StartAddressOfRawData;
 		size	= datasize + pdir->SizeOfZeroFill;
@@ -698,6 +698,6 @@
 		       FIXME("TLS Callbacks aren't going to be called\n");
 		}
 
-		TlsSetValue( wm->tlsindex, mem );
+		TlsSetValue( wm->ldr.TlsIndex, mem );
 	}
 }
Common subdirectories: misc7/CVS and misc/CVS
diff -u -x '*~' -x '.#*' misc7/version.c misc/version.c
--- misc7/version.c	2003-03-15 15:50:54.000000000 +0100
+++ misc/version.c	2003-03-20 20:20:15.000000000 +0100
@@ -453,7 +453,7 @@
 	from one windows version */
 	for ( wm = MODULE_modref_list; wm; wm=wm->next )
 	{
-          nt = RtlImageNtHeader(wm->module);
+          nt = RtlImageNtHeader(wm->ldr.BaseAddress);
           ophd = &nt->OptionalHeader;
 
 	  TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
@@ -472,7 +472,7 @@
 	      /* test if it is a special dll */
 	      if (!strcasecmp(wm->modname, special_dlls[i]))
 	      {
-	        DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
+	        DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->ldr.BaseAddress);
 	        if (WinVersion == NB_WINDOWS_VERSIONS)
 	          WinVersion = DllVersion;
 	        else {
diff -u -x '*~' -x '.#*' relay327/builtin32.c relay32/builtin32.c
--- relay327/builtin32.c	2003-03-15 08:49:00.000000000 +0100
+++ relay32/builtin32.c	2003-03-20 20:20:15.000000000 +0100
@@ -134,7 +134,7 @@
     }
     TRACE( "loaded %s %p %p\n", fullname, wm, module );
     HeapFree( GetProcessHeap(), 0, fullname );
-    wm->refCount++;  /* we don't support freeing builtin dlls (FIXME)*/
+    wm->ldr.LoadCount++;  /* we don't support freeing builtin dlls (FIXME)*/
 
     /* setup relay debugging entry points */
     if (TRACE_ON(relay)) RELAY_SetupDLL( (void *)module );
Common subdirectories: relay327/CVS and relay32/CVS
diff -u -x '*~' -x '.#*' relay327/relay386.c relay32/relay386.c
--- relay327/relay386.c	2003-03-01 14:42:13.000000000 +0100
+++ relay32/relay386.c	2003-03-20 20:20:15.000000000 +0100
@@ -239,7 +239,7 @@
     for (wm = MODULE_modref_list; wm; wm = wm->next)
     {
         if (!(wm->flags & WINE_MODREF_INTERNAL)) continue;
-        exp = RtlImageDirectoryEntryToData( wm->module, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size );
+        exp = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size );
         if (!exp) continue;
         debug = (DEBUG_ENTRY_POINT *)((char *)exp + size);
         if (debug <= relay && relay < debug + exp->NumberOfFunctions)
@@ -251,7 +251,7 @@
 
     /* Now find the function */
 
-    base = (char *)wm->module;
+    base = (char *)wm->ldr.BaseAddress;
     strcpy( buffer, base + exp->Name );
     p = buffer + strlen(buffer);
     if (p > buffer + 4 && !strcasecmp( p - 4, ".dll" )) p -= 4;
Common subdirectories: scheduler7/CVS and scheduler/CVS
diff -u -x '*~' -x '.#*' scheduler7/process.c scheduler/process.c
--- scheduler7/process.c	2003-03-20 19:37:43.000000000 +0100
+++ scheduler/process.c	2003-03-20 20:20:15.000000000 +0100
@@ -535,7 +535,7 @@
     /* create the main modref and load dependencies */
     if (!(wm = PE_CreateModule( current_process.module, main_exe_name, 0, 0, FALSE )))
         goto error;
-    wm->refCount++;
+    wm->ldr.LoadCount++;
 
     if (main_exe_file) CloseHandle( main_exe_file ); /* we no longer need it */
 
Only in scheduler: process.c.orig


More information about the wine-patches mailing list