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 <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-06-24 05:34:15 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
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-06-24 05:34:15 +02:00
|
|
|
|
2005-06-14 13:42:34 +02:00
|
|
|
#include "kernel_private.h"
|
|
|
|
|
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__
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( NtSetContextThread( handle, (const CONTEXT *)context ));
|
2018-06-06 20:30:20 +02:00
|
|
|
#elif defined(__x86_64__)
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( RtlWow64SetThreadContext( handle, context ));
|
2018-06-06 20:30:20 +02:00
|
|
|
#else
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( STATUS_NOT_IMPLEMENTED );
|
2018-06-06 20:30:20 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-06-06 20:30:19 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Wow64GetThreadContext [KERNEL32.@]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Wow64GetThreadContext( HANDLE handle, WOW64_CONTEXT *context)
|
|
|
|
{
|
|
|
|
#ifdef __i386__
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( NtGetContextThread( handle, (CONTEXT *)context ));
|
2018-06-06 20:30:19 +02:00
|
|
|
#elif defined(__x86_64__)
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( RtlWow64GetThreadContext( handle, context ));
|
2018-06-06 20:30:19 +02:00
|
|
|
#else
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( STATUS_NOT_IMPLEMENTED );
|
2018-06-06 20:30:19 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 05:34:15 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* SetThreadAffinityMask (KERNEL32.@)
|
|
|
|
*/
|
2020-05-26 12:29:06 +02:00
|
|
|
DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE thread, DWORD_PTR mask )
|
2003-06-24 05:34:15 +02:00
|
|
|
{
|
2020-05-26 12:29:06 +02:00
|
|
|
THREAD_BASIC_INFORMATION tbi;
|
|
|
|
|
|
|
|
if (!set_ntstatus( NtQueryInformationThread( thread, ThreadBasicInformation, &tbi, sizeof(tbi), NULL )))
|
2006-01-11 12:32:19 +01:00
|
|
|
return 0;
|
2020-05-26 12:29:06 +02:00
|
|
|
if (!set_ntstatus( NtSetInformationThread( thread, ThreadAffinityMask, &mask, sizeof(mask))))
|
2006-01-11 12:32:19 +01:00
|
|
|
return 0;
|
|
|
|
return tbi.AffinityMask;
|
2003-06-24 05:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-28 19:58:45 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetThreadSelectorEntry (KERNEL32.@)
|
|
|
|
*/
|
2020-05-26 12:29:06 +02:00
|
|
|
BOOL WINAPI GetThreadSelectorEntry( HANDLE thread, DWORD sel, LDT_ENTRY *ldtent )
|
2009-09-28 19:58:45 +02:00
|
|
|
{
|
|
|
|
THREAD_DESCRIPTOR_INFORMATION tdi;
|
|
|
|
|
|
|
|
tdi.Selector = sel;
|
2020-05-26 12:29:06 +02:00
|
|
|
if (!set_ntstatus( NtQueryInformationThread( thread, ThreadDescriptorTableEntry,
|
|
|
|
&tdi, sizeof(tdi), NULL )))
|
2009-09-28 19:58:45 +02:00
|
|
|
return FALSE;
|
|
|
|
*ldtent = tdi.Entry;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
}
|