https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fd3c571d3627f6026f130122f07d6747a67b8ded

commit fd3c571d3627f6026f130122f07d6747a67b8ded
Author:     Timo Kreuzer <timo.kreu...@reactos.org>
AuthorDate: Tue Sep 10 20:00:24 2024 +0300
Commit:     Timo Kreuzer <timo.kreu...@reactos.org>
CommitDate: Mon Sep 16 10:10:55 2024 +0300

    [RTL][KERNEL32][ROSAUTOTEST] Disable debug prompts during autotest
    
    This fixes timeouts + reboots for user mode assertion failures on the 
testbots. As a bonus it now shows a backtrace.
---
 dll/win32/kernel32/client/proc.c      |  6 ++++++
 modules/rostests/rosautotest/main.cpp | 39 +++++++++++++++++++++++++++++++++++
 sdk/include/ndk/pstypes.h             |  3 ++-
 sdk/lib/rtl/assert.c                  |  6 ++++++
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/dll/win32/kernel32/client/proc.c b/dll/win32/kernel32/client/proc.c
index b88212b3c59..669ede0e2f9 100644
--- a/dll/win32/kernel32/client/proc.c
+++ b/dll/win32/kernel32/client/proc.c
@@ -1628,6 +1628,12 @@ FatalExit(IN int ExitCode)
     CHAR Action[2];
     DbgPrint("FatalExit...\n\n");
 
+    /* Check for reactos specific flag (set by rosautotest) */
+    if (RtlGetNtGlobalFlags() & FLG_DISABLE_DEBUG_PROMPTS)
+    {
+        RtlRaiseStatus(STATUS_FATAL_APP_EXIT);
+    }
+
     while (TRUE)
     {
         DbgPrompt("A (Abort), B (Break), I (Ignore)? ", Action, 
sizeof(Action));
diff --git a/modules/rostests/rosautotest/main.cpp 
b/modules/rostests/rosautotest/main.cpp
index d671696e6d0..e808d5da91a 100644
--- a/modules/rostests/rosautotest/main.cpp
+++ b/modules/rostests/rosautotest/main.cpp
@@ -7,6 +7,8 @@
 
 #include "precomp.h"
 #include <cstdio>
+#include <ndk/setypes.h>
+#include <ndk/exfuncs.h>
 
 CConfiguration Configuration;
 
@@ -43,6 +45,41 @@ IntPrintUsage()
          << "    The test to be run. Needs to be a test of the specified 
module." << endl;
 }
 
+static
+VOID
+SetNtGlobalFlags()
+{
+    ULONG NtGlobalFlags = 0;
+    BOOLEAN PrivilegeEnabled;
+    NTSTATUS Status;
+
+    /* Enable SeDebugPrivilege */
+    Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, FALSE, 
&PrivilegeEnabled);
+    if (!NT_SUCCESS(Status))
+    {
+        DbgPrint("Failed to enable SeDebugPrivilege: 0x%08lx\n", Status);
+        return;
+    }
+
+    /* Get current NtGlobalFlags */
+    Status = NtQuerySystemInformation(SystemFlagsInformation, &NtGlobalFlags, 
sizeof(NtGlobalFlags), NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        DbgPrint("Failed to get NtGlobalFlags: 0x%08lx\n", Status);
+        return;
+    }
+
+    /* Disable debug prompts */
+    NtGlobalFlags |= FLG_DISABLE_DEBUG_PROMPTS;
+
+    /* Set new NtGlobalFlags */
+    Status = NtSetSystemInformation(SystemFlagsInformation, &NtGlobalFlags, 
sizeof(NtGlobalFlags));
+    if (!NT_SUCCESS(Status))
+    {
+        DbgPrint("Failed to set NtGlobalFlags: 0x%08lx\n", Status);
+    }
+}
+
 /**
  * Main entry point
  */
@@ -51,6 +88,8 @@ wmain(int argc, wchar_t* argv[])
 {
     int ReturnValue = 1;
 
+    SetNtGlobalFlags();
+
     try
     {
         stringstream ss;
diff --git a/sdk/include/ndk/pstypes.h b/sdk/include/ndk/pstypes.h
index 3a47b04a560..155b2e37d89 100644
--- a/sdk/include/ndk/pstypes.h
+++ b/sdk/include/ndk/pstypes.h
@@ -83,7 +83,8 @@ extern POBJECT_TYPE NTSYSAPI PsJobType;
 #define FLG_ENABLE_HANDLE_TYPE_TAGGING          0x01000000
 #define FLG_HEAP_PAGE_ALLOCS                    0x02000000
 #define FLG_DEBUG_INITIAL_COMMAND_EX            0x04000000
-#define FLG_VALID_BITS                          0x07FFFFFF
+#define FLG_DISABLE_DEBUG_PROMPTS               0x08000000 // ReactOS-specific
+#define FLG_VALID_BITS                          0x0FFFFFFF
 
 //
 // Flags for NtCreateProcessEx
diff --git a/sdk/lib/rtl/assert.c b/sdk/lib/rtl/assert.c
index 6f4facb6239..0a7e803ee31 100644
--- a/sdk/lib/rtl/assert.c
+++ b/sdk/lib/rtl/assert.c
@@ -42,6 +42,12 @@ RtlAssert(IN PVOID FailedAssertion,
                  (PSTR)FileName,
                  LineNumber);
 
+        /* Check for reactos specific flag (set by rosautotest) */
+        if (RtlGetNtGlobalFlags() & FLG_DISABLE_DEBUG_PROMPTS)
+        {
+            RtlRaiseStatus(STATUS_ASSERTION_FAILURE);
+        }
+
         /* Prompt for action */
         DbgPrompt("Break repeatedly, break Once, Ignore, "
                   "terminate Process or terminate Thread (boipt)? ",

Reply via email to