makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / kernel32 / thread.c
blobc0b36fae668f8bd0a8a7213cb29147b62ce9966e
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 "config.h"
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <sys/types.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winerror.h"
32 #include "winternl.h"
34 #include "kernel_private.h"
37 /***********************************************************************
38 * FreeLibraryAndExitThread (KERNEL32.@)
40 void WINAPI FreeLibraryAndExitThread(HINSTANCE hLibModule, DWORD dwExitCode)
42 FreeLibrary(hLibModule);
43 ExitThread(dwExitCode);
47 /***********************************************************************
48 * Wow64SetThreadContext [KERNEL32.@]
50 BOOL WINAPI Wow64SetThreadContext( HANDLE handle, const WOW64_CONTEXT *context)
52 #ifdef __i386__
53 NTSTATUS status = NtSetContextThread( handle, (const CONTEXT *)context );
54 #elif defined(__x86_64__)
55 NTSTATUS status = RtlWow64SetThreadContext( handle, context );
56 #else
57 NTSTATUS status = STATUS_NOT_IMPLEMENTED;
58 #endif
59 if (status) SetLastError( RtlNtStatusToDosError(status) );
60 return !status;
63 /***********************************************************************
64 * Wow64GetThreadContext [KERNEL32.@]
66 BOOL WINAPI Wow64GetThreadContext( HANDLE handle, WOW64_CONTEXT *context)
68 #ifdef __i386__
69 NTSTATUS status = NtGetContextThread( handle, (CONTEXT *)context );
70 #elif defined(__x86_64__)
71 NTSTATUS status = RtlWow64GetThreadContext( handle, context );
72 #else
73 NTSTATUS status = STATUS_NOT_IMPLEMENTED;
74 #endif
75 if (status) SetLastError( RtlNtStatusToDosError(status) );
76 return !status;
80 /**********************************************************************
81 * SetThreadAffinityMask (KERNEL32.@)
83 DWORD_PTR WINAPI SetThreadAffinityMask( HANDLE hThread, DWORD_PTR dwThreadAffinityMask )
85 NTSTATUS status;
86 THREAD_BASIC_INFORMATION tbi;
88 status = NtQueryInformationThread( hThread, ThreadBasicInformation,
89 &tbi, sizeof(tbi), NULL );
90 if (status)
92 SetLastError( RtlNtStatusToDosError(status) );
93 return 0;
95 status = NtSetInformationThread( hThread, ThreadAffinityMask,
96 &dwThreadAffinityMask,
97 sizeof(dwThreadAffinityMask));
98 if (status)
100 SetLastError( RtlNtStatusToDosError(status) );
101 return 0;
103 return tbi.AffinityMask;
107 /***********************************************************************
108 * GetThreadSelectorEntry (KERNEL32.@)
110 BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldtent )
112 THREAD_DESCRIPTOR_INFORMATION tdi;
113 NTSTATUS status;
115 tdi.Selector = sel;
116 status = NtQueryInformationThread( hthread, ThreadDescriptorTableEntry, &tdi, sizeof(tdi), NULL);
117 if (status)
119 SetLastError( RtlNtStatusToDosError(status) );
120 return FALSE;
122 *ldtent = tdi.Entry;
123 return TRUE;
127 /***********************************************************************
128 * GetCurrentThread [KERNEL32.@] Gets pseudohandle for current thread
130 * RETURNS
131 * Pseudohandle for the current thread
133 HANDLE WINAPI KERNEL32_GetCurrentThread(void)
135 return (HANDLE)~(ULONG_PTR)1;
138 /***********************************************************************
139 * GetCurrentProcessId (KERNEL32.@)
141 * Get the current process identifier.
143 * RETURNS
144 * current process identifier
146 DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
148 return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
151 /***********************************************************************
152 * GetCurrentThreadId (KERNEL32.@)
154 * Get the current thread identifier.
156 * RETURNS
157 * current thread identifier
159 DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
161 return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);