Commit 4a546903 authored by Ulrich Weigand's avatar Ulrich Weigand Committed by Alexandre Julliard

Added support for global handles, implemented ConvertToGlobalHandle.

Allocate startup data and 16-bit stack for initial process.
parent 7692b583
......@@ -138,9 +138,17 @@ extern BOOL32 HANDLE_SetObjPtr( PDB32 *pdb, HANDLE32 handle,
K32OBJ *ptr, DWORD access );
extern void HANDLE_CloseAll( PDB32 *pdb, K32OBJ *ptr );
/* Global handle macros */
#define HANDLE_OBFUSCATOR ((DWORD)0x544a4def)
#define HANDLE_IS_GLOBAL(h) (((DWORD)(h) ^ HANDLE_OBFUSCATOR) < 0x10000)
#define HANDLE_LOCAL_TO_GLOBAL(h) ((HANDLE32)((DWORD)(h) ^ HANDLE_OBFUSCATOR))
#define HANDLE_GLOBAL_TO_LOCAL(h) ((HANDLE32)((DWORD)(h) ^ HANDLE_OBFUSCATOR))
/* scheduler/process.c */
extern BOOL32 PROCESS_Init( void );
extern PDB32 *PROCESS_Current(void);
extern PDB32 *PROCESS_Initial(void);
extern PDB32 *PROCESS_GetPtr( HANDLE32 handle, DWORD access, int *server_handle );
extern PDB32 *PROCESS_IdToPDB( DWORD id );
extern PDB32 *PROCESS_Create( struct _NE_MODULE *pModule, LPCSTR cmd_line,
......
......@@ -338,7 +338,8 @@ static void EVENT_Destroy( K32OBJ *obj )
*/
HANDLE32 WINAPI VWin32_EventCreate(VOID)
{
return CreateEvent32A( NULL, FALSE, 0, NULL );
HANDLE32 hEvent = CreateEvent32A( NULL, FALSE, 0, NULL );
return ConvertToGlobalHandle( hEvent );
}
/***********************************************************************
......
......@@ -155,6 +155,11 @@ K32OBJ *HANDLE_GetObjPtr( PDB32 *pdb, HANDLE32 handle,
K32OBJ *ptr = NULL;
SYSTEM_LOCK();
if (HANDLE_IS_GLOBAL( handle ))
{
handle = HANDLE_GLOBAL_TO_LOCAL( handle );
pdb = PROCESS_Initial();
}
if ((handle > 0) && (handle < pdb->handle_table->count))
{
HANDLE_ENTRY *entry = &pdb->handle_table->entries[handle];
......
......@@ -40,6 +40,8 @@ const K32OBJ_OPS PROCESS_Ops =
PROCESS_Destroy /* destroy */
};
static DWORD PROCESS_InitialProcessID = 0;
/***********************************************************************
* PROCESS_Current
......@@ -49,6 +51,18 @@ PDB32 *PROCESS_Current(void)
return THREAD_Current()->process;
}
/***********************************************************************
* PROCESS_Initial
*
* FIXME: This works only while running all processes in the same
* address space (or, at least, the initial process is mapped
* into all address spaces as is KERNEL32 in Windows 95)
*
*/
PDB32 *PROCESS_Initial(void)
{
return PROCESS_IdToPDB( PROCESS_InitialProcessID );
}
/***********************************************************************
* PROCESS_GetPtr
......@@ -96,6 +110,11 @@ static BOOL32 PROCESS_BuildEnvDB( PDB32 *pdb )
return FALSE;
InitializeCriticalSection( &pdb->env_db->section );
/* Allocate startup info */
if (!(pdb->env_db->startup_info =
HeapAlloc( SystemHeap, HEAP_ZERO_MEMORY, sizeof(STARTUPINFO32A) )))
return FALSE;
/* Allocate the standard handles */
pdb->env_db->hStdin = FILE_DupUnixHandle( 0 );
......@@ -235,9 +254,11 @@ BOOL32 PROCESS_Init(void)
/* Create the initial process and thread structures */
if (!(pdb = PROCESS_CreatePDB( NULL ))) return FALSE;
if (!(thdb = THREAD_Create( pdb, 0, FALSE, NULL, NULL, NULL, NULL ))) return FALSE;
if (!(thdb = THREAD_Create( pdb, 0, TRUE, NULL, NULL, NULL, NULL ))) return FALSE;
thdb->unix_pid = getpid();
PROCESS_InitialProcessID = PDB_TO_PROCESS_ID(pdb);
/* Remember TEB selector of initial process for emergency use */
SYSLEVEL_EmergencyTeb = thdb->teb_sel;
......@@ -736,12 +757,24 @@ BOOL32 WINAPI WriteProcessMemory(HANDLE32 hProcess, LPVOID lpBaseAddress,
/***********************************************************************
* ConvertToGlobalHandle (KERNEL32)
* FIXME: this is not correctly implemented...
*/
HANDLE32 WINAPI ConvertToGlobalHandle(HANDLE32 h)
HANDLE32 WINAPI ConvertToGlobalHandle(HANDLE32 hSrc)
{
FIXME(process,"(%d): stub\n",h);
return h;
HANDLE32 hProcessInit, hDest;
/* Get a handle to the initial process */
hProcessInit = OpenProcess( PROCESS_ALL_ACCESS, FALSE, PROCESS_InitialProcessID );
/* Duplicate the handle into the initial process */
if ( !DuplicateHandle( GetCurrentProcess(), hSrc, hProcessInit, &hDest,
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE ) )
hDest = 0;
/* Close initial process handle */
CloseHandle( hProcessInit );
/* Return obfuscated global handle */
return hDest? HANDLE_LOCAL_TO_GLOBAL( hDest ) : 0;
}
/***********************************************************************
......
......@@ -365,7 +365,7 @@ void THREAD_Start( THDB *thdb )
LPTHREAD_START_ROUTINE func = (LPTHREAD_START_ROUTINE)thdb->entry_point;
assert( THREAD_Current() == thdb );
CLIENT_InitThread();
MODULE_InitializeDLLs( thdb->process, NULL, DLL_THREAD_ATTACH, NULL );
MODULE_InitializeDLLs( thdb->process, 0, DLL_THREAD_ATTACH, NULL );
ExitThread( func( thdb->entry_arg ) );
}
......@@ -413,7 +413,7 @@ void WINAPI ExitThread(
/* Remove thread from process's list */
THREAD_RemoveQueue( &thdb->process->thread_list, thdb );
MODULE_InitializeDLLs( thdb->process, NULL, DLL_THREAD_DETACH, NULL );
MODULE_InitializeDLLs( thdb->process, 0, DLL_THREAD_DETACH, NULL );
SYSTEM_LOCK();
thdb->exit_code = code;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment