2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Rtl user thread functions
5 * FILE: lib/ntdll/rtl/thread.c
9 * 09/10/99: Cleanup and full stack support.
10 * 25/04/03: Near rewrite. Made code more readable, replaced
11 * INITIAL_TEB with USER_STACK, added support for
13 * 28/04/03: Moved all code to a new statically linked
14 * library (ROSRTL) so it can be shared with
15 * kernel32.dll without exporting non-standard
16 * functions from ntdll.dll
19 /* INCLUDES *****************************************************************/
21 #include <ddk/ntddk.h>
23 #include <ntdll/rtl.h>
24 #include <rosrtl/thread.h>
27 #include <ntdll/ntdll.h>
29 /* FUNCTIONS ***************************************************************/
31 NTSTATUS STDCALL RtlCreateUserThread
34 PSECURITY_DESCRIPTOR SecurityDescriptor,
35 BOOLEAN CreateSuspended,
39 PTHREAD_START_ROUTINE StartAddress,
45 OBJECT_ATTRIBUTES oaThreadAttribs;
47 InitializeObjectAttributes
56 return RtlRosCreateUserThreadEx
68 (ULONG_PTR *)&Parameter
72 NTSTATUS STDCALL RtlInitializeContext
77 PTHREAD_START_ROUTINE StartAddress,
81 return RtlRosInitializeContextEx
88 (ULONG_PTR *)&Parameter
92 NTSTATUS STDCALL RtlFreeUserThreadStack
98 THREAD_BASIC_INFORMATION tbiInfo;
105 /* query basic information about the thread */
106 nErrCode = NtQueryInformationThread
109 ThreadBasicInformation,
116 if(!NT_SUCCESS(nErrCode)) return nErrCode;
117 if(tbiInfo.TebBaseAddress == NULL) return STATUS_ACCESS_VIOLATION;
119 pTeb = (PTEB)tbiInfo.TebBaseAddress;
121 /* read the base address of the stack to be deallocated */
122 nErrCode = NtReadVirtualMemory
125 &pTeb->DeallocationStack,
132 if(!NT_SUCCESS(nErrCode)) return nErrCode;
133 if(pStackBase == NULL) return STATUS_ACCESS_VIOLATION;
135 /* deallocate the stack */
136 nErrCode = NtFreeVirtualMemory(ProcessHandle, pStackBase, &nSize, MEM_RELEASE);
141 NTSTATUS STDCALL RtlExitUserThread(NTSTATUS nErrCode)
143 return NtTerminateThread(NtCurrentThread(), nErrCode);