[ros-diffs] [weiden] 13897: 1. fixed querying tokens

weiden at svn.reactos.com weiden at svn.reactos.com
Wed Mar 9 01:04:14 CET 2005


1. fixed querying tokens
2. implemented calling vectored exception handlers
Modified: branches/alex_devel_branch/reactos/lib/ntdll/def/ntdll.def
Modified: branches/alex_devel_branch/reactos/lib/ntdll/rtl/exception.c
Modified: branches/alex_devel_branch/reactos/lib/ntdll/rtl/misc.c
Modified: branches/alex_devel_branch/reactos/lib/rtl/sid.c
Modified:
branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ke/dpc.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/ke/ipi.c
Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/token.c
Modified: branches/alex_devel_branch/reactos/w32api/include/ddk/ntifs.h
  _____  

Modified: branches/alex_devel_branch/reactos/lib/ntdll/def/ntdll.def
--- branches/alex_devel_branch/reactos/lib/ntdll/def/ntdll.def
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/lib/ntdll/def/ntdll.def
2005-03-09 00:04:13 UTC (rev 13897)
@@ -363,7 +363,7 @@

 RtlCustomCPToUnicodeN at 24
 RtlCutoverTimeToSystemTime at 16
 RtlDeNormalizeProcessParams at 4
-RtlDecodePointer at 4=RtlEncodePointer at 4
+RtlDecodePointer=RtlEncodePointer at 4
 RtlDecompressBuffer at 24
 RtlDecompressFragment at 32
 RtlDelete at 4
  _____  

Modified: branches/alex_devel_branch/reactos/lib/ntdll/rtl/exception.c
--- branches/alex_devel_branch/reactos/lib/ntdll/rtl/exception.c
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/lib/ntdll/rtl/exception.c
2005-03-09 00:04:13 UTC (rev 13897)
@@ -31,6 +31,10 @@

   PVECTORED_EXCEPTION_HANDLER VectoredHandler;
 } RTL_VECTORED_EXCEPTION_HANDLER, *PRTL_VECTORED_EXCEPTION_HANDLER;
 
+/* FIXME - stupid ld won't resolve RtlDecodePointer! Since their
implementation
+           is the same just use RtlEncodePointer for now! */
+#define RtlDecodePointer RtlEncodePointer
+
 /* FUNCTIONS
***************************************************************/
 
 VOID STDCALL
@@ -44,20 +48,63 @@
 RtlpDispatchException(IN PEXCEPTION_RECORD  ExceptionRecord,
 	IN PCONTEXT  Context);
 
