2005-03-13 18:41:59 +00:00
|
|
|
/*
|
2008-08-24 15:41:13 +00:00
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* FILE: ntoskrnl/ke/profobj.c
|
2004-06-23 22:32:24 +00:00
|
|
|
* PURPOSE: Kernel Profiling
|
2005-01-26 13:58:37 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
2008-08-24 15:41:13 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2004-06-23 22:32:24 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2004-06-23 22:32:24 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
2005-01-07 06:54:27 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
KIRQL KiProfileIrql = PROFILE_LEVEL;
|
|
|
|
LIST_ENTRY KiProfileListHead;
|
|
|
|
LIST_ENTRY KiProfileSourceListHead;
|
|
|
|
KSPIN_LOCK KiProfileLock;
|
|
|
|
ULONG KiProfileTimeInterval = 78125; /* Default resolution 7.8ms (sysinternals) */
|
2009-10-29 19:58:41 +00:00
|
|
|
ULONG KiProfileAlignmentFixupInterval;
|
2005-01-07 06:54:27 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
2005-01-07 06:54:27 +00:00
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-03-13 18:41:59 +00:00
|
|
|
KeInitializeProfile(PKPROFILE Profile,
|
|
|
|
PKPROCESS Process,
|
|
|
|
PVOID ImageBase,
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
SIZE_T ImageSize,
|
2005-03-13 18:41:59 +00:00
|
|
|
ULONG BucketSize,
|
|
|
|
KPROFILE_SOURCE ProfileSource,
|
|
|
|
KAFFINITY Affinity)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Initialize the Header */
|
|
|
|
Profile->Type = ProfileObject;
|
|
|
|
Profile->Size = sizeof(KPROFILE);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Copy all the settings we were given */
|
|
|
|
Profile->Process = Process;
|
2005-11-27 19:21:19 +00:00
|
|
|
Profile->RangeBase = ImageBase;
|
2005-03-13 18:41:59 +00:00
|
|
|
Profile->BucketShift = BucketSize - 2; /* See ntinternals.net -- Alex */
|
2005-11-27 19:21:19 +00:00
|
|
|
Profile->RangeLimit = (PVOID)((ULONG_PTR)ImageBase + ImageSize);
|
|
|
|
Profile->Started = FALSE;
|
2005-03-13 18:41:59 +00:00
|
|
|
Profile->Source = ProfileSource;
|
2005-05-09 01:38:29 +00:00
|
|
|
Profile->Affinity = Affinity;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
BOOLEAN
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2009-10-29 19:58:41 +00:00
|
|
|
KeStartProfile(IN PKPROFILE Profile,
|
|
|
|
IN PVOID Buffer)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
PKPROFILE_SOURCE_OBJECT SourceBuffer;
|
|
|
|
PKPROFILE_SOURCE_OBJECT CurrentSource;
|
2009-10-29 19:58:41 +00:00
|
|
|
BOOLEAN FreeBuffer = TRUE, SourceFound = FALSE, StartedProfile;
|
2005-03-13 18:41:59 +00:00
|
|
|
PKPROCESS ProfileProcess;
|
2008-08-25 18:21:19 +00:00
|
|
|
PLIST_ENTRY NextEntry;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Allocate a buffer first, before we raise IRQL */
|
2005-05-09 01:38:29 +00:00
|
|
|
SourceBuffer = ExAllocatePoolWithTag(NonPagedPool,
|
2009-10-29 19:58:41 +00:00
|
|
|
sizeof(KPROFILE_SOURCE_OBJECT),
|
|
|
|
'forP');
|
|
|
|
if (!SourceBuffer) return FALSE;
|
2005-09-26 22:57:48 +00:00
|
|
|
RtlZeroMemory(SourceBuffer, sizeof(KPROFILE_SOURCE_OBJECT));
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Raise to profile IRQL and acquire the profile lock */
|
|
|
|
KeRaiseIrql(KiProfileIrql, &OldIrql);
|
2005-03-13 18:41:59 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel(&KiProfileLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Make sure it's not running */
|
2008-08-24 15:41:13 +00:00
|
|
|
if (!Profile->Started)
|
|
|
|
{
|
2005-11-27 19:21:19 +00:00
|
|
|
/* Set it as Started */
|
2005-03-13 18:41:59 +00:00
|
|
|
Profile->Buffer = Buffer;
|
2005-11-27 19:21:19 +00:00
|
|
|
Profile->Started = TRUE;
|
2009-10-29 19:58:41 +00:00
|
|
|
StartedProfile = TRUE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Get the process, if any */
|
|
|
|
ProfileProcess = Profile->Process;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-08-24 15:41:13 +00:00
|
|
|
/* Check where we should insert it */
|
|
|
|
if (ProfileProcess)
|
|
|
|
{
|
|
|
|
/* Insert it into the Process List */
|
2005-11-27 19:21:19 +00:00
|
|
|
InsertTailList(&ProfileProcess->ProfileListHead, &Profile->ProfileListEntry);
|
2008-08-24 15:41:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Insert it into the Global List */
|
2005-11-27 19:21:19 +00:00
|
|
|
InsertTailList(&KiProfileListHead, &Profile->ProfileListEntry);
|
2005-03-13 18:41:59 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-08-25 18:21:19 +00:00
|
|
|
/* Start looping */
|
|
|
|
for (NextEntry = KiProfileSourceListHead.Flink;
|
|
|
|
NextEntry != &KiProfileSourceListHead;
|
|
|
|
NextEntry = NextEntry->Flink)
|
2005-09-26 22:57:48 +00:00
|
|
|
{
|
2008-08-25 18:21:19 +00:00
|
|
|
/* Get the entry */
|
|
|
|
CurrentSource = CONTAINING_RECORD(NextEntry,
|
|
|
|
KPROFILE_SOURCE_OBJECT,
|
|
|
|
ListEntry);
|
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Check if it's the same as the one being requested now */
|
2008-08-24 15:41:13 +00:00
|
|
|
if (CurrentSource->Source == Profile->Source)
|
|
|
|
{
|
2008-08-25 18:21:19 +00:00
|
|
|
/* It is, break out */
|
|
|
|
SourceFound = TRUE;
|
2005-03-13 18:41:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* See if the loop found something */
|
2008-08-25 18:21:19 +00:00
|
|
|
if (!SourceFound)
|
2008-08-24 15:41:13 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Nothing found, use our allocated buffer */
|
2005-09-26 22:57:48 +00:00
|
|
|
CurrentSource = SourceBuffer;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Set up the Source Object */
|
2005-09-26 22:57:48 +00:00
|
|
|
CurrentSource->Source = Profile->Source;
|
|
|
|
InsertHeadList(&KiProfileSourceListHead, &CurrentSource->ListEntry);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Don't free the pool later on */
|
|
|
|
FreeBuffer = FALSE;
|
|
|
|
}
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
2009-10-29 19:58:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Already running so nothing to start */
|
|
|
|
StartedProfile = FALSE;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Release the profile lock */
|
2005-03-13 18:41:59 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&KiProfileLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Tell HAL to start the profile interrupt */
|
|
|
|
HalStartProfileInterrupt(Profile->Source);
|
|
|
|
|
|
|
|
/* Lower back to original IRQL */
|
|
|
|
KeLowerIrql(OldIrql);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Free the pool */
|
[NTOSKRNL]
Coverity code defects fixes :
- Cache: CID 701441
- Config: CIDs 716570, 716669, 716760
- Dbgk: Kdbg: CIDs 716571, 515128/9, 500432
- Ex: CIDs 500156/7, 515122, 716200/67, 701301, 514669
- Fsrtl: Fstub: CIDs 701341/2, 701288, 716770, 701302, and CIDs 716576/7/8 + 514636 + 716805 thanks to Thomas Faber
- Io: CIDs 514576, 514643, 514672/3, 716203, 716269, 716581, 716591, 716713
- Ke: CIDs 515125, 716592
- Ps: CIDs 716603/4, 701422
- Ob: Po: CIDs 514671/680, 701419/420/421, 716763, 716601/2
All the details are given in the different bug reports.
CORE-6677 CORE-6679 CORE-6680 CORE-6683 CORE-6686 CORE-6692 CORE-6693 CORE-6694 CORE-6695 CORE-6696 #comment Committed in rev.57400 #resolve #close
svn path=/trunk/; revision=57400
2012-09-27 17:16:31 +00:00
|
|
|
if (FreeBuffer) ExFreePoolWithTag(SourceBuffer, 'forP');
|
2009-10-29 19:58:41 +00:00
|
|
|
|
|
|
|
/* Return whether we could start the profile */
|
|
|
|
return StartedProfile;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-12-29 18:45:16 +00:00
|
|
|
BOOLEAN
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2009-10-29 19:58:41 +00:00
|
|
|
KeStopProfile(IN PKPROFILE Profile)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
KIRQL OldIrql;
|
|
|
|
PKPROFILE_SOURCE_OBJECT CurrentSource = NULL;
|
2008-08-25 18:21:19 +00:00
|
|
|
PLIST_ENTRY NextEntry;
|
2009-10-29 19:58:41 +00:00
|
|
|
BOOLEAN SourceFound = FALSE, StoppedProfile;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Raise to profile IRQL and acquire the profile lock */
|
|
|
|
KeRaiseIrql(KiProfileIrql, &OldIrql);
|
2005-03-13 18:41:59 +00:00
|
|
|
KeAcquireSpinLockAtDpcLevel(&KiProfileLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Make sure it's running */
|
2008-08-24 15:41:13 +00:00
|
|
|
if (Profile->Started)
|
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Remove it from the list and disable */
|
2005-11-27 19:21:19 +00:00
|
|
|
RemoveEntryList(&Profile->ProfileListEntry);
|
|
|
|
Profile->Started = FALSE;
|
2009-10-29 19:58:41 +00:00
|
|
|
StoppedProfile = TRUE;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2008-08-25 18:21:19 +00:00
|
|
|
/* Start looping */
|
|
|
|
for (NextEntry = KiProfileSourceListHead.Flink;
|
|
|
|
NextEntry != &KiProfileSourceListHead;
|
|
|
|
NextEntry = NextEntry->Flink)
|
2005-09-26 22:57:48 +00:00
|
|
|
{
|
2008-08-25 18:21:19 +00:00
|
|
|
/* Get the entry */
|
|
|
|
CurrentSource = CONTAINING_RECORD(NextEntry,
|
|
|
|
KPROFILE_SOURCE_OBJECT,
|
|
|
|
ListEntry);
|
|
|
|
|
|
|
|
/* Check if this is the Source Object */
|
2008-08-24 15:41:13 +00:00
|
|
|
if (CurrentSource->Source == Profile->Source)
|
|
|
|
{
|
2008-08-25 18:21:19 +00:00
|
|
|
/* Remember we found one */
|
|
|
|
SourceFound = TRUE;
|
|
|
|
|
|
|
|
/* Remove it and break out */
|
2005-09-26 22:57:48 +00:00
|
|
|
RemoveEntryList(&CurrentSource->ListEntry);
|
2007-10-19 23:21:45 +00:00
|
|
|
break;
|
2005-09-26 22:57:48 +00:00
|
|
|
}
|
2005-03-13 18:41:59 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
2009-10-29 19:58:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It wasn't! */
|
|
|
|
StoppedProfile = FALSE;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Release the profile lock */
|
2005-03-13 18:41:59 +00:00
|
|
|
KeReleaseSpinLockFromDpcLevel(&KiProfileLock);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Stop the profile interrupt */
|
|
|
|
HalStopProfileInterrupt(Profile->Source);
|
|
|
|
|
|
|
|
/* Lower back to original IRQL */
|
|
|
|
KeLowerIrql(OldIrql);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Free the Source Object */
|
2008-08-25 18:21:19 +00:00
|
|
|
if (SourceFound) ExFreePool(CurrentSource);
|
2005-12-29 18:45:16 +00:00
|
|
|
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Return whether we could stop the profile */
|
|
|
|
return StoppedProfile;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
ULONG
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2009-10-29 19:58:41 +00:00
|
|
|
KeQueryIntervalProfile(IN KPROFILE_SOURCE ProfileSource)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2009-10-29 19:58:41 +00:00
|
|
|
HAL_PROFILE_SOURCE_INFORMATION ProfileSourceInformation;
|
|
|
|
ULONG ReturnLength, Interval;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Check what profile this is */
|
2008-08-24 15:41:13 +00:00
|
|
|
if (ProfileSource == ProfileTime)
|
|
|
|
{
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Return the time interval */
|
|
|
|
Interval = KiProfileTimeInterval;
|
|
|
|
}
|
|
|
|
else if (ProfileSource == ProfileAlignmentFixup)
|
|
|
|
{
|
|
|
|
/* Return the alignment interval */
|
|
|
|
Interval = KiProfileAlignmentFixupInterval;
|
2008-08-24 15:41:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Request it from HAL */
|
|
|
|
ProfileSourceInformation.Source = ProfileSource;
|
|
|
|
Status = HalQuerySystemInformation(HalProfileSourceInformation,
|
|
|
|
sizeof(HAL_PROFILE_SOURCE_INFORMATION),
|
|
|
|
&ProfileSourceInformation,
|
|
|
|
&ReturnLength);
|
|
|
|
|
|
|
|
/* Check if HAL handled it and supports this profile */
|
|
|
|
if (NT_SUCCESS(Status) && (ProfileSourceInformation.Supported))
|
|
|
|
{
|
|
|
|
/* Get the interval */
|
|
|
|
Interval = ProfileSourceInformation.Interval;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Unsupported or invalid source, fail */
|
|
|
|
Interval = 0;
|
|
|
|
}
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
2009-10-29 19:58:41 +00:00
|
|
|
|
|
|
|
/* Return the interval we got */
|
|
|
|
return Interval;
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2015-08-29 14:30:29 +00:00
|
|
|
KeSetIntervalProfile(IN ULONG Interval,
|
|
|
|
IN KPROFILE_SOURCE ProfileSource)
|
2005-01-07 06:54:27 +00:00
|
|
|
{
|
2009-10-29 19:58:41 +00:00
|
|
|
HAL_PROFILE_SOURCE_INTERVAL ProfileSourceInterval;
|
|
|
|
|
|
|
|
/* Check what profile this is */
|
2008-08-24 15:41:13 +00:00
|
|
|
if (ProfileSource == ProfileTime)
|
|
|
|
{
|
2009-10-29 19:58:41 +00:00
|
|
|
/* Set the interval through HAL */
|
[HAL/NDK]
- Make Vector parameter in HalEnableSystemInterrupt, HalDisableSystemInterrupt and HalBeginSystemInterrupt an ULONG, not an UCHAR
[NDK]
- 64bit fixes for HANDLE_TABLE, KPROCESS, SECTION_IMAGE_INFORMATION, MMADDRESS_LIST, MMVAD_FLAGS, MMVAD, MMVAD_LONG, MMVAD_SHORT, MEMORY_DESCRIPTOR, MEMORY_ALLOCATION_DESCRIPTOR, LdrVerifyMappedImageMatchesChecksum
- KDPC_DATA::DpcQueueDepth is signed on amd64, unsigned on x86
[NTOSKRNL]
- Fix hundreds of MSVC and amd64 warnings
- add a pragma message to FstubFixupEfiPartition, since it looks broken
- Move portable Ke constants from <arch>/cpu.c to krnlinit.c
- Fixed a bug in amd64 KiGeneralProtectionFaultHandler
svn path=/trunk/; revision=53734
2011-09-18 13:11:45 +00:00
|
|
|
KiProfileTimeInterval = (ULONG)HalSetProfileInterval(Interval);
|
2009-10-29 19:58:41 +00:00
|
|
|
}
|
|
|
|
else if (ProfileSource == ProfileAlignmentFixup)
|
|
|
|
{
|
|
|
|
/* Set the alignment interval */
|
|
|
|
KiProfileAlignmentFixupInterval = Interval;
|
2008-08-24 15:41:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 19:58:41 +00:00
|
|
|
/* HAL handles any other interval */
|
|
|
|
ProfileSourceInterval.Source = ProfileSource;
|
|
|
|
ProfileSourceInterval.Interval = Interval;
|
|
|
|
HalSetSystemInformation(HalProfileSourceInterval,
|
|
|
|
sizeof(HAL_PROFILE_SOURCE_INTERVAL),
|
|
|
|
&ProfileSourceInterval);
|
2005-01-07 06:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
2005-03-13 18:41:59 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2009-10-29 19:58:41 +00:00
|
|
|
KeProfileInterrupt(IN PKTRAP_FRAME TrapFrame)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Called from HAL for Timer Profiling */
|
|
|
|
KeProfileInterruptWithSource(TrapFrame, ProfileTime);
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-03-13 18:41:59 +00:00
|
|
|
KiParseProfileList(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN KPROFILE_SOURCE Source,
|
|
|
|
IN PLIST_ENTRY ListHead)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
PULONG BucketValue;
|
|
|
|
PKPROFILE Profile;
|
2008-08-25 18:21:19 +00:00
|
|
|
PLIST_ENTRY NextEntry;
|
2009-10-04 16:53:15 +00:00
|
|
|
ULONG_PTR ProgramCounter;
|
|
|
|
|
|
|
|
/* Get the Program Counter */
|
|
|
|
ProgramCounter = KeGetTrapFramePc(TrapFrame);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Loop the List */
|
2008-08-25 18:21:19 +00:00
|
|
|
for (NextEntry = ListHead->Flink;
|
|
|
|
NextEntry != ListHead;
|
|
|
|
NextEntry = NextEntry->Flink)
|
2005-09-26 22:57:48 +00:00
|
|
|
{
|
2008-08-25 18:21:19 +00:00
|
|
|
/* Get the entry */
|
|
|
|
Profile = CONTAINING_RECORD(NextEntry, KPROFILE, ProfileListEntry);
|
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Check if the source is good, and if it's within the range */
|
2005-05-09 01:38:29 +00:00
|
|
|
if ((Profile->Source != Source) ||
|
2009-10-04 16:53:15 +00:00
|
|
|
(ProgramCounter < (ULONG_PTR)Profile->RangeBase) ||
|
|
|
|
(ProgramCounter > (ULONG_PTR)Profile->RangeLimit))
|
2008-08-24 15:41:13 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
continue;
|
2005-05-09 01:38:29 +00:00
|
|
|
}
|
2005-03-13 18:41:59 +00:00
|
|
|
|
2009-10-04 16:53:15 +00:00
|
|
|
/* Get the Pointer to the Bucket Value representing this Program Counter */
|
2015-08-29 14:30:29 +00:00
|
|
|
BucketValue = (PULONG)((ULONG_PTR)Profile->Buffer +
|
2015-08-29 14:35:02 +00:00
|
|
|
(((ProgramCounter - (ULONG_PTR)Profile->RangeBase)
|
|
|
|
>> Profile->BucketShift) &~ 0x3));
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Increment the value */
|
2015-08-29 14:30:29 +00:00
|
|
|
(*BucketValue)++;
|
2005-03-13 18:41:59 +00:00
|
|
|
}
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-03-13 18:41:59 +00:00
|
|
|
* @implemented
|
|
|
|
*
|
|
|
|
* Remarks:
|
|
|
|
* Called from HAL, this function looks up the process
|
|
|
|
* entries, finds the proper source object, verifies the
|
|
|
|
* ranges with the trapframe data, and inserts the information
|
|
|
|
* from the trap frame into the buffer, while using buckets and
|
|
|
|
* shifting like we specified. -- Alex
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-03-13 18:41:59 +00:00
|
|
|
KeProfileInterruptWithSource(IN PKTRAP_FRAME TrapFrame,
|
|
|
|
IN KPROFILE_SOURCE Source)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
PKPROCESS Process = KeGetCurrentThread()->ApcState.Process;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/* We have to parse 2 lists. Per-Process and System-Wide */
|
|
|
|
KiParseProfileList(TrapFrame, Source, &Process->ProfileListHead);
|
|
|
|
KiParseProfileList(TrapFrame, Source, &KiProfileListHead);
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
2005-02-14 05:36:04 +00:00
|
|
|
|
2005-03-13 18:41:59 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
2008-11-29 20:47:48 +00:00
|
|
|
NTAPI
|
2005-03-13 18:41:59 +00:00
|
|
|
KeSetProfileIrql(IN KIRQL ProfileIrql)
|
2005-02-14 05:36:04 +00:00
|
|
|
{
|
2005-03-13 18:41:59 +00:00
|
|
|
/* Set the IRQL at which Profiling will run */
|
|
|
|
KiProfileIrql = ProfileIrql;
|
2005-02-14 05:36:04 +00:00
|
|
|
}
|