#pragma alloc_text(INIT, ExpInitializeProfileImplementation)
#endif
-#define TAG_PROFILE TAG('P', 'r', 'o', 'f')
+#define TAG_PROFILE 'forP'
/* GLOBALS *******************************************************************/
PEPROCESS pProcess;
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
OBJECT_ATTRIBUTES ObjectAttributes;
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG Segment = 0, Log2 = 0;
+ NTSTATUS Status;
+ ULONG Log2 = 0;
+ ULONG_PTR Segment = 0;
PAGED_CODE();
/* Easy way out */
if (BufferSize < sizeof(ULONG)) return STATUS_INVALID_PARAMETER_7;
/* This will become a segmented profile object */
- Segment = (ULONG)RangeBase;
+ Segment = (ULONG_PTR)RangeBase;
RangeBase = 0;
/* Recalculate the bucket size */
if(PreviousMode != KernelMode)
{
/* Entry SEH */
- _SEH_TRY
+ _SEH2_TRY
{
/* Make sure that the handle pointer is valid */
ProbeForWriteHandle(ProfileHandle);
BufferSize,
sizeof(ULONG));
}
- _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
+ /* Return the exception code */
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
- _SEH_END;
-
- /* Bail out if we failed */
- if(!NT_SUCCESS(Status)) return Status;
+ _SEH2_END;
}
/* Check if a process was specified */
if (!NT_SUCCESS(Status))
{
/* Dereference the process object if it was specified */
- if (Process) ObDereferenceObject(Process);
+ if (pProcess) ObDereferenceObject(pProcess);
/* Return Status */
return Status;
}
/* Enter SEH */
- _SEH_TRY
+ _SEH2_TRY
{
/* Copy the created handle back to the caller*/
*ProfileHandle = hProfile;
}
- _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+ _SEH2_EXCEPT(ExSystemExceptionFilter())
{
- Status = _SEH_GetExceptionCode();
+ Status = _SEH2_GetExceptionCode();
}
- _SEH_END;
+ _SEH2_END;
/* Return Status */
return Status;
NTSTATUS Status = STATUS_SUCCESS;
/* Check if we were called from user-mode */
- if(PreviousMode != KernelMode)
+ if (PreviousMode != KernelMode)
{
/* Entry SEH Block */
- _SEH_TRY
+ _SEH2_TRY
{
/* Make sure the counter and frequency are valid */
ProbeForWriteLargeInteger(PerformanceCounter);
ProbeForWriteLargeInteger(PerformanceFrequency);
}
}
- _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
+ /* Return the exception code */
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
- _SEH_END;
-
- /* If the pointers are invalid, bail out */
- if(!NT_SUCCESS(Status)) return Status;
+ _SEH2_END;
}
/* Enter a new SEH Block */
- _SEH_TRY
+ _SEH2_TRY
{
/* Query the Kernel */
*PerformanceCounter = KeQueryPerformanceCounter(&PerfFrequency);
/* Return Frequency if requested */
- if(PerformanceFrequency) *PerformanceFrequency = PerfFrequency;
+ if (PerformanceFrequency) *PerformanceFrequency = PerfFrequency;
}
- _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+ _SEH2_EXCEPT(ExSystemExceptionFilter())
{
- Status = _SEH_GetExceptionCode();
+ /* Get the exception code */
+ Status = _SEH2_GetExceptionCode();
}
- _SEH_END;
+ _SEH2_END;
/* Return status to caller */
return Status;
/* Allocate a Kernel Profile Object. */
ProfileObject = ExAllocatePoolWithTag(NonPagedPool,
- sizeof(EPROFILE),
- TAG_PROFILE);
+ sizeof(EPROFILE),
+ TAG_PROFILE);
+ if (!ProfileObject)
+ {
+ /* Out of memory, fail */
+ KeReleaseMutex(&ExpProfileMutex, FALSE);
+ ObDereferenceObject(Profile);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
/* Allocate the Mdl Structure */
Profile->Mdl = MmCreateMdl(NULL, Profile->Buffer, Profile->BufferSize);
- /* Probe and Lock for Write Access */
- MmProbeAndLockPages(Profile->Mdl, PreviousMode, IoWriteAccess);
+ /* Protect this in SEH as we might raise an exception */
+ _SEH2_TRY
+ {
+ /* Probe and Lock for Write Access */
+ MmProbeAndLockPages(Profile->Mdl, PreviousMode, IoWriteAccess);
+ }
+ _SEH2_EXCEPT(ExSystemExceptionFilter())
+ {
+ /* Release our lock, free the buffer, dereference and return */
+ KeReleaseMutex(&ExpProfileMutex, FALSE);
+ ObDereferenceObject(Profile);
+ ExFreePool(ProfileObject);
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
+ }
+ _SEH2_END;
/* Map the pages */
TempLockedBufferAddress = MmMapLockedPages(Profile->Mdl, KernelMode);
PAGED_CODE();
/* Check if we were called from user-mode */
- if(PreviousMode != KernelMode)
+ if (PreviousMode != KernelMode)
{
/* Enter SEH Block */
- _SEH_TRY
+ _SEH2_TRY
{
/* Validate interval */
ProbeForWriteUlong(Interval);
}
- _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
+ /* Return the exception code */
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
- _SEH_END;
-
- /* If pointer was invalid, bail out */
- if(!NT_SUCCESS(Status)) return Status;
+ _SEH2_END;
}
/* Query the Interval */
ReturnInterval = KeQueryIntervalProfile(ProfileSource);
/* Enter SEH block for return */
- _SEH_TRY
+ _SEH2_TRY
{
/* Return the data */
*Interval = ReturnInterval;
}
- _SEH_EXCEPT(_SEH_ExSystemExceptionFilter)
+ _SEH2_EXCEPT(ExSystemExceptionFilter())
{
- Status = _SEH_GetExceptionCode();
+ /* Get the exception code */
+ Status = _SEH2_GetExceptionCode();
}
- _SEH_END;
+ _SEH2_END;
/* Return Success */
- return STATUS_SUCCESS;
+ return Status;
}
NTSTATUS