Moved all Wine internal definitions out of process.h.
diff --git a/dlls/crtdll/exit.c b/dlls/crtdll/exit.c
index 362f882..fc02cca 100644
--- a/dlls/crtdll/exit.c
+++ b/dlls/crtdll/exit.c
@@ -25,7 +25,6 @@
*/
#include "crtdll.h"
#include <errno.h>
-#include "process.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
diff --git a/dlls/crtdll/spawn.c b/dlls/crtdll/spawn.c
index 5768469..835bf57 100644
--- a/dlls/crtdll/spawn.c
+++ b/dlls/crtdll/spawn.c
@@ -32,7 +32,6 @@
* -File handles need some special handling. Sometimes children get
* open file handles, sometimes not. The docs are confusing.
* -No check for maximum path/argument/environment size is done.
- * -Wine has a "process.h" which is not the same as any crt version.
* Unresolved issues Uwe Bonnes 970904:
* -system-call calls another wine process, but without debugging arguments
* and uses the first wine executable in the path
@@ -40,7 +39,6 @@
#include "crtdll.h"
#include <errno.h>
-#include "process.h"
#include <stdlib.h>
diff --git a/dlls/crtdll/time.c b/dlls/crtdll/time.c
index 671288b..4e6744b 100644
--- a/dlls/crtdll/time.c
+++ b/dlls/crtdll/time.c
@@ -11,7 +11,6 @@
*/
#include "crtdll.h"
-#include "process.h"
#include <stdlib.h>
#include <sys/times.h>
diff --git a/dlls/kernel/utthunk.c b/dlls/kernel/utthunk.c
index 2888449..3b52fb0 100644
--- a/dlls/kernel/utthunk.c
+++ b/dlls/kernel/utthunk.c
@@ -5,11 +5,11 @@
*/
#include "wine/winbase16.h"
+#include "ntddk.h"
#include "heap.h"
#include "module.h"
#include "selectors.h"
#include "callback.h"
-#include "process.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(thunk);
@@ -51,6 +51,8 @@
} UTINFO;
+static UTINFO *UT_head; /* head of Universal Thunk list */
+
typedef DWORD (CALLBACK *UTGLUEPROC)( LPVOID lpBuff, DWORD dwUserDefined );
BOOL WINAPI UTRegister( HMODULE hModule, LPSTR lpsz16BITDLL,
@@ -173,8 +175,8 @@
ut->ut32.jmp = 0xe9;
ut->ut32.utglue32 = (DWORD)UTGlue32 - ((DWORD)&ut->ut32.utglue32 + sizeof(DWORD));
- ut->next = PROCESS_Current()->UTState;
- PROCESS_Current()->UTState = ut;
+ ut->next = UT_head;
+ UT_head = ut;
return ut;
}
@@ -186,7 +188,7 @@
{
UTINFO **ptr;
- for ( ptr = &PROCESS_Current()->UTState; *ptr; ptr = &(*ptr)->next )
+ for ( ptr = &UT_head; *ptr; ptr = &(*ptr)->next )
if ( *ptr == ut )
{
*ptr = ut->next;
@@ -203,7 +205,7 @@
{
UTINFO *ut;
- for ( ut = PROCESS_Current()->UTState; ut; ut =ut->next )
+ for ( ut = UT_head; ut; ut =ut->next )
if ( ut->hModule == hModule )
break;
@@ -231,12 +233,12 @@
/* Allocate UTINFO struct */
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
if ( (ut = UTFind( hModule )) != NULL )
ut = NULL;
else
ut = UTAlloc( hModule, hModule16, target16, pfnUT32CallBack );
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
if ( !ut )
{
@@ -276,14 +278,14 @@
UTINFO *ut;
HMODULE16 hModule16 = 0;
- EnterCriticalSection( &PROCESS_Current()->crit_section );
+ RtlAcquirePebLock();
ut = UTFind( hModule );
if ( !ut )
{
hModule16 = ut->hModule16;
UTFree( ut );
}
- LeaveCriticalSection( &PROCESS_Current()->crit_section );
+ RtlReleasePebLock();
if ( hModule16 )
FreeLibrary16( hModule16 );
diff --git a/include/Makefile.in b/include/Makefile.in
index 44ed9a4..14c69a9 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -51,6 +51,7 @@
oledlg.h \
oleidl.h \
poppack.h \
+ process.h \
prsht.h \
psapi.h \
pshpack1.h \
diff --git a/include/ldt.h b/include/ldt.h
index 4b35b70..9abd720 100644
--- a/include/ldt.h
+++ b/include/ldt.h
@@ -26,10 +26,10 @@
#define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \
PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << __AHSHIFT), LOWORD(off) )
-#define W32S_APPLICATION() (PROCESS_Current()->flags & PDB32_WIN32S_PROC)
-#define W32S_OFFSET 0x10000
-#define W32S_APP2WINE(addr, offset) ((addr)? (DWORD)(addr) + (DWORD)(offset) : 0)
-#define W32S_WINE2APP(addr, offset) ((addr)? (DWORD)(addr) - (DWORD)(offset) : 0)
+extern UINT W32S_offset;
+
+#define W32S_APP2WINE(addr) ((addr)? (DWORD)(addr) + W32S_offset : 0)
+#define W32S_WINE2APP(addr) ((addr)? (DWORD)(addr) - W32S_offset : 0)
#define FIRST_LDT_ENTRY_TO_ALLOC 17
diff --git a/include/module.h b/include/module.h
index 336686c..b7ea4c3 100644
--- a/include/module.h
+++ b/include/module.h
@@ -140,6 +140,7 @@
#define WINE_MODREF_DONT_RESOLVE_REFS 0x00000020
#define WINE_MODREF_MARKER 0x80000000
+extern WINE_MODREF *MODULE_modref_list;
/* Resource types */
@@ -231,4 +232,33 @@
extern void *BUILTIN32_dlopen( const char *name );
extern int BUILTIN32_dlclose( void *handle );
+/* USER signal proc flags and codes */
+/* See PROCESS_CallUserSignalProc for comments */
+#define USIG_FLAGS_WIN32 0x0001
+#define USIG_FLAGS_GUI 0x0002
+#define USIG_FLAGS_FEEDBACK 0x0004
+#define USIG_FLAGS_FAULT 0x0008
+
+#define USIG_DLL_UNLOAD_WIN16 0x0001
+#define USIG_DLL_UNLOAD_WIN32 0x0002
+#define USIG_FAULT_DIALOG_PUSH 0x0003
+#define USIG_FAULT_DIALOG_POP 0x0004
+#define USIG_DLL_UNLOAD_ORPHANS 0x0005
+#define USIG_THREAD_INIT 0x0010
+#define USIG_THREAD_EXIT 0x0020
+#define USIG_PROCESS_CREATE 0x0100
+#define USIG_PROCESS_INIT 0x0200
+#define USIG_PROCESS_EXIT 0x0300
+#define USIG_PROCESS_DESTROY 0x0400
+#define USIG_PROCESS_RUNNING 0x0500
+#define USIG_PROCESS_LOADED 0x0600
+
+/* scheduler/process.c */
+extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule );
+extern BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
+ LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
+ BOOL inherit, DWORD flags,
+ STARTUPINFOA *startup, PROCESS_INFORMATION *info,
+ LPCSTR lpCurrentDirectory );
+
#endif /* __WINE_MODULE_H */
diff --git a/include/process.h b/include/process.h
index 25f2739..eb03635 100644
--- a/include/process.h
+++ b/include/process.h
@@ -4,165 +4,8 @@
* Copyright 1996 Alexandre Julliard
*/
-#ifndef __WINE_PROCESS_H
-#define __WINE_PROCESS_H
-
-#include "windef.h"
-#include "module.h"
-#include "thread.h"
-
-struct _NE_MODULE;
-struct _THREAD_ENTRY;
-struct _UTINFO;
-
-/* Win32 process environment database */
-typedef struct
-{
- LPSTR environ; /* 00 Process environment strings */
- DWORD unknown1; /* 04 Unknown */
- LPSTR cmd_line; /* 08 Command line */
- LPSTR cur_dir; /* 0c Current directory */
- STARTUPINFOA *startup_info; /* 10 Startup information */
- HANDLE hStdin; /* 14 Handle for standard input */
- HANDLE hStdout; /* 18 Handle for standard output */
- HANDLE hStderr; /* 1c Handle for standard error */
- DWORD unknown2; /* 20 Unknown */
- DWORD inherit_console; /* 24 Inherit console flag */
- DWORD break_type; /* 28 Console events flag */
- void *break_sem; /* 2c SetConsoleCtrlHandler semaphore */
- void *break_event; /* 30 SetConsoleCtrlHandler event */
- void *break_thread; /* 34 SetConsoleCtrlHandler thread */
- void *break_handlers; /* 38 List of console handlers */
- /* The following are Wine-specific fields */
- CRITICAL_SECTION section; /* 3c Env DB critical section */
- LPWSTR cmd_lineW; /* 40 Unicode command line */
- WORD env_sel; /* 44 Environment strings selector */
-} ENVDB;
-
-/* Win32 process database */
-typedef struct _PDB
-{
- LONG header[2]; /* 00 Kernel object header */
- HMODULE module; /* 08 Main exe module (NT) */
- void *event; /* 0c Pointer to an event object (unused) */
- DWORD exit_code; /* 10 Process exit code */
- DWORD unknown2; /* 14 Unknown */
- HANDLE heap; /* 18 Default process heap */
- HANDLE mem_context; /* 1c Process memory context */
- DWORD flags; /* 20 Flags */
- void *pdb16; /* 24 DOS PSP */
- WORD PSP_sel; /* 28 Selector to DOS PSP */
- WORD imte; /* 2a IMTE for the process module */
- WORD threads; /* 2c Number of threads */
- WORD running_threads; /* 2e Number of running threads */
- WORD free_lib_count; /* 30 Recursion depth of FreeLibrary calls */
- WORD ring0_threads; /* 32 Number of ring 0 threads */
- HANDLE system_heap; /* 34 System heap to allocate handles */
- HTASK task; /* 38 Win16 task */
- void *mem_map_files; /* 3c Pointer to mem-mapped files */
- ENVDB *env_db; /* 40 Environment database */
- void *handle_table; /* 44 Handle table */
- struct _PDB *parent; /* 48 Parent process */
- WINE_MODREF *modref_list; /* 4c MODREF list */
- void *thread_list; /* 50 List of threads */
- void *debuggee_CB; /* 54 Debuggee context block */
- void *local_heap_free; /* 58 Head of local heap free list */
- DWORD unknown4; /* 5c Unknown */
- CRITICAL_SECTION crit_section; /* 60 Critical section */
- DWORD unknown5[3]; /* 78 Unknown */
- void *console; /* 84 Console */
- DWORD tls_bits[2]; /* 88 TLS in-use bits */
- DWORD process_dword; /* 90 Unknown */
- struct _PDB *group; /* 94 Process group */
- WINE_MODREF *exe_modref; /* 98 MODREF for the process EXE */
- LPTOP_LEVEL_EXCEPTION_FILTER top_filter; /* 9c Top exception filter */
- DWORD priority; /* a0 Priority level */
- HANDLE heap_list; /* a4 Head of process heap list */
- void *heap_handles; /* a8 Head of heap handles list */
- DWORD unknown6; /* ac Unknown */
- void *console_provider; /* b0 Console provider (??) */
- WORD env_selector; /* b4 Selector to process environment */
- WORD error_mode; /* b6 Error mode */
- HANDLE load_done_evt; /* b8 Event for process loading done */
- struct _UTINFO *UTState; /* bc Head of Univeral Thunk list */
- DWORD unknown8; /* c0 Unknown (NT) */
- LCID locale; /* c4 Locale to be queried by GetThreadLocale (NT) */
-} PDB;
-
-/* Process flags */
-#define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
-#define PDB32_WIN16_PROC 0x0008 /* Win16 process */
-#define PDB32_DOS_PROC 0x0010 /* Dos process */
-#define PDB32_CONSOLE_PROC 0x0020 /* Console process */
-#define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
-#define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
-
-/* USER signal proc flags and codes */
-/* See PROCESS_CallUserSignalProc for comments */
-#define USIG_FLAGS_WIN32 0x0001
-#define USIG_FLAGS_GUI 0x0002
-#define USIG_FLAGS_FEEDBACK 0x0004
-#define USIG_FLAGS_FAULT 0x0008
-
-#define USIG_DLL_UNLOAD_WIN16 0x0001
-#define USIG_DLL_UNLOAD_WIN32 0x0002
-#define USIG_FAULT_DIALOG_PUSH 0x0003
-#define USIG_FAULT_DIALOG_POP 0x0004
-#define USIG_DLL_UNLOAD_ORPHANS 0x0005
-#define USIG_THREAD_INIT 0x0010
-#define USIG_THREAD_EXIT 0x0020
-#define USIG_PROCESS_CREATE 0x0100
-#define USIG_PROCESS_INIT 0x0200
-#define USIG_PROCESS_EXIT 0x0300
-#define USIG_PROCESS_DESTROY 0x0400
-#define USIG_PROCESS_RUNNING 0x0500
-#define USIG_PROCESS_LOADED 0x0600
-
-/* [GS]etProcessDword offsets */
-#define GPD_APP_COMPAT_FLAGS (-56)
-#define GPD_LOAD_DONE_EVENT (-52)
-#define GPD_HINSTANCE16 (-48)
-#define GPD_WINDOWS_VERSION (-44)
-#define GPD_THDB (-40)
-#define GPD_PDB (-36)
-#define GPD_STARTF_SHELLDATA (-32)
-#define GPD_STARTF_HOTKEY (-28)
-#define GPD_STARTF_SHOWWINDOW (-24)
-#define GPD_STARTF_SIZE (-20)
-#define GPD_STARTF_POSITION (-16)
-#define GPD_STARTF_FLAGS (-12)
-#define GPD_PARENT (- 8)
-#define GPD_FLAGS (- 4)
-#define GPD_USERDATA ( 0)
-
-extern DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset );
-extern void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value );
-extern DWORD WINAPI MapProcessHandle( HANDLE handle );
-
-/* memory/environ.c */
-extern BOOL ENV_BuildEnvironment(void);
-
-/* scheduler/process.c */
-extern void PROCESS_InitWine( int argc, char *argv[] ) WINE_NORETURN;
-extern void PROCESS_InitWinelib( int argc, char *argv[] ) WINE_NORETURN;
-extern void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule );
-extern BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR env,
- LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
- BOOL inherit, DWORD flags,
- STARTUPINFOA *startup, PROCESS_INFORMATION *info,
- LPCSTR lpCurrentDirectory );
-
-extern PDB current_process;
-extern ENVDB current_envdb;
-extern STARTUPINFOA current_startupinfo;
-
-static inline PDB WINE_UNUSED *PROCESS_Current(void)
-{
- return ¤t_process;
-}
-
-/* definitions contained in Windows process.h file */
-/* FIXME: all the stuff above should be moved somewhere else */
+#ifndef _INC_PROCESS
+#define _INC_PROCESS
typedef void (*LPBEGINTHREAD)(LPVOID);
typedef UINT (WINAPI *LPBEGINTHREADEX)(LPVOID);
@@ -172,4 +15,4 @@
ULONG _beginthreadex(LPVOID,UINT,LPBEGINTHREADEX,LPVOID,UINT,LPUINT);
void _endthreadex(UINT);
-#endif /* __WINE_PROCESS_H */
+#endif /* _INC_PROCESS */
diff --git a/include/winbase.h b/include/winbase.h
index 5f10217..3a1e658 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -1880,13 +1880,33 @@
INT level;
} SYSLEVEL;
+/* [GS]etProcessDword offsets */
+#define GPD_APP_COMPAT_FLAGS (-56)
+#define GPD_LOAD_DONE_EVENT (-52)
+#define GPD_HINSTANCE16 (-48)
+#define GPD_WINDOWS_VERSION (-44)
+#define GPD_THDB (-40)
+#define GPD_PDB (-36)
+#define GPD_STARTF_SHELLDATA (-32)
+#define GPD_STARTF_HOTKEY (-28)
+#define GPD_STARTF_SHOWWINDOW (-24)
+#define GPD_STARTF_SIZE (-20)
+#define GPD_STARTF_POSITION (-16)
+#define GPD_STARTF_FLAGS (-12)
+#define GPD_PARENT (- 8)
+#define GPD_FLAGS (- 4)
+#define GPD_USERDATA ( 0)
+
void WINAPI DisposeLZ32Handle(HANDLE);
HANDLE WINAPI DosFileHandleToWin32Handle(HFILE);
+DWORD WINAPI GetProcessDword(DWORD,INT);
VOID WINAPI GetpWin16Lock(SYSLEVEL**);
DWORD WINAPI MapLS(LPCVOID);
+DWORD WINAPI MapProcessHandle(HANDLE);
LPVOID WINAPI MapSL(DWORD);
VOID WINAPI ReleaseThunkLock(DWORD*);
VOID WINAPI RestoreThunkLock(DWORD);
+void WINAPI SetProcessDword(DWORD,INT,DWORD);
VOID WINAPI UnMapLS(DWORD);
HFILE WINAPI Win32HandleToDosFileHandle(HANDLE);
DWORD WINAPI _ConfirmWin16Lock(void);
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)
diff --git a/memory/environ.c b/memory/environ.c
index 67f8d2c..e5e1781 100644
--- a/memory/environ.c
+++ b/memory/environ.c
@@ -9,10 +9,31 @@
#include "windef.h"
#include "winnls.h"
#include "winerror.h"
-#include "process.h"
+#include "ntddk.h"
#include "heap.h"
#include "selectors.h"
+/* Win32 process environment database */
+typedef struct _ENVDB
+{
+ LPSTR environ; /* 00 Process environment strings */
+ DWORD unknown1; /* 04 Unknown */
+ LPSTR cmd_line; /* 08 Command line */
+ LPSTR cur_dir; /* 0c Current directory */
+ STARTUPINFOA *startup_info; /* 10 Startup information */
+ HANDLE hStdin; /* 14 Handle for standard input */
+ HANDLE hStdout; /* 18 Handle for standard output */
+ HANDLE hStderr; /* 1c Handle for standard error */
+ DWORD unknown2; /* 20 Unknown */
+ DWORD inherit_console; /* 24 Inherit console flag */
+ DWORD break_type; /* 28 Console events flag */
+ void *break_sem; /* 2c SetConsoleCtrlHandler semaphore */
+ void *break_event; /* 30 SetConsoleCtrlHandler event */
+ void *break_thread; /* 34 SetConsoleCtrlHandler thread */
+ void *break_handlers; /* 38 List of console handlers */
+} ENVDB;
+
+
/* Format of an environment block:
* ASCIIZ string 1 (xx=yy format)
* ...
@@ -79,12 +100,13 @@
0, /* break_sem */
0, /* break_event */
0, /* break_thread */
- 0, /* break_handlers */
- CRITICAL_SECTION_INIT, /* section */
- 0, /* cmd_lineW */
- 0 /* env_sel */
+ 0 /* break_handlers */
};
+
+static WCHAR *cmdlineW; /* Unicode command line */
+static WORD env_sel; /* selector to the environment */
+
/***********************************************************************
* ENV_FindVariable
*
@@ -108,7 +130,7 @@
*
* Build the environment for the initial process
*/
-BOOL ENV_BuildEnvironment(void)
+ENVDB *ENV_BuildEnvironment(void)
{
extern char **environ;
LPSTR p, *e;
@@ -121,9 +143,9 @@
/* Now allocate the environment */
- if (!(p = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
+ if (!(p = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
current_envdb.environ = p;
- current_envdb.env_sel = SELECTOR_AllocBlock( p, 0x10000, WINE_LDT_FLAGS_DATA );
+ env_sel = SELECTOR_AllocBlock( p, 0x10000, WINE_LDT_FLAGS_DATA );
/* And fill it with the Unix environment */
@@ -136,6 +158,50 @@
/* Now add the program name */
FILL_EXTRA_ENV( p );
+ return ¤t_envdb;
+}
+
+
+/***********************************************************************
+ * ENV_BuildCommandLine
+ *
+ * Build the command line of a process from the argv array.
+ *
+ * Note that it does NOT necessarily include the file name.
+ * Sometimes we don't even have any command line options at all.
+ */
+BOOL ENV_BuildCommandLine( char **argv )
+{
+ int len, quote = 0;
+ char *p, **arg;
+
+ for (arg = argv, len = 0; *arg; arg++) len += strlen(*arg) + 1;
+ if ((argv[0]) && (quote = (strchr( argv[0], ' ' ) != NULL))) len += 2;
+ if (!(p = current_envdb.cmd_line = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
+ arg = argv;
+ if (quote)
+ {
+ *p++ = '\"';
+ strcpy( p, *arg );
+ p += strlen(p);
+ *p++ = '\"';
+ *p++ = ' ';
+ arg++;
+ }
+ while (*arg)
+ {
+ strcpy( p, *arg );
+ p += strlen(p);
+ *p++ = ' ';
+ arg++;
+ }
+ if (p > current_envdb.cmd_line) p--; /* remove last space */
+ *p = 0;
+ /* now allocate the Unicode version */
+ len = MultiByteToWideChar( CP_ACP, 0, current_envdb.cmd_line, -1, NULL, 0 );
+ if (!(cmdlineW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+ return FALSE;
+ MultiByteToWideChar( CP_ACP, 0, current_envdb.cmd_line, -1, cmdlineW, len );
return TRUE;
}
@@ -153,12 +219,7 @@
*/
LPWSTR WINAPI GetCommandLineW(void)
{
- EnterCriticalSection( ¤t_envdb.section );
- if (!current_envdb.cmd_lineW)
- current_envdb.cmd_lineW = HEAP_strdupAtoW( GetProcessHeap(), 0,
- current_envdb.cmd_line );
- LeaveCriticalSection( ¤t_envdb.section );
- return current_envdb.cmd_lineW;
+ return cmdlineW;
}
@@ -179,7 +240,7 @@
INT size;
LPWSTR ret;
- EnterCriticalSection( ¤t_envdb.section );
+ RtlAcquirePebLock();
size = HeapSize( GetProcessHeap(), 0, current_envdb.environ );
if ((ret = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) )) != NULL)
{
@@ -187,7 +248,7 @@
LPWSTR pW = ret;
while (size--) *pW++ = (WCHAR)(BYTE)*pA++;
}
- LeaveCriticalSection( ¤t_envdb.section );
+ RtlReleasePebLock();
return ret;
}
@@ -228,7 +289,7 @@
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
- EnterCriticalSection( ¤t_envdb.section );
+ RtlAcquirePebLock();
if ((p = ENV_FindVariable( current_envdb.environ, name, strlen(name) )))
{
ret = strlen(p);
@@ -241,7 +302,7 @@
}
else if (value) strcpy( value, p );
}
- LeaveCriticalSection( ¤t_envdb.section );
+ RtlReleasePebLock();
if (!ret)
SetLastError( ERROR_ENVVAR_NOT_FOUND );
return ret;
@@ -276,7 +337,7 @@
LPSTR p, env, new_env;
BOOL ret = FALSE;
- EnterCriticalSection( ¤t_envdb.section );
+ RtlAcquirePebLock();
env = p = current_envdb.environ;
/* Find a place to insert the string */
@@ -302,9 +363,7 @@
}
if (!(new_env = HeapReAlloc( GetProcessHeap(), 0, env, old_size + len )))
goto done;
- if (current_envdb.env_sel)
- current_envdb.env_sel = SELECTOR_ReallocBlock( current_envdb.env_sel,
- new_env, old_size + len );
+ if (env_sel) env_sel = SELECTOR_ReallocBlock( env_sel, new_env, old_size + len );
p = new_env + (p - env);
if (len > 0) memmove( p + len, p, old_size - (p - new_env) );
@@ -320,7 +379,7 @@
ret = TRUE;
done:
- LeaveCriticalSection( ¤t_envdb.section );
+ RtlReleasePebLock();
return ret;
}
@@ -350,7 +409,7 @@
LPCSTR p, var;
if (!count) dst = NULL;
- EnterCriticalSection( ¤t_envdb.section );
+ RtlAcquirePebLock();
while (*src)
{
@@ -395,7 +454,7 @@
count -= len;
}
}
- LeaveCriticalSection( ¤t_envdb.section );
+ RtlReleasePebLock();
/* Null-terminate the string */
if (dst)
@@ -426,6 +485,15 @@
/***********************************************************************
+ * GetDOSEnvironment (KERNEL.131)
+ */
+SEGPTR WINAPI GetDOSEnvironment16(void)
+{
+ return PTR_SEG_OFF_TO_SEGPTR( env_sel, 0 );
+}
+
+
+/***********************************************************************
* GetStdHandle (KERNEL32.276)
*/
HANDLE WINAPI GetStdHandle( DWORD std_handle )
diff --git a/memory/selector.c b/memory/selector.c
index 06398dc..35ac9a9 100644
--- a/memory/selector.c
+++ b/memory/selector.c
@@ -13,7 +13,6 @@
#include "miscemu.h"
#include "selectors.h"
#include "stackframe.h"
-#include "process.h"
#include "server.h"
#include "debugtools.h"
#include "toolhelp.h"
@@ -296,7 +295,7 @@
*/
DWORD base = GetSelectorBase( sel );
- return W32S_WINE2APP( base, W32S_APPLICATION() ? W32S_OFFSET : 0 );
+ return W32S_WINE2APP( base );
}
DWORD WINAPI GetSelectorBase( WORD sel )
{
@@ -320,8 +319,7 @@
* See the comment in msdos/vxd.c.
*/
- SetSelectorBase( sel,
- W32S_APP2WINE( base, W32S_APPLICATION() ? W32S_OFFSET : 0 ) );
+ SetSelectorBase( sel, W32S_APP2WINE( base ) );
return sel;
}
WORD WINAPI SetSelectorBase( WORD sel, DWORD base )
diff --git a/memory/virtual.c b/memory/virtual.c
index e231382..321681f 100644
--- a/memory/virtual.c
+++ b/memory/virtual.c
@@ -28,7 +28,6 @@
#include "wine/port.h"
#include "winerror.h"
#include "file.h"
-#include "process.h"
#include "global.h"
#include "server.h"
#include "debugtools.h"
diff --git a/misc/version.c b/misc/version.c
index d0539b6..3671ce2 100644
--- a/misc/version.c
+++ b/misc/version.c
@@ -15,7 +15,7 @@
#include "wingdi.h"
#include "winuser.h"
#include "wine/winbase16.h"
-#include "process.h"
+#include "module.h"
#include "options.h"
#include "debugtools.h"
#include "winerror.h"
@@ -259,26 +259,15 @@
* 5.12/5.00/5.00/4.00 Win98 calc
* x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
*/
-DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
+DWORD VERSION_GetLinkedDllVersion(void)
{
WINE_MODREF *wm;
DWORD WinVersion = NB_WINDOWS_VERSIONS;
PIMAGE_OPTIONAL_HEADER ophd;
- if (!pdb->exe_modref)
- {
- if (!pdb->modref_list)
- return WIN31;
-
- /* FIXME: The above condition will never trigger, since all our
- * standard dlls load their win32 equivalents. We have usually at
- * this point: kernel32.dll and ntdll.dll.
- */
- return WIN95;
- }
/* First check the native dlls provided. These have to be
from one windows version */
- for ( wm = pdb->modref_list; wm; wm=wm->next )
+ for ( wm = MODULE_modref_list; wm; wm=wm->next )
{
ophd = &(PE_HEADER(wm->module)->OptionalHeader);
@@ -319,10 +308,9 @@
if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
/* we are using no external system dlls, look at the exe */
- ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
+ ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
- TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
- pdb->exe_modref->modname,
+ TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
ophd->MajorImageVersion, ophd->MinorImageVersion,
@@ -373,7 +361,7 @@
return defaultWinVersion;
if (winver == 0xffff) /* to be determined */ {
- WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion( PROCESS_Current() );
+ WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
if (retver != WIN31) winver = retver;
return retver;
diff --git a/miscemu/main.c b/miscemu/main.c
index da547d9..666b8f8 100644
--- a/miscemu/main.c
+++ b/miscemu/main.c
@@ -11,9 +11,10 @@
#include "callback.h"
#include "options.h"
#include "dosexe.h"
-#include "process.h"
#include "debugtools.h"
+extern void PROCESS_InitWine( int argc, char *argv[] ) WINE_NORETURN;
+
/***********************************************************************
* Main loop of initial task
*/
diff --git a/msdos/dpmi.c b/msdos/dpmi.c
index 2a6de5a..692da54 100644
--- a/msdos/dpmi.c
+++ b/msdos/dpmi.c
@@ -19,7 +19,6 @@
#include "task.h"
#include "toolhelp.h"
#include "selectors.h"
-#include "process.h"
#include "callback.h"
#include "debugtools.h"
@@ -698,8 +697,6 @@
* shifted by 0x10000 relative to the OS linear address space.
* See the comment in msdos/vxd.c.
*/
- DWORD offset = W32S_APPLICATION() ? W32S_OFFSET : 0;
-
DWORD dw;
BYTE *ptr;
@@ -814,16 +811,16 @@
}
else
{
- CX_reg(context) = HIWORD(W32S_WINE2APP(dw, offset));
- DX_reg(context) = LOWORD(W32S_WINE2APP(dw, offset));
+ CX_reg(context) = HIWORD(W32S_WINE2APP(dw));
+ DX_reg(context) = LOWORD(W32S_WINE2APP(dw));
}
break;
case 0x0007: /* Set selector base address */
TRACE("set selector base address (0x%04x,0x%08lx)\n",
BX_reg(context),
- W32S_APP2WINE(MAKELONG(DX_reg(context),CX_reg(context)), offset));
- dw = W32S_APP2WINE(MAKELONG(DX_reg(context), CX_reg(context)), offset);
+ W32S_APP2WINE(MAKELONG(DX_reg(context),CX_reg(context))));
+ dw = W32S_APP2WINE(MAKELONG(DX_reg(context), CX_reg(context)));
if (dw < 0x10000)
/* app wants to access lower 64K of DOS memory, map it in now */
DOSMEM_Init(TRUE);
@@ -854,7 +851,7 @@
TRACE("get descriptor (0x%04x)\n",BX_reg(context));
{
LDT_ENTRY entry;
- wine_ldt_set_base( &entry, (void*)W32S_WINE2APP(wine_ldt_get_base(&entry), offset) );
+ wine_ldt_set_base( &entry, (void*)W32S_WINE2APP(wine_ldt_get_base(&entry)) );
/* FIXME: should use ES:EDI for 32-bit clients */
*(LDT_ENTRY *)PTR_SEG_OFF_TO_LIN( context->SegEs, LOWORD(context->Edi) ) = entry;
}
@@ -865,7 +862,7 @@
{
LDT_ENTRY entry = *(LDT_ENTRY *)PTR_SEG_OFF_TO_LIN( context->SegEs,
LOWORD(context->Edi) );
- wine_ldt_set_base( &entry, (void*)W32S_APP2WINE(wine_ldt_get_base(&entry), offset) );
+ wine_ldt_set_base( &entry, (void*)W32S_APP2WINE(wine_ldt_get_base(&entry)) );
wine_ldt_set_entry( LOWORD(context->Ebx), &entry );
}
break;
@@ -994,31 +991,30 @@
AX_reg(context) = 0x8012; /* linear memory not available */
SET_CFLAG(context);
} else {
- BX_reg(context) = SI_reg(context) = HIWORD(W32S_WINE2APP(ptr, offset));
- CX_reg(context) = DI_reg(context) = LOWORD(W32S_WINE2APP(ptr, offset));
+ BX_reg(context) = SI_reg(context) = HIWORD(W32S_WINE2APP(ptr));
+ CX_reg(context) = DI_reg(context) = LOWORD(W32S_WINE2APP(ptr));
}
break;
case 0x0502: /* Free memory block */
TRACE("free memory block (0x%08lx)\n",
- W32S_APP2WINE(MAKELONG(DI_reg(context),SI_reg(context)), offset));
- DPMI_xfree( (void *)W32S_APP2WINE(MAKELONG(DI_reg(context),
- SI_reg(context)), offset) );
+ W32S_APP2WINE(MAKELONG(DI_reg(context),SI_reg(context))));
+ DPMI_xfree( (void *)W32S_APP2WINE(MAKELONG(DI_reg(context), SI_reg(context))) );
break;
case 0x0503: /* Resize memory block */
TRACE("resize memory block (0x%08lx,%ld)\n",
- W32S_APP2WINE(MAKELONG(DI_reg(context),SI_reg(context)), offset),
+ W32S_APP2WINE(MAKELONG(DI_reg(context),SI_reg(context))),
MAKELONG(CX_reg(context),BX_reg(context)));
if (!(ptr = (BYTE *)DPMI_xrealloc(
- (void *)W32S_APP2WINE(MAKELONG(DI_reg(context),SI_reg(context)), offset),
+ (void *)W32S_APP2WINE(MAKELONG(DI_reg(context),SI_reg(context))),
MAKELONG(CX_reg(context),BX_reg(context)))))
{
AX_reg(context) = 0x8012; /* linear memory not available */
SET_CFLAG(context);
} else {
- BX_reg(context) = SI_reg(context) = HIWORD(W32S_WINE2APP(ptr, offset));
- CX_reg(context) = DI_reg(context) = LOWORD(W32S_WINE2APP(ptr, offset));
+ BX_reg(context) = SI_reg(context) = HIWORD(W32S_WINE2APP(ptr));
+ CX_reg(context) = DI_reg(context) = LOWORD(W32S_WINE2APP(ptr));
}
break;
@@ -1065,8 +1061,8 @@
}
else
{
- BX_reg(context) = HIWORD(W32S_WINE2APP(ptr, offset));
- CX_reg(context) = LOWORD(W32S_WINE2APP(ptr, offset));
+ BX_reg(context) = HIWORD(W32S_WINE2APP(ptr));
+ CX_reg(context) = LOWORD(W32S_WINE2APP(ptr));
RESET_CFLAG(context);
}
break;
diff --git a/msdos/vxd.c b/msdos/vxd.c
index ac9f97f..da9aa0a 100644
--- a/msdos/vxd.c
+++ b/msdos/vxd.c
@@ -16,9 +16,9 @@
#include "wine/winuser16.h"
#include "msdos.h"
#include "miscemu.h"
+#include "module.h"
#include "selectors.h"
#include "task.h"
-#include "process.h"
#include "file.h"
#include "debugtools.h"
@@ -33,6 +33,7 @@
CX_reg(context), DX_reg(context), SI_reg(context), \
DI_reg(context), (WORD)context->SegDs, (WORD)context->SegEs )
+UINT W32S_offset = 0;
static WORD VXD_WinVersion(void)
{
@@ -515,10 +516,8 @@
* any routine apart from those, e.g. some other VxD handler, that code
* would have to take the offset into account as well!)
*
- * The application of the offset is triggered by marking the current process
- * as a Win32s process by setting the PDB32_WIN32S_PROC flag in the process
- * database. This is done the first time any application calls the GetVersion()
- * service of the Win32s VxD. (Note that the flag is never removed.)
+ * The offset is set the first time any application calls the GetVersion()
+ * service of the Win32s VxD. (Note that the offset is never reset.)
*
*/
@@ -596,7 +595,7 @@
* performance of Win32s.
*/
- if (!(PROCESS_Current()->flags & PDB32_WIN32S_PROC))
+ if (!W32S_offset)
{
HMODULE16 hModule = GetModuleHandle16("win32s16");
SEGPTR func1 = (SEGPTR)GetProcAddress16(hModule, "SetFS");
@@ -633,9 +632,8 @@
* Mark process as Win32s, so that subsequent DPMI calls
* will perform the W32S_APP2WINE/W32S_WINE2APP address shift.
*/
-
- PROCESS_Current()->flags |= PDB32_WIN32S_PROC;
- break;
+ W32S_offset = 0x10000;
+ break;
case 0x0001: /* Install Exception Handling */
@@ -743,7 +741,7 @@
*/
struct Win32sModule *moduleTable =
- (struct Win32sModule *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
+ (struct Win32sModule *)W32S_APP2WINE(context->Edx);
struct Win32sModule *module = moduleTable + context->Ecx;
IMAGE_NT_HEADERS *nt_header = PE_HEADER(module->baseAddr);
@@ -835,7 +833,7 @@
* Output: EAX: 1 if OK
*/
- TRACE("UnMapModule: %lx\n", (DWORD)W32S_APP2WINE(context->Edx, W32S_OFFSET));
+ TRACE("UnMapModule: %lx\n", (DWORD)W32S_APP2WINE(context->Edx));
/* As we didn't map anything, there's nothing to unmap ... */
@@ -858,9 +856,9 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0], W32S_OFFSET);
- LPVOID base = (LPVOID) W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0]);
+ LPVOID base = (LPVOID) W32S_APP2WINE(stack[1]);
DWORD size = stack[2];
DWORD type = stack[3];
DWORD prot = stack[4];
@@ -883,8 +881,8 @@
result = (DWORD)VirtualAlloc(base, size, type, prot);
- if (W32S_WINE2APP(result, W32S_OFFSET))
- *retv = W32S_WINE2APP(result, W32S_OFFSET),
+ if (W32S_WINE2APP(result))
+ *retv = W32S_WINE2APP(result),
context->Eax = STATUS_SUCCESS;
else
*retv = 0,
@@ -907,9 +905,9 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0], W32S_OFFSET);
- LPVOID base = (LPVOID) W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0]);
+ LPVOID base = (LPVOID) W32S_APP2WINE(stack[1]);
DWORD size = stack[2];
DWORD type = stack[3];
DWORD result;
@@ -944,12 +942,12 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0], W32S_OFFSET);
- LPVOID base = (LPVOID) W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0]);
+ LPVOID base = (LPVOID) W32S_APP2WINE(stack[1]);
DWORD size = stack[2];
DWORD new_prot = stack[3];
- DWORD *old_prot = (DWORD *)W32S_APP2WINE(stack[4], W32S_OFFSET);
+ DWORD *old_prot = (DWORD *)W32S_APP2WINE(stack[4]);
DWORD result;
TRACE("VirtualProtect(%lx, %lx, %lx, %lx, %lx)\n",
@@ -981,11 +979,11 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0], W32S_OFFSET);
- LPVOID base = (LPVOID) W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0]);
+ LPVOID base = (LPVOID) W32S_APP2WINE(stack[1]);
LPMEMORY_BASIC_INFORMATION info =
- (LPMEMORY_BASIC_INFORMATION)W32S_APP2WINE(stack[2], W32S_OFFSET);
+ (LPMEMORY_BASIC_INFORMATION)W32S_APP2WINE(stack[2]);
DWORD len = stack[3];
DWORD result;
@@ -1064,11 +1062,11 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *) W32S_APP2WINE(context->Edx, W32S_OFFSET);
- HANDLE *retv = (HANDLE *)W32S_APP2WINE(stack[0], W32S_OFFSET);
+ DWORD *stack = (DWORD *) W32S_APP2WINE(context->Edx);
+ HANDLE *retv = (HANDLE *)W32S_APP2WINE(stack[0]);
DWORD flags1 = stack[1];
DWORD atom = stack[2];
- LARGE_INTEGER *size = (LARGE_INTEGER *)W32S_APP2WINE(stack[3], W32S_OFFSET);
+ LARGE_INTEGER *size = (LARGE_INTEGER *)W32S_APP2WINE(stack[3]);
DWORD protect = stack[4];
DWORD flags2 = stack[5];
HANDLE hFile = DosFileHandleToWin32Handle(stack[6]);
@@ -1117,8 +1115,8 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- HANDLE *retv = (HANDLE *)W32S_APP2WINE(stack[0], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ HANDLE *retv = (HANDLE *)W32S_APP2WINE(stack[0]);
DWORD protect = stack[1];
DWORD atom = stack[2];
@@ -1160,9 +1158,9 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
HANDLE handle = stack[0];
- DWORD *id = (DWORD *)W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *id = (DWORD *)W32S_APP2WINE(stack[1]);
TRACE("NtCloseSection(%lx, %lx)\n", (DWORD)handle, (DWORD)id);
@@ -1183,7 +1181,7 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
HANDLE handle = stack[0];
HANDLE new_handle;
@@ -1215,20 +1213,20 @@
* Output: EAX: NtStatus
*/
{
- DWORD * stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
+ DWORD * stack = (DWORD *)W32S_APP2WINE(context->Edx);
HANDLE SectionHandle = stack[0];
DWORD ProcessHandle = stack[1]; /* ignored */
- DWORD * BaseAddress = (DWORD *)W32S_APP2WINE(stack[2], W32S_OFFSET);
+ DWORD * BaseAddress = (DWORD *)W32S_APP2WINE(stack[2]);
DWORD ZeroBits = stack[3];
DWORD CommitSize = stack[4];
- LARGE_INTEGER *SectionOffset = (LARGE_INTEGER *)W32S_APP2WINE(stack[5], W32S_OFFSET);
- DWORD * ViewSize = (DWORD *)W32S_APP2WINE(stack[6], W32S_OFFSET);
+ LARGE_INTEGER *SectionOffset = (LARGE_INTEGER *)W32S_APP2WINE(stack[5]);
+ DWORD * ViewSize = (DWORD *)W32S_APP2WINE(stack[6]);
DWORD InheritDisposition = stack[7];
DWORD AllocationType = stack[8];
DWORD Protect = stack[9];
LPBYTE address = (LPBYTE)(BaseAddress?
- W32S_APP2WINE(*BaseAddress, W32S_OFFSET) : 0);
+ W32S_APP2WINE(*BaseAddress) : 0);
DWORD access = 0, result;
switch (Protect & ~(PAGE_GUARD|PAGE_NOCACHE))
@@ -1259,9 +1257,9 @@
TRACE("NtMapViewOfSection: result=%lx\n", result);
- if (W32S_WINE2APP(result, W32S_OFFSET))
+ if (W32S_WINE2APP(result))
{
- if (BaseAddress) *BaseAddress = W32S_WINE2APP(result, W32S_OFFSET);
+ if (BaseAddress) *BaseAddress = W32S_WINE2APP(result);
context->Eax = STATUS_SUCCESS;
}
else
@@ -1280,9 +1278,9 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
DWORD ProcessHandle = stack[0]; /* ignored */
- LPBYTE BaseAddress = (LPBYTE)W32S_APP2WINE(stack[1], W32S_OFFSET);
+ LPBYTE BaseAddress = (LPBYTE)W32S_APP2WINE(stack[1]);
TRACE("NtUnmapViewOfSection(%lx, %lx)\n",
ProcessHandle, (DWORD)BaseAddress);
@@ -1306,13 +1304,13 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
DWORD ProcessHandle = stack[0]; /* ignored */
- DWORD *BaseAddress = (DWORD *)W32S_APP2WINE(stack[1], W32S_OFFSET);
- DWORD *ViewSize = (DWORD *)W32S_APP2WINE(stack[2], W32S_OFFSET);
- DWORD *unknown = (DWORD *)W32S_APP2WINE(stack[3], W32S_OFFSET);
+ DWORD *BaseAddress = (DWORD *)W32S_APP2WINE(stack[1]);
+ DWORD *ViewSize = (DWORD *)W32S_APP2WINE(stack[2]);
+ DWORD *unknown = (DWORD *)W32S_APP2WINE(stack[3]);
- LPBYTE address = (LPBYTE)(BaseAddress? W32S_APP2WINE(*BaseAddress, W32S_OFFSET) : 0);
+ LPBYTE address = (LPBYTE)(BaseAddress? W32S_APP2WINE(*BaseAddress) : 0);
DWORD size = ViewSize? *ViewSize : 0;
TRACE("NtFlushVirtualMemory(%lx, %lx, %lx, %lx)\n",
@@ -1413,9 +1411,9 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0], W32S_OFFSET);
- LPVOID base = (LPVOID) W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0]);
+ LPVOID base = (LPVOID) W32S_APP2WINE(stack[1]);
DWORD size = stack[2];
DWORD result;
@@ -1447,9 +1445,9 @@
* Output: EAX: NtStatus
*/
{
- DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx, W32S_OFFSET);
- DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0], W32S_OFFSET);
- LPVOID base = (LPVOID) W32S_APP2WINE(stack[1], W32S_OFFSET);
+ DWORD *stack = (DWORD *)W32S_APP2WINE(context->Edx);
+ DWORD *retv = (DWORD *)W32S_APP2WINE(stack[0]);
+ LPVOID base = (LPVOID) W32S_APP2WINE(stack[1]);
DWORD size = stack[2];
DWORD result;
@@ -1487,8 +1485,8 @@
* FIXME: What about other OSes ?
*/
- context->Ecx = W32S_WINE2APP(0x00000000, W32S_OFFSET);
- context->Edx = W32S_WINE2APP(0xbfffffff, W32S_OFFSET);
+ context->Ecx = W32S_WINE2APP(0x00000000);
+ context->Edx = W32S_WINE2APP(0xbfffffff);
break;
@@ -1511,7 +1509,7 @@
};
struct Win32sMemoryInfo *info =
- (struct Win32sMemoryInfo *)W32S_APP2WINE(context->Esi, W32S_OFFSET);
+ (struct Win32sMemoryInfo *)W32S_APP2WINE(context->Esi);
FIXME("KGlobalMemStat(%lx)\n", (DWORD)info);
@@ -1548,7 +1546,7 @@
{
DWORD *stack = PTR_SEG_OFF_TO_LIN(LOWORD(context->Edx),
HIWORD(context->Edx));
- LPVOID base = (LPVOID)W32S_APP2WINE(stack[0], W32S_OFFSET);
+ LPVOID base = (LPVOID)W32S_APP2WINE(stack[0]);
DWORD size = stack[1];
DWORD type = stack[2];
DWORD prot = stack[3];
@@ -1565,8 +1563,8 @@
result = (DWORD)VirtualAlloc(base, size, type, prot);
- if (W32S_WINE2APP(result, W32S_OFFSET))
- context->Edx = W32S_WINE2APP(result, W32S_OFFSET),
+ if (W32S_WINE2APP(result))
+ context->Edx = W32S_WINE2APP(result),
context->Eax = STATUS_SUCCESS;
else
context->Edx = 0,
@@ -1590,7 +1588,7 @@
{
DWORD *stack = PTR_SEG_OFF_TO_LIN(LOWORD(context->Edx),
HIWORD(context->Edx));
- LPVOID base = (LPVOID)W32S_APP2WINE(stack[0], W32S_OFFSET);
+ LPVOID base = (LPVOID)W32S_APP2WINE(stack[0]);
DWORD size = stack[1];
DWORD type = stack[2];
DWORD result;
@@ -1620,7 +1618,7 @@
* Output: NtStatus
*/
{
- DWORD *ptr = (DWORD *)W32S_APP2WINE(context->Ecx, W32S_OFFSET);
+ DWORD *ptr = (DWORD *)W32S_APP2WINE(context->Ecx);
BOOL set = context->Edx;
TRACE("FWorkingSetSize(%lx, %lx)\n", (DWORD)ptr, (DWORD)set);
diff --git a/relay32/relay386.c b/relay32/relay386.c
index 33ba0e6..e302fec 100644
--- a/relay32/relay386.c
+++ b/relay32/relay386.c
@@ -16,7 +16,6 @@
#include "syslevel.h"
#include "main.h"
#include "module.h"
-#include "process.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(relay);
@@ -114,7 +113,7 @@
/* First find the module */
- for (wm = PROCESS_Current()->modref_list; wm; wm = wm->next)
+ for (wm = MODULE_modref_list; wm; wm = wm->next)
{
if (!(wm->flags & WINE_MODREF_INTERNAL)) continue;
base = (char *)wm->module;
diff --git a/scheduler/client.c b/scheduler/client.c
index fc69779..a936f73 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -31,7 +31,6 @@
#include <stdarg.h>
#include "wine/port.h"
-#include "process.h"
#include "thread.h"
#include "server.h"
#include "winerror.h"
diff --git a/scheduler/process.c b/scheduler/process.c
index 1a62176..c3a2aaa 100644
--- a/scheduler/process.c
+++ b/scheduler/process.c
@@ -15,7 +15,6 @@
#include "wine/winbase16.h"
#include "wine/exception.h"
#include "wine/library.h"
-#include "process.h"
#include "drive.h"
#include "main.h"
#include "module.h"
@@ -35,15 +34,80 @@
DECLARE_DEBUG_CHANNEL(relay);
DECLARE_DEBUG_CHANNEL(win32);
+struct _ENVDB;
+
+/* Win32 process database */
+typedef struct _PDB
+{
+ LONG header[2]; /* 00 Kernel object header */
+ HMODULE module; /* 08 Main exe module (NT) */
+ void *event; /* 0c Pointer to an event object (unused) */
+ DWORD exit_code; /* 10 Process exit code */
+ DWORD unknown2; /* 14 Unknown */
+ HANDLE heap; /* 18 Default process heap */
+ HANDLE mem_context; /* 1c Process memory context */
+ DWORD flags; /* 20 Flags */
+ void *pdb16; /* 24 DOS PSP */
+ WORD PSP_sel; /* 28 Selector to DOS PSP */
+ WORD imte; /* 2a IMTE for the process module */
+ WORD threads; /* 2c Number of threads */
+ WORD running_threads; /* 2e Number of running threads */
+ WORD free_lib_count; /* 30 Recursion depth of FreeLibrary calls */
+ WORD ring0_threads; /* 32 Number of ring 0 threads */
+ HANDLE system_heap; /* 34 System heap to allocate handles */
+ HTASK task; /* 38 Win16 task */
+ void *mem_map_files; /* 3c Pointer to mem-mapped files */
+ struct _ENVDB *env_db; /* 40 Environment database */
+ void *handle_table; /* 44 Handle table */
+ struct _PDB *parent; /* 48 Parent process */
+ void *modref_list; /* 4c MODREF list */
+ void *thread_list; /* 50 List of threads */
+ void *debuggee_CB; /* 54 Debuggee context block */
+ void *local_heap_free; /* 58 Head of local heap free list */
+ DWORD unknown4; /* 5c Unknown */
+ CRITICAL_SECTION crit_section; /* 60 Critical section */
+ DWORD unknown5[3]; /* 78 Unknown */
+ void *console; /* 84 Console */
+ DWORD tls_bits[2]; /* 88 TLS in-use bits */
+ DWORD process_dword; /* 90 Unknown */
+ struct _PDB *group; /* 94 Process group */
+ void *exe_modref; /* 98 MODREF for the process EXE */
+ void *top_filter; /* 9c Top exception filter */
+ DWORD priority; /* a0 Priority level */
+ HANDLE heap_list; /* a4 Head of process heap list */
+ void *heap_handles; /* a8 Head of heap handles list */
+ DWORD unknown6; /* ac Unknown */
+ void *console_provider; /* b0 Console provider (??) */
+ WORD env_selector; /* b4 Selector to process environment */
+ WORD error_mode; /* b6 Error mode */
+ HANDLE load_done_evt; /* b8 Event for process loading done */
+ void *UTState; /* bc Head of Univeral Thunk list */
+ DWORD unknown8; /* c0 Unknown (NT) */
+ LCID locale; /* c4 Locale to be queried by GetThreadLocale (NT) */
+} PDB;
+
PDB current_process;
+/* Process flags */
+#define PDB32_DEBUGGED 0x0001 /* Process is being debugged */
+#define PDB32_WIN16_PROC 0x0008 /* Win16 process */
+#define PDB32_DOS_PROC 0x0010 /* Dos process */
+#define PDB32_CONSOLE_PROC 0x0020 /* Console process */
+#define PDB32_FILE_APIS_OEM 0x0040 /* File APIs are OEM */
+#define PDB32_WIN32S_PROC 0x8000 /* Win32s process */
+
static char **main_exe_argv;
static char main_exe_name[MAX_PATH];
static HANDLE main_exe_file = INVALID_HANDLE_VALUE;
-static HMODULE main_module;
unsigned int server_startticks;
+/* memory/environ.c */
+extern struct _ENVDB *ENV_BuildEnvironment(void);
+extern BOOL ENV_BuildCommandLine( char **argv );
+extern STARTUPINFOA current_startupinfo;
+
+
/***********************************************************************
* PROCESS_CallUserSignalProc
*
@@ -178,7 +242,6 @@
current_process.ring0_threads = 1;
current_process.group = ¤t_process;
current_process.priority = 8; /* Normal */
- current_process.env_db = ¤t_envdb;
/* Setup the server connection */
NtCurrentTeb()->socket = CLIENT_InitServer();
@@ -201,9 +264,12 @@
current_startupinfo.dwFlags = req->start_flags;
server_startticks = req->server_start;
current_startupinfo.wShowWindow = req->cmd_show;
- current_envdb.hStdin = current_startupinfo.hStdInput = req->hstdin;
- current_envdb.hStdout = current_startupinfo.hStdOutput = req->hstdout;
- current_envdb.hStderr = current_startupinfo.hStdError = req->hstderr;
+ current_startupinfo.hStdInput = req->hstdin;
+ current_startupinfo.hStdOutput = req->hstdout;
+ current_startupinfo.hStdError = req->hstderr;
+ SetStdHandle( STD_INPUT_HANDLE, current_startupinfo.hStdInput );
+ SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
+ SetStdHandle( STD_ERROR_HANDLE, current_startupinfo.hStdError );
}
}
SERVER_END_REQ;
@@ -214,10 +280,7 @@
current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
/* Copy the parent environment */
- if (!ENV_BuildEnvironment()) return FALSE;
-
- /* Initialize the critical sections */
- InitializeCriticalSection( ¤t_process.crit_section );
+ if (!(current_process.env_db = ENV_BuildEnvironment())) return FALSE;
/* Parse command line arguments */
OPTIONS_ParseOptions( argv );
@@ -227,45 +290,6 @@
/***********************************************************************
- * build_command_line
- *
- * Build the command line of a process from the argv array.
- *
- * Note that it does NOT necessarily include the file name.
- * Sometimes we don't even have any command line options at all.
- */
-static inline char *build_command_line( char **argv )
-{
- int len, quote = 0;
- char *cmdline, *p, **arg;
-
- for (arg = argv, len = 0; *arg; arg++) len += strlen(*arg) + 1;
- if ((argv[0]) && (quote = (strchr( argv[0], ' ' ) != NULL))) len += 2;
- if (!(p = cmdline = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
- arg = argv;
- if (quote)
- {
- *p++ = '\"';
- strcpy( p, *arg );
- p += strlen(p);
- *p++ = '\"';
- *p++ = ' ';
- arg++;
- }
- while (*arg)
- {
- strcpy( p, *arg );
- p += strlen(p);
- *p++ = ' ';
- arg++;
- }
- if (p > cmdline) p--; /* remove last space */
- *p = 0;
- return cmdline;
-}
-
-
-/***********************************************************************
* start_process
*
* Startup routine of a new process. Runs on the new process stack.
@@ -277,10 +301,10 @@
WINE_MODREF *wm;
/* build command line */
- if (!(current_envdb.cmd_line = build_command_line( main_exe_argv ))) goto error;
+ if (!ENV_BuildCommandLine( main_exe_argv )) goto error;
/* create 32-bit module for main exe */
- if (!(main_module = BUILTIN32_LoadExeModule( main_module ))) goto error;
+ if (!(current_process.module = BUILTIN32_LoadExeModule( current_process.module ))) goto error;
/* use original argv[0] as name for the main module */
if (!main_exe_name[0])
@@ -290,16 +314,16 @@
}
/* Retrieve entry point address */
- entry = (LPTHREAD_START_ROUTINE)((char*)main_module +
- PE_HEADER(main_module)->OptionalHeader.AddressOfEntryPoint);
- console_app = (PE_HEADER(main_module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
+ entry = (LPTHREAD_START_ROUTINE)((char*)current_process.module +
+ PE_HEADER(current_process.module)->OptionalHeader.AddressOfEntryPoint);
+ console_app = (PE_HEADER(current_process.module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
if (console_app) current_process.flags |= PDB32_CONSOLE_PROC;
/* Signal the parent process to continue */
SERVER_START_REQ
{
struct init_process_done_request *req = server_alloc_req( sizeof(*req), 0 );
- req->module = (void *)main_module;
+ req->module = (void *)current_process.module;
req->entry = entry;
req->name = main_exe_name;
req->gui = !console_app;
@@ -314,14 +338,14 @@
if (!SIGNAL_Init()) goto error;
/* create the main modref and load dependencies */
- if (!(wm = PE_CreateModule( main_module, main_exe_name, 0, main_exe_file, FALSE )))
+ if (!(wm = PE_CreateModule( current_process.module, main_exe_name, 0, main_exe_file, FALSE )))
goto error;
wm->refCount++;
- EnterCriticalSection( ¤t_process.crit_section );
+ RtlAcquirePebLock();
PE_InitTls();
- MODULE_DllProcessAttach( current_process.exe_modref, (LPVOID)1 );
- LeaveCriticalSection( ¤t_process.crit_section );
+ MODULE_DllProcessAttach( NULL, (LPVOID)1 );
+ RtlReleasePebLock();
/* Get pointers to USER routines called by KERNEL */
THUNK_InitCallout();
@@ -344,7 +368,7 @@
/* Call UserSignalProc ( USIG_PROCESS_RUNNING ... ) only for non-GUI win32 apps */
if (console_app) PROCESS_CallUserSignalProc( USIG_PROCESS_RUNNING, 0 );
- TRACE_(relay)( "Starting Win32 process %s (entryproc=%p)\n", current_process.exe_modref->filename, entry );
+ TRACE_(relay)( "Starting Win32 process %s (entryproc=%p)\n", main_exe_name, entry );
if (debugged) DbgBreakPoint();
/* FIXME: should use _PEB as parameter for NT 3.5 programs !
* Dunno about other OSs */
@@ -443,11 +467,11 @@
}
/* first try Win32 format; this will fail if the file is not a PE binary */
- if ((main_module = PE_LoadImage( main_exe_file, main_exe_name, 0 )))
+ if ((current_process.module = PE_LoadImage( main_exe_file, main_exe_name, 0 )))
{
- if (PE_HEADER(main_module)->FileHeader.Characteristics & IMAGE_FILE_DLL)
+ if (PE_HEADER(current_process.module)->FileHeader.Characteristics & IMAGE_FILE_DLL)
ExitProcess( ERROR_BAD_EXE_FORMAT );
- stack_size = PE_HEADER(main_module)->OptionalHeader.SizeOfStackReserve;
+ stack_size = PE_HEADER(current_process.module)->OptionalHeader.SizeOfStackReserve;
goto found;
}
@@ -1367,6 +1391,115 @@
return old;
}
+
+/**********************************************************************
+ * TlsAlloc [KERNEL32.530] Allocates a TLS index.
+ *
+ * Allocates a thread local storage index
+ *
+ * RETURNS
+ * Success: TLS Index
+ * Failure: 0xFFFFFFFF
+ */
+DWORD WINAPI TlsAlloc( void )
+{
+ DWORD i, mask, ret = 0;
+ DWORD *bits = current_process.tls_bits;
+ RtlAcquirePebLock();
+ if (*bits == 0xffffffff)
+ {
+ bits++;
+ ret = 32;
+ if (*bits == 0xffffffff)
+ {
+ RtlReleasePebLock();
+ SetLastError( ERROR_NO_MORE_ITEMS );
+ return 0xffffffff;
+ }
+ }
+ for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
+ *bits |= mask;
+ RtlReleasePebLock();
+ return ret + i;
+}
+
+
+/**********************************************************************
+ * TlsFree [KERNEL32.531] Releases a TLS index.
+ *
+ * Releases a thread local storage index, making it available for reuse
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ */
+BOOL WINAPI TlsFree(
+ DWORD index) /* [in] TLS Index to free */
+{
+ DWORD mask = (1 << (index & 31));
+ DWORD *bits = current_process.tls_bits;
+ if (index >= 64)
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return FALSE;
+ }
+ if (index >= 32) bits++;
+ RtlAcquirePebLock();
+ if (!(*bits & mask)) /* already free? */
+ {
+ RtlReleasePebLock();
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return FALSE;
+ }
+ *bits &= ~mask;
+ NtCurrentTeb()->tls_array[index] = 0;
+ /* FIXME: should zero all other thread values */
+ RtlReleasePebLock();
+ return TRUE;
+}
+
+
+/**********************************************************************
+ * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
+ *
+ * RETURNS
+ * Success: Value stored in calling thread's TLS slot for index
+ * Failure: 0 and GetLastError returns NO_ERROR
+ */
+LPVOID WINAPI TlsGetValue(
+ DWORD index) /* [in] TLS index to retrieve value for */
+{
+ if (index >= 64)
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return NULL;
+ }
+ SetLastError( ERROR_SUCCESS );
+ return NtCurrentTeb()->tls_array[index];
+}
+
+
+/**********************************************************************
+ * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
+ *
+ * RETURNS
+ * Success: TRUE
+ * Failure: FALSE
+ */
+BOOL WINAPI TlsSetValue(
+ DWORD index, /* [in] TLS index to set value for */
+ LPVOID value) /* [in] Value to be stored */
+{
+ if (index >= 64)
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return FALSE;
+ }
+ NtCurrentTeb()->tls_array[index] = value;
+ return TRUE;
+}
+
+
/***********************************************************************
* GetCurrentProcess (KERNEL32.198)
*/
diff --git a/scheduler/thread.c b/scheduler/thread.c
index 603101f..cd06bbd 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -15,7 +15,6 @@
#include <unistd.h>
#include "wine/winbase16.h"
#include "thread.h"
-#include "process.h"
#include "task.h"
#include "module.h"
#include "global.h"
@@ -35,6 +34,8 @@
/* TEB of the initial thread */
static TEB initial_teb;
+extern struct _PDB current_process;
+
/***********************************************************************
* THREAD_IsWin16
*/
@@ -239,8 +240,8 @@
if ((teb = THREAD_InitStack( NULL, stack_size, alloc_stack16 )))
{
- teb->tibflags = (current_process.flags & PDB32_WIN16_PROC) ? 0 : TEBF_WIN32;
- teb->process = ¤t_process;
+ teb->tibflags = TEBF_WIN32;
+ teb->process = NtCurrentTeb()->process;
teb->socket = fd;
fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */
TRACE("(%p) succeeded\n", teb);
@@ -304,7 +305,6 @@
close( socket );
return 0;
}
- teb->tibflags |= TEBF_WIN32;
teb->entry_point = start;
teb->entry_arg = param;
teb->startup = THREAD_Start;
@@ -379,115 +379,6 @@
}
-/**********************************************************************
- * TlsAlloc [KERNEL32.530] Allocates a TLS index.
- *
- * Allocates a thread local storage index
- *
- * RETURNS
- * Success: TLS Index
- * Failure: 0xFFFFFFFF
- */
-DWORD WINAPI TlsAlloc( void )
-{
- DWORD i, mask, ret = 0;
- DWORD *bits = current_process.tls_bits;
- EnterCriticalSection( ¤t_process.crit_section );
- if (*bits == 0xffffffff)
- {
- bits++;
- ret = 32;
- if (*bits == 0xffffffff)
- {
- LeaveCriticalSection( ¤t_process.crit_section );
- SetLastError( ERROR_NO_MORE_ITEMS );
- return 0xffffffff;
- }
- }
- for (i = 0, mask = 1; i < 32; i++, mask <<= 1) if (!(*bits & mask)) break;
- *bits |= mask;
- LeaveCriticalSection( ¤t_process.crit_section );
- return ret + i;
-}
-
-
-/**********************************************************************
- * TlsFree [KERNEL32.531] Releases a TLS index.
- *
- * Releases a thread local storage index, making it available for reuse
- *
- * RETURNS
- * Success: TRUE
- * Failure: FALSE
- */
-BOOL WINAPI TlsFree(
- DWORD index) /* [in] TLS Index to free */
-{
- DWORD mask;
- DWORD *bits = current_process.tls_bits;
- if (index >= 64)
- {
- SetLastError( ERROR_INVALID_PARAMETER );
- return FALSE;
- }
- EnterCriticalSection( ¤t_process.crit_section );
- if (index >= 32) bits++;
- mask = (1 << (index & 31));
- if (!(*bits & mask)) /* already free? */
- {
- LeaveCriticalSection( ¤t_process.crit_section );
- SetLastError( ERROR_INVALID_PARAMETER );
- return FALSE;
- }
- *bits &= ~mask;
- NtCurrentTeb()->tls_array[index] = 0;
- /* FIXME: should zero all other thread values */
- LeaveCriticalSection( ¤t_process.crit_section );
- return TRUE;
-}
-
-
-/**********************************************************************
- * TlsGetValue [KERNEL32.532] Gets value in a thread's TLS slot
- *
- * RETURNS
- * Success: Value stored in calling thread's TLS slot for index
- * Failure: 0 and GetLastError returns NO_ERROR
- */
-LPVOID WINAPI TlsGetValue(
- DWORD index) /* [in] TLS index to retrieve value for */
-{
- if (index >= 64)
- {
- SetLastError( ERROR_INVALID_PARAMETER );
- return NULL;
- }
- SetLastError( ERROR_SUCCESS );
- return NtCurrentTeb()->tls_array[index];
-}
-
-
-/**********************************************************************
- * TlsSetValue [KERNEL32.533] Stores a value in the thread's TLS slot.
- *
- * RETURNS
- * Success: TRUE
- * Failure: FALSE
- */
-BOOL WINAPI TlsSetValue(
- DWORD index, /* [in] TLS index to set value for */
- LPVOID value) /* [in] Value to be stored */
-{
- if (index >= 64)
- {
- SetLastError( ERROR_INVALID_PARAMETER );
- return FALSE;
- }
- NtCurrentTeb()->tls_array[index] = value;
- return TRUE;
-}
-
-
/***********************************************************************
* SetThreadContext [KERNEL32.670] Sets context of thread.
*
diff --git a/win32/console.c b/win32/console.c
index b862f2a..a50b384 100644
--- a/win32/console.c
+++ b/win32/console.c
@@ -43,7 +43,6 @@
#include "wine/keyboard16.h"
#include "thread.h"
#include "file.h"
-#include "process.h"
#include "winerror.h"
#include "wincon.h"
#include "heap.h"
diff --git a/win32/device.c b/win32/device.c
index fd32d9c..4f5e1be 100644
--- a/win32/device.c
+++ b/win32/device.c
@@ -27,7 +27,6 @@
#include "winreg.h"
#include "winerror.h"
#include "file.h"
-#include "process.h"
#include "heap.h"
#include "winioctl.h"
#include "winnt.h"
diff --git a/win32/except.c b/win32/except.c
index 49c7205..d606dd7 100644
--- a/win32/except.c
+++ b/win32/except.c
@@ -29,7 +29,6 @@
#include "wine/exception.h"
#include "selectors.h"
#include "callback.h"
-#include "process.h"
#include "thread.h"
#include "stackframe.h"
#include "server.h"
@@ -37,6 +36,8 @@
DEFAULT_DEBUG_CHANNEL(seh);
+static PTOP_LEVEL_EXCEPTION_FILTER top_filter;
+
/*******************************************************************
* RaiseException (KERNEL32.418)
@@ -143,7 +144,6 @@
*/
DWORD WINAPI UnhandledExceptionFilter(PEXCEPTION_POINTERS epointers)
{
- PDB* pdb = PROCESS_Current();
char format[256];
char buffer[256];
HKEY hDbgConf;
@@ -179,9 +179,9 @@
FIXME("Unsupported yet debug continue value %d (please report)\n", status);
}
- if (pdb->top_filter)
+ if (top_filter)
{
- DWORD ret = pdb->top_filter( epointers );
+ DWORD ret = top_filter( epointers );
if (ret != EXCEPTION_CONTINUE_SEARCH) return ret;
}
@@ -265,9 +265,8 @@
LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilter(
LPTOP_LEVEL_EXCEPTION_FILTER filter )
{
- PDB *pdb = PROCESS_Current();
- LPTOP_LEVEL_EXCEPTION_FILTER old = pdb->top_filter;
- pdb->top_filter = filter;
+ LPTOP_LEVEL_EXCEPTION_FILTER old = top_filter;
+ top_filter = filter;
return old;
}
diff --git a/win32/file.c b/win32/file.c
index d0902b0..4e56ee7 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -23,7 +23,6 @@
#include "winbase.h"
#include "winerror.h"
#include "file.h"
-#include "process.h"
#include "heap.h"
#include "debugtools.h"
diff --git a/windows/user.c b/windows/user.c
index 4229299..6febd94 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -24,7 +24,7 @@
#include "sysmetrics.h"
#include "callback.h"
#include "local.h"
-#include "process.h"
+#include "module.h"
#include "debugtools.h"
DECLARE_DEBUG_CHANNEL(hook);