ReactOS  0.4.14-dev-376-gaedba84
profile.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for profile.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define TAG_PROFILE   'forP'
 

Functions

VOID NTAPI ExpDeleteProfile (PVOID ObjectBody)
 
BOOLEAN INIT_FUNCTION NTAPI ExpInitializeProfileImplementation (VOID)
 
NTSTATUS NTAPI NtCreateProfile (OUT PHANDLE ProfileHandle, IN HANDLE Process OPTIONAL, IN PVOID RangeBase, IN SIZE_T RangeSize, IN ULONG BucketSize, IN PVOID Buffer, IN ULONG BufferSize, IN KPROFILE_SOURCE ProfileSource, IN KAFFINITY Affinity)
 
NTSTATUS NTAPI NtQueryPerformanceCounter (OUT PLARGE_INTEGER PerformanceCounter, OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL)
 
NTSTATUS NTAPI NtStartProfile (IN HANDLE ProfileHandle)
 
NTSTATUS NTAPI NtStopProfile (IN HANDLE ProfileHandle)
 
NTSTATUS NTAPI NtQueryIntervalProfile (IN KPROFILE_SOURCE ProfileSource, OUT PULONG Interval)
 
NTSTATUS NTAPI NtSetIntervalProfile (IN ULONG Interval, IN KPROFILE_SOURCE Source)
 

Variables

POBJECT_TYPE ExProfileObjectType = NULL
 
KMUTEX ExpProfileMutex
 
GENERIC_MAPPING ExpProfileMapping
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file profile.c.

◆ TAG_PROFILE

#define TAG_PROFILE   'forP'

Definition at line 20 of file profile.c.

Function Documentation

◆ ExpDeleteProfile()

VOID NTAPI ExpDeleteProfile ( PVOID  ObjectBody)

Definition at line 39 of file profile.c.

40 {
41  PEPROFILE Profile;
42  ULONG State;
43 
44  /* Typecast the Object */
45  Profile = ObjectBody;
46 
47  /* Check if there if the Profile was started */
48  if (Profile->LockedBufferAddress)
49  {
50  /* Stop the Profile */
51  State = KeStopProfile(Profile->ProfileObject);
52  ASSERT(State != FALSE);
53 
54  /* Unmap the Locked Buffer */
55  MmUnmapLockedPages(Profile->LockedBufferAddress, Profile->Mdl);
56  MmUnlockPages(Profile->Mdl);
57  IoFreeMdl(Profile->Mdl);
59  }
60 
61  /* Check if a Process is associated and reference it */
62  if (Profile->Process) ObDereferenceObject(Profile->Process);
63 }
PVOID LockedBufferAddress
Definition: extypes.h:562
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
BOOLEAN NTAPI KeStopProfile(struct _KPROFILE *Profile)
#define TAG_PROFILE
Definition: profile.c:20
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PKPROFILE ProfileObject
Definition: extypes.h:561
enum State_ State
Definition: pofuncs.h:54
PEPROCESS Process
Definition: extypes.h:555
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PMDL Mdl
Definition: extypes.h:563

Referenced by ExpInitializeProfileImplementation().

◆ ExpInitializeProfileImplementation()

BOOLEAN INIT_FUNCTION NTAPI ExpInitializeProfileImplementation ( VOID  )

Definition at line 68 of file profile.c.

69 {
70  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
73  DPRINT("Creating Profile Object Type\n");
74 
75  /* Initialize the Mutex to lock the States */
77 
78  /* Create the Event Pair Object Type */
79  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
80  RtlInitUnicodeString(&Name, L"Profile");
81  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
82  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KPROFILE);
83  ObjectTypeInitializer.GenericMapping = ExpProfileMapping;
84  ObjectTypeInitializer.PoolType = NonPagedPool;
85  ObjectTypeInitializer.DeleteProcedure = ExpDeleteProfile;
86  ObjectTypeInitializer.ValidAccessMask = PROFILE_ALL_ACCESS;
87  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
88  Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ExProfileObjectType);
89  if (!NT_SUCCESS(Status)) return FALSE;
90  return TRUE;
91 }
KMUTEX ExpProfileMutex
Definition: profile.c:25
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:24
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1048
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_OPENLINK
Definition: winternl.h:230
VOID NTAPI ExpDeleteProfile(PVOID ObjectBody)
Definition: profile.c:39
struct NameRec_ * Name
Definition: cdprocs.h:464
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
GENERIC_MAPPING ExpProfileMapping
Definition: profile.c:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define PROFILE_ALL_ACCESS
Definition: extypes.h:131
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
struct _KPROFILE KPROFILE
ULONG DefaultNonPagedPoolCharge
Definition: obtypes.h:365

