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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-06-24 05:34:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "ntstatus.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-06-24 05:34:15 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2008-07-03 12:57:43 +02:00
|
|
|
#include "winternl.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-06-24 05:34:15 +02:00
|
|
|
#include "wine/server.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2003-06-24 05:34:15 +02:00
|
|
|
#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
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FreeLibraryAndExitThread (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
|
|
|
|
{
|
|
|
|
FreeLibrary(hLibModule);
|
|
|
|
ExitThread(dwExitCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-06 20:30:20 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Wow64SetThreadContext [KERNEL32.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Wow64SetThreadContext( HANDLE handle, const WOW64_CONTEXT *context)
|
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
NTSTATUS status = NtSetContextThread( handle, (const CONTEXT *)context );
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
NTSTATUS status = RtlWow64SetThreadContext( handle, context );
|
|
|
|
#else
|
|
|
|
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
FIXME("not implemented on this platform\n");
|
|
|
|
#endif
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
2018-06-06 20:30:19 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Wow64GetThreadContext [KERNEL32.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Wow64GetThreadContext( HANDLE handle, WOW64_CONTEXT *context)
|
|
|
|
{
|
|
|
|
#ifdef __i386__
|
|
|
|
NTSTATUS status = NtGetContextThread( handle, (CONTEXT *)context );
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
NTSTATUS status = RtlWow64GetThreadContext( handle, context );
|
|
|
|
#else
|
|
|
|
NTSTATUS status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
FIXME("not implemented on this platform\n");
|
|
|
|
#endif
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 05:34:15 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* SetThreadAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
2007-05-21 15:12:50 +02:00
|
|
|
DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD_PTR dwThreadAffinityMask )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2006-01-11 12:32:19 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
THREAD_BASIC_INFORMATION tbi;
|
|
|
|
|
|
|
|
status = NtQueryInformationThread( hThread, ThreadBasicInformation,
|
|
|
|
&tbi, sizeof(tbi), NULL );
|
|
|
|
if (status)
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2006-01-11 12:32:19 +01:00
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
2006-01-11 12:32:19 +01:00
|
|
|
status = NtSetInformationThread( hThread, ThreadAffinityMask,
|
|
|
|
&dwThreadAffinityMask,
|
|
|
|
sizeof(dwThreadAffinityMask));
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return tbi.AffinityMask;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 19:58:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetThreadSelectorEntry (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldtent )
|
|
|
|
{
|
|
|
|
THREAD_DESCRIPTOR_INFORMATION tdi;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
tdi.Selector = sel;
|
|
|
|
status = NtQueryInformationThread( hthread, ThreadDescriptorTableEntry, &tdi, sizeof(tdi), NULL);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*ldtent = tdi.Entry;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-21 22:02:12 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* QueueUserWorkItem (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI QueueUserWorkItem( LPTHREAD_START_ROUTINE Function, PVOID Context, ULONG Flags )
|
|
|
|
{
|
2006-03-13 12:29:04 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%p,%p,0x%08x)\n", Function, Context, Flags);
|
2006-03-13 12:29:04 +01:00
|
|
|
|
|
|
|
status = RtlQueueWorkItem( Function, Context, Flags );
|
|
|
|
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
2005-02-21 22:02:12 +01:00
|
|
|
}
|
2003-06-24 05:34:15 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Pseudohandle for the current thread
|
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
HANDLE WINAPI KERNEL32_GetCurrentThread(void)
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2008-12-08 15:51:22 +01:00
|
|
|
return (HANDLE)~(ULONG_PTR)1;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
2003-10-08 05:57:02 +02:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* SetLastError (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Sets the last-error code.
|
2005-11-08 12:01:03 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
2003-10-08 05:57:02 +02:00
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
void WINAPI KERNEL32_SetLastError( DWORD error ) /* [in] Per-thread error code */
|
2003-10-08 05:57:02 +02:00
|
|
|
{
|
2003-11-25 02:53:23 +01:00
|
|
|
NtCurrentTeb()->LastErrorValue = error;
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* GetLastError (KERNEL32.@)
|
|
|
|
*
|
2005-11-08 12:01:03 +01:00
|
|
|
* Get the last-error code.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* last-error code.
|
2003-10-08 05:57:02 +02:00
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
DWORD WINAPI KERNEL32_GetLastError(void)
|
2003-10-08 05:57:02 +02:00
|
|
|
{
|
2003-11-25 02:53:23 +01:00
|
|
|
return NtCurrentTeb()->LastErrorValue;
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentProcessId (KERNEL32.@)
|
|
|
|
*
|
2005-11-08 12:01:03 +01:00
|
|
|
* Get the current process identifier.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* current process identifier
|
2003-10-08 05:57:02 +02:00
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
|
2003-10-08 05:57:02 +02:00
|
|
|
{
|
2007-05-23 09:36:53 +02:00
|
|
|
return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetCurrentThreadId (KERNEL32.@)
|
|
|
|
*
|
2005-11-08 12:01:03 +01:00
|
|
|
* Get the current thread identifier.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* current thread identifier
|
2003-10-08 05:57:02 +02:00
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
|
2003-10-08 05:57:02 +02:00
|
|
|
{
|
2007-05-23 09:36:53 +02:00
|
|
|
return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);
|
2003-10-08 05:57:02 +02:00
|
|
|
}
|
|
|
|
|
2010-05-07 14:07:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetProcessHeap (KERNEL32.@)
|
|
|
|
*/
|
2019-06-26 12:41:22 +02:00
|
|
|
HANDLE WINAPI KERNEL32_GetProcessHeap(void)
|
2010-05-07 14:07:45 +02:00
|
|
|
{
|
|
|
|
return NtCurrentTeb()->Peb->ProcessHeap;
|
|
|
|
}
|
|
|
|
|
2015-07-03 02:00:14 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* CallbackMayRunLong (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CallbackMayRunLong( TP_CALLBACK_INSTANCE *instance )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
TRACE( "%p\n", instance );
|
|
|
|
|
|
|
|
status = TpCallbackMayRunLong( instance );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|