Make PDB, ENVDB and STARTUPINFO global variables.

Added 'module' field in PDB, and removed Wine-specific fields.
This commit is contained in:
Alexandre Julliard 2000-08-09 22:33:42 +00:00
parent 46733de12b
commit 52900c818f
7 changed files with 218 additions and 237 deletions

View File

@ -43,7 +43,7 @@ typedef struct
typedef struct _PDB
{
LONG header[2]; /* 00 Kernel object header */
DWORD unknown1; /* 08 Unknown */
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 */
@ -52,7 +52,7 @@ typedef struct _PDB
DWORD flags; /* 20 Flags */
void *pdb16; /* 24 DOS PSP */
WORD PSP_sel; /* 28 Selector to DOS PSP */
WORD module; /* 2a IMTE for the process module */
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 */
@ -87,10 +87,6 @@ typedef struct _PDB
struct _UTINFO *UTState; /* bc Head of Univeral Thunk list */
DWORD unknown8; /* c0 Unknown (NT) */
LCID locale; /* c4 Locale to be queried by GetThreadLocale (NT) */
/* The following are Wine-specific fields */
HANDLE *dos_handles; /* Handles mapping DOS -> Win32 */
WORD winver; /* Windows version figured out by VERSION_GetVersion */
struct _SERVICETABLE *service_table; /* Service table for service thread */
} PDB;
/* Process flags */
@ -149,7 +145,6 @@ 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 PDB *PROCESS_IdToPDB( DWORD id );
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,
@ -157,9 +152,13 @@ extern BOOL PROCESS_Create( HFILE hFile, LPCSTR filename, LPSTR cmd_line, LPCSTR
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 NtCurrentTeb()->process;
return &current_process;
}
#endif /* __WINE_PROCESS_H */

View File

@ -863,7 +863,10 @@ WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename, DWORD flags,
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 */

View File

@ -15,7 +15,6 @@
#include "file.h"
#include "global.h"
#include "instance.h"
#include "message.h"
#include "miscemu.h"
#include "module.h"
#include "neexe.h"
@ -224,7 +223,6 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline,
HTASK16 hTask;
TDB *pTask;
char name[10];
PDB *pdb32 = PROCESS_Current();
/* Allocate the task structure */
@ -270,7 +268,7 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline,
/* Allocate a selector for the PDB */
pTask->hPDB = GLOBAL_CreateBlock( GMEM_FIXED, &pTask->pdb, sizeof(PDB16),
pModule->self, FALSE, FALSE, FALSE, NULL );
pModule->self, FALSE, FALSE, FALSE );
/* Fill the PDB */
@ -286,17 +284,17 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline,
(int)&((PDB16 *)0)->fileHandles );
pTask->pdb.hFileHandles = 0;
memset( pTask->pdb.fileHandles, 0xff, sizeof(pTask->pdb.fileHandles) );
pTask->pdb.environment = pdb32->env_db->env_sel;
pTask->pdb.environment = current_envdb.env_sel;
pTask->pdb.nbFiles = 20;
/* Fill the command line */
if (!cmdline)
{
cmdline = pdb32->env_db->cmd_line;
cmdline = current_envdb.cmd_line;
/* remove the first word (program name) */
if (*cmdline == '"')
if (!(cmdline = strchr( cmdline+1, '"' ))) cmdline = pdb32->env_db->cmd_line;
if (!(cmdline = strchr( cmdline+1, '"' ))) cmdline = current_envdb.cmd_line;
while (*cmdline && (*cmdline != ' ') && (*cmdline != '\t')) cmdline++;
while ((*cmdline == ' ') || (*cmdline == '\t')) cmdline++;
len = strlen(cmdline);
@ -316,7 +314,7 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline,
pTask->hCSAlias = GLOBAL_CreateBlock( GMEM_FIXED, (void *)pTask,
sizeof(TDB), pTask->hPDB, TRUE,
FALSE, FALSE, NULL );
FALSE, FALSE );
/* Set the owner of the environment block */

View File

