/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
- * FILE: lib/kernel32/thread/thread.c
+ * FILE: dll/win32/kernel32/client/thread.c
* PURPOSE: Thread functions
- * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
- * Ariadne ( ariadne@xs4all.nl)
+ * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
+ * Ariadne (ariadne@xs4all.nl)
*
*/
/* FUNCTIONS ******************************************************************/
-static
-LONG BaseThreadExceptionFilter(EXCEPTION_POINTERS * ExceptionInfo)
-{
- LONG ExceptionDisposition = EXCEPTION_EXECUTE_HANDLER;
- LPTOP_LEVEL_EXCEPTION_FILTER RealFilter;
- RealFilter = RtlDecodePointer(GlobalTopLevelExceptionFilter);
-
- if (RealFilter != NULL)
- {
- _SEH2_TRY
- {
- ExceptionDisposition = RealFilter(ExceptionInfo);
- }
- _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
- {
- ExceptionDisposition = UnhandledExceptionFilter(ExceptionInfo);
- }
- _SEH2_END;
- }
-
- return ExceptionDisposition;
-}
-
__declspec(noreturn)
VOID
WINAPI
/* Get the exit code from the Thread Start */
ExitThread((lpStartAddress)((PVOID)lpParameter));
}
- _SEH2_EXCEPT(BaseThreadExceptionFilter(_SEH2_GetExceptionInformation()))
+ _SEH2_EXCEPT(UnhandledExceptionFilter(_SEH2_GetExceptionInformation()))
{
/* Get the Exit code from the SEH Handler */
if (!BaseRunningInServerProcess)
*/
HANDLE
WINAPI
+DECLSPEC_HOTPATCH
CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
IN DWORD dwStackSize,
IN LPTHREAD_START_ROUTINE lpStartAddress,
ULONG Dummy;
PTEB Teb;
THREAD_BASIC_INFORMATION ThreadBasicInfo;
- PVOID ActivationContextStack = NULL;
+ PACTIVATION_CONTEXT_STACK ActivationContextStack = NULL;
ACTIVATION_CONTEXT_BASIC_INFORMATION ActCtxInfo;
ULONG_PTR Cookie;
ULONG ReturnLength;
- DPRINT("CreateRemoteThread: hProcess: %ld dwStackSize: %ld lpStartAddress"
- ": %p lpParameter: %lx, dwCreationFlags: %lx\n", hProcess,
+ SIZE_T ReturnSize;
+ DPRINT("CreateRemoteThread: hProcess: %p dwStackSize: %lu lpStartAddress"
+ ": %p lpParameter: %p, dwCreationFlags: %lx\n", hProcess,
dwStackSize, lpStartAddress, lpParameter, dwCreationFlags);
/* Clear the Context */
dwCreationFlags & STACK_SIZE_PARAM_IS_A_RESERVATION ?
dwStackSize : 0,
&InitialTeb);
- if(!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return NULL;
Teb->ActivationContextStackPointer = ActivationContextStack;
/* Query the Context */
- // WARNING!!! THIS IS USING THE WIN32 FLAG BECAUSE REACTOS CONTINUES TO BE A POS!!! ///
- Status = RtlQueryInformationActivationContext(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX,
+ Status = RtlQueryInformationActivationContext(RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT,
NULL,
0,
ActivationContextBasicInformation,
&ActCtxInfo,
sizeof(ActCtxInfo),
- &ReturnLength);
+ &ReturnSize);
if (!NT_SUCCESS(Status))
{
/* Fail */
ERROR_DBGBREAK("SXS: %s - Failing thread create because "
"RtlQueryInformationActivationContext() failed with status %08lx\n",
__FUNCTION__, Status);
+
+ /* Free the activation context stack */
+ // RtlFreeThreadActivationContextStack();
+ RtlFreeActivationContextStack(Teb->ActivationContextStackPointer);
+
return NULL;
}
ERROR_DBGBREAK("SXS: %s - Failing thread create because "
"RtlActivateActivationContextEx() failed with status %08lx\n",
__FUNCTION__, Status);
+
+ /* Free the activation context stack */
+ // RtlFreeThreadActivationContextStack();
+ RtlFreeActivationContextStack(Teb->ActivationContextStackPointer);
+
return NULL;
}
}
/* Notify CSR */
if (!BaseRunningInServerProcess)
{
- /* Notify CSR */
Status = BasepNotifyCsrOfThread(hThread, &ClientId);
ASSERT(NT_SUCCESS(Status));
}
IN DWORD dwExitCode)
{
NTSTATUS Status;
+#if DBG
PRTL_CRITICAL_SECTION LoaderLock;
THREAD_BASIC_INFORMATION ThreadInfo;
+#endif /* DBG */
/* Check for invalid thread handle */
if (!hThread)
return FALSE;
}
+#if DBG
/* Get the loader lock */
LoaderLock = NtCurrentPeb()->LoaderLock;
if (LoaderLock)
&ThreadInfo,
sizeof(ThreadInfo),
NULL);
- if (!NT_SUCCESS(Status))
+ if (NT_SUCCESS(Status))
{
- /* Assert that we don't hold the loader lock */
- ASSERT(NtCurrentTeb()->ClientId.UniqueThread != ThreadInfo.ClientId.UniqueThread);
- ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
+ /* If terminating the current thread, we must not hold the loader lock */
+ if (NtCurrentTeb()->ClientId.UniqueThread == ThreadInfo.ClientId.UniqueThread)
+ ASSERT(NtCurrentTeb()->ClientId.UniqueThread != LoaderLock->OwningThread);
}
}
+#endif /* DBG */
/* Now terminate the thread */
Status = NtTerminateThread(hThread, dwExitCode);
SetThreadUILanguage(IN LANGID LangId)
{
UNIMPLEMENTED;
- return NtCurrentTeb()->CurrentLocale;
+ return (LANGID)NtCurrentTeb()->CurrentLocale;
}
/*
/* Zero the activation context and query information on it */
RtlZeroMemory(&ActCtxInfo, sizeof(ActCtxInfo));
- // WARNING!!! THIS IS USING THE WIN32 FLAG BECAUSE REACTOS CONTINUES TO BE A POS!!! ///
- Status = RtlQueryInformationActivationContext(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX,
+ Status = RtlQueryInformationActivationContext(RTL_QUERY_ACTIVATION_CONTEXT_FLAG_USE_ACTIVE_ACTIVATION_CONTEXT,
NULL,
0,
ActivationContextBasicInformation,
WINAPI
SetThreadStackGuarantee(IN OUT PULONG StackSizeInBytes)
{
- UNIMPLEMENTED;
- return FALSE;
+ static int once;
+ if (once++ == 0)
+ DPRINT1("SetThreadStackGuarantee(%p): stub\n", StackSizeInBytes);
+ return TRUE;
}
/*