ReactOS  0.4.15-dev-3175-g222acf5
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 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 16 of file profile.c.

Function Documentation

◆ ExpDeleteProfile()

VOID NTAPI ExpDeleteProfile ( PVOID  ObjectBody)

Definition at line 35 of file profile.c.

36 {
37  PEPROFILE Profile;
38  ULONG State;
39 
40  /* Typecast the Object */
41  Profile = ObjectBody;
42 
43  /* Check if there if the Profile was started */
44  if (Profile->LockedBufferAddress)
45  {
46  /* Stop the Profile */
47  State = KeStopProfile(Profile->ProfileObject);
48  ASSERT(State != FALSE);
49 
50  /* Unmap the Locked Buffer */
51  MmUnmapLockedPages(Profile->LockedBufferAddress, Profile->Mdl);
52  MmUnlockPages(Profile->Mdl);
53  IoFreeMdl(Profile->Mdl);
55  }
56 
57  /* Check if a Process is associated and reference it */
58  if (Profile->Process) ObDereferenceObject(Profile->Process);
59 }
PVOID LockedBufferAddress
Definition: extypes.h:562
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1426
#define FALSE
Definition: types.h:117
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:828
BOOLEAN NTAPI KeStopProfile(struct _KPROFILE *Profile)
#define ASSERT(a)
Definition: mode.c:44
#define ObDereferenceObject
Definition: obfuncs.h:203
#define TAG_PROFILE
Definition: profile.c:16
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
PKPROFILE ProfileObject
Definition: extypes.h:561
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 NTAPI ExpInitializeProfileImplementation ( VOID  )

Definition at line 64 of file profile.c.

65 {
66  OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
69  DPRINT("Creating Profile Object Type\n");
70 
71  /* Initialize the Mutex to lock the States */
73 
74  /* Create the Event Pair Object Type */
75  RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
76  RtlInitUnicodeString(&Name, L"Profile");
77  ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
78  ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(KPROFILE);
79  ObjectTypeInitializer.GenericMapping = ExpProfileMapping;
80  ObjectTypeInitializer.PoolType = NonPagedPool;
81  ObjectTypeInitializer.DeleteProcedure = ExpDeleteProfile;
82  ObjectTypeInitializer.ValidAccessMask = PROFILE_ALL_ACCESS;
83  ObjectTypeInitializer.InvalidAttributes = OBJ_OPENLINK;
84  Status = ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &ExProfileObjectType);
85  if (!NT_SUCCESS(Status)) return FALSE;
86  return TRUE;
87 }
#define OBJ_OPENLINK
Definition: winternl.h:230
KMUTEX ExpProfileMutex
Definition: profile.c:21
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:20
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 FALSE
Definition: types.h:117
VOID NTAPI ExpDeleteProfile(PVOID ObjectBody)
Definition: profile.c:35
struct NameRec_ * Name
Definition: cdprocs.h:459
Status
Definition: gdiplustypes.h:24
GENERIC_MAPPING ExpProfileMapping
Definition: profile.c:23
#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
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define DPRINT
Definition: sndvol32.h:71
#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 91 of file profile.c.

