Fixed skipped events from keyboard:
authorArt Yerkes <art.yerkes@gmail.com>
Fri, 18 Nov 2005 10:53:32 +0000 (10:53 +0000)
committerArt Yerkes <art.yerkes@gmail.com>
Fri, 18 Nov 2005 10:53:32 +0000 (10:53 +0000)
- Wait for IO if it would be pending
- Don't copy into UserBuffer directly in read because it'll be
  overwritten.  Use Irp->AssociatedIrp.SystemBuffer.

svn path=/trunk/; revision=19322

reactos/drivers/input/kbdclass/kbdclass.c
reactos/subsys/win32k/ntuser/input.c

index 5211e83..eb22e9b 100644 (file)
@@ -369,6 +369,8 @@ ClassCallback(
 
        ASSERT(ClassDeviceExtension->Common.IsClassDO);
 
 
        ASSERT(ClassDeviceExtension->Common.IsClassDO);
 
+       KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
+
        DPRINT("ClassCallback()\n");
        /* A filter driver might have consumed all the data already; I'm
         * not sure if they are supposed to move the packets when they
        DPRINT("ClassCallback()\n");
        /* A filter driver might have consumed all the data already; I'm
         * not sure if they are supposed to move the packets when they
@@ -382,6 +384,8 @@ ClassCallback(
 
                /* A read request is waiting for input, so go straight to it */
                /* FIXME: use SEH */
 
                /* A read request is waiting for input, so go straight to it */
                /* FIXME: use SEH */
+               DPRINT("Immediate Completion: %x\n", DataStart->MakeCode);
+
                RtlCopyMemory(
                        Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->AssociatedIrp.SystemBuffer,
                        DataStart,
                RtlCopyMemory(
                        Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->AssociatedIrp.SystemBuffer,
                        DataStart,
@@ -403,8 +407,6 @@ ClassCallback(
        /* If we have data from the port driver and a higher service to send the data to */
        if (InputCount != 0)
        {
        /* If we have data from the port driver and a higher service to send the data to */
        if (InputCount != 0)
        {
-               KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
-
                if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
                        ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
                else
                if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
                        ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
                else
@@ -428,7 +430,6 @@ ClassCallback(
                ClassDeviceExtension->PortData += ReadSize;
                ClassDeviceExtension->InputCount += ReadSize;
 
                ClassDeviceExtension->PortData += ReadSize;
                ClassDeviceExtension->InputCount += ReadSize;
 
-               KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
                (*ConsumedCount) += ReadSize;
        }
        else
                (*ConsumedCount) += ReadSize;
        }
        else
@@ -436,6 +437,8 @@ ClassCallback(
                DPRINT("ClassCallBack() entered, InputCount = %lu - DOING NOTHING\n", InputCount);
        }
 
                DPRINT("ClassCallBack() entered, InputCount = %lu - DOING NOTHING\n", InputCount);
        }
 
+       KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
+
        if (Irp != NULL)
        {
                IoStartNextPacket(ClassDeviceObject, FALSE);
        if (Irp != NULL)
        {
                IoStartNextPacket(ClassDeviceObject, FALSE);
@@ -575,11 +578,17 @@ ClassStartIo(
 
                KeAcquireSpinLock(&DeviceExtension->SpinLock, &oldIrql);
 
 
                KeAcquireSpinLock(&DeviceExtension->SpinLock, &oldIrql);
 
+               DPRINT("Mdl: %x, UserBuffer: %x, InputCount: %d, Data: %x\n",
+                      Irp->MdlAddress,
+                      Irp->UserBuffer,
+                      DeviceExtension->InputCount,
+                      (DeviceExtension->PortData-DeviceExtension->InputCount)->MakeCode);
+
                /* FIXME: use SEH */
                RtlCopyMemory(
                /* FIXME: use SEH */
                RtlCopyMemory(
-                       Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->UserBuffer,
-                       DeviceExtension->PortData - DeviceExtension->InputCount,
-                       sizeof(KEYBOARD_INPUT_DATA));
+                   Irp->AssociatedIrp.SystemBuffer,
+                   DeviceExtension->PortData - DeviceExtension->InputCount,
+                   sizeof(KEYBOARD_INPUT_DATA));
 
                if (DeviceExtension->InputCount > 1)
                {
 
                if (DeviceExtension->InputCount > 1)
                {
index 4d8e545..f9e77ff 100644 (file)
@@ -413,7 +413,6 @@ KeyboardThreadMain(PVOID StartContext)
    struct _ETHREAD *FocusThread;
    extern NTSTATUS Win32kInitWin32Thread(PETHREAD Thread);
 
    struct _ETHREAD *FocusThread;
    extern NTSTATUS Win32kInitWin32Thread(PETHREAD Thread);
 
-
    PKEYBOARD_INDICATOR_TRANSLATION IndicatorTrans = NULL;
    UINT ModifierState = 0;
    USHORT LastMakeCode = 0;
    PKEYBOARD_INDICATOR_TRANSLATION IndicatorTrans = NULL;
    UINT ModifierState = 0;
    USHORT LastMakeCode = 0;
@@ -486,8 +485,10 @@ KeyboardThreadMain(PVOID StartContext)
          HWND hWnd;
          int id;
 
          HWND hWnd;
          int id;
 
+        DPRINT("KeyInput @ %08x\n", &KeyInput);
+
          Status = NtReadFile (KeyboardDeviceHandle,
          Status = NtReadFile (KeyboardDeviceHandle,
-                              NULL,
+                             NULL,
                               NULL,
                               NULL,
                               &Iosb,
                               NULL,
                               NULL,
                               &Iosb,
@@ -495,6 +496,22 @@ KeyboardThreadMain(PVOID StartContext)
                               sizeof(KEYBOARD_INPUT_DATA),
                               NULL,
                               NULL);
                               sizeof(KEYBOARD_INPUT_DATA),
                               NULL,
                               NULL);
+
+         if(Status == STATUS_ALERTED && !InputThreadsRunning)
+         {
+            break;
+         }
+         if(Status == STATUS_PENDING)
+         {
+            NtWaitForSingleObject(KeyboardDeviceHandle, FALSE, NULL);
+            Status = Iosb.Status;
+         }
+         if(!NT_SUCCESS(Status))
+         {
+            DPRINT1("Win32K: Failed to read from mouse.\n");
+            return; //(Status);
+         }
+
          DPRINT("KeyRaw: %s %04x\n",
                 (KeyInput.Flags & KEY_BREAK) ? "up" : "down",
                 KeyInput.MakeCode );
          DPRINT("KeyRaw: %s %04x\n",
                 (KeyInput.Flags & KEY_BREAK) ? "up" : "down",
                 KeyInput.MakeCode );