mfmediaengine: Remove unnecessary import library.
[wine.git] / dlls / kernel32 / thread.c
blob050bd41655332c0f04b08afd7d63e8101bed38f8
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 "wine/debug.h"
34 #include "kernel_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(thread);
38 /***********************************************************************
39 * BaseThreadInitThunk (KERNEL32.@)
41 #ifdef __i386__
42 __ASM_FASTCALL_FUNC( BaseThreadInitThunk, 12,
43 "pushl %ebp\n\t"
44 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
45 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
46 "movl %esp,%ebp\n\t"
47 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
48 "pushl %ebx\n\t"
49 __ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
50 "movl 8(%ebp),%ebx\n\t"
51 /* deliberately mis-align the stack by 8, Doom 3 needs this */
52 "pushl 4(%ebp)\n\t" /* Driller expects readable address at this offset */
53 "pushl 4(%ebp)\n\t"
54 "pushl %ebx\n\t"
55 "call *%edx\n\t"
56 "movl %eax,(%esp)\n\t"
57 "call " __ASM_STDCALL( "RtlExitUserThread", 4 ))
58 #else
59 void __fastcall BaseThreadInitThunk( DWORD unknown, LPTHREAD_START_ROUTINE entry, void *arg )
61 RtlExitUserThread( entry( arg ) );
63 #endif
65 /***********************************************************************
66 * FreeLibraryAndExitThread (KERNEL32.@)
68 void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
70 FreeLibrary(hLibModule);
71 ExitThread(dwExitCode);
75 /***********************************************************************
76 * Wow64SetThreadContext [KERNEL32.@]
78 BOOL WINAPI Wow64SetThreadContext( HANDLE handle, const WOW64_CONTEXT *context)
80 #ifdef __i386__
81 return set_ntstatus( NtSetContextThread( handle, (const CONTEXT *)context ));
82 #elif defined(__x86_64__)
83 return set_ntstatus( RtlWow64SetThreadContext( handle, context ));
84 #else
85 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
86 #endif
89 /***********************************************************************
90 * Wow64GetThreadContext [KERNEL32.@]
92 BOOL WINAPI Wow64GetThreadContext( HANDLE handle, WOW64_CONTEXT *context)
94 #ifdef __i386__
95 return set_ntstatus( NtGetContextThread( handle, (CONTEXT *)context ));
96 #elif defined(__x86_64__)
97 return set_ntstatus( RtlWow64GetThreadContext( handle, context ));
98 #else
99 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
100 #endif
104 /***********************************************************************
105 * Wow64GetThreadSelectorEntry [KERNEL32.@]
107 BOOL WINAPI Wow64GetThreadSelectorEntry( HANDLE thread, DWORD selector, WOW64_LDT_ENTRY *selector_entry)
109 FIXME("(%p %u %p): stub\n", thread, selector, selector_entry);
110 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
114 /**********************************************************************
115 * SetThreadAffinityMask (KERNEL32.@)
117 DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE thread, DWORD_PTR mask )
119 THREAD_BASIC_INFORMATION tbi;
121 if (!set_ntstatus( NtQueryInformationThread( thread, ThreadBasicInformation, &tbi, sizeof(tbi), NULL )))
122 return 0;
123 if (!set_ntstatus( NtSetInformationThread( thread, ThreadAffinityMask, &mask, sizeof(mask))))
124 return 0;
125 return tbi.AffinityMask;
129 /***********************************************************************
130 * GetThreadSelectorEntry (KERNEL32.@)
132 BOOL WINAPI GetThreadSelectorEntry( HANDLE thread, DWORD sel, LDT_ENTRY *ldtent )
134 THREAD_DESCRIPTOR_INFORMATION tdi;
136 tdi.Selector = sel;
137 if (!set_ntstatus( NtQueryInformationThread( thread, ThreadDescriptorTableEntry,
138 &tdi, sizeof(tdi), NULL )))
139 return FALSE;
140 *ldtent = tdi.Entry;
141 return TRUE;
145 /***********************************************************************
146 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
148 * RETURNS
149 * Pseudohandle for the current thread
151 HANDLE WINAPI KERNEL32_GetCurrentThread(void)
153 return (HANDLE)~(ULONG_PTR)1;
156 /***********************************************************************
157 * GetCurrentProcessId (KERNEL32.@)
159 * Get the current process identifier.
161 * RETURNS
162 * current process identifier
164 DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
166 return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
169 /***********************************************************************
170 * GetCurrentThreadId (KERNEL32.@)
172 * Get the current thread identifier.
174 * RETURNS
175 * current thread identifier
177 DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
179 return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);