@ -41,6 +41,49 @@ static const char ENV_program_name[] = "C:\\WINDOWS\\SYSTEM\\KRNL386.EXE";
PUT_WORD( (p) + 1, 1 ); \
strcpy( (p) + 3, ENV_program_name );
STARTUPINFOA current_startupinfo =
{
sizeof(STARTUPINFOA), /* cb */
0, /* lpReserved */
0, /* lpDesktop */
0, /* lpTitle */
0, /* dwX */
0, /* dwY */
0, /* dwXSize */
0, /* dwYSize */
0, /* dwXCountChars */
0, /* dwYCountChars */
0, /* dwFillAttribute */
0, /* dwFlags */
0, /* wShowWindow */
0, /* cbReserved2 */
0, /* lpReserved2 */
0, /* hStdInput */
0, /* hStdOutput */
0 /* hStdError */
};
ENVDB current_envdb =
{
0, /* environ */
0, /* unknown1 */
0, /* cmd_line */
0, /* cur_dir */
&current_startupinfo, /* startup_info */
0, /* hStdin */
0, /* hStdout */
0, /* hStderr */
0, /* unknown2 */
0, /* inherit_console */
0, /* break_type */
0, /* break_sem */
0, /* break_event */
0, /* break_thread */
0, /* break_handlers */
CRITICAL_SECTION_INIT, /* section */
0, /* cmd_lineW */
0 /* env_sel */
};
/***********************************************************************
* ENV_FindVariable
@ -79,9 +122,8 @@ BOOL ENV_BuildEnvironment(void)
/* Now allocate the environment */
if (!(p = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
PROCESS_Current()->env_db->environ = p;
PROCESS_Current()->env_db->env_sel = SELECTOR_AllocBlock( p, 0x10000, SEGMENT_DATA,
FALSE, FALSE );
current_envdb.environ = p;
current_envdb.env_sel = SELECTOR_AllocBlock( p, 0x10000, SEGMENT_DATA, FALSE, FALSE );
/* And fill it with the Unix environment */
@ -103,7 +145,7 @@ BOOL ENV_BuildEnvironment(void)
*/
LPSTR WINAPI GetCommandLineA(void)
{
return PROCESS_Current()->env_db->cmd_line;
return current_envdb.cmd_line;
}
/***********************************************************************
@ -111,13 +153,12 @@ LPSTR WINAPI GetCommandLineA(void)
*/
LPWSTR WINAPI GetCommandLineW(void)
{
PDB *pdb = PROCESS_Current();
EnterCriticalSection( &pdb->env_db->section );
if (!pdb->env_db->cmd_lineW)
pdb->env_db->cmd_lineW = HEAP_strdupAtoW( GetProcessHeap(), 0,
pdb->env_db->cmd_line );
LeaveCriticalSection( &pdb->env_db->section );
return pdb->env_db->cmd_lineW;
EnterCriticalSection( &current_envdb.section );
if (!current_envdb.cmd_lineW)
current_envdb.cmd_lineW = HEAP_strdupAtoW( GetProcessHeap(), 0,
current_envdb.cmd_line );
LeaveCriticalSection( &current_envdb.section );
return current_envdb.cmd_lineW;
}
@ -126,8 +167,7 @@ LPWSTR WINAPI GetCommandLineW(void)
*/
LPSTR WINAPI GetEnvironmentStringsA(void)
{
PDB *pdb = PROCESS_Current();
return pdb->env_db->environ;
return current_envdb.environ;
}
@ -138,17 +178,16 @@ LPWSTR WINAPI GetEnvironmentStringsW(void)
{
INT size;
LPWSTR ret;
PDB *pdb = PROCESS_Current();
EnterCriticalSection( &pdb->env_db->section );
size = HeapSize( GetProcessHeap(), 0, pdb->env_db->environ );
EnterCriticalSection( &current_envdb.section );
size = HeapSize( GetProcessHeap(), 0, current_envdb.environ );
if ((ret = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) )) != NULL)
{
LPSTR pA = pdb->env_db->environ;
LPSTR pA = current_envdb.environ;
LPWSTR pW = ret;
while (size--) *pW++ = (WCHAR)(BYTE)*pA++;
}
LeaveCriticalSection( &pdb->env_db->section );
LeaveCriticalSection( &current_envdb.section );
return ret;
}
@ -158,8 +197,7 @@ LPWSTR WINAPI GetEnvironmentStringsW(void)
*/
BOOL WINAPI FreeEnvironmentStringsA( LPSTR ptr )
{
PDB *pdb = PROCESS_Current();
if (ptr != pdb->env_db->environ)
if (ptr != current_envdb.environ)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
@ -184,15 +222,14 @@ DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size )
{
LPCSTR p;
INT ret = 0;
PDB *pdb = PROCESS_Current();
if (!name || !*name)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
EnterCriticalSection( &pdb->env_db->section );
if ((p = ENV_FindVariable( pdb->env_db->environ, name, strlen(name) )))
EnterCriticalSection( &current_envdb.section );
if ((p = ENV_FindVariable( current_envdb.environ, name, strlen(name) )))
{
ret = strlen(p);
if (size <= ret)
@ -204,7 +241,7 @@ DWORD WINAPI GetEnvironmentVariableA( LPCSTR name, LPSTR value, DWORD size )
}
else if (value) strcpy( value, p );
}
LeaveCriticalSection( &pdb->env_db->section );
LeaveCriticalSection( &current_envdb.section );
return ret; /* FIXME: SetLastError */
}
@ -235,10 +272,9 @@ BOOL WINAPI SetEnvironmentVariableA( LPCSTR name, LPCSTR value )
INT old_size, len, res;
LPSTR p, env, new_env;
BOOL ret = FALSE;
PDB *pdb = PROCESS_Current();
EnterCriticalSection( &pdb->env_db->section );
env = p = pdb->env_db->environ;
EnterCriticalSection( &current_envdb.section );
env = p = current_envdb.environ;
/* Find a place to insert the string */
@ -263,8 +299,8 @@ BOOL WINAPI SetEnvironmentVariableA( LPCSTR name, LPCSTR value )
}
if (!(new_env = HeapReAlloc( GetProcessHeap(), 0, env, old_size + len )))
goto done;
if (pdb->env_db->env_sel)
SELECTOR_MoveBlock( pdb->env_db->env_sel, new_env );
if (current_envdb.env_sel)
SELECTOR_MoveBlock( current_envdb.env_sel, new_env );
p = new_env + (p - env);
if (len > 0) memmove( p + len, p, old_size - (p - new_env) );
@ -276,11 +312,11 @@ BOOL WINAPI SetEnvironmentVariableA( LPCSTR name, LPCSTR value )
strcat( p, "=" );
strcat( p, value );
}
pdb->env_db->environ = new_env;
current_envdb.environ = new_env;
ret = TRUE;
done:
LeaveCriticalSection( &pdb->env_db->section );
LeaveCriticalSection( &current_envdb.section );
return ret;
}
@ -308,10 +344,9 @@ DWORD WINAPI ExpandEnvironmentStringsA( LPCSTR src, LPSTR dst, DWORD count )
{
DWORD len, total_size = 1; /* 1 for terminating '\0' */
LPCSTR p, var;
PDB *pdb = PROCESS_Current();
if (!count) dst = NULL;
EnterCriticalSection( &pdb->env_db->section );
EnterCriticalSection( &current_envdb.section );
while (*src)
{
@ -327,7 +362,7 @@ DWORD WINAPI ExpandEnvironmentStringsA( LPCSTR src, LPSTR dst, DWORD count )
if ((p = strchr( src + 1, '%' )))
{
len = p - src - 1; /* Length of the variable name */
if ((var = ENV_FindVariable( pdb->env_db->environ,
if ((var = ENV_FindVariable( current_envdb.environ,
src + 1, len )))
{
src += len + 2; /* Skip the variable name */
@ -356,7 +391,7 @@ DWORD WINAPI ExpandEnvironmentStringsA( LPCSTR src, LPSTR dst, DWORD count )
count -= len;
}
}
LeaveCriticalSection( &pdb->env_db->section );
LeaveCriticalSection( &current_envdb.section );
/* Null-terminate the string */
if (dst)
@ -385,3 +420,68 @@ DWORD WINAPI ExpandEnvironmentStringsW( LPCWSTR src, LPWSTR dst, DWORD len )
return ret;
}
/***********************************************************************
* GetStdHandle (KERNEL32.276)
*/
HANDLE WINAPI GetStdHandle( DWORD std_handle )
{
switch(std_handle)
{
case STD_INPUT_HANDLE: return current_envdb.hStdin;
case STD_OUTPUT_HANDLE: return current_envdb.hStdout;
case STD_ERROR_HANDLE: return current_envdb.hStderr;
}
SetLastError( ERROR_INVALID_PARAMETER );
return INVALID_HANDLE_VALUE;
}
/***********************************************************************
* SetStdHandle (KERNEL32.506)
*/
BOOL WINAPI SetStdHandle( DWORD std_handle, HANDLE handle )
{
switch(std_handle)
{
case STD_INPUT_HANDLE: current_envdb.hStdin = handle; return TRUE;
case STD_OUTPUT_HANDLE: current_envdb.hStdout = handle; return TRUE;
case STD_ERROR_HANDLE: current_envdb.hStderr = handle; return TRUE;
}
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
/***********************************************************************
* GetStartupInfoA (KERNEL32.273)
*/
VOID WINAPI GetStartupInfoA( LPSTARTUPINFOA info )
{
*info = current_startupinfo;
}
/***********************************************************************
* GetStartupInfoW (KERNEL32.274)
*/
VOID WINAPI GetStartupInfoW( LPSTARTUPINFOW info )
{
info->cb = sizeof(STARTUPINFOW);
info->dwX = current_startupinfo.dwX;
info->dwY = current_startupinfo.dwY;
info->dwXSize = current_startupinfo.dwXSize;
info->dwXCountChars = current_startupinfo.dwXCountChars;
info->dwYCountChars = current_startupinfo.dwYCountChars;
info->dwFillAttribute = current_startupinfo.dwFillAttribute;
info->dwFlags = current_startupinfo.dwFlags;
info->wShowWindow = current_startupinfo.wShowWindow;
info->cbReserved2 = current_startupinfo.cbReserved2;
info->lpReserved2 = current_startupinfo.lpReserved2;
info->hStdInput = current_startupinfo.hStdInput;
info->hStdOutput = current_startupinfo.hStdOutput;
info->hStdError = current_startupinfo.hStdError;
info->lpReserved = HEAP_strdupAtoW (GetProcessHeap(), 0, current_startupinfo.lpReserved );
info->lpDesktop = HEAP_strdupAtoW (GetProcessHeap(), 0, current_startupinfo.lpDesktop );
info->lpTitle = HEAP_strdupAtoW (GetProcessHeap(), 0, current_startupinfo.lpTitle );
}

View File

@ -36,26 +36,13 @@ DEFAULT_DEBUG_CHANNEL(process);
DECLARE_DEBUG_CHANNEL(relay);
DECLARE_DEBUG_CHANNEL(win32);
PDB current_process;
static ENVDB initial_envdb;
static STARTUPINFOA initial_startup;
static char **main_exe_argv;
static char *main_exe_name;
static HFILE main_exe_file = -1;
/***********************************************************************
* PROCESS_IdToPDB
*
* Convert a process id to a PDB, making sure it is valid.
*/
PDB *PROCESS_IdToPDB( DWORD pid )
{
if (!pid || pid == GetCurrentProcessId()) return PROCESS_Current();
return NULL;
}
/***********************************************************************
* PROCESS_CallUserSignalProc
*
@ -130,8 +117,8 @@ PDB *PROCESS_IdToPDB( DWORD pid )
*/
void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
{
DWORD flags = PROCESS_Current()->flags;
DWORD startup_flags = PROCESS_Current()->env_db->startup_info->dwFlags;
DWORD flags = current_process.flags;
DWORD startup_flags = current_startupinfo.dwFlags;
DWORD dwFlags = 0;
/* Determine dwFlags */
@ -178,21 +165,18 @@ void PROCESS_CallUserSignalProc( UINT uCode, HMODULE hModule )
static BOOL process_init( char *argv[] )
{
struct init_process_request *req;
PDB *pdb = PROCESS_Current();
/* store the program name */
argv0 = argv[0];
/* Fill the initial process structure */
pdb->exit_code = STILL_ACTIVE;
pdb->threads = 1;
pdb->running_threads = 1;
pdb->ring0_threads = 1;
pdb->env_db = &initial_envdb;
pdb->group = pdb;
pdb->priority = 8; /* Normal */
pdb->winver = 0xffff; /* to be determined */
initial_envdb.startup_info = &initial_startup;
current_process.exit_code = STILL_ACTIVE;
current_process.threads = 1;
current_process.running_threads = 1;
current_process.ring0_threads = 1;
current_process.group = &current_process;
current_process.priority = 8; /* Normal */
current_process.env_db = &current_envdb;
/* Setup the server connection */
NtCurrentTeb()->socket = CLIENT_InitServer();
@ -206,18 +190,18 @@ static BOOL process_init( char *argv[] )
if (server_call( REQ_INIT_PROCESS )) return FALSE;
main_exe_file = req->exe_file;
if (req->filename[0]) main_exe_name = strdup( req->filename );
initial_startup.dwFlags = req->start_flags;
initial_startup.wShowWindow = req->cmd_show;
initial_envdb.hStdin = initial_startup.hStdInput = req->hstdin;
initial_envdb.hStdout = initial_startup.hStdOutput = req->hstdout;
initial_envdb.hStderr = initial_startup.hStdError = req->hstderr;
current_startupinfo.dwFlags = req->start_flags;
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;
/* Remember TEB selector of initial process for emergency use */
SYSLEVEL_EmergencyTeb = NtCurrentTeb()->teb_sel;
/* Create the system and process heaps */
if (!HEAP_CreateSystemHeap()) return FALSE;
pdb->heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
/* Copy the parent environment */
if (!ENV_BuildEnvironment()) return FALSE;
@ -226,8 +210,7 @@ static BOOL process_init( char *argv[] )
if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return FALSE;
/* Initialize the critical sections */
InitializeCriticalSection( &pdb->crit_section );
InitializeCriticalSection( &initial_envdb.section );
InitializeCriticalSection( &current_process.crit_section );
/* Initialize syslevel handling */
SYSLEVEL_Init();
@ -316,25 +299,24 @@ static void start_process(void)
int debugged, console_app;
UINT cmdShow = SW_SHOWNORMAL;
LPTHREAD_START_ROUTINE entry;
PDB *pdb = PROCESS_Current();
HMODULE module = pdb->exe_modref->module;
HMODULE module = current_process.exe_modref->module;
/* Increment EXE refcount */
pdb->exe_modref->refCount++;
current_process.exe_modref->refCount++;
/* build command line */
if (!(pdb->env_db->cmd_line = build_command_line( main_exe_argv ))) goto error;
if (!(current_envdb.cmd_line = build_command_line( main_exe_argv ))) goto error;
/* Retrieve entry point address */
entry = (LPTHREAD_START_ROUTINE)((char*)module + PE_HEADER(module)->OptionalHeader.AddressOfEntryPoint);
console_app = (PE_HEADER(module)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
if (console_app) pdb->flags |= PDB32_CONSOLE_PROC;
if (console_app) current_process.flags |= PDB32_CONSOLE_PROC;
/* Signal the parent process to continue */
req->module = (void *)module;
req->entry = entry;
req->name = &pdb->exe_modref->filename;
req->name = &current_process.exe_modref->filename;
req->gui = !console_app;
server_call( REQ_INIT_PROCESS_DONE );
debugged = req->debugged;
@ -348,8 +330,8 @@ static void start_process(void)
if (!LoadLibraryA( "KERNEL32" )) goto error;
/* Create 16-bit task */
if (pdb->env_db->startup_info->dwFlags & STARTF_USESHOWWINDOW)
cmdShow = pdb->env_db->startup_info->wShowWindow;
if (current_startupinfo.dwFlags & STARTF_USESHOWWINDOW)
cmdShow = current_startupinfo.wShowWindow;
if (!TASK_Create( (NE_MODULE *)GlobalLock16( MapHModuleLS(module) ), cmdShow,
NtCurrentTeb(), NULL, 0 ))
goto error;
@ -357,10 +339,10 @@ static void start_process(void)
/* Load the system dlls */
if (!load_system_dlls()) goto error;
EnterCriticalSection( &pdb->crit_section );
EnterCriticalSection( &current_process.crit_section );
PE_InitTls();
MODULE_DllProcessAttach( pdb->exe_modref, (LPVOID)1 );
LeaveCriticalSection( &pdb->crit_section );
MODULE_DllProcessAttach( current_process.exe_modref, (LPVOID)1 );
LeaveCriticalSection( &current_process.crit_section );
/* Call UserSignalProc ( USIG_PROCESS_RUNNING ... ) only for non-GUI win32 apps */
if (console_app) PROCESS_CallUserSignalProc( USIG_PROCESS_RUNNING, 0 );
@ -479,7 +461,7 @@ void PROCESS_InitWine( int argc, char *argv[] )
/* create 32-bit module for main exe */
if (!(main_module = BUILTIN32_LoadExeModule())) goto error;
NtCurrentTeb()->tibflags &= ~TEBF_WIN32;
PROCESS_Current()->flags |= PDB32_WIN16_PROC;
current_process.flags |= PDB32_WIN16_PROC;
SYSLEVEL_EnterWin16Lock();
PROCESS_Start( main_module, -1, NULL );
}
@ -873,12 +855,12 @@ BOOL WINAPI TerminateProcess( HANDLE handle, DWORD exit_code )
*/
DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
{
PDB *process = PROCESS_IdToPDB( dwProcessID );
TDB *pTask;
DWORD x, y;
TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
if ( !process )
if (dwProcessID && dwProcessID != GetCurrentProcessId())
{
ERR("%d: process %lx not accessible\n", offset, dwProcessID);
return 0;
@ -891,7 +873,7 @@ DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
return pTask? pTask->compat_flags : 0;
case GPD_LOAD_DONE_EVENT:
return process->load_done_evt;
return current_process.load_done_evt;
case GPD_HINSTANCE16:
pTask = (TDB *)GlobalLock16( GetCurrentTask() );
@ -902,46 +884,45 @@ DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
return pTask? pTask->version : 0;
case GPD_THDB:
if ( process != PROCESS_Current() ) return 0;
return (DWORD)NtCurrentTeb() - 0x10 /* FIXME */;
case GPD_PDB:
return (DWORD)process;
return (DWORD)&current_process;
case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
return process->env_db->startup_info->hStdOutput;
return current_startupinfo.hStdOutput;
case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
return process->env_db->startup_info->hStdInput;
return current_startupinfo.hStdInput;
case GPD_STARTF_SHOWWINDOW:
return process->env_db->startup_info->wShowWindow;
return current_startupinfo.wShowWindow;
case GPD_STARTF_SIZE:
x = process->env_db->startup_info->dwXSize;
x = current_startupinfo.dwXSize;
if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
y = process->env_db->startup_info->dwYSize;
y = current_startupinfo.dwYSize;
if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
return MAKELONG( x, y );
case GPD_STARTF_POSITION:
x = process->env_db->startup_info->dwX;
x = current_startupinfo.dwX;
if ( x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
y = process->env_db->startup_info->dwY;
y = current_startupinfo.dwY;
if ( y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
return MAKELONG( x, y );
case GPD_STARTF_FLAGS:
return process->env_db->startup_info->dwFlags;
return current_startupinfo.dwFlags;
case GPD_PARENT:
return 0;
case GPD_FLAGS:
return process->flags;
return current_process.flags;
case GPD_USERDATA:
return process->process_dword;
return current_process.process_dword;
default:
ERR_(win32)("Unknown offset %d\n", offset );
@ -955,10 +936,9 @@ DWORD WINAPI GetProcessDword( DWORD dwProcessID, INT offset )
*/
void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
{
PDB *process = PROCESS_IdToPDB( dwProcessID );
TRACE_(win32)("(%ld, %d)\n", dwProcessID, offset );
if ( !process )
if (dwProcessID && dwProcessID != GetCurrentProcessId())
{
ERR("%d: process %lx not accessible\n", offset, dwProcessID);
return;
@ -984,7 +964,7 @@ void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
break;
case GPD_USERDATA:
process->process_dword = value;
current_process.process_dword = value;
break;
default:
@ -1079,58 +1059,19 @@ BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess,
}
/***********************************************************************
* GetStdHandle (KERNEL32.276)
*/
HANDLE WINAPI GetStdHandle( DWORD std_handle )
{
PDB *pdb = PROCESS_Current();
switch(std_handle)
{
case STD_INPUT_HANDLE: return pdb->env_db->hStdin;
case STD_OUTPUT_HANDLE: return pdb->env_db->hStdout;
case STD_ERROR_HANDLE: return pdb->env_db->hStderr;
}
SetLastError( ERROR_INVALID_PARAMETER );
return INVALID_HANDLE_VALUE;
}
/***********************************************************************
* SetStdHandle (KERNEL32.506)
*/
BOOL WINAPI SetStdHandle( DWORD std_handle, HANDLE handle )
{
PDB *pdb = PROCESS_Current();
/* FIXME: should we close the previous handle? */
switch(std_handle)
{
case STD_INPUT_HANDLE:
pdb->env_db->hStdin = handle;
return TRUE;
case STD_OUTPUT_HANDLE:
pdb->env_db->hStdout = handle;
return TRUE;
case STD_ERROR_HANDLE:
pdb->env_db->hStderr = handle;
return TRUE;
}
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
/***********************************************************************
* GetProcessVersion (KERNEL32)
*/
DWORD WINAPI GetProcessVersion( DWORD processid )
{
TDB *pTask;
PDB *pdb = PROCESS_IdToPDB( processid );
IMAGE_NT_HEADERS *nt;
if (!pdb) return 0;
if (!(pTask = (TDB *)GlobalLock16( pdb->task ))) return 0;
return (pTask->version&0xff) | (((pTask->version >>8) & 0xff)<<16);
if (processid && processid != GetCurrentProcessId())
return 0; /* FIXME: should use ReadProcessMemory */
if ((nt = RtlImageNtHeader( current_process.module )))
return ((nt->OptionalHeader.MajorSubsystemVersion << 16) |
nt->OptionalHeader.MinorSubsystemVersion);
return 0;
}
/***********************************************************************
@ -1138,11 +1079,11 @@ DWORD WINAPI GetProcessVersion( DWORD processid )
*/
DWORD WINAPI GetProcessFlags( DWORD processid )
{
PDB *pdb = PROCESS_IdToPDB( processid );
if (!pdb) return 0;
return pdb->flags;
if (processid && processid != GetCurrentProcessId()) return 0;
return current_process.flags;
}
/***********************************************************************
* SetProcessWorkingSetSize [KERNEL32.662]
* Sets the min/max working set sizes for a specified process.
@ -1391,8 +1332,8 @@ BOOL WINAPI GetExitCodeProcess(
*/
UINT WINAPI SetErrorMode( UINT mode )
{
UINT old = PROCESS_Current()->error_mode;
PROCESS_Current()->error_mode = mode;
UINT old = current_process.error_mode;
current_process.error_mode = mode;
return old;
}

View File

@ -35,9 +35,6 @@ DEFAULT_DEBUG_CHANNEL(thread);
/* TEB of the initial thread */
static TEB initial_teb;
/* The initial process PDB */
static PDB initial_pdb;
/***********************************************************************
* THREAD_IsWin16
*/
@ -216,7 +213,7 @@ void THREAD_Init(void)
{
THREAD_InitTEB( &initial_teb );
assert( initial_teb.teb_sel );
initial_teb.process = &initial_pdb;
initial_teb.process = &current_process;
SYSDEPS_SetCurThread( &initial_teb );
}
}
@ -233,8 +230,8 @@ TEB *THREAD_Create( int fd, DWORD stack_size, BOOL alloc_stack16 )
if ((teb = THREAD_InitStack( NULL, stack_size, alloc_stack16 )))
{
teb->tibflags = (PROCESS_Current()->flags & PDB32_WIN16_PROC) ? 0 : TEBF_WIN32;
teb->process = PROCESS_Current();
teb->tibflags = (current_process.flags & PDB32_WIN16_PROC) ? 0 : TEBF_WIN32;
teb->process = &current_process;
teb->socket = fd;
fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */
TRACE("(%p) succeeded\n", teb);
@ -368,24 +365,23 @@ void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
*/
DWORD WINAPI TlsAlloc( void )
{
PDB *process = PROCESS_Current();
DWORD i, mask, ret = 0;
DWORD *bits = process->tls_bits;
EnterCriticalSection( &process->crit_section );
DWORD *bits = current_process.tls_bits;
EnterCriticalSection( &current_process.crit_section );
if (*bits == 0xffffffff)
{
bits++;
ret = 32;
if (*bits == 0xffffffff)
{
LeaveCriticalSection( &process->crit_section );
LeaveCriticalSection( &current_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( &process->crit_section );
LeaveCriticalSection( &current_process.crit_section );
return ret + i;
}
@ -402,27 +398,26 @@ DWORD WINAPI TlsAlloc( void )
BOOL WINAPI TlsFree(
DWORD index) /* [in] TLS Index to free */
{
PDB *process = PROCESS_Current();
DWORD mask;
DWORD *bits = process->tls_bits;
DWORD *bits = current_process.tls_bits;
if (index >= 64)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
EnterCriticalSection( &process->crit_section );
EnterCriticalSection( &current_process.crit_section );
if (index >= 32) bits++;
mask = (1 << (index & 31));
if (!(*bits & mask)) /* already free? */
{
LeaveCriticalSection( &process->crit_section );
LeaveCriticalSection( &current_process.crit_section );
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
*bits &= ~mask;
NtCurrentTeb()->tls_array[index] = 0;
/* FIXME: should zero all other thread values */
LeaveCriticalSection( &process->crit_section );
LeaveCriticalSection( &current_process.crit_section );
return TRUE;
}

View File

@ -14,7 +14,6 @@
#include "heap.h"
#include "task.h"
#include "debugtools.h"
#include "process.h"
DEFAULT_DEBUG_CHANNEL(win32);
@ -26,60 +25,6 @@ static WINE_EXCEPTION_FILTER(page_fault)
return EXCEPTION_CONTINUE_SEARCH;
}
/***********************************************************************
* GetStartupInfoA (KERNEL32.273)
*/
VOID WINAPI GetStartupInfoA(LPSTARTUPINFOA lpStartupInfo)
{
LPSTARTUPINFOA startup;
startup = ((LPSTARTUPINFOA )PROCESS_Current()->env_db->startup_info);
memcpy ( lpStartupInfo, startup, sizeof (STARTUPINFOA) );
TRACE("size: %ld\n"
"\tlpReserverd: %s, lpDesktop: %s, lpTitle: %s\n"
"\tdwX: %ld, dwY: %ld, dwXSize: %ld, dwYSize: %ld\n"
"\tdwFlags: %lx, wShowWindow: %x\n", lpStartupInfo->cb,
debugstr_a(lpStartupInfo->lpReserved),
debugstr_a(lpStartupInfo->lpDesktop),
debugstr_a(lpStartupInfo->lpTitle),
lpStartupInfo->dwX, lpStartupInfo->dwY,
lpStartupInfo->dwXSize, lpStartupInfo->dwYSize,
lpStartupInfo->dwFlags, lpStartupInfo->wShowWindow );
}
/***********************************************************************
* GetStartupInfoW (KERNEL32.274)
*/
VOID WINAPI GetStartupInfoW(LPSTARTUPINFOW lpStartupInfo)
{
STARTUPINFOA startup;
GetStartupInfoA ( &startup );
lpStartupInfo->cb = sizeof(STARTUPINFOW);
lpStartupInfo->lpReserved =
HEAP_strdupAtoW (GetProcessHeap(), 0, startup.lpReserved );
lpStartupInfo->lpDesktop =
HEAP_strdupAtoW (GetProcessHeap(), 0, startup.lpDesktop );
lpStartupInfo->lpTitle =
HEAP_strdupAtoW (GetProcessHeap(), 0, startup.lpTitle );
lpStartupInfo->dwX = startup.dwX;
lpStartupInfo->dwY = startup.dwY;
lpStartupInfo->dwXSize = startup.dwXSize;
lpStartupInfo->dwXCountChars = startup.dwXCountChars;
lpStartupInfo->dwYCountChars = startup.dwYCountChars;
lpStartupInfo->dwFillAttribute = startup.dwFillAttribute;
lpStartupInfo->dwFlags = startup.dwFlags;
lpStartupInfo->wShowWindow = startup.wShowWindow;
lpStartupInfo->cbReserved2 = startup.cbReserved2;
lpStartupInfo->lpReserved2 = startup.lpReserved2;
lpStartupInfo->hStdInput = startup.hStdInput;
lpStartupInfo->hStdOutput = startup.hStdOutput;
lpStartupInfo->hStdError = startup.hStdError;
}
/***********************************************************************
* GetComputerNameA (KERNEL32.165)
*/