Moved all Wine internal definitions out of process.h.
diff --git a/loader/dos/module.c b/loader/dos/module.c
index 41f1bc3..d1193f8 100644
--- a/loader/dos/module.c
+++ b/loader/dos/module.c
@@ -26,7 +26,6 @@
#include "selectors.h"
#include "file.h"
#include "ldt.h"
-#include "process.h"
#include "miscemu.h"
#include "debugtools.h"
#include "dosexe.h"
diff --git a/loader/elf.c b/loader/elf.c
index 2813d18..816b709 100644
--- a/loader/elf.c
+++ b/loader/elf.c
@@ -17,7 +17,6 @@
#include <sys/types.h>
#include "snoop.h"
-#include "process.h"
#include "heap.h"
#include "file.h"
#include "module.h"
diff --git a/loader/module.c b/loader/module.c
index 7434ca6..a741b91 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -15,7 +15,7 @@
#include "winerror.h"
#include "heap.h"
#include "file.h"
-#include "process.h"
+#include "module.h"
#include "selectors.h"
#include "debugtools.h"
#include "callback.h"
@@ -25,6 +25,10 @@
DEFAULT_DEBUG_CHANNEL(module);
DECLARE_DEBUG_CHANNEL(win32);
+WINE_MODREF *MODULE_modref_list = NULL;
+
+static WINE_MODREF *exe_modref;
+static int free_lib_count; /* recursion depth of FreeLibrary calls */
/*************************************************************************
* MODULE32_LookupHMODULE
@@ -36,14 +40,14 @@
WINE_MODREF *wm;
if (!hmod)
- return PROCESS_Current()->exe_modref;
+ return exe_modref;
if (!HIWORD(hmod)) {
ERR("tried to lookup 0x%04x in win32 module handler!\n",hmod);
SetLastError( ERROR_INVALID_HANDLE );
return NULL;
}
- for ( wm = PROCESS_Current()->modref_list; wm; wm=wm->next )
+ for ( wm = MODULE_modref_list; wm; wm=wm->next )
if (wm->module == hmod)
return wm;
SetLastError( ERROR_INVALID_HANDLE );
@@ -76,9 +80,15 @@
if ((wm->short_modname = strrchr( wm->short_filename, '\\' ))) wm->short_modname++;
else wm->short_modname = wm->short_filename;
- wm->next = PROCESS_Current()->modref_list;
+ wm->next = MODULE_modref_list;
if (wm->next) wm->next->prev = wm;
- PROCESS_Current()->modref_list = wm;
+ MODULE_modref_list = wm;
+
+ if (!(PE_HEADER(hModule)->FileHeader.Characteristics & IMAGE_FILE_DLL))
+ {
+ if (!exe_modref) exe_modref = wm;
+ else FIXME( "Trying to load second .EXE file: %s\n", filename );
+ }
}
return wm;
}
@@ -139,20 +149,21 @@
* list after the attach notification has returned. This implies that the
* detach notifications are called in the reverse of the sequence the attach
* notifications *returned*.
- *
- * NOTE: Assumes that the process critical section is held!
- *
*/
BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
{
BOOL retv = TRUE;
int i;
+
+ RtlAcquirePebLock();
+
+ if (!wm) wm = exe_modref;
assert( wm );
/* prevent infinite recursion in case of cyclical dependencies */
if ( ( wm->flags & WINE_MODREF_MARKER )
|| ( wm->flags & WINE_MODREF_PROCESS_ATTACHED ) )
- return retv;
+ goto done;
TRACE("(%s,%p) - START\n", wm->modname, lpReserved );
@@ -179,8 +190,8 @@
if ( wm->next ) wm->next->prev = wm->prev;
wm->prev = NULL;
- wm->next = PROCESS_Current()->modref_list;
- PROCESS_Current()->modref_list = wm->next->prev = wm;
+ wm->next = MODULE_modref_list;
+ MODULE_modref_list = wm->next->prev = wm;
}
/* Remove recursion flag */
@@ -188,6 +199,8 @@
TRACE("(%s,%p) - END\n", wm->modname, lpReserved );
+ done:
+ RtlReleasePebLock();
return retv;
}
@@ -202,11 +215,11 @@
{
WINE_MODREF *wm;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
do
{
- for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next )
+ for ( wm = MODULE_modref_list; wm; wm = wm->next )
{
/* Check whether to detach this DLL */
if ( !(wm->flags & WINE_MODREF_PROCESS_ATTACHED) )
@@ -224,7 +237,7 @@
}
} while ( wm );
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
}
/*************************************************************************
@@ -238,9 +251,9 @@
{
WINE_MODREF *wm;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
- for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next )
+ for ( wm = MODULE_modref_list; wm; wm = wm->next )
if ( !wm->next )
break;
@@ -254,7 +267,7 @@
MODULE_InitDLL( wm, DLL_THREAD_ATTACH, lpReserved );
}
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
}
/*************************************************************************
@@ -268,9 +281,9 @@
{
WINE_MODREF *wm;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
- for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next )
+ for ( wm = MODULE_modref_list; wm; wm = wm->next )
{
if ( !(wm->flags & WINE_MODREF_PROCESS_ATTACHED) )
continue;
@@ -280,7 +293,7 @@
MODULE_InitDLL( wm, DLL_THREAD_DETACH, lpReserved );
}
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
}
/****************************************************************************
@@ -293,7 +306,7 @@
WINE_MODREF *wm;
BOOL retval = TRUE;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
wm = MODULE32_LookupHMODULE( hModule );
if ( !wm )
@@ -301,7 +314,7 @@
else
wm->flags |= WINE_MODREF_NO_DLL_CALLS;
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
return retval;
}
@@ -432,7 +445,7 @@
if (!(p = strrchr( dllname, '.')) || strchr( p, '/' ) || strchr( p, '\\'))
strcat( dllname, ".DLL" );
- for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next )
+ for ( wm = MODULE_modref_list; wm; wm = wm->next )
{
if ( !FILE_strcasecmp( dllname, wm->modname ) )
break;
@@ -1155,7 +1168,7 @@
WINE_MODREF *wm;
if ( module == NULL )
- wm = PROCESS_Current()->exe_modref;
+ wm = exe_modref;
else
wm = MODULE_FindModule( module );
@@ -1190,13 +1203,13 @@
{
WINE_MODREF *wm;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
lpFileName[0] = 0;
if ((wm = MODULE32_LookupHMODULE( hModule )))
lstrcpynA( lpFileName, wm->filename, size );
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
TRACE("%s\n", lpFileName );
return strlen(lpFileName);
}
@@ -1249,7 +1262,7 @@
return hmod;
}
- EnterCriticalSection(&PROCESS_Current()->crit_section);
+ RtlAcquirePebLock();
wm = MODULE_LoadLibraryExA( libname, hfile, flags );
if ( wm )
@@ -1263,8 +1276,7 @@
}
}
- LeaveCriticalSection(&PROCESS_Current()->crit_section);
-
+ RtlReleasePebLock();
return wm ? wm->module : 0;
}
@@ -1323,7 +1335,7 @@
strcat( filename, ".DLL" );
}
- EnterCriticalSection(&PROCESS_Current()->crit_section);
+ RtlAcquirePebLock();
/* Check for already loaded module */
if (!(pwm = MODULE_FindModule(filename)) &&
@@ -1361,7 +1373,7 @@
fixup_imports( pwm );
}
TRACE("Already loaded module '%s' at 0x%08x, count=%d, \n", filename, pwm->module, pwm->refCount);
- LeaveCriticalSection(&PROCESS_Current()->crit_section);
+ RtlReleasePebLock();
HeapFree ( GetProcessHeap(), 0, filename );
return pwm;
}
@@ -1407,7 +1419,7 @@
/* decrement the dependencies through the MODULE_FreeLibrary call. */
pwm->refCount++;
- LeaveCriticalSection(&PROCESS_Current()->crit_section);
+ RtlReleasePebLock();
SetLastError( err ); /* restore last error */
HeapFree ( GetProcessHeap(), 0, filename );
return pwm;
@@ -1417,7 +1429,7 @@
break;
}
- LeaveCriticalSection(&PROCESS_Current()->crit_section);
+ RtlReleasePebLock();
error:
WARN("Failed to load module '%s'; error=0x%08lx, \n", filename, GetLastError());
HeapFree ( GetProcessHeap(), 0, filename );
@@ -1477,7 +1489,7 @@
{
WINE_MODREF *wm, *next;
- for(wm = PROCESS_Current()->modref_list; wm; wm = next)
+ for(wm = MODULE_modref_list; wm; wm = next)
{
next = wm->next;
@@ -1489,8 +1501,8 @@
wm->next->prev = wm->prev;
if(wm->prev)
wm->prev->next = wm->next;
- if(wm == PROCESS_Current()->modref_list)
- PROCESS_Current()->modref_list = wm->next;
+ if(wm == MODULE_modref_list)
+ MODULE_modref_list = wm->next;
TRACE(" unloading %s\n", wm->filename);
/* VirtualFree( (LPVOID)wm->module, 0, MEM_RELEASE ); */ /* FIXME */
@@ -1511,8 +1523,8 @@
BOOL retv = FALSE;
WINE_MODREF *wm;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
- PROCESS_Current()->free_lib_count++;
+ RtlAcquirePebLock();
+ free_lib_count++;
wm = MODULE32_LookupHMODULE( hLibModule );
if ( !wm || !hLibModule )
@@ -1520,8 +1532,8 @@
else
retv = MODULE_FreeLibrary( wm );
- PROCESS_Current()->free_lib_count--;
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ free_lib_count--;
+ RtlReleasePebLock();
return retv;
}
@@ -1569,7 +1581,7 @@
MODULE_DecRefCount( wm );
/* Call process detach notifications */
- if ( PROCESS_Current()->free_lib_count <= 1 )
+ if ( free_lib_count <= 1 )
{
MODULE_DllProcessDetach( FALSE, NULL );
SERVER_START_REQ
@@ -1700,13 +1712,13 @@
else
TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
if ((wm = MODULE32_LookupHMODULE( hModule )))
{
retproc = wm->find_export( wm, function, snoop );
if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
}
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
return retproc;
}
diff --git a/loader/ne/module.c b/loader/ne/module.c
index e8c2908..f6cbefc 100644
--- a/loader/ne/module.c
+++ b/loader/ne/module.c
@@ -19,7 +19,6 @@
#include "heap.h"
#include "task.h"
#include "global.h"
-#include "process.h"
#include "snoop.h"
#include "builtin16.h"
#include "stackframe.h"
@@ -1073,6 +1072,7 @@
if (hThread == -1) return 0;
if (!(teb = THREAD_Create( socket, 0, FALSE ))) goto error;
+ teb->tibflags &= ~TEBF_WIN32;
teb->startup = NE_InitProcess;
/* Create a task for this process */
diff --git a/loader/pe_image.c b/loader/pe_image.c
index e37689d..dae4523 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -31,7 +31,6 @@
#endif
#include "wine/winbase16.h"
#include "winerror.h"
-#include "process.h"
#include "snoop.h"
#include "server.h"
#include "debugtools.h"
@@ -639,21 +638,6 @@
if ( pe_export )
dump_exports( hModule );
- /* The exe_modref must be in place, before implicit linked DLLs are loaded
- by fixup_imports, otherwhise GetModuleFileName will not work and modules
- in the executables directory can not be found */
-
- if (!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL))
- {
- if ( PROCESS_Current()->exe_modref )
- FIXME( "Trying to load second .EXE file: %s\n", filename );
- else
- {
- PROCESS_Current()->exe_modref = wm;
- PROCESS_Current()->module = wm->module;
- }
- }
-
/* Fixup Imports */
if (!(wm->flags & WINE_MODREF_DONT_RESOLVE_REFS) && fixup_imports( wm ))
@@ -661,7 +645,7 @@
/* remove entry from modref chain */
if ( !wm->prev )
- PROCESS_Current()->modref_list = wm->next;
+ MODULE_modref_list = wm->next;
else
wm->prev->next = wm->next;
@@ -791,7 +775,7 @@
PIMAGE_TLS_DIRECTORY pdir;
int delta;
- for (wm = PROCESS_Current()->modref_list;wm;wm=wm->next) {
+ for (wm = MODULE_modref_list;wm;wm=wm->next) {
peh = PE_HEADER(wm->module);
delta = wm->module - peh->OptionalHeader.ImageBase;
if (!peh->OptionalHeader.DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress)
diff --git a/loader/pe_resource.c b/loader/pe_resource.c
index bf0823c..f30ca65 100644
--- a/loader/pe_resource.c
+++ b/loader/pe_resource.c
@@ -20,7 +20,6 @@
#include "module.h"
#include "heap.h"
#include "task.h"
-#include "process.h"
#include "stackframe.h"
#include "debugtools.h"
diff --git a/loader/resource.c b/loader/resource.c
index bec3444..06cd355 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -22,7 +22,6 @@
#include "callback.h"
#include "cursoricon.h"
#include "task.h"
-#include "process.h"
#include "module.h"
#include "file.h"
#include "debugtools.h"
diff --git a/loader/task.c b/loader/task.c
index cd140fd..4cb9f81 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -18,7 +18,6 @@
#include "instance.h"
#include "miscemu.h"
#include "module.h"
-#include "process.h"
#include "queue.h"
#include "selectors.h"
#include "stackframe.h"
@@ -283,17 +282,18 @@
(int)&((PDB16 *)0)->fileHandles );
pTask->pdb.hFileHandles = 0;
memset( pTask->pdb.fileHandles, 0xff, sizeof(pTask->pdb.fileHandles) );
- pTask->pdb.environment = current_envdb.env_sel;
+ /* FIXME: should we make a copy of the environment? */
+ pTask->pdb.environment = SELECTOROF(GetDOSEnvironment16());
pTask->pdb.nbFiles = 20;
/* Fill the command line */
if (!cmdline)
{
- cmdline = current_envdb.cmd_line;
+ cmdline = GetCommandLineA();
/* remove the first word (program name) */
if (*cmdline == '"')
- if (!(cmdline = strchr( cmdline+1, '"' ))) cmdline = current_envdb.cmd_line;
+ if (!(cmdline = strchr( cmdline+1, '"' ))) cmdline = GetCommandLineA();
while (*cmdline && (*cmdline != ' ') && (*cmdline != '\t')) cmdline++;
while ((*cmdline == ' ') || (*cmdline == '\t')) cmdline++;
len = strlen(cmdline);
@@ -314,10 +314,6 @@
pTask->hCSAlias = GLOBAL_CreateBlock( GMEM_FIXED, (void *)pTask,
sizeof(TDB), pTask->hPDB, WINE_LDT_FLAGS_CODE );
- /* Set the owner of the environment block */
-
- FarSetOwner16( pTask->pdb.environment, pTask->hPDB );
-
/* Default DTA overwrites command line */
pTask->dta = PTR_SEG_OFF_TO_SEGPTR( pTask->hPDB,
@@ -1320,18 +1316,6 @@
/***********************************************************************
- * GetDOSEnvironment (KERNEL.131)
- */
-SEGPTR WINAPI GetDOSEnvironment16(void)
-{
- TDB *pTask;
-
- if (!(pTask = (TDB *)GlobalLock16( GetCurrentTask() ))) return 0;
- return PTR_SEG_OFF_TO_SEGPTR( pTask->pdb.environment, 0 );
-}
-
-
-/***********************************************************************
* GetNumTasks (KERNEL.152)
*/
UINT16 WINAPI GetNumTasks16(void)