4 * Copyright 1996, 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/server.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(thread);
30 /***********************************************************************
31 * NtOpenThread (NTDLL.@)
32 * ZwOpenThread (NTDLL.@)
34 NTSTATUS WINAPI NtOpenThread( HANDLE *handle, ACCESS_MASK access,
35 const OBJECT_ATTRIBUTES *attr, const CLIENT_ID *id )
39 SERVER_START_REQ( open_thread )
41 req->tid = (thread_id_t)id->UniqueThread;
43 req->inherit = attr && (attr->Attributes & OBJ_INHERIT);
44 ret = wine_server_call( req );
45 *handle = reply->handle;
52 /******************************************************************************
53 * NtSuspendThread (NTDLL.@)
54 * ZwSuspendThread (NTDLL.@)
56 NTSTATUS WINAPI NtSuspendThread( HANDLE handle, PULONG count )
60 SERVER_START_REQ( suspend_thread )
63 if (!(ret = wine_server_call( req ))) *count = reply->count;
70 /******************************************************************************
71 * NtResumeThread (NTDLL.@)
72 * ZwResumeThread (NTDLL.@)
74 NTSTATUS WINAPI NtResumeThread( HANDLE handle, PULONG count )
78 SERVER_START_REQ( resume_thread )
81 if (!(ret = wine_server_call( req ))) *count = reply->count;
88 /******************************************************************************
89 * NtTerminateThread (NTDLL.@)
90 * ZwTerminateThread (NTDLL.@)
92 NTSTATUS WINAPI NtTerminateThread( HANDLE handle, LONG exit_code )
97 SERVER_START_REQ( terminate_thread )
100 req->exit_code = exit_code;
101 ret = wine_server_call( req );
102 self = !ret && reply->self;
109 if (last) exit( exit_code );
113 RemoveEntryList( &NtCurrentTeb()->TlsLinks );
115 SYSDEPS_ExitThread( exit_code );
122 /******************************************************************************
123 * NtQueueApcThread (NTDLL.@)
125 NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1,
126 ULONG_PTR arg2, ULONG_PTR arg3 )
129 SERVER_START_REQ( queue_apc )
131 req->handle = handle;
134 req->arg1 = (void *)arg1;
135 req->arg2 = (void *)arg2;
136 req->arg3 = (void *)arg3;
137 ret = wine_server_call( req );
144 /***********************************************************************
145 * NtSetContextThread (NTDLL.@)
146 * ZwSetContextThread (NTDLL.@)
148 NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
152 SERVER_START_REQ( set_thread_context )
154 req->handle = handle;
155 req->flags = context->ContextFlags;
156 wine_server_add_data( req, context, sizeof(*context) );
157 ret = wine_server_call( req );
164 /***********************************************************************
165 * NtGetContextThread (NTDLL.@)
166 * ZwGetContextThread (NTDLL.@)
168 NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
172 SERVER_START_REQ( get_thread_context )
174 req->handle = handle;
175 req->flags = context->ContextFlags;
176 wine_server_add_data( req, context, sizeof(*context) );
177 wine_server_set_reply( req, context, sizeof(*context) );
178 ret = wine_server_call( req );
185 /******************************************************************************
186 * NtQueryInformationThread (NTDLL.@)
187 * ZwQueryInformationThread (NTDLL.@)
189 NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
190 void *data, ULONG length, ULONG *ret_len )
196 case ThreadBasicInformation:
198 THREAD_BASIC_INFORMATION info;
200 SERVER_START_REQ( get_thread_info )
202 req->handle = handle;
204 if (!(status = wine_server_call( req )))
206 info.ExitStatus = reply->exit_code;
207 info.TebBaseAddress = reply->teb;
208 info.ClientId.UniqueProcess = (HANDLE)reply->pid;
209 info.ClientId.UniqueThread = (HANDLE)reply->tid;
210 info.AffinityMask = reply->affinity;
211 info.Priority = reply->priority;
212 info.BasePriority = reply->priority; /* FIXME */
216 if (status == STATUS_SUCCESS)
218 if (data) memcpy( data, &info, min( length, sizeof(info) ));
219 if (ret_len) *ret_len = min( length, sizeof(info) );
225 case ThreadBasePriority:
226 case ThreadAffinityMask:
227 case ThreadImpersonationToken:
228 case ThreadDescriptorTableEntry:
229 case ThreadEnableAlignmentFaultFixup:
230 case ThreadEventPair_Reusable:
231 case ThreadQuerySetWin32StartAddress:
232 case ThreadZeroTlsCell:
233 case ThreadPerformanceCount:
234 case ThreadAmILastThread:
235 case ThreadIdealProcessor:
236 case ThreadPriorityBoost:
237 case ThreadSetTlsArrayAddress:
238 case ThreadIsIoPending:
240 FIXME( "info class %d not supported yet\n", class );
241 return STATUS_NOT_IMPLEMENTED;
246 /******************************************************************************
247 * NtSetInformationThread (NTDLL.@)
248 * ZwSetInformationThread (NTDLL.@)
250 NTSTATUS WINAPI NtSetInformationThread( HANDLE handle, THREADINFOCLASS class,
251 LPCVOID data, ULONG length )
255 case ThreadZeroTlsCell:
256 if (handle == GetCurrentThread())
258 LIST_ENTRY *entry = &NtCurrentTeb()->TlsLinks;
261 if (length != sizeof(DWORD)) return STATUS_INVALID_PARAMETER;
262 index = *(DWORD *)data;
263 if (index >= 64) return STATUS_INVALID_PARAMETER;
267 TEB *teb = CONTAINING_RECORD(entry, TEB, TlsLinks);
268 teb->TlsSlots[index] = 0;
269 entry = entry->Flink;
270 } while (entry != &NtCurrentTeb()->TlsLinks);
272 return STATUS_SUCCESS;
274 FIXME( "ZeroTlsCell not supported on other threads\n" );
275 return STATUS_NOT_IMPLEMENTED;
277 case ThreadBasicInformation:
280 case ThreadBasePriority:
281 case ThreadAffinityMask:
282 case ThreadImpersonationToken:
283 case ThreadDescriptorTableEntry:
284 case ThreadEnableAlignmentFaultFixup:
285 case ThreadEventPair_Reusable:
286 case ThreadQuerySetWin32StartAddress:
287 case ThreadPerformanceCount:
288 case ThreadAmILastThread:
289 case ThreadIdealProcessor:
290 case ThreadPriorityBoost:
291 case ThreadSetTlsArrayAddress:
292 case ThreadIsIoPending:
294 FIXME( "info class %d not supported yet\n", class );
295 return STATUS_NOT_IMPLEMENTED;