Fix build
[reactos.git] / reactos / ntoskrnl / ke / profile.c
index cb2279b..1ebea23 100644 (file)
@@ -3,7 +3,7 @@
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/profile.c
  * PURPOSE:         Kernel Profiling
- * 
+ *
  * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
  */
 
@@ -22,8 +22,8 @@ ULONG KiProfileTimeInterval = 78125; /* Default resolution 7.8ms (sysinternals)
 
 /* FUNCTIONS *****************************************************************/
 
-STDCALL 
 VOID
+STDCALL
 KeInitializeProfile(PKPROFILE Profile,
                     PKPROCESS Process,
                     PVOID ImageBase,
@@ -35,197 +35,185 @@ KeInitializeProfile(PKPROFILE Profile,
     /* Initialize the Header */
     Profile->Type = ProfileObject;
     Profile->Size = sizeof(KPROFILE);
-    
+
     /* Copy all the settings we were given */
     Profile->Process = Process;
-    Profile->RegionStart = ImageBase;
+    Profile->RangeBase = ImageBase;
     Profile->BucketShift = BucketSize - 2; /* See ntinternals.net -- Alex */
-    Profile->RegionEnd = (PVOID)(ULONG_PTR)ImageBase + ImageSize;
-    Profile->Active = FALSE;
+    Profile->RangeLimit = (PVOID)((ULONG_PTR)ImageBase + ImageSize);
+    Profile->Started = FALSE;
     Profile->Source = ProfileSource;
-    Profile->Affinity = Affinity;    
+    Profile->Affinity = Affinity;
 }
 
-STDCALL
 VOID
+STDCALL
 KeStartProfile(PKPROFILE Profile,
                PVOID Buffer)
 {
     KIRQL OldIrql;
     PKPROFILE_SOURCE_OBJECT SourceBuffer;
-    PKPROFILE_SOURCE_OBJECT Source = NULL;
     PKPROFILE_SOURCE_OBJECT CurrentSource;
     BOOLEAN FreeBuffer = TRUE;
     PKPROCESS ProfileProcess;
-    PLIST_ENTRY ListEntry;
-    
+
     /* Allocate a buffer first, before we raise IRQL */
-    SourceBuffer = ExAllocatePoolWithTag(NonPagedPool, 
+    SourceBuffer = ExAllocatePoolWithTag(NonPagedPool,
                                           sizeof(KPROFILE_SOURCE_OBJECT),
                                           TAG('P', 'r', 'o', 'f'));
-    RtlZeroMemory(Source, sizeof(KPROFILE_SOURCE_OBJECT));
-    
+    RtlZeroMemory(SourceBuffer, sizeof(KPROFILE_SOURCE_OBJECT));
+
     /* Raise to PROFILE_LEVEL */
     KeRaiseIrql(PROFILE_LEVEL, &OldIrql);
     KeAcquireSpinLockAtDpcLevel(&KiProfileLock);
-    
+
     /* Make sure it's not running */
-    if (!Profile->Active) {
-    
-        /* Set it as active */
+    if (!Profile->Started) {
+
+        /* Set it as Started */
         Profile->Buffer = Buffer;
-        Profile->Active = TRUE;
-        
+        Profile->Started = TRUE;
+
         /* Get the process, if any */
         ProfileProcess = Profile->Process;
-        
+
         /* Insert it into the Process List or Global List */
         if (ProfileProcess) {
-        
-            InsertTailList(&ProfileProcess->ProfileListHead, &Profile->ListEntry);
-            
+
+            InsertTailList(&ProfileProcess->ProfileListHead, &Profile->ProfileListEntry);
+
         } else {
-        
-            InsertTailList(&KiProfileListHead, &Profile->ListEntry);
+
+            InsertTailList(&KiProfileListHead, &Profile->ProfileListEntry);
         }
-        
+
         /* Check if this type of profile (source) is already running */
-        for (ListEntry = KiProfileSourceListHead.Flink; 
-             ListEntry != &KiProfileSourceListHead; 
-             ListEntry = ListEntry->Flink) {
-                 
-            /* Get the Source Object */
-            CurrentSource = CONTAINING_RECORD(ListEntry, 
-                                              KPROFILE_SOURCE_OBJECT,
-                                              ListEntry);
-            
+        LIST_FOR_EACH(CurrentSource, &KiProfileSourceListHead, KPROFILE_SOURCE_OBJECT, ListEntry)
+        {
             /* Check if it's the same as the one being requested now */
             if (CurrentSource->Source == Profile->Source) {
-            
-                Source = CurrentSource;
                 break;
             }
         }
-        
+
         /* See if the loop found something */
-        if (!Source) {
-            
+        if (!CurrentSource) {
+
             /* Nothing found, use our allocated buffer */
-            Source = SourceBuffer;
-            
+            CurrentSource = SourceBuffer;
+
             /* Set up the Source Object */
-            Source->Source = Profile->Source;
-            InsertHeadList(&KiProfileSourceListHead, &Source->ListEntry);
-            
+            CurrentSource->Source = Profile->Source;
+            InsertHeadList(&KiProfileSourceListHead, &CurrentSource->ListEntry);
+
             /* Don't free the pool later on */
             FreeBuffer = FALSE;
         }
     }
-    
+
     /* Lower the IRQL */
     KeReleaseSpinLockFromDpcLevel(&KiProfileLock);
     KeLowerIrql(OldIrql);
-    
+
     /* FIXME: Tell HAL to Start the Profile Interrupt */
     //HalStartProfileInterrupt(Profile->Source);
-    
+
     /* Free the pool */
     if (!FreeBuffer) ExFreePool(SourceBuffer);
 }
 
+BOOLEAN
 STDCALL
-VOID
 KeStopProfile(PKPROFILE Profile)
 {
     KIRQL OldIrql;
-    PLIST_ENTRY ListEntry;
     PKPROFILE_SOURCE_OBJECT CurrentSource = NULL;
-    
+
     /* Raise to PROFILE_LEVEL and acquire spinlock */
     KeRaiseIrql(PROFILE_LEVEL, &OldIrql);
     KeAcquireSpinLockAtDpcLevel(&KiProfileLock);
-    
+
     /* Make sure it's running */
-    if (Profile->Active) {
-    
+    if (Profile->Started) {
+
         /* Remove it from the list and disable */
-        RemoveEntryList(&Profile->ListEntry);
-        Profile->Active = FALSE;
-        
+        RemoveEntryList(&Profile->ProfileListEntry);
+        Profile->Started = FALSE;
+
         /* Find the Source Object */
-        for (ListEntry = KiProfileSourceListHead.Flink; 
-             CurrentSource->Source != Profile->Source; 
-             ListEntry = ListEntry->Flink) {
-                 
-            /* Get the Source Object */
-            CurrentSource = CONTAINING_RECORD(ListEntry, 
-                                              KPROFILE_SOURCE_OBJECT,
-                                              ListEntry);
+        LIST_FOR_EACH(CurrentSource, &KiProfileSourceListHead, KPROFILE_SOURCE_OBJECT, ListEntry) 
+        {
+            if (CurrentSource->Source == Profile->Source) {
+                /* Remove it */
+                RemoveEntryList(&CurrentSource->ListEntry);
+                break;   
+            }
         }
-        
-        /* Remove it */
-        RemoveEntryList(&CurrentSource->ListEntry);
+
     }
-    
+
     /* Lower IRQL */
     KeReleaseSpinLockFromDpcLevel(&KiProfileLock);
     KeLowerIrql(OldIrql);
-    
+
     /* Stop Profiling. FIXME: Implement in HAL */
     //HalStopProfileInterrupt(Profile->Source);
-    
+
     /* Free the Source Object */
     if (CurrentSource) ExFreePool(CurrentSource);
+
+    /* FIXME */
+    return FALSE;
 }
 
-STDCALL
 ULONG
+STDCALL
 KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource)
 {
     /* Check if this is the timer profile */
     if (ProfileSource == ProfileTime) {
-    
+
         /* Return the good old 100ns sampling interval */
         return KiProfileTimeInterval;
-    
+
     } else {
-    
+
         /* Request it from HAL. FIXME: What structure is used? */
         HalQuerySystemInformation(HalProfileSourceInformation,
                                   sizeof(NULL),
                                   NULL,
                                   NULL);
-        
+
         return 0;
     }
 }
 
-STDCALL    
-VOID 
+VOID
+STDCALL
 KeSetIntervalProfile(KPROFILE_SOURCE ProfileSource,
                      ULONG Interval)
 {
     /* Check if this is the timer profile */
     if (ProfileSource == ProfileTime) {
-    
+
         /* Set the good old 100ns sampling interval */
         KiProfileTimeInterval = Interval;
-    
+
     } else {
-    
+
         /* Set it with HAL. FIXME: What structure is used? */
         HalSetSystemInformation(HalProfileSourceInformation,
                                   sizeof(NULL),
                                   NULL);
-        
+
     }
 }
 
 /*
  * @implemented
  */
-STDCALL
 VOID
+STDCALL
 KeProfileInterrupt(PKTRAP_FRAME TrapFrame)
 {
     /* Called from HAL for Timer Profiling */
@@ -240,27 +228,23 @@ KiParseProfileList(IN PKTRAP_FRAME TrapFrame,
 {
     PULONG BucketValue;
     PKPROFILE Profile;
-    PLIST_ENTRY NextEntry;
-    
+
     /* Loop the List */
-    for (NextEntry = ListHead->Flink; NextEntry != ListHead; NextEntry = NextEntry->Flink) {
-    
-        /* Get the Current Profile in the List */
-        Profile = CONTAINING_RECORD(NextEntry, KPROFILE, ListEntry);
-        
+    LIST_FOR_EACH(Profile, ListHead, KPROFILE, ProfileListEntry)
+    {
         /* Check if the source is good, and if it's within the range */
-        if ((Profile->Source != Source) || 
-            (TrapFrame->Eip < (ULONG_PTR)Profile->RegionStart) || 
-            (TrapFrame->Eip > (ULONG_PTR)Profile->RegionEnd)) {
-            
+        if ((Profile->Source != Source) ||
+            (TrapFrame->Eip < (ULONG_PTR)Profile->RangeBase) ||
+            (TrapFrame->Eip > (ULONG_PTR)Profile->RangeLimit)) {
+
             continue;
-        }   
+        }
 
         /* Get the Pointer to the Bucket Value representing this EIP */
-        BucketValue = (PULONG)(((ULONG_PTR)(Profile->Buffer + 
-                               (TrapFrame->Eip - (ULONG_PTR)Profile->RegionStart))
+        BucketValue = (PULONG)((((ULONG_PTR)Profile->Buffer +
+                               (TrapFrame->Eip - (ULONG_PTR)Profile->RangeBase))
                                 >> Profile->BucketShift) &~ 0x3);
-        
+
         /* Increment the value */
         ++BucketValue;
     }
@@ -276,13 +260,13 @@ KiParseProfileList(IN PKTRAP_FRAME TrapFrame,
  *         from the trap frame into the buffer, while using buckets and
  *         shifting like we specified. -- Alex
  */
-STDCALL
 VOID
+STDCALL
 KeProfileInterruptWithSource(IN PKTRAP_FRAME TrapFrame,
                              IN KPROFILE_SOURCE Source)
 {
     PKPROCESS Process = KeGetCurrentThread()->ApcState.Process;
-    
+
     /* We have to parse 2 lists. Per-Process and System-Wide */
     KiParseProfileList(TrapFrame, Source, &Process->ProfileListHead);
     KiParseProfileList(TrapFrame, Source, &KiProfileListHead);
@@ -291,8 +275,8 @@ KeProfileInterruptWithSource(IN PKTRAP_FRAME TrapFrame,
 /*
  * @implemented
  */
-STDCALL
 VOID
+STDCALL
 KeSetProfileIrql(IN KIRQL ProfileIrql)
 {
     /* Set the IRQL at which Profiling will run */