+EXCEPTION_DISPOSITION
+RtlpExecuteVectoredExceptionHandlers(IN PEXCEPTION_RECORD
ExceptionRecord,
+                                     IN PCONTEXT  Context)
+{
+  PLIST_ENTRY CurrentEntry;
+  PRTL_VECTORED_EXCEPTION_HANDLER veh;
+  PVECTORED_EXCEPTION_HANDLER VectoredHandler;
+  EXCEPTION_POINTERS ExceptionInfo;
+  
+  ExceptionInfo.ExceptionRecord = ExceptionRecord;
+  ExceptionInfo.ContextRecord = Context;
+  
+  if(RtlpVectoredExceptionHead.Flink != &RtlpVectoredExceptionHead)
+  {
+    RtlEnterCriticalSection(&RtlpVectoredExceptionLock);
+    for(CurrentEntry = RtlpVectoredExceptionHead.Flink;
+        CurrentEntry != &RtlpVectoredExceptionHead;
+        CurrentEntry = CurrentEntry->Flink)
+    {
+      veh = CONTAINING_RECORD(CurrentEntry,
+                              RTL_VECTORED_EXCEPTION_HANDLER,
+                              ListEntry);
+      VectoredHandler = RtlDecodePointer(veh->VectoredHandler);
+      if(VectoredHandler(&ExceptionInfo) ==
EXCEPTION_CONTINUE_EXECUTION)
+      {
+        RtlLeaveCriticalSection(&RtlpVectoredExceptionLock);
+        return ExceptionContinueSearch;
+      }
+    }
+    RtlLeaveCriticalSection(&RtlpVectoredExceptionLock);
+  }
+  
+  return ExceptionContinueExecution;
+}
+
 VOID STDCALL
 KiUserExceptionDispatcher(PEXCEPTION_RECORD ExceptionRecord,
 			  PCONTEXT Context)
 {
   EXCEPTION_RECORD NestedExceptionRecord;
   NTSTATUS Status;
-
-  if (RtlpDispatchException(ExceptionRecord, Context) !=
ExceptionContinueExecution)
+  
+  if(RtlpExecuteVectoredExceptionHandlers(ExceptionRecord,
+                                          Context) !=
ExceptionContinueExecution)
     {
       Status = NtContinue(Context, FALSE);
     }
   else
     {
-      Status = NtRaiseException(ExceptionRecord, Context, FALSE);
+      if(RtlpDispatchException(ExceptionRecord, Context) !=
ExceptionContinueExecution)
+        {
+          Status = NtContinue(Context, FALSE);
+        }
+      else
+        {
+          Status = NtRaiseException(ExceptionRecord, Context, FALSE);
+        }
     }
 
   NestedExceptionRecord.ExceptionCode = Status;
  _____  

Modified: branches/alex_devel_branch/reactos/lib/ntdll/rtl/misc.c
--- branches/alex_devel_branch/reactos/lib/ntdll/rtl/misc.c
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/lib/ntdll/rtl/misc.c
2005-03-09 00:04:13 UTC (rev 13897)
@@ -131,7 +131,7 @@

   if(!NT_SUCCESS(Status))
   {
     DPRINT1("Failed to receive the process cookie! Status: 0x%x\n",
Status);
-    return NULL;
+    return Pointer;
   }
 
   return (PVOID)((ULONG_PTR)Pointer ^ Cookie);
  _____  

Modified: branches/alex_devel_branch/reactos/lib/rtl/sid.c
--- branches/alex_devel_branch/reactos/lib/rtl/sid.c	2005-03-08
23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/lib/rtl/sid.c	2005-03-09
00:04:13 UTC (rev 13897)
@@ -200,7 +200,7 @@

       RtlCopySid(SidLength,
                  SidArea,
                  Src[i].Sid);
-      SidArea = SidArea + SidLength;
+      SidArea = (PVOID)((ULONG_PTR)SidArea + SidLength);
    }
    *RemainingSidArea = SidArea;
    *RemainingSidAreaSize = Length;
  _____  

