2003-06-24 05:34:15 +02:00
|
|
|
/*
|
|
|
|
* Win32 threads
|
|
|
|
*
|
|
|
|
* Copyright 1996 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-06-24 05:34:15 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_TIMES_H
|
|
|
|
#include <sys/times.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#include "windef.h"
|
2003-06-24 05:34:15 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "thread.h"
|
2005-05-16 19:52:10 +02:00
|
|
|
#include "module.h"
|
2003-09-17 07:31:32 +02:00
|
|
|
#include "wine/winbase16.h"
|
2003-11-27 01:59:36 +01:00
|
|
|
#include "wine/exception.h"
|
2003-09-17 07:31:32 +02:00
|
|
|
#include "wine/library.h"
|
2003-11-06 00:31:11 +01:00
|
|
|
#include "wine/pthread.h"
|
2003-06-24 05:34:15 +02:00
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2005-06-14 13:42:34 +02:00
|
|
|
#include "kernel_private.h"
|
|
|
|
|
2003-06-24 05:34:15 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(thread);
|
2003-09-17 07:31:32 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* THREAD_InitStack
|
|
|
|
*
|
|
|
|
* Allocate the stack of a thread.
|
|
|
|
*/
|
|
|
|
TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
|
|
|
|
{
|
2003-11-04 05:50:18 +01:00
|
|
|
DWORD old_prot;
|
2003-09-17 07:31:32 +02:00
|
|
|
DWORD page_size = getpagesize();
|
|
|
|
void *base;
|
|
|
|
|
|
|
|
stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
|
2003-11-18 01:14:17 +01:00
|
|
|
if (stack_size < 1024 * 1024) stack_size = 1024 * 1024; /* Xlib needs a large stack */
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2005-06-21 11:57:53 +02:00
|
|
|
if (!(base = VirtualAlloc( NULL, stack_size, MEM_COMMIT, PAGE_READWRITE )))
|
2003-09-17 07:31:32 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
teb->DeallocationStack = base;
|
2003-11-04 05:50:18 +01:00
|
|
|
teb->Tib.StackBase = (char *)base + stack_size;
|
2003-09-17 07:31:32 +02:00
|
|
|
teb->Tib.StackLimit = base; /* note: limit is lower than base since the stack grows down */
|
|
|
|
|
|
|
|
/* Setup guard pages */
|
|
|
|
|
2005-06-21 11:57:53 +02:00
|
|
|
VirtualProtect( base, 1, PAGE_READWRITE | PAGE_GUARD, &old_prot );
|
2003-09-17 07:31:32 +02:00
|
|
|
return teb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 01:16:20 +01:00
|
|
|
struct new_thread_info
|
|
|
|
{
|
|
|
|
LPTHREAD_START_ROUTINE func;
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
2003-09-17 07:31:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* THREAD_Start
|
|
|
|
*
|
|
|
|
* Start execution of a newly created thread. Does not return.
|
|
|
|
*/
|
2003-10-31 01:16:20 +01:00
|
|
|
static void CALLBACK THREAD_Start( void *ptr )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-31 01:16:20 +01:00
|
|
|
struct new_thread_info *info = ptr;
|
|
|
|
LPTHREAD_START_ROUTINE func = info->func;
|
|
|
|
void *arg = info->arg;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-31 01:16:20 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
2003-09-17 07:31:32 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(relay))
|
|
|
|
DPRINTF("%04lx:Starting thread (entryproc=%p)\n", GetCurrentThreadId(), func );
|
|
|
|
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
MODULE_DllThreadAttach( NULL );
|
2003-10-31 01:16:20 +01:00
|
|
|
ExitThread( func( arg ) );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
__EXCEPT(UnhandledExceptionFilter)
|
|
|
|
{
|
|
|
|
TerminateThread( GetCurrentThread(), GetExceptionCode() );
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateThread( SECURITY_ATTRIBUTES *sa, SIZE_T stack,
|
|
|
|
LPTHREAD_START_ROUTINE start, LPVOID param,
|
|
|
|
DWORD flags, LPDWORD id )
|
2004-09-22 04:54:13 +02:00
|
|
|
{
|
|
|
|
return CreateRemoteThread( GetCurrentProcess(),
|
|
|
|
sa, stack, start, param, flags, id );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* CreateRemoteThread (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Creates a thread that runs in the address space of another process
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Handle to the new thread.
|
|
|
|
* Failure: NULL. Use GetLastError() to find the error cause.
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Improper memory allocation: there's no ability to free new_thread_info
|
|
|
|
* in other process.
|
|
|
|
* Bad start address for RtlCreateUserThread because the library
|
|
|
|
* may be loaded at different address in other process.
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateRemoteThread( HANDLE hProcess, SECURITY_ATTRIBUTES *sa, SIZE_T stack,
|
|
|
|
LPTHREAD_START_ROUTINE start, LPVOID param,
|
|
|
|
DWORD flags, LPDWORD id )
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-31 01:16:20 +01:00
|
|
|
HANDLE handle;
|
|
|
|
CLIENT_ID client_id;
|
|
|
|
NTSTATUS status;
|
|
|
|
SIZE_T stack_reserve = 0, stack_commit = 0;
|
|
|
|
struct new_thread_info *info;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-31 01:16:20 +01:00
|
|
|
if (!(info = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*info) )))
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-31 01:16:20 +01:00
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
2003-09-17 07:31:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2003-10-31 01:16:20 +01:00
|
|
|
info->func = start;
|
|
|
|
info->arg = param;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2003-10-31 01:16:20 +01:00
|
|
|
if (flags & STACK_SIZE_PARAM_IS_A_RESERVATION) stack_reserve = stack;
|
|
|
|
else stack_commit = stack;
|
2003-09-17 07:31:32 +02:00
|
|
|
|
2004-12-01 16:37:26 +01:00
|
|
|
status = RtlCreateUserThread( hProcess, NULL, TRUE,
|
2003-10-31 01:16:20 +01:00
|
|
|
NULL, stack_reserve, stack_commit,
|
|
|
|
THREAD_Start, info, &handle, &client_id );
|
|
|
|
if (status == STATUS_SUCCESS)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-31 01:16:20 +01:00
|
|
|
if (id) *id = (DWORD)client_id.UniqueThread;
|
|
|
|
if (sa && (sa->nLength >= sizeof(*sa)) && sa->bInheritHandle)
|
|
|
|
SetHandleInformation( handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT );
|
2004-12-01 16:37:26 +01:00
|
|
|
if (!(flags & CREATE_SUSPENDED))
|
|
|
|
{
|
|
|
|
ULONG ret;
|
|
|
|
if (NtResumeThread( handle, &ret ))
|
|
|
|
{
|
|
|
|
NtClose( handle );
|
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
handle = 0;
|
|
|
|
}
|
|
|
|
}
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2003-10-31 01:16:20 +01:00
|
|
|
else
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2003-10-31 01:16:20 +01:00
|
|
|
RtlFreeHeap( GetProcessHeap(), 0, info );
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
handle = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenThread [KERNEL32.@] Retrieves a handle to a thread from its thread id
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenThread( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId )
|
|
|
|
{
|
2005-06-27 14:03:56 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE handle;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
CLIENT_ID cid;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = bInheritHandle ? OBJ_INHERIT : 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
cid.UniqueProcess = 0; /* FIXME */
|
|
|
|
cid.UniqueThread = (HANDLE)dwThreadId;
|
|
|
|
status = NtOpenThread( &handle, dwDesiredAccess, &attr, &cid );
|
|
|
|
if (status)
|
2003-09-17 07:31:32 +02:00
|
|
|
{
|
2005-06-27 14:03:56 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
handle = 0;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
2005-06-27 14:03:56 +02:00
|
|
|
return handle;
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* ExitThread [KERNEL32.@] Ends a thread
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* None
|
|
|
|
*/
|
|
|
|
void WINAPI ExitThread( DWORD code ) /* [in] Exit code for this thread */
|
|
|
|
{
|
|
|
|
BOOL last;
|
|
|
|
SERVER_START_REQ( terminate_thread )
|
|
|
|
{
|
|
|
|
/* send the exit code to the server */
|
|
|
|
req->handle = GetCurrentThread();
|
|
|
|
req->exit_code = code;
|
|
|
|
wine_server_call( req );
|
|
|
|
last = reply->last;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
{
|
|
|
|
LdrShutdownProcess();
|
|
|
|
exit( code );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LdrShutdownThread();
|
2005-06-05 20:38:48 +02:00
|
|
|
wine_server_exit_thread( code );
|
2003-09-17 07:31:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* TerminateThread [KERNEL32.@] Terminates a thread
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI TerminateThread( HANDLE handle, /* [in] Handle to thread */
|
|
|
|
DWORD exit_code) /* [in] Exit code for thread */
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtTerminateThread( handle, exit_code );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FreeLibraryAndExitThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLibModule);
|
|
|
|
ExitThread(dwExitCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetExitCodeThread (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Gets termination status of thread.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetExitCodeThread(
|
|
|
|
HANDLE hthread, /* [in] Handle to thread */
|
|
|
|
LPDWORD exitcode) /* [out] Address to receive termination status */
|
|
|
|
{
|
|
|
|
THREAD_BASIC_INFORMATION info;
|
|
|
|
NTSTATUS status = NtQueryInformationThread( hthread, ThreadBasicInformation,
|
|
|
|
&info, sizeof(info), NULL );
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (exitcode) *exitcode = info.ExitStatus;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetThreadContext [KERNEL32.@] Sets context of thread.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
|
|
|
|
const CONTEXT *context ) /* [in] Address of context structure */
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtSetContextThread( handle, context );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetThreadContext [KERNEL32.@] Retrieves context of thread.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetThreadContext( HANDLE handle, /* [in] Handle to thread with context */
|
|
|
|
CONTEXT *context ) /* [out] Address of context structure */
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtGetContextThread( handle, context );
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SuspendThread [KERNEL32.@] Suspends a thread.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Previous suspend count
|
|
|
|
* Failure: 0xFFFFFFFF
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SuspendThread( HANDLE hthread ) /* [in] Handle to the thread */
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
NTSTATUS status = NtSuspendThread( hthread, &ret );
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
ret = ~0U;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* ResumeThread [KERNEL32.@] Resumes a thread.
|
|
|
|
*
|
|
|
|
* Decrements a thread's suspend count. When count is zero, the
|
|
|
|
* execution of the thread is resumed.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Previous suspend count
|
|
|
|
* Failure: 0xFFFFFFFF
|
|
|
|
* Already running: 0
|
|
|
|
*/
|
|
|
|
DWORD WINAPI ResumeThread( HANDLE hthread ) /* [in] Identifies thread to restart */
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
NTSTATUS status = NtResumeThread( hthread, &ret );
|
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
ret = ~0U;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetThreadPriority [KERNEL32.@] Returns priority for thread.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Thread's priority level.
|
|
|
|
* Failure: THREAD_PRIORITY_ERROR_RETURN
|
|
|
|
*/
|
|
|
|
INT WINAPI GetThreadPriority(
|
|
|
|
HANDLE hthread) /* [in] Handle to thread */
|
|
|
|
{
|
2003-07-09 04:57:57 +02:00
|
|
|
THREAD_BASIC_INFORMATION info;
|
|
|
|
NTSTATUS status = NtQueryInformationThread( hthread, ThreadBasicInformation,
|
|
|
|
&info, sizeof(info), NULL );
|
|
|
|
|
|
|
|
if (status)
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2003-07-09 04:57:57 +02:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return THREAD_PRIORITY_ERROR_RETURN;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
2003-07-09 04:57:57 +02:00
|
|
|
return info.Priority;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetThreadPriority [KERNEL32.@] Sets priority for thread.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetThreadPriority(
|
|
|
|
HANDLE hthread, /* [in] Handle to thread */
|
|
|
|
INT priority) /* [in] Thread priority level */
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ( set_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = hthread;
|
|
|
|
req->priority = priority;
|
|
|
|
req->mask = SET_THREAD_INFO_PRIORITY;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetThreadPriorityBoost [KERNEL32.@] Returns priority boost for thread.
|
|
|
|
*
|
|
|
|
* Always reports that priority boost is disabled.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE.
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetThreadPriorityBoost(
|
|
|
|
HANDLE hthread, /* [in] Handle to thread */
|
|
|
|
PBOOL pstate) /* [out] pointer to var that receives the boost state */
|
|
|
|
{
|
|
|
|
if (pstate) *pstate = FALSE;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetThreadPriorityBoost [KERNEL32.@] Sets priority boost for thread.
|
|
|
|
*
|
|
|
|
* Priority boost is not implemented. Thsi function always returns
|
|
|
|
* FALSE and sets last error to ERROR_CALL_NOT_IMPLEMENTED
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Always returns FALSE to indicate a failure
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetThreadPriorityBoost(
|
|
|
|
HANDLE hthread, /* [in] Handle to thread */
|
|
|
|
BOOL disable) /* [in] TRUE to disable priority boost */
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetThreadAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD dwThreadAffinityMask )
|
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
SERVER_START_REQ( set_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = hThread;
|
|
|
|
req->affinity = dwThreadAffinityMask;
|
|
|
|
req->mask = SET_THREAD_INFO_AFFINITY;
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
/* FIXME: should return previous value */
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetThreadIdealProcessor [KERNEL32.@] Obtains timing information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Value of last call to SetThreadIdealProcessor
|
|
|
|
* Failure: -1
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SetThreadIdealProcessor(
|
|
|
|
HANDLE hThread, /* [in] Specifies the thread of interest */
|
|
|
|
DWORD dwIdealProcessor) /* [in] Specifies the new preferred processor */
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n",hThread);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return -1L;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* callback for QueueUserAPC */
|
|
|
|
static void CALLBACK call_user_apc( ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3 )
|
|
|
|
{
|
|
|
|
PAPCFUNC func = (PAPCFUNC)arg1;
|
|
|
|
func( arg2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* QueueUserAPC (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI QueueUserAPC( PAPCFUNC func, HANDLE hthread, ULONG_PTR data )
|
|
|
|
{
|
|
|
|
NTSTATUS status = NtQueueApcThread( hthread, call_user_apc, (ULONG_PTR)func, data, 0 );
|
|
|
|
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
2005-02-21 22:02:12 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* QueueUserWorkItem (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueueUserWorkItem( LPTHREAD_START_ROUTINE Function, PVOID Context, ULONG Flags )
|
|
|
|
{
|
|
|
|
FIXME("(%p,%p,0x%08lx): stub\n", Function, Context, Flags);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetThreadTimes [KERNEL32.@] Obtains timing information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetThreadTimes(
|
|
|
|
HANDLE thread, /* [in] Specifies the thread of interest */
|
|
|
|
LPFILETIME creationtime, /* [out] When the thread was created */
|
|
|
|
LPFILETIME exittime, /* [out] When the thread was destroyed */
|
|
|
|
LPFILETIME kerneltime, /* [out] Time thread spent in kernel mode */
|
|
|
|
LPFILETIME usertime) /* [out] Time thread spent in user mode */
|
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
if (creationtime || exittime)
|
|
|
|
{
|
|
|
|
/* We need to do a server call to get the creation time or exit time */
|
|
|
|
/* This works on any thread */
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_thread_info )
|
|
|
|
{
|
|
|
|
req->handle = thread;
|
|
|
|
req->tid_in = 0;
|
|
|
|
if ((ret = !wine_server_call_err( req )))
|
|
|
|
{
|
|
|
|
if (creationtime)
|
|
|
|
RtlSecondsSince1970ToTime( reply->creation_time, (LARGE_INTEGER*)creationtime );
|
|
|
|
if (exittime)
|
|
|
|
RtlSecondsSince1970ToTime( reply->exit_time, (LARGE_INTEGER*)exittime );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
if (ret && (kerneltime || usertime))
|
|
|
|
{
|
|
|
|
/* We call times(2) for kernel time or user time */
|
|
|
|
/* We can only (portably) do this for the current thread */
|
|
|
|
if (thread == GetCurrentThread())
|
|
|
|
{
|
|
|
|
ULONGLONG time;
|
|
|
|
struct tms time_buf;
|
|
|
|
long clocks_per_sec = sysconf(_SC_CLK_TCK);
|
|
|
|
|
|
|
|
times(&time_buf);
|
|
|
|
if (kerneltime)
|
|
|
|
{
|
|
|
|
time = (ULONGLONG)time_buf.tms_stime * 10000000 / clocks_per_sec;
|
|
|
|
kerneltime->dwHighDateTime = time >> 32;
|
|
|
|
kerneltime->dwLowDateTime = (DWORD)time;
|
|
|
|
}
|
|
|
|
if (usertime)
|
|
|
|
{
|
|
|
|
time = (ULONGLONG)time_buf.tms_utime * 10000000 / clocks_per_sec;
|
|
|
|
usertime->dwHighDateTime = time >> 32;
|
|
|
|
usertime->dwLowDateTime = (DWORD)time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (kerneltime) kerneltime->dwHighDateTime = kerneltime->dwLowDateTime = 0;
|
|
|
|
if (usertime) usertime->dwHighDateTime = usertime->dwLowDateTime = 0;
|
|
|
|
FIXME("Cannot get kerneltime or usertime of other threads\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* VWin32_BoostThreadGroup [KERNEL.535]
|
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_BoostThreadGroup( DWORD threadId, INT boost )
|
|
|
|
{
|
|
|
|
FIXME("(0x%08lx,%d): stub\n", threadId, boost);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* VWin32_BoostThreadStatic [KERNEL.536]
|
|
|
|
*/
|
|
|
|
VOID WINAPI VWin32_BoostThreadStatic( DWORD threadId, INT boost )
|
|
|
|
{
|
|
|
|
FIXME("(0x%08lx,%d): stub\n", threadId, boost);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Pseudohandle for the current thread
|
|
|
|
*/
|
|
|
|
#undef GetCurrentThread
|
|
|
|
HANDLE WINAPI GetCurrentThread(void)
|
|
|
|
{
|
|
|
|
return (HANDLE)0xfffffffe;
|
|
|
|
}
|
2003-10-08 05:57:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __i386__
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetLastError (KERNEL.147)
|
|
|
|
* SetLastError (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* void WINAPI SetLastError( DWORD error ); */
|
|
|
|
__ASM_GLOBAL_FUNC( SetLastError,
|
|
|
|
"movl 4(%esp),%eax\n\t"
|
|
|
|
".byte 0x64\n\t"
|
2003-11-25 02:53:23 +01:00
|
|
|
"movl %eax,0x34\n\t"
|
2004-06-14 19:04:34 +02:00
|
|
|
"ret $4" )
|
2003-10-08 05:57:02 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetLastError (KERNEL.148)
|
|
|
|
* GetLastError (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* DWORD WINAPI GetLastError(void); */
|
2004-06-14 19:04:34 +02:00
|
|
|
__ASM_GLOBAL_FUNC( GetLastError, ".byte 0x64\n\tmovl 0x34,%eax\n\tret" )
|
2003-10-08 05:57:02 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentProcessId (KERNEL.471)
|
|
|
|
* GetCurrentProcessId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* DWORD WINAPI GetCurrentProcessId(void) */
|
2004-06-14 19:04:34 +02:00
|
|
|
__ASM_GLOBAL_FUNC( GetCurrentProcessId, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" )
|
2003-10-08 05:57:02 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentThreadId (KERNEL.462)
|
|
|
|
* GetCurrentThreadId (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
/* DWORD WINAPI GetCurrentThreadId(void) */
|
2004-06-14 19:04:34 +02:00
|
|
|
__ASM_GLOBAL_FUNC( GetCurrentThreadId, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" )
|
2003-10-08 05:57:02 +02:00
|
|
|
|
|
|
|
#else /* __i386__ */
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetLastError (KERNEL.147)
|
|
|
|
* SetLastError (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Sets the last-error code.
|
|
|
|
*/
|
|
|
|
void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
|
|
|
|
{
|
2003-11-25 02:53:23 +01:00
|
|
|
NtCurrentTeb()->LastErrorValue = error;
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetLastError (KERNEL.148)
|
|
|
|
* GetLastError (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Returns last-error code.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetLastError(void)
|
|
|
|
{
|
2003-11-25 02:53:23 +01:00
|
|
|
return NtCurrentTeb()->LastErrorValue;
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentProcessId (KERNEL.471)
|
|
|
|
* GetCurrentProcessId (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Returns process identifier.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetCurrentProcessId(void)
|
|
|
|
{
|
|
|
|
return (DWORD)NtCurrentTeb()->ClientId.UniqueProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentThreadId (KERNEL.462)
|
|
|
|
* GetCurrentThreadId (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Returns thread identifier.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetCurrentThreadId(void)
|
|
|
|
{
|
|
|
|
return (DWORD)NtCurrentTeb()->ClientId.UniqueThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __i386__ */
|