[NTOSKRNL]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 19 Feb 2011 21:50:11 +0000 (21:50 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 19 Feb 2011 21:50:11 +0000 (21:50 +0000)
Add support for debug pre/post syscall hooks, that can be registered from win32k. They only exist on DBG versions.

svn path=/trunk/; revision=50823

reactos/ntoskrnl/include/internal/kd.h
reactos/ntoskrnl/kd/kdmain.c
reactos/ntoskrnl/ke/i386/traphdlr.c

index b61d498..53ee9b0 100644 (file)
@@ -363,3 +363,12 @@ extern KD_CONTEXT KdpContext;
 extern ULONG Kd_WIN2000_Mask;
 
 #endif
+
+#if DBG
+#define ID_Win32PreServiceHook 'WSH0'
+#define ID_Win32PostServiceHook 'WSH1'
+typedef void (NTAPI *PKDBG_PRESERVICEHOOK)(ULONG, PULONG_PTR);
+typedef ULONG_PTR (NTAPI *PKDBG_POSTSERVICEHOOK)(ULONG, ULONG_PTR);
+extern PKDBG_PRESERVICEHOOK KeWin32PreServiceHook;
+extern PKDBG_POSTSERVICEHOOK KeWin32PostServiceHook;
+#endif
index 6b16582..ac1f0bc 100644 (file)
@@ -71,7 +71,7 @@ KdpServiceDispatcher(ULONG Service,
                 case EnterDebugger:
                     DbgBreakPoint();
                     break;
-                    
+
                 case KdSpare3:
                     MmDumpArmPfnDatabase(FALSE);
                     break;
@@ -82,6 +82,23 @@ KdpServiceDispatcher(ULONG Service,
             break;
         }
 
+        /* Register a debug callback */
+        case 'CsoR':
+        {
+            switch (Buffer1Length)
+            {
+                case ID_Win32PreServiceHook:
+                    KeWin32PreServiceHook = Buffer1;
+                    break;
+
+                case ID_Win32PostServiceHook:
+                    KeWin32PostServiceHook = Buffer1;
+                    break;
+
+            }
+            break;
+        }
+
         /* Special  case for stack frame dumps */
         case 'DsoR':
         {
index 4822b71..1d3b098 100644 (file)
@@ -46,6 +46,10 @@ UCHAR KiTrapIoTable[] =
 };
 
 PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler;
+#if DBG
+PKDBG_PRESERVICEHOOK KeWin32PreServiceHook = NULL;
+PKDBG_POSTSERVICEHOOK KeWin32PostServiceHook = NULL;
+#endif
 
 
 /* TRAP EXIT CODE *************************************************************/
@@ -1443,6 +1447,28 @@ KiDebugServiceHandler(IN PKTRAP_FRAME TrapFrame)
     KiDebugHandler(TrapFrame, TrapFrame->Eax, TrapFrame->Ecx, TrapFrame->Edx);
 }
 
+
+FORCEINLINE
+VOID
+KiDbgPreServiceHook(ULONG SystemCallNumber, PULONG_PTR Arguments)
+{
+#if DBG
+    if (SystemCallNumber >= 0x1000 && KeWin32PreServiceHook)
+        KeWin32PreServiceHook(SystemCallNumber, Arguments);
+#endif
+}
+
+FORCEINLINE
+ULONG_PTR
+KiDbgPostServiceHook(ULONG SystemCallNumber, ULONG_PTR Result)
+{
+#if DBG
+    if (SystemCallNumber >= 0x1000 && KeWin32PostServiceHook)
+        return KeWin32PostServiceHook(SystemCallNumber, Result);
+#endif
+    return Result;
+}
+
 DECLSPEC_NORETURN
 VOID
 FORCEINLINE
@@ -1553,10 +1579,16 @@ KiSystemCall(IN PKTRAP_FRAME TrapFrame,
         while (TRUE);
     }
     
+    /* Call pre-service debug hook */
+    KiDbgPreServiceHook(SystemCallNumber, Arguments);
+
     /* Get the handler and make the system call */
     Handler = (PVOID)DescriptorTable->Base[Id];
     Result = KiSystemCallTrampoline(Handler, Arguments, StackBytes);
     
+    /* Call post-service debug hook */
+    Result = KiDbgPostServiceHook(SystemCallNumber, Result);
+
     /* Make sure we're exiting correctly */
     KiExitSystemCallDebugChecks(Id, TrapFrame);