- use inlined probing macros for basic types
- minor optimizations by comparing the processor mode against KernelMode (==0) instead of UserMode (==1)
Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c
Modified: trunk/reactos/ntoskrnl/ex/event.c
Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c
Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
Modified: trunk/reactos/ntoskrnl/io/file.c
Modified: trunk/reactos/ntoskrnl/io/iocomp.c
Modified: trunk/reactos/ntoskrnl/io/plugplay.c
Modified: trunk/reactos/ntoskrnl/kdbg/kdb.c
Modified: trunk/reactos/ntoskrnl/ke/apc.c
Modified: trunk/reactos/ntoskrnl/ke/catch.c
Modified: trunk/reactos/ntoskrnl/ke/i386/fpu.c
Modified: trunk/reactos/ntoskrnl/ke/kthread.c
Modified: trunk/reactos/ntoskrnl/ke/queue.c
Modified: trunk/reactos/ntoskrnl/ke/wait.c
Modified: trunk/reactos/ntoskrnl/lpc/connect.c
Modified: trunk/reactos/ntoskrnl/mm/mdl.c
Modified: trunk/reactos/ntoskrnl/mm/pagefile.c
Modified: trunk/reactos/ntoskrnl/mm/section.c
Modified: trunk/reactos/ntoskrnl/mm/virtual.c
Modified: trunk/reactos/ntoskrnl/ob/dirobj.c
Modified: trunk/reactos/ntoskrnl/ob/handle.c
Modified: trunk/reactos/ntoskrnl/ob/symlink.c
Modified: trunk/reactos/ntoskrnl/ob/wait.c
Modified: trunk/reactos/ntoskrnl/ps/job.c
Modified: trunk/reactos/ntoskrnl/ps/security.c
Modified: trunk/reactos/ntoskrnl/ps/suspend.c
Modified: trunk/reactos/ntoskrnl/rtl/capture.c
Modified: trunk/reactos/ntoskrnl/se/acl.c
Modified: trunk/reactos/ntoskrnl/se/sd.c
Modified: trunk/reactos/ntoskrnl/se/sid.c
Modified: trunk/reactos/ntoskrnl/se/token.c

Modified: trunk/reactos/ntoskrnl/cm/ntfunc.c
--- trunk/reactos/ntoskrnl/cm/ntfunc.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/cm/ntfunc.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -1145,9 +1145,7 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(KeyHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(KeyHandle);
     }
     _SEH_HANDLE
     {

Modified: trunk/reactos/ntoskrnl/ex/event.c
--- trunk/reactos/ntoskrnl/ex/event.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ex/event.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -242,7 +242,7 @@
             EventHandle, PreviousState);
 
     /* Check buffer validity */