100 {
101  HANDLE hProfile;
102  PEPROFILE Profile;
103  PEPROCESS pProcess;
107  ULONG Log2 = 0;
108  ULONG_PTR Segment = 0;
109  PAGED_CODE();
110 
111  /* Easy way out */
113 
114  /* Check if this is a low-memory profile */
115  if ((!BucketSize) && (RangeBase < (PVOID)(0x10000)))
116  {
117  /* Validate size */
118  if (BufferSize < sizeof(ULONG)) return STATUS_INVALID_PARAMETER_7;
119 
120  /* This will become a segmented profile object */
121  Segment = (ULONG_PTR)RangeBase;
122  RangeBase = 0;
123 
124  /* Recalculate the bucket size */
125  BucketSize = RangeSize / (BufferSize / sizeof(ULONG));
126 
127  /* Convert it to log2 */
128  BucketSize--;
129  while (BucketSize >>= 1) Log2++;
130  BucketSize += Log2 + 1;
131  }
132 
133  /* Validate bucket size */
134  if ((BucketSize > 31) || (BucketSize < 2))
135  {
136  DPRINT1("Bucket size invalid\n");
138  }
139 
140  /* Make sure that the buckets can map the range */
141  if ((RangeSize >> (BucketSize - 2)) > BufferSize)
142  {
143  DPRINT1("Bucket size too small\n");
145  }
146 
147  /* Make sure that the range isn't too gigantic */
148  if (((ULONG_PTR)RangeBase + RangeSize) < RangeSize)
149  {
150  DPRINT1("Range too big\n");
151  return STATUS_BUFFER_OVERFLOW;
152  }
153 
154  /* Check if we were called from user-mode */
155  if(PreviousMode != KernelMode)
156  {
157  /* Entry SEH */
158  _SEH2_TRY
159  {
160  /* Make sure that the handle pointer is valid */
161  ProbeForWriteHandle(ProfileHandle);
162 
163  /* Check if the buffer is valid */
165  BufferSize,
166  sizeof(ULONG));
167  }
169  {
170  /* Return the exception code */
172  }
173  _SEH2_END;
174  }
175 
176  /* Check if a process was specified */
177  if (Process)
178  {
179  /* Reference it */
183  PreviousMode,
184  (PVOID*)&pProcess,
185  NULL);
186  if (!NT_SUCCESS(Status)) return(Status);
187  }
188  else
189  {
190  /* Segmented profile objects cannot be used system-wide */
191  if (Segment) return STATUS_INVALID_PARAMETER;
192 
193  /* No process was specified, which means a System-Wide Profile */
194  pProcess = NULL;
195 
196  /* For this, we need to check the Privilege */
198  {
199  DPRINT1("NtCreateProfile: Caller requires the SeSystemProfilePrivilege privilege!\n");
201  }
202  }
203 
204  /* Create the object */
206  NULL,
207  0,
208  NULL,
209  NULL);
213  PreviousMode,
214  NULL,
215  sizeof(EPROFILE),
216  0,
217  sizeof(EPROFILE) + sizeof(KPROFILE),
218  (PVOID*)&Profile);
219  if (!NT_SUCCESS(Status))
220  {
221  /* Dereference the process object if it was specified */
222  if (pProcess) ObDereferenceObject(pProcess);
223 
224  /* Return Status */
225  return Status;
226  }
227 
228  /* Initialize it */
229  Profile->RangeBase = RangeBase;
230  Profile->RangeSize = RangeSize;
231  Profile->Buffer = Buffer;
232  Profile->BufferSize = BufferSize;
233  Profile->BucketSize = BucketSize;
234  Profile->LockedBufferAddress = NULL;
235  Profile->Segment = Segment;
236  Profile->ProfileSource = ProfileSource;
237  Profile->Affinity = Affinity;
238  Profile->Process = pProcess;
239 
240  /* Insert into the Object Tree */
241  Status = ObInsertObject ((PVOID)Profile,
242  NULL,
244  0,
245  NULL,
246  &hProfile);
247 
248  /* Check for Success */
249  if (!NT_SUCCESS(Status))
250  {
251  /* Dereference Process on failure */
252  if (pProcess) ObDereferenceObject(pProcess);
253  return Status;
254  }
255 
256  /* Enter SEH */
257  _SEH2_TRY
258  {
259  /* Copy the created handle back to the caller*/
260  *ProfileHandle = hProfile;
261  }
263  {
265  }
266  _SEH2_END;
267 
268  /* Return Status */
269  return Status;
270 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:20
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
ULONG BufferSize
Definition: extypes.h:559
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:166
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
PVOID LockedBufferAddress
Definition: extypes.h:562
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
const LUID SeSystemProfilePrivilege
Definition: priv.c:28
PVOID RangeBase
Definition: extypes.h:556
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
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:494
KAFFINITY Affinity
Definition: extypes.h:566
PVOID Buffer
Definition: extypes.h:558
Definition: bufpool.h:45
ULONG BucketSize
Definition: extypes.h:560
_Inout_ PVOID Segment
Definition: exfuncs.h:1101
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:481
SIZE_T RangeSize
Definition: extypes.h:557
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ObDereferenceObject
Definition: obfuncs.h:203
_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
_SEH2_END
Definition: create.c:4400
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:2931
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
PEPROCESS Process
Definition: extypes.h:555
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:738
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:40
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
POBJECT_TYPE PsProcessType
Definition: process.c:20
#define PROFILE_CONTROL
Definition: extypes.h:130
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
#define PAGED_CODE()

◆ NtQueryIntervalProfile()

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

Definition at line 467 of file profile.c.