Referenced by ExpInitSystemPhase1().

◆ NtCreateProfile()

NTSTATUS NTAPI NtCreateProfile ( OUT PHANDLE  ProfileHandle,
IN HANDLE Process  OPTIONAL,
IN PVOID  RangeBase,
IN SIZE_T  RangeSize,
IN ULONG  BucketSize,
IN PVOID  Buffer,
IN ULONG  BufferSize,
IN KPROFILE_SOURCE  ProfileSource,
IN KAFFINITY  Affinity 
)

Definition at line 95 of file profile.c.

104 {
105  HANDLE hProfile;
106  PEPROFILE Profile;
107  PEPROCESS pProcess;
111  ULONG Log2 = 0;
112  ULONG_PTR Segment = 0;
113  PAGED_CODE();
114 
115  /* Easy way out */
117 
118  /* Check if this is a low-memory profile */
119  if ((!BucketSize) && (RangeBase < (PVOID)(0x10000)))
120  {
121  /* Validate size */
122  if (BufferSize < sizeof(ULONG)) return STATUS_INVALID_PARAMETER_7;
123 
124  /* This will become a segmented profile object */
125  Segment = (ULONG_PTR)RangeBase;
126  RangeBase = 0;
127 
128  /* Recalculate the bucket size */
129  BucketSize = RangeSize / (BufferSize / sizeof(ULONG));
130 
131  /* Convert it to log2 */
132  BucketSize--;
133  while (BucketSize >>= 1) Log2++;
134  BucketSize += Log2 + 1;
135  }
136 
137  /* Validate bucket size */
138  if ((BucketSize > 31) || (BucketSize < 2))
139  {
140  DPRINT1("Bucket size invalid\n");
142  }
143 
144  /* Make sure that the buckets can map the range */
145  if ((RangeSize >> (BucketSize - 2)) > BufferSize)
146  {
147  DPRINT1("Bucket size too small\n");
149  }
150 
151  /* Make sure that the range isn't too gigantic */
152  if (((ULONG_PTR)RangeBase + RangeSize) < RangeSize)
153  {
154  DPRINT1("Range too big\n");
155  return STATUS_BUFFER_OVERFLOW;
156  }
157 
158  /* Check if we were called from user-mode */
159  if(PreviousMode != KernelMode)
160  {
161  /* Entry SEH */
162  _SEH2_TRY
163  {
164  /* Make sure that the handle pointer is valid */
165  ProbeForWriteHandle(ProfileHandle);
166 
167  /* Check if the buffer is valid */
169  BufferSize,
170  sizeof(ULONG));
171  }
173  {
174  /* Return the exception code */
176  }
177  _SEH2_END;
178  }
179 
180  /* Check if a process was specified */
181  if (Process)
182  {
183  /* Reference it */
187  PreviousMode,
188  (PVOID*)&pProcess,
189  NULL);
190  if (!NT_SUCCESS(Status)) return(Status);
191  }
192  else
193  {
194  /* Segmented profile objects cannot be used system-wide */
195  if (Segment) return STATUS_INVALID_PARAMETER;
196 
197  /* No process was specified, which means a System-Wide Profile */
198  pProcess = NULL;
199 
200  /* For this, we need to check the Privilege */
202  {
203  DPRINT1("NtCreateProfile: Caller requires the SeSystemProfilePrivilege privilege!\n");
205  }
206  }
207 
208  /* Create the object */
210  NULL,
211  0,
212  NULL,
213  NULL);
217  PreviousMode,
218  NULL,
219  sizeof(EPROFILE),
220  0,
221  sizeof(EPROFILE) + sizeof(KPROFILE),
222  (PVOID*)&Profile);
223  if (!NT_SUCCESS(Status))
224  {
225  /* Dereference the process object if it was specified */
226  if (pProcess) ObDereferenceObject(pProcess);
227 
228  /* Return Status */
229  return Status;
230  }
231 
232  /* Initialize it */
233  Profile->RangeBase = RangeBase;
234  Profile->RangeSize = RangeSize;
235  Profile->Buffer = Buffer;
236  Profile->BufferSize = BufferSize;
237  Profile->BucketSize = BucketSize;
238  Profile->LockedBufferAddress = NULL;
239  Profile->Segment = Segment;
240  Profile->ProfileSource = ProfileSource;
241  Profile->Affinity = Affinity;
242  Profile->Process = pProcess;
243 
244  /* Insert into the Object Tree */
245  Status = ObInsertObject ((PVOID)Profile,
246  NULL,
248  0,
249  NULL,
250  &hProfile);
251 
252  /* Check for Success */
253  if (!NT_SUCCESS(Status))
254  {
255  /* Dereference Process on failure */
256  if (pProcess) ObDereferenceObject(pProcess);
257  return Status;
258  }
259 
260  /* Enter SEH */
261  _SEH2_TRY
262  {
263  /* Copy the created handle back to the caller*/
264  *ProfileHandle = hProfile;
265  }
267  {
269  }
270  _SEH2_END;
271 
272  /* Return Status */
273  return Status;
274 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:24
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
ULONG BufferSize
Definition: extypes.h:559
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:158
PVOID LockedBufferAddress
Definition: extypes.h:562
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
const LUID SeSystemProfilePrivilege
Definition: priv.c:32
PVOID RangeBase
Definition: extypes.h:556
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
KAFFINITY Affinity
Definition: extypes.h:566
smooth NULL
Definition: ftsmooth.c:416
PVOID Buffer
Definition: extypes.h:558
Definition: bufpool.h:45
ULONG BucketSize
Definition: extypes.h:560
_Inout_ PVOID Segment
Definition: exfuncs.h:893
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
#define STATUS_INVALID_PARAMETER_7
Definition: ntstatus.h:467
SIZE_T RangeSize
Definition: extypes.h:557
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
#define ProbeForWriteHandle(Ptr)
Definition: probe.h:43
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
ULONG_PTR Segment
Definition: extypes.h:564
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
PEPROCESS Process
Definition: extypes.h:555
#define DPRINT1
Definition: precomp.h:8
KPROFILE_SOURCE ProfileSource
Definition: extypes.h:565
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
POBJECT_TYPE PsProcessType
Definition: process.c:20
#define PROFILE_CONTROL
Definition: extypes.h:130

