Made GetProcessHeap(), GetCurrentProcessId(), GetCurrentThread() and
GetCurrentProcess() inline.
diff --git a/include/process.h b/include/process.h
index c5ea777..341b54c 100644
--- a/include/process.h
+++ b/include/process.h
@@ -15,9 +15,6 @@
struct _THREAD_ENTRY;
struct _UTINFO;
-/* Current Process pseudo-handle - Returned by GetCurrentProcess*/
-#define CURRENT_PROCESS_PSEUDOHANDLE ((HANDLE)0x7fffffff)
-
/* Win32 process environment database */
typedef struct
{
diff --git a/include/thread.h b/include/thread.h
index 6ba215a..4471906 100644
--- a/include/thread.h
+++ b/include/thread.h
@@ -44,7 +44,7 @@
struct _TEB *self; /* 12- 18 Pointer to this structure */
WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
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 */
HQUEUE16 queue; /* 1!- 28 Message queue (NT: DWORD ActiveRpcHandle)*/
WORD pad1; /* --n 2a */
@@ -113,16 +113,13 @@
#define TEBF_WIN32 0x0001
#define TEBF_TRAP 0x0002
-/* The pseudo handle value returned by GetCurrentThread */
-#define CURRENT_THREAD_PSEUDOHANDLE 0xfffffffe
-
/* The per-thread signal stack size */
#define SIGNAL_STACK_SIZE 16384
/* scheduler/thread.c */
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 );
extern BOOL THREAD_IsWin16( TEB *thdb );
extern TEB *THREAD_IdToTEB( DWORD id );
diff --git a/include/winbase.h b/include/winbase.h
index 0a5949c..3af19ce 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -237,6 +237,8 @@
#define INVALID_HANDLE_VALUE16 ((HANDLE16) -1)
#define INVALID_HANDLE_VALUE ((HANDLE) -1)
+#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
+
/* comm */
#define CBR_110 0xFF10
@@ -1269,13 +1271,12 @@
DWORD WINAPI GetConsoleTitleA(LPSTR,DWORD);
DWORD WINAPI GetConsoleTitleW(LPWSTR,DWORD);
#define GetConsoleTitle WINELIB_NAME_AW(GetConsoleTitle)
-BOOL WINAPI GetCommMask(HANDLE, LPDWORD);
-BOOL WINAPI GetCommModemStatus(HANDLE, LPDWORD);
-HANDLE WINAPI GetCurrentProcess(void);
-DWORD WINAPI GetCurrentProcessId(void);
-HANDLE WINAPI GetCurrentThread(void);
-INT WINAPI GetDateFormatA(LCID,DWORD,LPSYSTEMTIME,LPCSTR,LPSTR,INT);
-INT WINAPI GetDateFormatW(LCID,DWORD,LPSYSTEMTIME,LPCWSTR,LPWSTR,INT);
+BOOL WINAPI GetCommMask(HANDLE, LPDWORD);
+BOOL WINAPI GetCommModemStatus(HANDLE, LPDWORD);
+HANDLE WINAPI GetCurrentProcess(void);
+HANDLE WINAPI GetCurrentThread(void);
+INT WINAPI GetDateFormatA(LCID,DWORD,LPSYSTEMTIME,LPCSTR,LPSTR,INT);
+INT WINAPI GetDateFormatW(LCID,DWORD,LPSYSTEMTIME,LPCWSTR,LPWSTR,INT);
#define GetDateFormat WINELIB_NAME_AW(GetDateFormat)
LPSTR WINAPI GetEnvironmentStringsA(void);
LPWSTR WINAPI GetEnvironmentStringsW(void);
@@ -1310,7 +1311,6 @@
UINT WINAPI GetOEMCP(void);
BOOL WINAPI GetOldestEventLogRecord(HANDLE,PDWORD);
DWORD WINAPI GetPriorityClass(HANDLE);
-HANDLE WINAPI GetProcessHeap(void);
DWORD WINAPI GetProcessVersion(DWORD);
BOOL WINAPI GetSecurityDescriptorControl(PSECURITY_DESCRIPTOR,PSECURITY_DESCRIPTOR_CONTROL,LPDWORD);
BOOL WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR,LPBOOL,PACL *,LPBOOL);
@@ -1816,6 +1816,14 @@
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)
{
@@ -1830,9 +1838,19 @@
__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__ */
+DWORD WINAPI GetCurrentProcessId(void);
DWORD WINAPI GetCurrentThreadId(void);
DWORD WINAPI GetLastError(void);
+HANDLE WINAPI GetProcessHeap(void);
PVOID WINAPI InterlockedCompareExchange(PVOID*,PVOID,PVOID);
LONG WINAPI InterlockedDecrement(PLONG);
LONG WINAPI InterlockedExchange(PLONG,LONG);
@@ -1841,6 +1859,10 @@
VOID WINAPI SetLastError(DWORD);
#endif /* __i386__ && __GNUC__ */
+#ifdef __WINE__
+#define GetCurrentProcess() ((HANDLE)0xffffffff)
+#define GetCurrentThread() ((HANDLE)0xfffffffe)
+#endif
#ifdef __cplusplus
}
diff --git a/scheduler/client.c b/scheduler/client.c
index 6770a7d..1743323 100644
--- a/scheduler/client.c
+++ b/scheduler/client.c
@@ -499,6 +499,7 @@
if (teb->buffer == (void*)-1) server_perror( "mmap" );
first_req = teb->buffer;
teb->process->server_pid = first_req->pid;
+ teb->pid = first_req->pid;
teb->tid = first_req->tid;
if (first_req->version != SERVER_PROTOCOL_VERSION)
server_protocol_error( "version mismatch %d/%d.\n"
diff --git a/scheduler/process.c b/scheduler/process.c
index 284aae7..9a314bf 100644
--- a/scheduler/process.c
+++ b/scheduler/process.c
@@ -277,6 +277,7 @@
if (!pdb) return NULL;
pdb->exit_code = STILL_ACTIVE;
+ pdb->heap = GetProcessHeap();
pdb->threads = 1;
pdb->running_threads = 1;
pdb->ring0_threads = 1;
@@ -364,8 +365,6 @@
PDB *pdb = PROCESS_Current();
NE_MODULE *pModule = NE_GetPtr( pdb->module );
LPCSTR filename = ((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName;
- IMAGE_OPTIONAL_HEADER *header = !pModule->module32? NULL :
- &PE_HEADER(pModule->module32)->OptionalHeader;
/* Get process type */
enum { PROC_DOS, PROC_WIN16, PROC_WIN32 } type;
@@ -379,15 +378,6 @@
/* Initialize the critical 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 */
if (!PROCESS_CreateEnvDB()) goto error;
@@ -567,9 +557,8 @@
/* 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;
- teb->tid = (void *)info->dwThreadId;
teb->startup = PROCESS_Start;
fd = -1; /* don't close it */
@@ -783,15 +772,6 @@
}
-/***********************************************************************
- * GetCurrentProcess (KERNEL32.198)
- */
-HANDLE WINAPI GetCurrentProcess(void)
-{
- return CURRENT_PROCESS_PSEUDOHANDLE;
-}
-
-
/*********************************************************************
* OpenProcess (KERNEL32.543)
*/
@@ -820,15 +800,6 @@
}
/***********************************************************************
- * GetCurrentProcessId (KERNEL32.199)
- */
-DWORD WINAPI GetCurrentProcessId(void)
-{
- return (DWORD)PROCESS_Current()->server_pid;
-}
-
-
-/***********************************************************************
* GetThreadLocale (KERNEL32.295)
*/
LCID WINAPI GetThreadLocale(void)
@@ -1211,3 +1182,12 @@
PROCESS_Current()->error_mode = mode;
return old;
}
+
+/***********************************************************************
+ * GetCurrentProcess (KERNEL32.198)
+ */
+#undef GetCurrentProcess
+HANDLE WINAPI GetCurrentProcess(void)
+{
+ return 0xffffffff;
+}
diff --git a/scheduler/thread.c b/scheduler/thread.c
index 00ec37b..d1f47bb 100644
--- a/scheduler/thread.c
+++ b/scheduler/thread.c
@@ -195,7 +195,7 @@
* allocate in this area and don't support a granularity of 4kb
* 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 )
{
TEB *teb = VirtualAlloc(0, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
@@ -208,6 +208,7 @@
teb->process = pdb;
teb->exit_code = STILL_ACTIVE;
teb->socket = fd;
+ teb->pid = pid;
teb->tid = tid;
fcntl( fd, F_SETFD, 1 ); /* set close on exec flag */
@@ -270,7 +271,8 @@
if (server_call_fd( REQ_NEW_THREAD, -1, &socket )) return 0;
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 );
return 0;
@@ -342,18 +344,6 @@
}
-/***********************************************************************
- * 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.
*
@@ -824,6 +814,19 @@
}
+/***********************************************************************
+ * GetCurrentThread [KERNEL32.200] Gets pseudohandle for current thread
+ *
+ * RETURNS
+ * Pseudohandle for the current thread
+ */
+#undef GetCurrentThread
+HANDLE WINAPI GetCurrentThread(void)
+{
+ return 0xfffffffe;
+}
+
+
#ifdef __i386__
/* void WINAPI SetLastError( DWORD error ); */
@@ -836,6 +839,9 @@
/* DWORD WINAPI GetLastError(void); */
__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) */
__ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" );
@@ -858,6 +864,14 @@
}
/***********************************************************************
+ * GetCurrentProcessId [KERNEL32.199] Returns process identifier.
+ */
+DWORD WINAPI GetCurrentProcessId(void)
+{
+ return (DWORD)NtCurrentTeb()->pid;
+}
+
+/***********************************************************************
* GetCurrentThreadId [KERNEL32.201] Returns thread identifier.
*/
DWORD WINAPI GetCurrentThreadId(void)
diff --git a/windows/queue.c b/windows/queue.c
index 9d3036d..4cbc329 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -1403,7 +1403,7 @@
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;
QUEUE_Unlock( queue );