469 {
471  ULONG ReturnInterval;
473  PAGED_CODE();
474 
475  /* Check if we were called from user-mode */
476  if (PreviousMode != KernelMode)
477  {
478  /* Enter SEH Block */
479  _SEH2_TRY
480  {
481  /* Validate interval */
483  }
485  {
486  /* Return the exception code */
488  }
489  _SEH2_END;
490  }
491 
492  /* Query the Interval */
493  ReturnInterval = (ULONG)KeQueryIntervalProfile(ProfileSource);
494 
495  /* Enter SEH block for return */
496  _SEH2_TRY
497  {
498  /* Return the data */
499  *Interval = ReturnInterval;
500  }
502  {
503  /* Get the exception code */
505  }
506  _SEH2_END;
507 
508  /* Return Success */
509  return Status;
510 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
_SEH2_TRY
Definition: create.c:4226
ULONG NTAPI KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource)
DWORD Interval
Definition: netstat.c:33
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_SEH2_END
Definition: create.c:4400
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define PAGED_CODE()

◆ NtQueryPerformanceCounter()

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

Definition at line 274 of file profile.c.

276 {
278  LARGE_INTEGER PerfFrequency;
280 
281  /* Check if we were called from user-mode */
282  if (PreviousMode != KernelMode)
283  {
284  /* Entry SEH Block */
285  _SEH2_TRY
286  {
287  /* Make sure the counter and frequency are valid */
288  ProbeForWriteLargeInteger(PerformanceCounter);
289  if (PerformanceFrequency)
290  {
291  ProbeForWriteLargeInteger(PerformanceFrequency);
292  }
293  }
295  {
296  /* Return the exception code */
298  }
299  _SEH2_END;
300  }
301 
302  /* Enter a new SEH Block */
303  _SEH2_TRY
304  {
305  /* Query the Kernel */
306  *PerformanceCounter = KeQueryPerformanceCounter(&PerfFrequency);
307 
308  /* Return Frequency if requested */
309  if (PerformanceFrequency) *PerformanceFrequency = PerfFrequency;
310  }
312  {
313  /* Get the exception code */
315  }
316  _SEH2_END;
317 
318  /* Return status to caller */
319  return Status;
320 }
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:3070
_SEH2_TRY
Definition: create.c:4226
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_SEH2_END
Definition: create.c:4400
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#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 514 of file profile.c.

516 {
517  /* Let the Kernel do the job */
519 
520  /* Nothing can go wrong */
521  return STATUS_SUCCESS;
522 }
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
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ NtStartProfile()

NTSTATUS NTAPI NtStartProfile ( IN HANDLE  ProfileHandle)

Definition at line 324 of file profile.c.

