ntdll: Fix SMT CPU flag reporting.
[wine/zf.git] / dlls / kernel32 / thread.c
blob1cd309d84b4547a56a8a146038483f5ad8293828
1 /*
2 * Win32 threads
4 * Copyright 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <sys/types.h>
25 #include "ntstatus.h"
26 #define WIN32_NO_STATUS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "winternl.h"
32 #include "wine/asm.h"
33 #include "kernel_private.h"
36 #ifdef __i386__
37 __ASM_STDCALL_FUNC( __fastcall_BaseThreadInitThunk, 12,
38 "pushl %ebp\n\t"
39 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
40 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
41 "movl %esp,%ebp\n\t"
42 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
43 "pushl %ebx\n\t"
44 __ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
45 "movl 8(%ebp),%ebx\n\t"
46 /* deliberately mis-align the stack by 8, Doom 3 needs this */
47 "pushl 4(%ebp)\n\t" /* Driller expects readable address at this offset */
48 "pushl 4(%ebp)\n\t"
49 "pushl %ebx\n\t"
50 "call *%edx\n\t"
51 "movl %eax,(%esp)\n\t"
52 "call " __ASM_STDCALL( "RtlExitUserThread", 4 ))
53 #endif
55 /***********************************************************************
56 * BaseThreadInitThunk (KERNEL32.@)
58 void __fastcall BaseThreadInitThunk( DWORD unknown, LPTHREAD_START_ROUTINE entry, void *arg )
60 RtlExitUserThread( entry( arg ) );
64 /***********************************************************************
65 * FreeLibraryAndExitThread (KERNEL32.@)
67 void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
69 FreeLibrary(hLibModule);
70 ExitThread(dwExitCode);
74 /***********************************************************************
75 * Wow64SetThreadContext [KERNEL32.@]
77 BOOL WINAPI Wow64SetThreadContext( HANDLE handle, const WOW64_CONTEXT *context)
79 #ifdef __i386__
80 return set_ntstatus( NtSetContextThread( handle, (const CONTEXT *)context ));
81 #elif defined(__x86_64__)
82 return set_ntstatus( RtlWow64SetThreadContext( handle, context ));
83 #else
84 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
85 #endif
88 /***********************************************************************
89 * Wow64GetThreadContext [KERNEL32.@]
91 BOOL WINAPI Wow64GetThreadContext( HANDLE handle, WOW64_CONTEXT *context)
93 #ifdef __i386__
94 return set_ntstatus( NtGetContextThread( handle, (CONTEXT *)context ));
95 #elif defined(__x86_64__)
96 return set_ntstatus( RtlWow64GetThreadContext( handle, context ));
97 #else
98 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
99 #endif
103 /**********************************************************************
104 * SetThreadAffinityMask (KERNEL32.@)
106 DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE thread, DWORD_PTR mask )
108 THREAD_BASIC_INFORMATION tbi;
110 if (!set_ntstatus( NtQueryInformationThread( thread, ThreadBasicInformation, &tbi, sizeof(tbi), NULL )))
111 return 0;
112 if (!set_ntstatus( NtSetInformationThread( thread, ThreadAffinityMask, &mask, sizeof(mask))))
113 return 0;
114 return tbi.AffinityMask;
118 /***********************************************************************
119 * GetThreadSelectorEntry (KERNEL32.@)
121 BOOL WINAPI GetThreadSelectorEntry( HANDLE thread, DWORD sel, LDT_ENTRY *ldtent )
123 THREAD_DESCRIPTOR_INFORMATION tdi;
125 tdi.Selector = sel;
126 if (!set_ntstatus( NtQueryInformationThread( thread, ThreadDescriptorTableEntry,
127 &tdi, sizeof(tdi), NULL )))
128 return FALSE;
129 *ldtent = tdi.Entry;
130 return TRUE;
134 /***********************************************************************
135 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
137 * RETURNS
138 * Pseudohandle for the current thread
140 HANDLE WINAPI KERNEL32_GetCurrentThread(void)
142 return (HANDLE)~(ULONG_PTR)1;
145 /***********************************************************************
146 * GetCurrentProcessId (KERNEL32.@)
148 * Get the current process identifier.
150 * RETURNS
151 * current process identifier
153 DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
155 return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
158 /***********************************************************************
159 * GetCurrentThreadId (KERNEL32.@)
161 * Get the current thread identifier.
163 * RETURNS
164 * current thread identifier
166 DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
168 return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);