Modified:
branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h
--- branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/ntoskrnl/include/internal/ob.h
2005-03-09 00:04:13 UTC (rev 13897)
@@ -377,10 +377,8 @@

     else if(ClassList[Class].RequiredSize##Mode > 0 &&
\
             (BufferLen) != ClassList[Class].RequiredSize##Mode)
\
     {
\
-      if((!(ClassList[Class].Flags & ICIF_##Mode##_SIZE_VARIABLE) &&
\
-           (BufferLen) != ClassList[Class].RequiredSize##Mode) ||
\
-         ((ClassList[Class].Flags & ICIF_##Mode##_SIZE_VARIABLE) &&
\
-          (BufferLen) < ClassList[Class].RequiredSize##Mode))
\
+      if(!(ClassList[Class].Flags & ICIF_##Mode##_SIZE_VARIABLE) &&
\
+           (BufferLen) != ClassList[Class].RequiredSize##Mode)
\
       {
\
         *(StatusVar) = STATUS_INFO_LENGTH_MISMATCH;
\
       }
\
  _____  

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ke/dpc.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ke/dpc.c
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ke/dpc.c
2005-03-09 00:04:13 UTC (rev 13897)
@@ -513,7 +513,7 @@

 #endif
             Prcb->DpcRoutineActive = TRUE;
 
-        DPRINT("&Pcr->PrcbData.DpcData[0].DpcListHead: %x\n",
&Prcb->DpcData[0].DpcListHead);
+        DPRINT("&Prcb->DpcData[0].DpcListHead: %x\n",
&Prcb->DpcData[0].DpcListHead);
         /* Loop while we have entries */
         while (!IsListEmpty(&Prcb->DpcData[0].DpcListHead)) {
             
  _____  

Modified: branches/alex_devel_branch/reactos/ntoskrnl/ke/ipi.c
--- branches/alex_devel_branch/reactos/ntoskrnl/ke/ipi.c
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/ntoskrnl/ke/ipi.c
2005-03-09 00:04:13 UTC (rev 13897)
@@ -119,18 +119,18 @@

 KiIpiSendPacket(ULONG TargetSet, VOID STDCALL (*WorkerRoutine)(PVOID),
PVOID Argument, ULONG Count, BOOLEAN Synchronize)
 {
     ULONG i, Processor, CurrentProcessor;
-    PKPCR Pcr, CurrentPcr;
+    PKPRCB Prcb, CurrentPrcb;
     KIRQL oldIrql;
 
 
     ASSERT(KeGetCurrentIrql() == SYNCH_LEVEL);
 
-    CurrentPcr = KeGetCurrentKPCR();
-    InterlockedExchangeUL(&CurrentPcr->PrcbData.TargetSet, TargetSet);
-    InterlockedExchangeUL(&CurrentPcr->PrcbData.WorkerRoutine,
(ULONG_PTR)WorkerRoutine);
-    InterlockedExchangePointer(&CurrentPcr->PrcbData.CurrentPacket[0],
Argument);
-    InterlockedExchangeUL(&CurrentPcr->PrcbData.CurrentPacket[1],
Count);
-    InterlockedExchangeUL(&CurrentPcr->PrcbData.CurrentPacket[2],
Synchronize ? 1 : 0);
+    CurrentPrcb = KeGetCurrentPrcb();
+    InterlockedExchangeUL(&CurrentPrcb->TargetSet, TargetSet);
+    InterlockedExchangeUL(&CurrentPrcb->WorkerRoutine,
(ULONG_PTR)WorkerRoutine);
+    InterlockedExchangePointer(&CurrentPrcb->CurrentPacket[0],
Argument);
+    InterlockedExchangeUL(&CurrentPrcb->CurrentPacket[1], Count);
+    InterlockedExchangeUL(&CurrentPrcb->CurrentPacket[2], Synchronize ?
1 : 0);
 
     CurrentProcessor = 1 << KeGetCurrentProcessorNumber();
 
@@ -138,9 +138,9 @@
     {
        if (TargetSet & Processor)
        {
-          Pcr = (PKPCR)(KPCR_BASE + i * PAGE_SIZE);
-          while(0 !=
InterlockedCompareExchangeUL(&Pcr->PrcbData.SignalDone,
(LONG)&CurrentPcr->PrcbData, 0));
-	  Ke386TestAndSetBit(IPI_REQUEST_FUNCTIONCALL,
&Pcr->PrcbData.IpiFrozen);
+          Prcb = ((PKPCR)(KPCR_BASE + i * PAGE_SIZE))->Prcb;
+          while(0 != InterlockedCompareExchangeUL(&Prcb->SignalDone,
(LONG)CurrentPrcb, 0));
+	  Ke386TestAndSetBit(IPI_REQUEST_FUNCTIONCALL,
&Prcb->IpiFrozen);
 	  if (Processor != CurrentProcessor)
 	  {
 	     HalRequestIpi(i);
  _____  

Modified: branches/alex_devel_branch/reactos/ntoskrnl/se/token.c
--- branches/alex_devel_branch/reactos/ntoskrnl/se/token.c
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/ntoskrnl/se/token.c
2005-03-09 00:04:13 UTC (rev 13897)
@@ -643,7 +643,6 @@

 
   if(!NT_SUCCESS(Status))
   {
-    /* Invalid buffers */
     DPRINT("NtQueryInformationToken() failed, Status: 0x%x\n", Status);
     return Status;
   }
@@ -664,15 +663,15 @@
         
         DPRINT("NtQueryInformationToken(TokenUser)\n");
         RequiredLength = sizeof(TOKEN_USER) +
-                         RtlLengthSidAndAttributes(1,
Token->UserAndGroups);
+                         RtlLengthSid(Token->UserAndGroups[0].Sid);
 
         _SEH_TRY
         {
           if(TokenInformationLength >= RequiredLength)
           {
             Status = RtlCopySidAndAttributesArray(1,
-                                                  Token->UserAndGroups,
-                                                  RequiredLength,
+
&Token->UserAndGroups[0],
+                                                  RequiredLength -
sizeof(TOKEN_USER),
                                                   &tu->User,
                                                   (PSID)(tu + 1),
                                                   &Unused.Ptr,
@@ -702,21 +701,22 @@
         PTOKEN_GROUPS tg = (PTOKEN_GROUPS)TokenInformation;
         
         DPRINT("NtQueryInformationToken(TokenGroups)\n");
-        RequiredLength = sizeof(TOKEN_GROUPS) +
-
RtlLengthSidAndAttributes(Token->UserAndGroupCount - 1,
&Token->UserAndGroups[1]) +
-                         sizeof(SID_AND_ATTRIBUTES);
+        RequiredLength = sizeof(tg->GroupCount) +
+
RtlLengthSidAndAttributes(Token->UserAndGroupCount - 1,
&Token->UserAndGroups[1]);
 
         _SEH_TRY
         {
           if(TokenInformationLength >= RequiredLength)
           {
-            PSID_AND_ATTRIBUTES Sid =
(PSID_AND_ATTRIBUTES)((ULONG_PTR)TokenInformation +
-
RequiredLength - sizeof(SID_AND_ATTRIBUTES));
+            ULONG SidLen = RequiredLength - sizeof(tg->GroupCount) -
+                           ((Token->UserAndGroupCount - 1) *
sizeof(SID_AND_ATTRIBUTES));
+            PSID_AND_ATTRIBUTES Sid =
(PSID_AND_ATTRIBUTES)((ULONG_PTR)TokenInformation +
sizeof(tg->GroupCount) +
+
((Token->UserAndGroupCount - 1) * sizeof(SID_AND_ATTRIBUTES)));
 
             tg->GroupCount = Token->UserAndGroupCount - 1;
             Status =
RtlCopySidAndAttributesArray(Token->UserAndGroupCount - 1,
 
&Token->UserAndGroups[1],
-                                                  RequiredLength,
+                                                  SidLen,
                                                   &tg->Groups[0],
                                                   (PSID)Sid,
                                                   &Unused.Ptr,
@@ -746,7 +746,7 @@
         PTOKEN_PRIVILEGES tp = (PTOKEN_PRIVILEGES)TokenInformation;
         
         DPRINT("NtQueryInformationToken(TokenPrivileges)\n");
-        RequiredLength = sizeof(TOKEN_PRIVILEGES) +
+        RequiredLength = sizeof(tp->PrivilegeCount) +
                          (Token->PrivilegeCount *
sizeof(LUID_AND_ATTRIBUTES));
 
         _SEH_TRY
@@ -1096,6 +1096,7 @@
         {
           _SEH_TRY
           {
+            /* buffer size was already verified, no need to check here
again */
             *(PULONG)TokenInformation = SessionId;
 
             if(ReturnLength != NULL)
@@ -1357,6 +1358,7 @@
 
         _SEH_TRY
         {
+          /* buffer size was already verified, no need to check here
again */
           SessionId = *(PULONG)TokenInformation;
         }
         _SEH_HANDLE
  _____  

Modified: branches/alex_devel_branch/reactos/w32api/include/ddk/ntifs.h
--- branches/alex_devel_branch/reactos/w32api/include/ddk/ntifs.h
2005-03-08 23:33:28 UTC (rev 13896)
+++ branches/alex_devel_branch/reactos/w32api/include/ddk/ntifs.h
2005-03-09 00:04:13 UTC (rev 13897)
@@ -1218,13 +1218,23 @@

     ULONG   LastIndexValue;
 } GENERATE_NAME_CONTEXT, *PGENERATE_NAME_CONTEXT;
 
+typedef struct _HANDLE_TABLE_ENTRY_INFO {
+    ULONG AuditMask;
+} HANDLE_TABLE_ENTRY_INFO, *PHANDLE_TABLE_ENTRY_INFO;
+
 typedef struct _HANDLE_TABLE_ENTRY {
-    PVOID   Object;
-    ULONG   ObjectAttributes;
-    ULONG   GrantedAccess;
-    USHORT  GrantedAccessIndex;
-    USHORT  CreatorBackTraceIndex;
-    ULONG   NextFreeTableEntry;
+    union {
+        PVOID Object;
+        ULONG ObAttributes;
+        PHANDLE_TABLE_ENTRY_INFO InfoTable;
+        ULONG_PTR Value;
+    } u1;
+    union {
+        ULONG GrantedAccess;
+        USHORT GrantedAccessIndex;
+        LONG NextFreeTableEntry;
+    } u2;
+    USHORT CreatorBackTraceIndex;
 } HANDLE_TABLE_ENTRY, *PHANDLE_TABLE_ENTRY;
 
 typedef struct _MAPPING_PAIR {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.reactos.org/pipermail/ros-diffs/attachments/20050309/81d1fe2b/attachment.html


More information about the Ros-diffs mailing list