325 {
326  PEPROFILE Profile;
329  PVOID TempLockedBufferAddress;
331  PAGED_CODE();
332 
333  /* Get the Object */
334  Status = ObReferenceObjectByHandle(ProfileHandle,
337  PreviousMode,
338  (PVOID*)&Profile,
339  NULL);
340  if (!NT_SUCCESS(Status)) return(Status);
341 
342  /* To avoid a Race, wait on the Mutex */
344  Executive,
345  KernelMode,
346  FALSE,
347  NULL);
348 
349  /* The Profile can still be enabled though, so handle that */
350  if (Profile->LockedBufferAddress)
351  {
352  /* Release our lock, dereference and return */
354  ObDereferenceObject(Profile);
356  }
357 
358  /* Allocate a Kernel Profile Object. */
360  sizeof(*ProfileObject),
361  TAG_PROFILE);
362  if (!ProfileObject)
363  {
364  /* Out of memory, fail */
366  ObDereferenceObject(Profile);
368  }
369 
370  /* Allocate the Mdl Structure */
371  Profile->Mdl = IoAllocateMdl(Profile->Buffer, Profile->BufferSize, FALSE, FALSE, NULL);
372 
373  /* Protect this in SEH as we might raise an exception */
374  _SEH2_TRY
375  {
376  /* Probe and Lock for Write Access */
378  }
380  {
381  /* Release our lock, free the buffer, dereference and return */
383  ObDereferenceObject(Profile);
386  }
387  _SEH2_END;
388 
389  /* Map the pages */
390  TempLockedBufferAddress = MmMapLockedPages(Profile->Mdl, KernelMode);
391 
392  /* Initialize the Kernel Profile Object */
393  Profile->ProfileObject = ProfileObject;
395  &Profile->Process->Pcb,
396  Profile->RangeBase,
397  Profile->RangeSize,
398  Profile->BucketSize,
399  Profile->ProfileSource,
400  Profile->Affinity);
401 
402  /* Start the Profiling */
403  KeStartProfile(ProfileObject, TempLockedBufferAddress);
404 
405  /* Now it's safe to save this */
406  Profile->LockedBufferAddress = TempLockedBufferAddress;
407 
408  /* Release mutex, dereference and return */
410  ObDereferenceObject(Profile);
411  return STATUS_SUCCESS;
412 }
KMUTEX ExpProfileMutex
Definition: profile.c:21
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:20
#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:3070
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:809
_SEH2_TRY
Definition: create.c:4226
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:494
#define FALSE
Definition: types.h:117
KAFFINITY Affinity
Definition: extypes.h:566
PVOID Buffer
Definition: extypes.h:558
ULONG BucketSize
Definition: extypes.h:560
SIZE_T RangeSize
Definition: extypes.h:557
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define TAG_PROFILE
Definition: profile.c:16
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
BOOLEAN NTAPI KeStartProfile(struct _KPROFILE *Profile, PVOID Buffer)
KPROCESS Pcb
Definition: pstypes.h:1262
VOID NTAPI KeInitializeProfile(struct _KPROFILE *Profile, struct _KPROCESS *Process, PVOID ImageBase, SIZE_T ImageSize, ULONG BucketSize, KPROFILE_SOURCE ProfileSource, KAFFINITY Affinity)
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:4400
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:922
PEPROCESS Process
Definition: extypes.h:555
#define STATUS_PROFILING_NOT_STOPPED
Definition: ntstatus.h:420
#define NULL
Definition: types.h:112
KPROFILE_SOURCE ProfileSource
Definition: extypes.h:565
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define PROFILE_CONTROL
Definition: extypes.h:130
PMDL Mdl
Definition: extypes.h:563
#define PAGED_CODE()

◆ NtStopProfile()

NTSTATUS NTAPI NtStopProfile ( IN HANDLE  ProfileHandle)

Definition at line 416 of file profile.c.

417 {
418  PEPROFILE Profile;
421  PAGED_CODE();
422 
423  /* Get the Object */
424  Status = ObReferenceObjectByHandle(ProfileHandle,
427  PreviousMode,
428  (PVOID*)&Profile,
429  NULL);
430  if (!NT_SUCCESS(Status)) return(Status);
431 
432  /* Get the Mutex */
434  Executive,
435  KernelMode,
436  FALSE,
437  NULL);
438 
439  /* Make sure the Profile Object is really Started */
440  if (!Profile->LockedBufferAddress)
441  {
443  goto Exit;
444  }
445 
446  /* Stop the Profile */
447  KeStopProfile(Profile->ProfileObject);
448 
449  /* Unlock the Buffer */
450  MmUnmapLockedPages(Profile->LockedBufferAddress, Profile->Mdl);
451  MmUnlockPages(Profile->Mdl);
452  IoFreeMdl(Profile->Mdl);
454 
455  /* Clear the Locked Buffer pointer, meaning the Object is Stopped */
456  Profile->LockedBufferAddress = NULL;
457 
458 Exit:
459  /* Release Mutex, Dereference and Return */
461  ObDereferenceObject(Profile);
462  return Status;
463 }
KMUTEX ExpProfileMutex
Definition: profile.c:21
POBJECT_TYPE ExProfileObjectType
Definition: profile.c:20
PVOID LockedBufferAddress
Definition: extypes.h:562
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1426
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
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
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:494
#define FALSE
Definition: types.h:117
VOID NTAPI MmUnmapLockedPages(IN PVOID BaseAddress, IN PMDL Mdl)
Definition: mdlsup.c:828
BOOLEAN NTAPI KeStopProfile(struct _KPROFILE *Profile)
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
#define ObDereferenceObject
Definition: obfuncs.h:203
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define TAG_PROFILE
Definition: profile.c:16
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
PKPROFILE ProfileObject
Definition: extypes.h:561
#define NULL
Definition: types.h:112
#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:419
#define PAGED_CODE()

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 23 of file profile.c.

Referenced by ExpInitializeProfileImplementation().

◆ ExpProfileMutex

KMUTEX ExpProfileMutex

Definition at line 21 of file profile.c.

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

◆ ExProfileObjectType

POBJECT_TYPE ExProfileObjectType = NULL