Made GetProcessHeap(), GetCurrentProcessId(), GetCurrentThread() and

GetCurrentProcess() inline.
This commit is contained in:
Alexandre Julliard 2000-04-11 20:01:59 +00:00
parent e8d2aa5e65
commit 114830e8a9
7 changed files with 73 additions and 62 deletions

View File

@ -15,9 +15,6 @@ struct _NE_MODULE;
struct _THREAD_ENTRY; struct _THREAD_ENTRY;
struct _UTINFO; struct _UTINFO;
/* Current Process pseudo-handle - Returned by GetCurrentProcess*/
#define CURRENT_PROCESS_PSEUDOHANDLE ((HANDLE)0x7fffffff)
/* Win32 process environment database */ /* Win32 process environment database */
typedef struct typedef struct
{ {

View File

@ -44,7 +44,7 @@ typedef struct _TEB
struct _TEB *self; /* 12- 18 Pointer to this structure */ struct _TEB *self; /* 12- 18 Pointer to this structure */
WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */ WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
WORD mutex_count; /* 1-n 1e Win16 mutex count */ WORD mutex_count; /* 1-n 1e Win16 mutex count */
DWORD debug_context; /* 1!n 20 Debug context (NT: PVOID UniqueProcess) */ void *pid; /* !2- 20 Process id (win95: debug context) */
void *tid; /* -2- 24 Thread id */ void *tid; /* -2- 24 Thread id */
HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/ HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/
WORD pad1; /* --n 2a */ WORD pad1; /* --n 2a */
@ -113,16 +113,13 @@ typedef struct _TEB
#define TEBF_WIN32 0x0001 #define TEBF_WIN32 0x0001
#define TEBF_TRAP 0x0002 #define TEBF_TRAP 0x0002
/* The pseudo handle value returned by GetCurrentThread */
#define CURRENT_THREAD_PSEUDOHANDLE 0xfffffffe
/* The per-thread signal stack size */ /* The per-thread signal stack size */
#define SIGNAL_STACK_SIZE 16384 #define SIGNAL_STACK_SIZE 16384
/* scheduler/thread.c */ /* scheduler/thread.c */
extern TEB *THREAD_CreateInitialThread( struct _PDB *pdb, int server_fd ); extern TEB *THREAD_CreateInitialThread( struct _PDB *pdb, int server_fd );
extern TEB *THREAD_Create( struct _PDB *pdb, void *tid, int fd, DWORD flags, extern TEB *THREAD_Create( struct _PDB *pdb, void *pid, void *tid, int fd, DWORD flags,
DWORD stack_size, BOOL alloc_stack16 ); DWORD stack_size, BOOL alloc_stack16 );
extern BOOL THREAD_IsWin16( TEB *thdb ); extern BOOL THREAD_IsWin16( TEB *thdb );
extern TEB *THREAD_IdToTEB( DWORD id ); extern TEB *THREAD_IdToTEB( DWORD id );

View File

@ -237,6 +237,8 @@ typedef struct
#define INVALID_HANDLE_VALUE16 ((HANDLE16) -1) #define INVALID_HANDLE_VALUE16 ((HANDLE16) -1)
#define INVALID_HANDLE_VALUE ((HANDLE) -1) #define INVALID_HANDLE_VALUE ((HANDLE) -1)
#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
/* comm */ /* comm */
#define CBR_110 0xFF10 #define CBR_110 0xFF10
@ -1269,13 +1271,12 @@ UINT WINAPI GetConsoleOutputCP(void);
DWORD WINAPI GetConsoleTitleA(LPSTR,DWORD); DWORD WINAPI GetConsoleTitleA(LPSTR,DWORD);
DWORD WINAPI GetConsoleTitleW(LPWSTR,DWORD); DWORD WINAPI GetConsoleTitleW(LPWSTR,DWORD);
#define GetConsoleTitle WINELIB_NAME_AW(GetConsoleTitle) #define GetConsoleTitle WINELIB_NAME_AW(GetConsoleTitle)
BOOL WINAPI GetCommMask(HANDLE, LPDWORD); BOOL WINAPI GetCommMask(HANDLE, LPDWORD);
BOOL WINAPI GetCommModemStatus(HANDLE, LPDWORD); BOOL WINAPI GetCommModemStatus(HANDLE, LPDWORD);
HANDLE WINAPI GetCurrentProcess(void); HANDLE WINAPI GetCurrentProcess(void);
DWORD WINAPI GetCurrentProcessId(void); HANDLE WINAPI GetCurrentThread(void);
HANDLE WINAPI GetCurrentThread(void); INT WINAPI GetDateFormatA(LCID,DWORD,LPSYSTEMTIME,LPCSTR,LPSTR,INT);
INT WINAPI GetDateFormatA(LCID,DWORD,LPSYSTEMTIME,LPCSTR,LPSTR,INT); INT WINAPI GetDateFormatW(LCID,DWORD,LPSYSTEMTIME,LPCWSTR,LPWSTR,INT);
INT WINAPI GetDateFormatW(LCID,DWORD,LPSYSTEMTIME,LPCWSTR,LPWSTR,INT);
#define GetDateFormat WINELIB_NAME_AW(GetDateFormat) #define GetDateFormat WINELIB_NAME_AW(GetDateFormat)
LPSTR WINAPI GetEnvironmentStringsA(void); LPSTR WINAPI GetEnvironmentStringsA(void);
LPWSTR WINAPI GetEnvironmentStringsW(void); LPWSTR WINAPI GetEnvironmentStringsW(void);
@ -1310,7 +1311,6 @@ BOOL WINAPI GetNumberOfEventLogRecords(HANDLE,PDWORD);
UINT WINAPI GetOEMCP(void); UINT WINAPI GetOEMCP(void);
BOOL WINAPI GetOldestEventLogRecord(HANDLE,PDWORD); BOOL WINAPI GetOldestEventLogRecord(HANDLE,PDWORD);
DWORD WINAPI GetPriorityClass(HANDLE); DWORD WINAPI GetPriorityClass(HANDLE);
HANDLE WINAPI GetProcessHeap(void);
DWORD WINAPI GetProcessVersion(DWORD); DWORD WINAPI GetProcessVersion(DWORD);
BOOL WINAPI GetSecurityDescriptorControl(PSECURITY_DESCRIPTOR,PSECURITY_DESCRIPTOR_CONTROL,LPDWORD); BOOL WINAPI GetSecurityDescriptorControl(PSECURITY_DESCRIPTOR,PSECURITY_DESCRIPTOR_CONTROL,LPDWORD);
BOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR,LPBOOL,PACL *,LPBOOL); BOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR,LPBOOL,PACL *,LPBOOL);
@ -1816,6 +1816,14 @@ extern inline DWORD WINAPI GetLastError(void)
return ret; return ret;
} }
extern inline DWORD WINAPI GetCurrentProcessId(void);
extern inline DWORD WINAPI GetCurrentProcessId(void)
{
DWORD ret;
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x20,%0" : "=r" (ret) );
return ret;
}
extern inline DWORD WINAPI GetCurrentThreadId(void); extern inline DWORD WINAPI GetCurrentThreadId(void);
extern inline DWORD WINAPI GetCurrentThreadId(void) extern inline DWORD WINAPI GetCurrentThreadId(void)
{ {
@ -1830,9 +1838,19 @@ extern inline void WINAPI SetLastError( DWORD err )
__asm__ __volatile__( ".byte 0x64\n\tmovl %0,0x60" : : "r" (err) : "memory" ); __asm__ __volatile__( ".byte 0x64\n\tmovl %0,0x60" : : "r" (err) : "memory" );
} }
extern inline HANDLE WINAPI GetProcessHeap(void);
extern inline HANDLE WINAPI GetProcessHeap(void)
{
DWORD *pdb;
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x30,%0" : "=r" (pdb) );
return pdb[0x18 / sizeof(DWORD)]; /* get dword at offset 0x18 in pdb */
}
#else /* __i386__ && __GNUC__ */ #else /* __i386__ && __GNUC__ */
DWORD WINAPI GetCurrentProcessId(void);
DWORD WINAPI GetCurrentThreadId(void); DWORD WINAPI GetCurrentThreadId(void);
DWORD WINAPI GetLastError(void); DWORD WINAPI GetLastError(void);
HANDLE WINAPI GetProcessHeap(void);
PVOID WINAPI InterlockedCompareExchange(PVOID*,PVOID,PVOID); PVOID WINAPI InterlockedCompareExchange(PVOID*,PVOID,PVOID);
LONG WINAPI InterlockedDecrement(PLONG); LONG WINAPI InterlockedDecrement(PLONG);
LONG WINAPI InterlockedExchange(PLONG,LONG); LONG WINAPI InterlockedExchange(PLONG,LONG);
@ -1841,6 +1859,10 @@ LONG WINAPI InterlockedIncrement(PLONG);
VOID WINAPI SetLastError(DWORD); VOID WINAPI SetLastError(DWORD);
#endif /* __i386__ && __GNUC__ */ #endif /* __i386__ && __GNUC__ */
#ifdef __WINE__
#define GetCurrentProcess() ((HANDLE)0xffffffff)
#define GetCurrentThread() ((HANDLE)0xfffffffe)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -499,6 +499,7 @@ int CLIENT_InitThread(void)
if (teb->buffer == (void*)-1) server_perror( "mmap" ); if (teb->buffer == (void*)-1) server_perror( "mmap" );
first_req = teb->buffer; first_req = teb->buffer;
teb->process->server_pid = first_req->pid; teb->process->server_pid = first_req->pid;
teb->pid = first_req->pid;
teb->tid = first_req->tid; teb->tid = first_req->tid;
if (first_req->version != SERVER_PROTOCOL_VERSION) if (first_req->version != SERVER_PROTOCOL_VERSION)
server_protocol_error( "version mismatch %d/%d.\n" server_protocol_error( "version mismatch %d/%d.\n"

View File

@ -277,6 +277,7 @@ static PDB *PROCESS_CreatePDB( PDB *parent, BOOL inherit )
if (!pdb) return NULL; if (!pdb) return NULL;
pdb->exit_code = STILL_ACTIVE; pdb->exit_code = STILL_ACTIVE;
pdb->heap = GetProcessHeap();
pdb->threads = 1; pdb->threads = 1;
pdb->running_threads = 1; pdb->running_threads = 1;
pdb->ring0_threads = 1; pdb->ring0_threads = 1;
@ -364,8 +365,6 @@ void PROCESS_Start(void)
PDB *pdb = PROCESS_Current(); PDB *pdb = PROCESS_Current();
NE_MODULE *pModule = NE_GetPtr( pdb->module ); NE_MODULE *pModule = NE_GetPtr( pdb->module );
LPCSTR filename = ((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName; LPCSTR filename = ((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName;
IMAGE_OPTIONAL_HEADER *header = !pModule->module32? NULL :
&PE_HEADER(pModule->module32)->OptionalHeader;
/* Get process type */ /* Get process type */
enum { PROC_DOS, PROC_WIN16, PROC_WIN32 } type; enum { PROC_DOS, PROC_WIN16, PROC_WIN32 } type;
@ -379,15 +378,6 @@ void PROCESS_Start(void)
/* Initialize the critical section */ /* Initialize the critical section */
InitializeCriticalSection( &pdb->crit_section ); InitializeCriticalSection( &pdb->crit_section );
/* Create the heap */
if (!(pdb->heap = GetProcessHeap()))
{
if (!(pdb->heap = HeapCreate( HEAP_GROWABLE,
header? header->SizeOfHeapReserve : 0x10000,
header? header->SizeOfHeapCommit : 0 )))
goto error;
}
/* Create the environment db */ /* Create the environment db */
if (!PROCESS_CreateEnvDB()) goto error; if (!PROCESS_CreateEnvDB()) goto error;
@ -567,9 +557,8 @@ PDB *PROCESS_Create( NE_MODULE *pModule, HFILE hFile, LPCSTR cmd_line, LPCSTR en
/* Create the main thread */ /* Create the main thread */
if (!(teb = THREAD_Create( pdb, req->tid, fd, flags & CREATE_SUSPENDED, if (!(teb = THREAD_Create( pdb, req->pid, req->tid, fd, flags & CREATE_SUSPENDED,
size, alloc_stack16 ))) goto error; size, alloc_stack16 ))) goto error;
teb->tid = (void *)info->dwThreadId;
teb->startup = PROCESS_Start; teb->startup = PROCESS_Start;
fd = -1; /* don't close it */ fd = -1; /* don't close it */
@ -783,15 +772,6 @@ void WINAPI SetProcessDword( DWORD dwProcessID, INT offset, DWORD value )
} }
/***********************************************************************
* GetCurrentProcess (KERNEL32.198)
*/
HANDLE WINAPI GetCurrentProcess(void)
{
return CURRENT_PROCESS_PSEUDOHANDLE;
}
/********************************************************************* /*********************************************************************
* OpenProcess (KERNEL32.543) * OpenProcess (KERNEL32.543)
*/ */
@ -819,15 +799,6 @@ DWORD WINAPI MapProcessHandle( HANDLE handle )
return ret; return ret;
} }
/***********************************************************************
* GetCurrentProcessId (KERNEL32.199)
*/
DWORD WINAPI GetCurrentProcessId(void)
{
return (DWORD)PROCESS_Current()->server_pid;
}
/*********************************************************************** /***********************************************************************
* GetThreadLocale (KERNEL32.295) * GetThreadLocale (KERNEL32.295)
*/ */
@ -1211,3 +1182,12 @@ UINT WINAPI SetErrorMode( UINT mode )
PROCESS_Current()->error_mode = mode; PROCESS_Current()->error_mode = mode;
return old; return old;
} }
/***********************************************************************
* GetCurrentProcess (KERNEL32.198)
*/
#undef GetCurrentProcess
HANDLE WINAPI GetCurrentProcess(void)
{
return 0xffffffff;
}

View File

@ -195,7 +195,7 @@ TEB *THREAD_CreateInitialThread( PDB *pdb, int server_fd )
* allocate in this area and don't support a granularity of 4kb * allocate in this area and don't support a granularity of 4kb
* yet we leave it to VirtualAlloc to choose an address. * yet we leave it to VirtualAlloc to choose an address.
*/ */
TEB *THREAD_Create( PDB *pdb, void *tid, int fd, DWORD flags, TEB *THREAD_Create( PDB *pdb, void *pid, void *tid, int fd, DWORD flags,
DWORD stack_size, BOOL alloc_stack16 ) DWORD stack_size, BOOL alloc_stack16 )
{ {
TEB *teb = VirtualAlloc(0, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE); TEB *teb = VirtualAlloc(0, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
@ -208,6 +208,7 @@ TEB *THREAD_Create( PDB *pdb, void *tid, int fd, DWORD flags,
teb->process = pdb; teb->process = pdb;
teb->exit_code = STILL_ACTIVE; teb->exit_code = STILL_ACTIVE;
teb->socket = fd; teb->socket = fd;
teb->pid = pid;
teb->tid = tid; teb->tid = tid;
fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */ fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */
@ -270,7 +271,8 @@ HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, DWORD stack,
if (server_call_fd( REQ_NEW_THREAD, -1, &socket )) return 0; if (server_call_fd( REQ_NEW_THREAD, -1, &socket )) return 0;
handle = req->handle; handle = req->handle;
if (!(teb = THREAD_Create( PROCESS_Current(), req->tid, socket, flags, stack, TRUE ))) if (!(teb = THREAD_Create( PROCESS_Current(), (void *)GetCurrentProcessId(),
req->tid, socket, flags, stack, TRUE )))
{ {
close( socket ); close( socket );
return 0; return 0;
@ -342,18 +344,6 @@ void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
} }
/***********************************************************************
* GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
*
* RETURNS
* Pseudohandle for the current thread
*/
HANDLE WINAPI GetCurrentThread(void)
{
return CURRENT_THREAD_PSEUDOHANDLE;
}
/********************************************************************** /**********************************************************************
* SetLastErrorEx [USER32.485] Sets the last-error code. * SetLastErrorEx [USER32.485] Sets the last-error code.
* *
@ -824,6 +814,19 @@ BOOL WINAPI SetThreadLocale(
} }
/***********************************************************************
* GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
*
* RETURNS
* Pseudohandle for the current thread
*/
#undef GetCurrentThread
HANDLE WINAPI GetCurrentThread(void)
{
return 0xfffffffe;
}
#ifdef __i386__ #ifdef __i386__
/* void WINAPI SetLastError( DWORD error ); */ /* void WINAPI SetLastError( DWORD error ); */
@ -836,6 +839,9 @@ __ASM_GLOBAL_FUNC( SetLastError,
/* DWORD WINAPI GetLastError(void); */ /* DWORD WINAPI GetLastError(void); */
__ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" ); __ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x60,%eax\n\tret" );
/* DWORD WINAPI GetCurrentProcessId(void) */
__ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" );
/* DWORD WINAPI GetCurrentThreadId(void) */ /* DWORD WINAPI GetCurrentThreadId(void) */
__ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" ); __ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
@ -857,6 +863,14 @@ DWORD WINAPI GetLastError(void)
return NtCurrentTeb()->last_error; return NtCurrentTeb()->last_error;
} }
/***********************************************************************
* GetCurrentProcessId [KERNEL32.199] Returns process identifier.
*/
DWORD WINAPI GetCurrentProcessId(void)
{
return (DWORD)NtCurrentTeb()->pid;
}
/*********************************************************************** /***********************************************************************
* GetCurrentThreadId [KERNEL32.201] Returns thread identifier. * GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
*/ */

View File

@ -1403,7 +1403,7 @@ DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process )
if (!queue) return 0; if (!queue) return 0;
if ( process ) *process = (DWORD)queue->teb->process->server_pid; if ( process ) *process = (DWORD)queue->teb->pid;
retvalue = (DWORD)queue->teb->tid; retvalue = (DWORD)queue->teb->tid;
QUEUE_Unlock( queue ); QUEUE_Unlock( queue );