◆ NtQueryIntervalProfile()

NTSTATUS NTAPI NtQueryIntervalProfile ( IN KPROFILE_SOURCE  ProfileSource,
OUT PULONG  Interval 
)

Definition at line 471 of file profile.c.

473 {
475  ULONG ReturnInterval;
477  PAGED_CODE();
478 
479  /* Check if we were called from user-mode */
480  if (PreviousMode != KernelMode)
481  {
482  /* Enter SEH Block */
483  _SEH2_TRY
484  {
485  /* Validate interval */
487  }
489  {
490  /* Return the exception code */
492  }
493  _SEH2_END;
494  }
495 
496  /* Query the Interval */
497  ReturnInterval = (ULONG)KeQueryIntervalProfile(ProfileSource);
498 
499  /* Enter SEH block for return */
500  _SEH2_TRY
501  {
502  /* Return the data */
503  *Interval = ReturnInterval;
504  }
506  {
507  /* Get the exception code */
509  }
510  _SEH2_END;
511 
512  /* Return Success */
513  return Status;
514 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG NTAPI KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource)
DWORD Interval
Definition: netstat.c:33
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ NtQueryPerformanceCounter()

NTSTATUS NTAPI NtQueryPerformanceCounter ( OUT PLARGE_INTEGER  PerformanceCounter,
OUT PLARGE_INTEGER PerformanceFrequency  OPTIONAL 
)

Definition at line 278 of file profile.c.

