include: Make sure __int64 is correctly defined on PPC64.
[wine.git] / dlls / kernel32 / thread.c
blob1f4f938af5126b2558f3a138d1d4e2a5274fdd55
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 /***********************************************************************
37 * BaseThreadInitThunk (KERNEL32.@)
39 #ifdef __i386__
40 __ASM_FASTCALL_FUNC( BaseThreadInitThunk, 12,
41 "pushl %ebp\n\t"
42 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
43 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
44 "movl %esp,%ebp\n\t"
45 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
46 "pushl %ebx\n\t"
47 __ASM_CFI(".cfi_rel_offset %ebx,-4\n\t")
48 "movl 8(%ebp),%ebx\n\t"
49 /* deliberately mis-align the stack by 8, Doom 3 needs this */
50 "pushl 4(%ebp)\n\t" /* Driller expects readable address at this offset */
51 "pushl 4(%ebp)\n\t"
52 "pushl %ebx\n\t"
53 "call *%edx\n\t"
54 "movl %eax,(%esp)\n\t"
55 "call " __ASM_STDCALL( "RtlExitUserThread", 4 ))
56 #else
57 void __fastcall BaseThreadInitThunk( DWORD unknown, LPTHREAD_START_ROUTINE entry, void *arg )
59 RtlExitUserThread( entry( arg ) );
61 #endif
63 /***********************************************************************
64 * FreeLibraryAndExitThread (KERNEL32.@)
66 void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
68 FreeLibrary(hLibModule);
69 ExitThread(dwExitCode);
73 /***********************************************************************
74 * Wow64SetThreadContext [KERNEL32.@]
76 BOOL WINAPI Wow64SetThreadContext( HANDLE handle, const WOW64_CONTEXT *context)
78 #ifdef __i386__
79 return set_ntstatus( NtSetContextThread( handle, (const CONTEXT *)context ));
80 #elif defined(__x86_64__)
81 return set_ntstatus( RtlWow64SetThreadContext( handle, context ));
82 #else
83 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
84 #endif
87 /***********************************************************************
88 * Wow64GetThreadContext [KERNEL32.@]
90 BOOL WINAPI Wow64GetThreadContext( HANDLE handle, WOW64_CONTEXT *context)
92 #ifdef __i386__
93 return set_ntstatus( NtGetContextThread( handle, (CONTEXT *)context ));
94 #elif defined(__x86_64__)
95 return set_ntstatus( RtlWow64GetThreadContext( handle, context ));
96 #else
97 return set_ntstatus( STATUS_NOT_IMPLEMENTED );
98 #endif
102 /**********************************************************************
103 * SetThreadAffinityMask (KERNEL32.@)
105 DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE thread, DWORD_PTR mask )
107 THREAD_BASIC_INFORMATION tbi;
109 if (!set_ntstatus( NtQueryInformationThread( thread, ThreadBasicInformation, &tbi, sizeof(tbi), NULL )))
110 return 0;
111 if (!set_ntstatus( NtSetInformationThread( thread, ThreadAffinityMask, &mask, sizeof(mask))))
112 return 0;
113 return tbi.AffinityMask;
117 /***********************************************************************
118 * GetThreadSelectorEntry (KERNEL32.@)
120 BOOL WINAPI GetThreadSelectorEntry( HANDLE thread, DWORD sel, LDT_ENTRY *ldtent )
122 THREAD_DESCRIPTOR_INFORMATION tdi;
124 tdi.Selector = sel;
125 if (!set_ntstatus( NtQueryInformationThread( thread, ThreadDescriptorTableEntry,
126 &tdi, sizeof(tdi), NULL )))
127 return FALSE;
128 *ldtent = tdi.Entry;
129 return TRUE;
133 /***********************************************************************
134 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
136 * RETURNS
137 * Pseudohandle for the current thread
139 HANDLE WINAPI KERNEL32_GetCurrentThread(void)
141 return (HANDLE)~(ULONG_PTR)1;
144 /***********************************************************************
145 * GetCurrentProcessId (KERNEL32.@)
147 * Get the current process identifier.
149 * RETURNS
150 * current process identifier
152 DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
154 return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
157 /***********************************************************************
158 * GetCurrentThreadId (KERNEL32.@)
160 * Get the current thread identifier.
162 * RETURNS
163 * current thread identifier
165 DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
167 return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);