distinguish kmode and umode alertability
Modified: trunk/reactos/include/ddk/types.h
Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
Modified: trunk/reactos/ntoskrnl/ke/alert.c
Modified: trunk/reactos/w32api/include/ddk/winddk.h

Modified: trunk/reactos/include/ddk/types.h
--- trunk/reactos/include/ddk/types.h	2005-02-15 11:46:31 UTC (rev 13580)
+++ trunk/reactos/include/ddk/types.h	2005-02-15 13:40:10 UTC (rev 13581)
@@ -8,7 +8,7 @@
 /*
  * Various other types (all quite pointless)
  */
-typedef CCHAR KPROCESSOR_MODE;
+typedef UCHAR KPROCESSOR_MODE;
 typedef UCHAR KIRQL;
 typedef KIRQL* PKIRQL;
 typedef ULONG IO_ALLOCATION_ACTION;

Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
--- trunk/reactos/ntoskrnl/include/internal/ps.h	2005-02-15 11:46:31 UTC (rev 13580)
+++ trunk/reactos/ntoskrnl/include/internal/ps.h	2005-02-15 13:40:10 UTC (rev 13581)
@@ -73,7 +73,7 @@
    
    /* Thread state (one of THREAD_STATE_xxx constants below) */
    UCHAR             State;               /* 2D */
-   UCHAR             Alerted[2];          /* 2E */
+   BOOLEAN           Alerted[2];          /* 2E */
    UCHAR             Iopl;                /* 30 */
    UCHAR             NpxState;            /* 31 */
    CHAR              Saturation;          /* 32 */

Modified: trunk/reactos/ntoskrnl/ke/alert.c
--- trunk/reactos/ntoskrnl/ke/alert.c	2005-02-15 11:46:31 UTC (rev 13580)
+++ trunk/reactos/ntoskrnl/ke/alert.c	2005-02-15 13:40:10 UTC (rev 13581)
@@ -37,14 +37,11 @@
    OldIrql = KeAcquireDispatcherDatabaseLock();
    KiAcquireSpinLock(&Thread->ApcQueueLock);
    
-   /* NOTE: Albert Almeida claims Alerted[1] is never used. Two kind of 
-    * alerts _do_ seem useless. -Gunnar
-    */
-   OldState = Thread->Alerted[0];
+   OldState = Thread->Alerted[AlertMode];
    
    /* If the Thread is Alerted, Clear it */
    if (OldState) {
-      Thread->Alerted[0] = FALSE;  
+      Thread->Alerted[AlertMode] = FALSE;
    } else if ((AlertMode == UserMode) && (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))) {
       /* If the mode is User and the Queue isn't empty, set Pending */
       Thread->ApcState.UserApcPending = TRUE;
@@ -65,20 +62,19 @@
    oldIrql = KeAcquireDispatcherDatabaseLock();
       
 
-   /* Return if thread is already alerted.
-    * NOTE: Albert Almeida claims Alerted[1] is never used. Two kind of 
-    * alerts _do_ seem useless. -Gunnar
-    */
-   if (Thread->Alerted[0] == FALSE)
+   /* Return if thread is already alerted. */
+   if (Thread->Alerted[AlertMode] == FALSE)
    {
-      Thread->Alerted[0] = TRUE;
-
       if (Thread->State == THREAD_STATE_BLOCKED &&
-          Thread->WaitMode == AlertMode &&
+          (AlertMode == KernelMode || Thread->WaitMode == AlertMode) &&
           Thread->Alertable)
       {
          KiAbortWaitThread(Thread, STATUS_ALERTED);
       }
+      else
+      {
+         Thread->Alerted[AlertMode] = TRUE;
+      }
    }
    
    KeReleaseDispatcherDatabaseLock(oldIrql);
@@ -124,11 +120,12 @@
    return(Status);
      }
 
-   /* FIXME: should we always use UserMode here, even if the ntoskrnl exported
-    * ZwAlertThread was called?
-    * -Gunnar
-    */ 
-   KeAlertThread((PKTHREAD)Thread, PreviousMode);
+   /* do an alert depending on the processor mode. If some kmode code wants to
+      enforce a umode alert it should call KeAlertThread() directly. If kmode
+      code wants to do a kmode alert it's sufficient to call it with Zw or just
+      use KeAlertThread() directly */
+
+   KeAlertThread(&Thread->Tcb, PreviousMode);
    
    ObDereferenceObject(Thread);
    return(STATUS_SUCCESS);
@@ -142,11 +139,12 @@
 STDCALL
 NtTestAlert(VOID)
 {
+   KPROCESSOR_MODE PreviousMode;
+   
+   PreviousMode = ExGetPreviousMode();
+   
    /* Check and Alert Thread if needed */
-   if (KeTestAlertThread(KeGetPreviousMode())) {
-      return STATUS_ALERTED;
-   } else {
-      return STATUS_SUCCESS;
-   }
+   
+   return KeTestAlertThread(PreviousMode) ? STATUS_ALERTED : STATUS_SUCCESS;
 }
 

Modified: trunk/reactos/w32api/include/ddk/winddk.h
--- trunk/reactos/w32api/include/ddk/winddk.h	2005-02-15 11:46:31 UTC (rev 13580)
+++ trunk/reactos/w32api/include/ddk/winddk.h	2005-02-15 13:40:10 UTC (rev 13581)
@@ -134,7 +134,7 @@
 typedef UCHAR KIRQL, *PKIRQL;
 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
 typedef ULONG KAFFINITY, *PKAFFINITY;
-typedef CCHAR KPROCESSOR_MODE;
+typedef UCHAR KPROCESSOR_MODE;
 
 typedef enum _MODE {
   KernelMode,