[KERNEL32] Use the default UnhandledExceptionFilter in BaseThreadStartup.
[reactos.git] / dll / win32 / kernel32 / client / thread.c
index 504c035..2ff0102 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * 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)
  *
  */
 
@@ -26,29 +26,6 @@ BasepNotifyCsrOfThread(IN HANDLE ThreadHandle,
 
 /* 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
@@ -68,7 +45,7 @@ BaseThreadStartup(IN LPTHREAD_START_ROUTINE lpStartAddress,
         /* 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)
@@ -131,6 +108,7 @@ BaseDispatchApc(IN PAPCFUNC ApcRoutine,
  */
 HANDLE
 WINAPI
+DECLSPEC_HOTPATCH
 CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes,
              IN DWORD dwStackSize,
              IN LPTHREAD_START_ROUTINE lpStartAddress,
@@ -175,8 +153,9 @@ CreateRemoteThread(IN HANDLE hProcess,
     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 */
@@ -260,14 +239,13 @@ CreateRemoteThread(IN HANDLE hProcess,
         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 */
@@ -572,8 +550,10 @@ TerminateThread(IN HANDLE hThread,
                 IN DWORD dwExitCode)
 {
     NTSTATUS Status;
+#if DBG
     PRTL_CRITICAL_SECTION LoaderLock;
     THREAD_BASIC_INFORMATION ThreadInfo;
+#endif /* DBG */
 
     /* Check for invalid thread handle */
     if (!hThread)
@@ -583,6 +563,7 @@ TerminateThread(IN HANDLE hThread,
         return FALSE;
     }
 
+#if DBG
     /* Get the loader lock */
     LoaderLock = NtCurrentPeb()->LoaderLock;
     if (LoaderLock)
@@ -593,13 +574,14 @@ TerminateThread(IN HANDLE hThread,
                                           &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);
@@ -917,7 +899,7 @@ WINAPI
 SetThreadUILanguage(IN LANGID LangId)
 {
     UNIMPLEMENTED;
-    return NtCurrentTeb()->CurrentLocale;
+    return (LANGID)NtCurrentTeb()->CurrentLocale;
 }
 
 /*
@@ -934,8 +916,7 @@ QueueUserAPC(IN PAPCFUNC pfnAPC,
 
     /* 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,
@@ -975,8 +956,10 @@ BOOL
 WINAPI
 SetThreadStackGuarantee(IN OUT PULONG StackSizeInBytes)
 {
-    UNIMPLEMENTED;
-    return FALSE;
+    static int once;
+    if (once++ == 0)
+         DPRINT1("SetThreadStackGuarantee(%p): stub\n", StackSizeInBytes);
+    return TRUE;
 }
 
 /*