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
23 #include <sys/types.h>
26 #define WIN32_NO_STATUS
33 #include "wine/debug.h"
34 #include "kernel_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(thread
);
38 /***********************************************************************
39 * BaseThreadInitThunk (KERNEL32.@)
42 __ASM_FASTCALL_FUNC( BaseThreadInitThunk
, 12,
44 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
45 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
47 __ASM_CFI(".cfi_def_cfa_register %ebp\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 */
56 "movl %eax,(%esp)\n\t"
57 "call " __ASM_STDCALL( "RtlExitUserThread", 4 ))
59 void __fastcall
BaseThreadInitThunk( DWORD unknown
, LPTHREAD_START_ROUTINE entry
, void *arg
)
61 RtlExitUserThread( entry( arg
) );
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
)
81 return set_ntstatus( NtSetContextThread( handle
, (const CONTEXT
*)context
));
82 #elif defined(__x86_64__)
83 return set_ntstatus( RtlWow64SetThreadContext( handle
, context
));
85 return set_ntstatus( STATUS_NOT_IMPLEMENTED
);
89 /***********************************************************************
90 * Wow64GetThreadContext [KERNEL32.@]
92 BOOL WINAPI
Wow64GetThreadContext( HANDLE handle
, WOW64_CONTEXT
*context
)
95 return set_ntstatus( NtGetContextThread( handle
, (CONTEXT
*)context
));
96 #elif defined(__x86_64__)
97 return set_ntstatus( RtlWow64GetThreadContext( handle
, context
));
99 return set_ntstatus( STATUS_NOT_IMPLEMENTED
);
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
)))
123 if (!set_ntstatus( NtSetInformationThread( thread
, ThreadAffinityMask
, &mask
, sizeof(mask
))))
125 return tbi
.AffinityMask
;
129 /***********************************************************************
130 * GetThreadSelectorEntry (KERNEL32.@)
132 BOOL WINAPI
GetThreadSelectorEntry( HANDLE thread
, DWORD sel
, LDT_ENTRY
*ldtent
)
134 THREAD_DESCRIPTOR_INFORMATION tdi
;
137 if (!set_ntstatus( NtQueryInformationThread( thread
, ThreadDescriptorTableEntry
,
138 &tdi
, sizeof(tdi
), NULL
)))
145 /***********************************************************************
146 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
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.
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.
175 * current thread identifier
177 DWORD WINAPI
KERNEL32_GetCurrentThreadId(void)
179 return HandleToULong(NtCurrentTeb()->ClientId
.UniqueThread
);