280 {
282  LARGE_INTEGER PerfFrequency;
284 
285  /* Check if we were called from user-mode */
286  if (PreviousMode != KernelMode)
287  {
288  /* Entry SEH Block */
289  _SEH2_TRY
290  {
291  /* Make sure the counter and frequency are valid */
292  ProbeForWriteLargeInteger(PerformanceCounter);
293  if (PerformanceFrequency)
294  {
295  ProbeForWriteLargeInteger(PerformanceFrequency);
296  }
297  }
299  {
300  /* Return the exception code */
302  }
303  _SEH2_END;
304  }
305 
306  /* Enter a new SEH Block */
307  _SEH2_TRY
308  {
309  /* Query the Kernel */
310  *PerformanceCounter = KeQueryPerformanceCounter(&PerfFrequency);
311 
312  /* Return Frequency if requested */
313  if (PerformanceFrequency) *PerformanceFrequency = PerfFrequency;
314  }
316  {
317  /* Get the exception code */
319  }
320  _SEH2_END;
321 
322  /* Return status to caller */
323  return Status;
324 }
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ProbeForWriteLargeInteger(Ptr)
Definition: probe.h:46

Referenced by ClockInitialize(), ClockUpdate(), EnableHardwareTimer(), LdrpInitSecurityCookie(), PulseSample(), QueryPerformanceCounter(), QueryPerformanceFrequency(), queue_current_time(), and SpeakerInitialize().

◆ NtSetIntervalProfile()

NTSTATUS NTAPI NtSetIntervalProfile ( IN ULONG  Interval,
IN KPROFILE_SOURCE  Source 
)

Definition at line 518 of file profile.c.

520 {
521  /* Let the Kernel do the job */
523 
524  /* Nothing can go wrong */
525  return STATUS_SUCCESS;
526 }
DWORD Interval
Definition: netstat.c:33
VOID NTAPI KeSetIntervalProfile(ULONG Interval, KPROFILE_SOURCE ProfileSource)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ NtStartProfile()

NTSTATUS NTAPI NtStartProfile ( IN HANDLE  ProfileHandle)

Definition at line 328 of file profile.c.

329 {
330  PEPROFILE Profile;
333  PVOID TempLockedBufferAddress;
335  PAGED_CODE();
336 
337  /* Get the Object */
338  Status = ObReferenceObjectByHandle(ProfileHandle,
341  PreviousMode,
342  (PVOID*)&Profile,
343  NULL);
344  if (!NT_SUCCESS(Status)) return(Status);
345 
346  /* To avoid a Race, wait on the Mutex */
348  Executive,
349  KernelMode,
350  FALSE,
351  NULL);
352 
353  /* The Profile can still be enabled though, so handle that */
354  if (Profile->LockedBufferAddress)
355  {
356  /* Release our lock, dereference and return */
358  ObDereferenceObject(Profile);
360  }
361 
362  /* Allocate a Kernel Profile Object. */
364  sizeof(*ProfileObject),
365  TAG_PROFILE);
366  if (!ProfileObject)
367  {
368  /* Out of memory, fail */
370  ObDereferenceObject(Profile);
372  }
373 
374  /* Allocate the Mdl Structure */
375  Profile->Mdl = IoAllocateMdl(Profile->Buffer, Profile->BufferSize, FALSE, FALSE, NULL);
376 
377  /* Protect this in SEH as we might raise an exception */
378  _SEH2_TRY
379  {
380  /* Probe and Lock for Write Access */
382  }
384  {
385  /* Release our lock, free the buffer, dereference and return */
387  ObDereferenceObject(Profile);
390  }
391  _SEH2_END;
392 
393  /* Map the pages */
394  TempLockedBufferAddress = MmMapLockedPages(Profile->Mdl, KernelMode);
395 
396  /* Initialize the Kernel Profile Object */
397  Profile->ProfileObject = ProfileObject;
399  &Profile->Process->Pcb,
400  Profile->RangeBase,
401  Profile->RangeSize,
402  Profile->BucketSize,
403  Profile->ProfileSource,
404  Profile->Affinity);
405 
406  /* Start the Profiling */
407  KeStartProfile(ProfileObject, TempLockedBufferAddress);
408 
409  /* Now it's safe to save this */
410  Profile->LockedBufferAddress = TempLockedBufferAddress;
411 
412  /* Release mutex, dereference and return */
414  ObDereferenceObject(Profile);
415  return STATUS_SUCCESS;
416 }
KMUTEX ExpProfileMutex
Definition: profile.c:25
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:24
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ULONG BufferSize
Definition: extypes.h:559
PVOID LockedBufferAddress
Definition: extypes.h:562
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PVOID RangeBase
Definition: extypes.h:556
PVOID NTAPI MmMapLockedPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode)
Definition: mdlsup.c:822
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
KAFFINITY Affinity
Definition: extypes.h:566
smooth NULL
Definition: ftsmooth.c:416
PVOID Buffer
Definition: extypes.h:558
ULONG BucketSize
Definition: extypes.h:560
SIZE_T RangeSize
Definition: extypes.h:557
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define TAG_PROFILE
Definition: profile.c:20
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN NTAPI KeStartProfile(struct _KPROFILE *Profile, PVOID Buffer)
KPROCESS Pcb
Definition: pstypes.h:1193
VOID NTAPI KeInitializeProfile(struct _KPROFILE *Profile, struct _KPROCESS *Process, PVOID ImageBase, SIZE_T ImageSize, ULONG BucketSize, KPROFILE_SOURCE ProfileSource, KAFFINITY Affinity)
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
PKPROFILE ProfileObject
Definition: extypes.h:561
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
PEPROCESS Process
Definition: extypes.h:555
#define STATUS_PROFILING_NOT_STOPPED
Definition: ntstatus.h:406
KPROFILE_SOURCE ProfileSource
Definition: extypes.h:565
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define PROFILE_CONTROL
Definition: extypes.h:130
PMDL Mdl
Definition: extypes.h:563