-    if(PreviousState && PreviousMode == UserMode) {
+    if(PreviousState && PreviousMode != KernelMode) {
 
         _SEH_TRY {
 
@@ -376,7 +376,7 @@
             EventHandle, PreviousState);
 
     /* Check buffer validity */
-    if(PreviousState && PreviousMode == UserMode) {
+    if(PreviousState && PreviousMode != KernelMode) {
 
         _SEH_TRY {
 
@@ -441,7 +441,7 @@
            EventHandle, PreviousState);
 
     /* Check buffer validity */
-    if(PreviousState != NULL && PreviousMode == UserMode) {
+    if(PreviousState != NULL && PreviousMode != KernelMode) {
 
         _SEH_TRY {
 

Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c
--- trunk/reactos/ntoskrnl/ex/sysinfo.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ex/sysinfo.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -1541,7 +1541,7 @@
   
   _SEH_TRY
     {
-      if (PreviousMode == UserMode)
+      if (PreviousMode != KernelMode)
         {
           /* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
           ProbeForWrite(SystemInformation, Length, 1); 

Modified: trunk/reactos/ntoskrnl/include/internal/ob.h
--- trunk/reactos/ntoskrnl/include/internal/ob.h	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/include/internal/ob.h	2005-08-21 19:04:23 UTC (rev 17467)
@@ -261,7 +261,7 @@
 
 #define ProbeQueryInfoBuffer(Buffer, BufferLen, Alignment, RetLen, PrevMode, StatusVar) \
   do {                                                                         \
-  if(PrevMode == UserMode)                                                     \
+  if(PrevMode != KernelMode)                                                     \
   {                                                                            \
     _SEH_TRY                                                                   \
     {                                                                          \
@@ -291,7 +291,7 @@
 
 #define ProbeSetInfoBuffer(Buffer, BufferLen, Alignment, PrevMode, StatusVar) \
   do {                                                                         \
-  if(PrevMode == UserMode)                                                     \
+  if(PrevMode != KernelMode)                                                     \
   {                                                                            \
     _SEH_TRY                                                                   \
     {                                                                          \

Modified: trunk/reactos/ntoskrnl/io/file.c
--- trunk/reactos/ntoskrnl/io/file.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/io/file.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -781,18 +781,13 @@
    {
      _SEH_TRY
      {
-       ProbeForWrite(FileHandle,
-                     sizeof(HANDLE),
-                     sizeof(ULONG));
+       ProbeForWriteHandle(FileHandle);
        ProbeForWrite(IoStatusBlock,
                      sizeof(IO_STATUS_BLOCK),
                      sizeof(ULONG));
        if(AllocationSize != NULL)
        {
-         ProbeForRead(AllocationSize,
-                      sizeof(LARGE_INTEGER),
-                      sizeof(ULONG));
-         SafeAllocationSize = *AllocationSize;
+         SafeAllocationSize = ProbeForReadLargeInteger(AllocationSize);
        }
        else
          SafeAllocationSize.QuadPart = 0;
@@ -1395,7 +1390,7 @@
    LARGE_INTEGER Interval;
 
    if ((ULONG_PTR)IoStatusBlock >= (ULONG_PTR)MmUserProbeAddress &&
-       KeGetPreviousMode() == UserMode)
+       KeGetPreviousMode() != KernelMode)
       return STATUS_ACCESS_VIOLATION;
 
    Status = ObReferenceObjectByHandle(FileHandle, 0, IoFileObjectType,

Modified: trunk/reactos/ntoskrnl/io/iocomp.c
--- trunk/reactos/ntoskrnl/io/iocomp.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/io/iocomp.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -237,9 +237,7 @@
 
         _SEH_TRY {
 
-            ProbeForWrite(IoCompletionHandle,
-                          sizeof(HANDLE),
-                          sizeof(ULONG));
+            ProbeForWriteHandle(IoCompletionHandle);
         } _SEH_HANDLE {
 
             Status = _SEH_GetExceptionCode();
@@ -309,9 +307,7 @@
 
         _SEH_TRY {
 
-            ProbeForWrite(IoCompletionHandle,
-                          sizeof(HANDLE),
-                          sizeof(ULONG));
+            ProbeForWriteHandle(IoCompletionHandle);
         } _SEH_HANDLE {
 
             Status = _SEH_GetExceptionCode();
@@ -432,21 +428,14 @@
 
         _SEH_TRY {
 
-            ProbeForWrite(CompletionKey,
-                          sizeof(PVOID),
-                          sizeof(ULONG));
-            ProbeForWrite(CompletionContext,
-                          sizeof(PVOID),
-                          sizeof(ULONG));
+            ProbeForWritePointer(CompletionKey);
+            ProbeForWritePointer(CompletionContext);
             ProbeForWrite(IoStatusBlock,
                           sizeof(IO_STATUS_BLOCK),
                           sizeof(ULONG));
             if (Timeout != NULL) {
 
-                ProbeForRead(Timeout,
-                             sizeof(LARGE_INTEGER),
-                             sizeof(ULONG));
-                SafeTimeout = *Timeout;
+                SafeTimeout = ProbeForReadLargeInteger(Timeout);
                 Timeout = &SafeTimeout;
             }
         } _SEH_HANDLE {

Modified: trunk/reactos/ntoskrnl/io/plugplay.c
--- trunk/reactos/ntoskrnl/io/plugplay.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/io/plugplay.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -173,7 +173,7 @@
   DPRINT("NtGetPlugPlayEvent() called\n");
 
   /* Function can only be called from user-mode */
-  if (KeGetPreviousMode() != UserMode)
+  if (KeGetPreviousMode() == KernelMode)
   {
     DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
     return STATUS_ACCESS_DENIED;
@@ -636,7 +636,7 @@
            PlugPlayControlClass, Buffer, BufferLength);
 
     /* Function can only be called from user-mode */
-    if (KeGetPreviousMode() != UserMode)
+    if (KeGetPreviousMode() == KernelMode)
     {
         DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
         return STATUS_ACCESS_DENIED;

Modified: trunk/reactos/ntoskrnl/kdbg/kdb.c
--- trunk/reactos/ntoskrnl/kdbg/kdb.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/kdbg/kdb.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -1206,7 +1206,7 @@
    ul = min(ExpNr, RTL_NUMBER_OF(KdbEnterConditions) - 1);
    EnterCondition = KdbEnterConditions[ul][FirstChance ? 0 : 1];
    if (EnterCondition == KdbDoNotEnter ||
-       (EnterCondition == KdbEnterFromUmode && PreviousMode != UserMode) ||
+       (EnterCondition == KdbEnterFromUmode && PreviousMode == KernelMode) ||
        (EnterCondition == KdbEnterFromKmode && PreviousMode != KernelMode))
    {
       EnterConditionMet = FALSE;

Modified: trunk/reactos/ntoskrnl/ke/apc.c
--- trunk/reactos/ntoskrnl/ke/apc.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ke/apc.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -360,7 +360,7 @@
         }
 
    } else if ((Thread->State == Waiting) &&
-              (Thread->WaitMode == UserMode) &&
+              (Thread->WaitMode != KernelMode) &&
               (Thread->Alertable)) {
 
         DPRINT("Waking up Thread for User-Mode APC Delivery \n");
@@ -703,7 +703,7 @@
 
     /* Now we do the User APCs */
     if ((!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])) &&
-        (DeliveryMode == UserMode) && (Thread->ApcState.UserApcPending == TRUE)) {
+        (DeliveryMode != KernelMode) && (Thread->ApcState.UserApcPending == TRUE)) {
 
         /* It's not pending anymore */
         Thread->ApcState.UserApcPending = FALSE;

Modified: trunk/reactos/ntoskrnl/ke/catch.c
--- trunk/reactos/ntoskrnl/ke/catch.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ke/catch.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -63,7 +63,7 @@
         TContext.ContextFlags = CONTEXT_FULL;
 
         /* Check the mode */
-        if (PreviousMode == UserMode)
+        if (PreviousMode != KernelMode)
         {
             /* Add Debugger Registers if this is User Mode */
             TContext.ContextFlags = TContext.ContextFlags | CONTEXT_DEBUGGER;
@@ -91,7 +91,7 @@
     if (Action != kdDoNotHandleException)
     {
         /* See what kind of Exception this is */
-        if (PreviousMode == UserMode)
+        if (PreviousMode != KernelMode)
         {
             /* User mode exception, search the frames if we have to */
             if (SearchFrames)

Modified: trunk/reactos/ntoskrnl/ke/i386/fpu.c
--- trunk/reactos/ntoskrnl/ke/i386/fpu.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ke/i386/fpu.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -498,7 +498,7 @@
 
       PreviousMode = ((Tf->Cs & 0xffff) == USER_CS) ? (UserMode) : (KernelMode);
       DPRINT("Math/Xmm fault happened! (PreviousMode = %s)\n",
-              (PreviousMode == UserMode) ? ("UserMode") : ("KernelMode"));
+              (PreviousMode != KernelMode) ? ("UserMode") : ("KernelMode"));
 
       ASSERT(NpxThread == CurrentThread); /* FIXME: Is not always true I think */
 

Modified: trunk/reactos/ntoskrnl/ke/kthread.c
--- trunk/reactos/ntoskrnl/ke/kthread.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ke/kthread.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -1435,7 +1435,7 @@
 
         Thread->Alerted[AlertMode] = FALSE;
 
-    } else if ((AlertMode == UserMode) && (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))) {
+    } else if ((AlertMode != KernelMode) && (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))) {
 
         /* If the mode is User and the Queue isn't empty, set Pending */
         Thread->ApcState.UserApcPending = TRUE;
@@ -1480,9 +1480,7 @@
 
         _SEH_TRY {
 
-            ProbeForWrite(SuspendCount,
-                          sizeof(HANDLE),
-                          sizeof(ULONG));
+            ProbeForWriteUlong(SuspendCount);
 
         } _SEH_HANDLE {
 
@@ -1578,26 +1576,30 @@
     /* Check if parameters are valid */
     if(PreviousMode != KernelMode) {
 
+        Status = STATUS_SUCCESS;
+        
         _SEH_TRY {
 
-            ProbeForRead(DelayInterval,
-                         sizeof(LARGE_INTEGER),
-                         sizeof(ULONG));
-
             /* make a copy on the kernel stack and let DelayInterval point to it so
                we don't need to wrap KeDelayExecutionThread in SEH! */
-            SafeInterval = *DelayInterval;
+            SafeInterval = ProbeForReadLargeInteger(DelayInterval);
+            DelayInterval = &SafeInterval;
 
         } _SEH_HANDLE {
 
             Status = _SEH_GetExceptionCode();
         } _SEH_END;
+        
+        if (!NT_SUCCESS(Status))
+        {
+            return Status;
+        }
    }
 
    /* Call the Kernel Function */
    Status = KeDelayExecutionThread(PreviousMode,
                                    Alertable,
-                                   &SafeInterval);
+                                   DelayInterval);
 
    /* Return Status */
    return Status;

Modified: trunk/reactos/ntoskrnl/ke/queue.c
--- trunk/reactos/ntoskrnl/ke/queue.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ke/queue.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -223,7 +223,7 @@
             Thread->WaitBlockList = &Thread->WaitBlock[0];
 
             /* Fail if there's an APC Pending */
-            if (WaitMode == UserMode && Thread->ApcState.UserApcPending) {
+            if (WaitMode != KernelMode && Thread->ApcState.UserApcPending) {
 
                 /* Return the status and increase the pending threads */
                 ListEntry = (PLIST_ENTRY)STATUS_USER_APC;

Modified: trunk/reactos/ntoskrnl/ke/wait.c
--- trunk/reactos/ntoskrnl/ke/wait.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ke/wait.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -47,7 +47,7 @@
 
         /* If there are User APCs Pending, then we can't really be alertable */
         } else if ((!IsListEmpty(&CurrentThread->ApcState.ApcListHead[UserMode])) &&
-                    (WaitMode == UserMode)) {
+                    (WaitMode != KernelMode)) {
 
             DPRINT("APCs are Pending\n");
             CurrentThread->ApcState.UserApcPending = TRUE;
@@ -55,7 +55,7 @@
         }
 
     /* If there are User APCs Pending and we are waiting in usermode, then we must notify the caller */
-    } else if ((CurrentThread->ApcState.UserApcPending) && (WaitMode == UserMode)) {
+    } else if ((CurrentThread->ApcState.UserApcPending) && (WaitMode != KernelMode)) {
             DPRINT("APCs are Pending\n");
             *Status = STATUS_USER_APC;
     }

Modified: trunk/reactos/ntoskrnl/lpc/connect.c
--- trunk/reactos/ntoskrnl/lpc/connect.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/lpc/connect.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -265,14 +265,10 @@
     {
       _SEH_TRY
         {
-          ProbeForWrite(UnsafeConnectedPortHandle,
-                        sizeof(HANDLE),
-                        sizeof(ULONG));
+          ProbeForWriteHandle(UnsafeConnectedPortHandle);
           if (UnsafeMaximumMessageSize != NULL)
             {
-              ProbeForWrite(UnsafeMaximumMessageSize,
-                            sizeof(ULONG),
-                            sizeof(ULONG));
+              ProbeForWriteUlong(UnsafeMaximumMessageSize);
             }
         }
       _SEH_HANDLE
@@ -341,10 +337,7 @@
         {
           _SEH_TRY
             {
-              ProbeForRead(UnsafeConnectDataLength,
-                           sizeof(ULONG),
-                           1);
-              ConnectDataLength = *UnsafeConnectDataLength;
+              ConnectDataLength = ProbeForReadUlong(UnsafeConnectDataLength);
             }
           _SEH_HANDLE
             {
@@ -374,9 +367,7 @@
             {
               _SEH_TRY
                 {
-                  ProbeForWrite(UnsafeConnectData,
-                                ConnectDataLength,
-                                1);
+                  ProbeForWriteUlong(UnsafeConnectData);
                   RtlCopyMemory(ConnectData,
                                 UnsafeConnectData,
                                 ConnectDataLength);

Modified: trunk/reactos/ntoskrnl/mm/mdl.c
--- trunk/reactos/ntoskrnl/mm/mdl.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/mm/mdl.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -778,7 +778,7 @@
    /* Calculate the number of pages required. */
    PageCount = PAGE_ROUND_UP(Mdl->ByteCount + Mdl->ByteOffset) / PAGE_SIZE;
 
-   if (AccessMode == UserMode)
+   if (AccessMode != KernelMode)
    {
       MEMORY_AREA *Result;
       LARGE_INTEGER BoundaryAddressMultiple;
@@ -885,7 +885,7 @@
       {
          return NULL;
       }
-      if (AccessMode == UserMode)
+      if (AccessMode != KernelMode)
       {
          /* Throw exception */
          ExRaiseStatus(STATUS_ACCESS_VIOLATION);

Modified: trunk/reactos/ntoskrnl/mm/pagefile.c
--- trunk/reactos/ntoskrnl/mm/pagefile.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/mm/pagefile.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -801,18 +801,12 @@
    {
       return(Status);
    }
-   if (PreviousMode == UserMode)
+   if (PreviousMode != KernelMode)
    {
       _SEH_TRY
       {
-         ProbeForRead(InitialSize,
-                      sizeof(LARGE_INTEGER),
-                      sizeof(ULONG));
-         SafeInitialSize = *InitialSize;
-         ProbeForRead(MaximumSize,
-                      sizeof(LARGE_INTEGER),
-                      sizeof(ULONG));
-         SafeMaximumSize = *MaximumSize;
+         SafeInitialSize = ProbeForReadLargeInteger(InitialSize);
+         SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
       }
       _SEH_HANDLE
       {

Modified: trunk/reactos/ntoskrnl/mm/section.c
--- trunk/reactos/ntoskrnl/mm/section.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/mm/section.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -3317,11 +3317,8 @@
    {
      _SEH_TRY
      {
-       ProbeForRead(MaximumSize,
-                    sizeof(LARGE_INTEGER),
-                    sizeof(ULONG));
        /* make a copy on the stack */
-       SafeMaximumSize = *MaximumSize;
+       SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
        MaximumSize = &SafeMaximumSize;
      }
      _SEH_HANDLE
@@ -3401,9 +3398,7 @@
    {
      _SEH_TRY
      {
-       ProbeForWrite(SectionHandle,
-                     sizeof(HANDLE),
-                     sizeof(ULONG));
+       ProbeForWriteHandle(SectionHandle);
      }
      _SEH_HANDLE
      {
@@ -3573,21 +3568,15 @@
      {
        if(BaseAddress != NULL)
        {
-         ProbeForWrite(BaseAddress,
-                       sizeof(PVOID),
-                       sizeof(ULONG));
+         ProbeForWritePointer(BaseAddress);
          SafeBaseAddress = *BaseAddress;
        }
        if(SectionOffset != NULL)
        {
-         ProbeForWrite(SectionOffset,
-                       sizeof(LARGE_INTEGER),
-                       sizeof(ULONG));
+         ProbeForWriteLargeInteger(SectionOffset);
          SafeSectionOffset = *SectionOffset;
        }
-       ProbeForWrite(ViewSize,
-                     sizeof(ULONG),
-                     sizeof(ULONG));
+       ProbeForWriteUlong(ViewSize);
        SafeViewSize = *ViewSize;
      }
      _SEH_HANDLE
@@ -4133,11 +4122,8 @@
    {
      _SEH_TRY
      {
-       ProbeForRead(NewMaximumSize,
-                    sizeof(LARGE_INTEGER),
-                    sizeof(ULONG));
        /* make a copy on the stack */
-       SafeNewMaximumSize = *NewMaximumSize;
+       SafeNewMaximumSize = ProbeForReadLargeInteger(NewMaximumSize);
        NewMaximumSize = &SafeNewMaximumSize;
      }
      _SEH_HANDLE

Modified: trunk/reactos/ntoskrnl/mm/virtual.c
--- trunk/reactos/ntoskrnl/mm/virtual.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/mm/virtual.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -303,9 +303,7 @@
      {
        _SEH_TRY
          {
-           ProbeForWrite(UnsafeResultLength,
-                         sizeof(ULONG),
-                         sizeof(ULONG));
+           ProbeForWriteUlong(UnsafeResultLength);
          }
        _SEH_HANDLE
          {
@@ -458,15 +456,9 @@
      {
        _SEH_TRY
          {
-           ProbeForWrite(UnsafeBaseAddress,
-                         sizeof(PVOID),
-                         sizeof(ULONG));
-           ProbeForWrite(UnsafeBaseAddress,
-                         sizeof(ULONG),
-                         sizeof(ULONG));
-           ProbeForWrite(UnsafeOldAccessProtection,
-                         sizeof(ULONG),
-                         sizeof(ULONG));
+           ProbeForWritePointer(UnsafeBaseAddress);
+           ProbeForWriteUlong(UnsafeNumberOfBytesToProtect);
+           ProbeForWriteUlong(UnsafeOldAccessProtection);
 
            BaseAddress = *UnsafeBaseAddress;
            NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect;
@@ -573,9 +565,7 @@
                      1);
        if(NumberOfBytesRead != NULL)
        {
-         ProbeForWrite(NumberOfBytesRead,
-                       sizeof(ULONG),
-                       sizeof(ULONG));
+         ProbeForWriteUlong(NumberOfBytesRead);
        }
      }
      _SEH_HANDLE
@@ -776,9 +766,7 @@
      {
        _SEH_TRY
          {
-           ProbeForWrite(NumberOfBytesWritten,
-                         sizeof(ULONG),
-                         sizeof(ULONG));
+           ProbeForWriteUlong(NumberOfBytesWritten);
          }
        _SEH_HANDLE
          {

Modified: trunk/reactos/ntoskrnl/ob/dirobj.c
--- trunk/reactos/ntoskrnl/ob/dirobj.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ob/dirobj.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -58,9 +58,7 @@
    {
      _SEH_TRY
      {
-       ProbeForWrite(DirectoryHandle,
-                     sizeof(HANDLE),
-                     sizeof(ULONG));
+       ProbeForWriteHandle(DirectoryHandle);
      }
      _SEH_HANDLE
      {
@@ -186,18 +184,14 @@
       ProbeForWrite(Buffer,
                     BufferLength,
                     sizeof(WCHAR));
-      ProbeForWrite(Context,
-                    sizeof(ULONG),
-                    sizeof(ULONG));
+      ProbeForWriteUlong(Context);
       if(!RestartScan)
       {
         SkipEntries = *Context;
       }
       if(ReturnLength != NULL)
       {
-        ProbeForWrite(ReturnLength,
-                      sizeof(ULONG),
-                      sizeof(ULONG));
+        ProbeForWriteUlong(ReturnLength);
       }
     }
     _SEH_HANDLE
@@ -449,9 +443,7 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(DirectoryHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(DirectoryHandle);
     }
     _SEH_HANDLE
     {

Modified: trunk/reactos/ntoskrnl/ob/handle.c
--- trunk/reactos/ntoskrnl/ob/handle.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ob/handle.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -388,9 +388,7 @@
    {
      _SEH_TRY
      {
-       ProbeForWrite(TargetHandle,
-                     sizeof(HANDLE),
-                     sizeof(ULONG));
+       ProbeForWriteHandle(TargetHandle);
      }
      _SEH_HANDLE
      {

Modified: trunk/reactos/ntoskrnl/ob/symlink.c
--- trunk/reactos/ntoskrnl/ob/symlink.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ob/symlink.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -186,9 +186,7 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(LinkHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(LinkHandle);
     }
     _SEH_HANDLE
     {
@@ -303,9 +301,7 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(LinkHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(LinkHandle);
     }
     _SEH_HANDLE
     {
@@ -388,9 +384,7 @@
 
       if(ResultLength != NULL)
       {
-        ProbeForWrite(ResultLength,
-                      sizeof(ULONG),
-                      sizeof(ULONG));
+        ProbeForWriteUlong(ResultLength);
       }
     }
     _SEH_HANDLE

Modified: trunk/reactos/ntoskrnl/ob/wait.c
--- trunk/reactos/ntoskrnl/ob/wait.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ob/wait.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -75,12 +75,8 @@
             
             if(TimeOut)
             {
-                ProbeForRead(TimeOut,
-                             sizeof(LARGE_INTEGER),
-                             sizeof(ULONG));
-
                 /* Make a local copy of the timeout on the stack */
-                SafeTimeOut = *TimeOut;
+                SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
                 TimeOut = &SafeTimeOut;
             }
         }
@@ -273,11 +269,8 @@
     {
         _SEH_TRY
         {
-            ProbeForRead(TimeOut,
-                         sizeof(LARGE_INTEGER),
-                         sizeof(ULONG));
             /* Make a copy on the stack */
-            SafeTimeOut = *TimeOut;
+            SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
             TimeOut = &SafeTimeOut;
         }
         _SEH_HANDLE
@@ -354,11 +347,8 @@
     {
         _SEH_TRY
         {
-            ProbeForRead(TimeOut,
-                         sizeof(LARGE_INTEGER),
-                         sizeof(ULONG));
             /* Make a copy on the stack */
-            SafeTimeOut = *TimeOut;
+            SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
             TimeOut = &SafeTimeOut;
         }
         _SEH_HANDLE

Modified: trunk/reactos/ntoskrnl/ps/job.c
--- trunk/reactos/ntoskrnl/ps/job.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ps/job.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -212,7 +212,7 @@
     CurrentProcess = PsGetCurrentProcess();
 
     /* check for valid buffers */
-    if(PreviousMode == UserMode)
+    if(PreviousMode != KernelMode)
     {
         _SEH_TRY
         {
@@ -382,7 +382,7 @@
     PreviousMode = ExGetPreviousMode();
 
     /* check for valid buffers */
-    if(PreviousMode == UserMode)
+    if(PreviousMode != KernelMode)
     {
         _SEH_TRY
         {

Modified: trunk/reactos/ntoskrnl/ps/security.c
--- trunk/reactos/ntoskrnl/ps/security.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ps/security.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -75,7 +75,7 @@
 
    PreviousMode = ExGetPreviousMode();
 
-   if(PreviousMode == UserMode)
+   if(PreviousMode != KernelMode)
    {
      _SEH_TRY
      {

Modified: trunk/reactos/ntoskrnl/ps/suspend.c
--- trunk/reactos/ntoskrnl/ps/suspend.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/ps/suspend.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -45,7 +45,7 @@
            ThreadHandle, SuspendCount);
 
     /* Check buffer validity */
-    if(SuspendCount && PreviousMode == UserMode) {
+    if(SuspendCount && PreviousMode != KernelMode) {
 
         _SEH_TRY {
 

Modified: trunk/reactos/ntoskrnl/rtl/capture.c
--- trunk/reactos/ntoskrnl/rtl/capture.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/rtl/capture.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -32,7 +32,7 @@
    * Copy the source string structure to kernel space.
    */
 
-  if(CurrentMode == UserMode)
+  if(CurrentMode != KernelMode)
   {
     RtlZeroMemory(&Src, sizeof(Src));
 

Modified: trunk/reactos/ntoskrnl/se/acl.c
--- trunk/reactos/ntoskrnl/se/acl.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/se/acl.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -354,7 +354,7 @@
   PAGED_CODE();
 
   if(CapturedAcl != NULL &&
-     (AccessMode == UserMode ||
+     (AccessMode != KernelMode ||
       (AccessMode == KernelMode && CaptureIfKernel)))
   {
     ExFreePool(CapturedAcl);

Modified: trunk/reactos/ntoskrnl/se/sd.c
--- trunk/reactos/ntoskrnl/se/sd.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/se/sd.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -338,7 +338,7 @@
   PAGED_CODE();
 
   if(CapturedSecurityQualityOfService != NULL &&
-     (AccessMode == UserMode ||
+     (AccessMode != KernelMode ||
       (AccessMode == KernelMode && CaptureIfKernel)))
   {
     ExFreePool(CapturedSecurityQualityOfService);
@@ -819,7 +819,7 @@
               and CaptureIfKernelMode that you previously passed to
               SeCaptureSecurityDescriptor() in order to avoid memory leaks! */
   if(CapturedSecurityDescriptor != NULL &&
-     (CurrentMode == UserMode ||
+     (CurrentMode != KernelMode ||
       (CurrentMode == KernelMode && CaptureIfKernelMode)))
   {
     /* only delete the descriptor when SeCaptureSecurityDescriptor() allocated one! */

Modified: trunk/reactos/ntoskrnl/se/sid.c
--- trunk/reactos/ntoskrnl/se/sid.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/se/sid.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -316,7 +316,7 @@
   PAGED_CODE();
 
   if(CapturedSid != NULL &&
-     (AccessMode == UserMode ||
+     (AccessMode != KernelMode ||
       (AccessMode == KernelMode && CaptureIfKernel)))
   {
     ExFreePool(CapturedSid);

Modified: trunk/reactos/ntoskrnl/se/token.c
--- trunk/reactos/ntoskrnl/se/token.c	2005-08-21 17:38:07 UTC (rev 17466)
+++ trunk/reactos/ntoskrnl/se/token.c	2005-08-21 19:04:23 UTC (rev 17467)
@@ -1440,9 +1440,7 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(NewTokenHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(NewTokenHandle);
     }
     _SEH_HANDLE
     {
@@ -2053,6 +2051,7 @@
   ULONG uLength;
   ULONG i;
   ULONG nTokenPrivileges = 0;
+  LARGE_INTEGER LocalExpirationTime = {};
   KPROCESSOR_MODE PreviousMode;
   NTSTATUS Status = STATUS_SUCCESS;
 
@@ -2064,15 +2063,11 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(TokenHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(TokenHandle);
       ProbeForRead(AuthenticationId,
                    sizeof(LUID),
                    sizeof(ULONG));
-      ProbeForRead(ExpirationTime,
-                   sizeof(LARGE_INTEGER),
-                   sizeof(ULONG));
+      LocalExpirationTime = ProbeForReadLargeInteger(ExpirationTime);
       ProbeForRead(TokenUser,
                    sizeof(TOKEN_USER),
                    sizeof(ULONG));
@@ -2110,6 +2105,7 @@
   else
   {
     nTokenPrivileges = TokenPrivileges->PrivilegeCount;
+    LocalExpirationTime = *ExpirationTime;
   }
 
   Status = ZwAllocateLocallyUniqueId(&TokenId);
@@ -2383,9 +2379,7 @@
   {
     _SEH_TRY
     {
-      ProbeForWrite(TokenHandle,
-                    sizeof(HANDLE),
-                    sizeof(ULONG));
+      ProbeForWriteHandle(TokenHandle);
     }
     _SEH_HANDLE
     {