◆ NtStopProfile()

NTSTATUS NTAPI NtStopProfile ( IN HANDLE  ProfileHandle)

Definition at line 420 of file profile.c.

421 {
422  PEPROFILE Profile;
425  PAGED_CODE();
426 
427  /* Get the Object */
428  Status = ObReferenceObjectByHandle(ProfileHandle,
431  PreviousMode,
432  (PVOID*)&Profile,
433  NULL);
434  if (!NT_SUCCESS(Status)) return(Status);
435 
436  /* Get the Mutex */
438  Executive,
439  KernelMode,
440  FALSE,
441  NULL);
442 
443  /* Make sure the Profile Object is really Started */
444  if (!Profile->LockedBufferAddress)
445  {
447  goto Exit;
448  }
449 
450  /* Stop the Profile */
451  KeStopProfile(Profile->ProfileObject);
452 
453  /* Unlock the Buffer */
454  MmUnmapLockedPages(Profile->LockedBufferAddress, Profile->Mdl);
455  MmUnlockPages(Profile->Mdl);
456  IoFreeMdl(Profile->Mdl);
458 
459  /* Clear the Locked Buffer pointer, meaning the Object is Stopped */
460  Profile->LockedBufferAddress = NULL;
461 
462 Exit:
463  /* Release Mutex, Dereference and Return */
465  ObDereferenceObject(Profile);
466  return Status;
467 }
KMUTEX ExpProfileMutex
Definition: profile.c:25
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:24
PVOID LockedBufferAddress
Definition: extypes.h:562
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LONG NTAPI KeReleaseMutex(IN PKMUTEX Mutex, IN BOOLEAN Wait)
Definition: mutex.c:189
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:841
BOOLEAN NTAPI KeStopProfile(struct _KPROFILE *Profile)
smooth NULL
Definition: ftsmooth.c:416
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define TAG_PROFILE
Definition: profile.c:20
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
Status
Definition: gdiplustypes.h:24
PKPROFILE ProfileObject
Definition: extypes.h:561
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define PROFILE_CONTROL
Definition: extypes.h:130
PMDL Mdl
Definition: extypes.h:563
#define STATUS_PROFILING_NOT_STARTED
Definition: ntstatus.h:405

Variable Documentation

◆ ExpProfileMapping

GENERIC_MAPPING ExpProfileMapping
Initial value:
=
{
}
#define STANDARD_RIGHTS_WRITE
Definition: nt_native.h:66
#define STANDARD_RIGHTS_EXECUTE
Definition: nt_native.h:67
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define PROFILE_ALL_ACCESS
Definition: extypes.h:131
#define PROFILE_CONTROL
Definition: extypes.h:130

Definition at line 27 of file profile.c.

Referenced by ExpInitializeProfileImplementation().

◆ ExpProfileMutex

KMUTEX ExpProfileMutex

Definition at line 25 of file profile.c.

Referenced by ExpInitializeProfileImplementation(), NtStartProfile(), and NtStopProfile().

◆ ExProfileObjectType

POBJECT_TYPE ExProfileObjectType = NULL