- minor optimizations by comparing the processor mode against KernelMode (==0) instead of UserMode (==1)
svn path=/trunk/; revision=17467
{
_SEH_TRY
{
- ProbeForWrite(KeyHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(KeyHandle);
}
_SEH_HANDLE
{
EventHandle, PreviousState);
/* Check buffer validity */
- if(PreviousState && PreviousMode == UserMode) {
+ if(PreviousState && PreviousMode != KernelMode) {
_SEH_TRY {
EventHandle, PreviousState);
/* Check buffer validity */
- if(PreviousState && PreviousMode == UserMode) {
+ if(PreviousState && PreviousMode != KernelMode) {
_SEH_TRY {
EventHandle, PreviousState);
/* Check buffer validity */
- if(PreviousState != NULL && PreviousMode == UserMode) {
+ if(PreviousState != NULL && PreviousMode != KernelMode) {
_SEH_TRY {
_SEH_TRY
{
- if (PreviousMode == UserMode)
+ if (PreviousMode != KernelMode)
{
/* SystemKernelDebuggerInformation needs only BOOLEAN alignment */
ProbeForWrite(SystemInformation, Length, 1);
#define ProbeQueryInfoBuffer(Buffer, BufferLen, Alignment, RetLen, PrevMode, StatusVar) \
do { \
- if(PrevMode == UserMode) \
+ if(PrevMode != KernelMode) \
{ \
_SEH_TRY \
{ \
#define ProbeSetInfoBuffer(Buffer, BufferLen, Alignment, PrevMode, StatusVar) \
do { \
- if(PrevMode == UserMode) \
+ if(PrevMode != KernelMode) \
{ \
_SEH_TRY \
{ \
{
_SEH_TRY
{
- ProbeForWrite(FileHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(FileHandle);
ProbeForWrite(IoStatusBlock,
sizeof(IO_STATUS_BLOCK),
sizeof(ULONG));
if(AllocationSize != NULL)
{
- ProbeForRead(AllocationSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
- SafeAllocationSize = *AllocationSize;
+ SafeAllocationSize = ProbeForReadLargeInteger(AllocationSize);
}
else
SafeAllocationSize.QuadPart = 0;
LARGE_INTEGER Interval;
if ((ULONG_PTR)IoStatusBlock >= (ULONG_PTR)MmUserProbeAddress &&
- KeGetPreviousMode() == UserMode)
+ KeGetPreviousMode() != KernelMode)
return STATUS_ACCESS_VIOLATION;
Status = ObReferenceObjectByHandle(FileHandle, 0, IoFileObjectType,
_SEH_TRY {
- ProbeForWrite(IoCompletionHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(IoCompletionHandle);
} _SEH_HANDLE {
Status = _SEH_GetExceptionCode();
_SEH_TRY {
- ProbeForWrite(IoCompletionHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(IoCompletionHandle);
} _SEH_HANDLE {
Status = _SEH_GetExceptionCode();
_SEH_TRY {
- ProbeForWrite(CompletionKey,
- sizeof(PVOID),
- sizeof(ULONG));
- ProbeForWrite(CompletionContext,
- sizeof(PVOID),
- sizeof(ULONG));
+ ProbeForWritePointer(CompletionKey);
+ ProbeForWritePointer(CompletionContext);
ProbeForWrite(IoStatusBlock,
sizeof(IO_STATUS_BLOCK),
sizeof(ULONG));
if (Timeout != NULL) {
- ProbeForRead(Timeout,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
- SafeTimeout = *Timeout;
+ SafeTimeout = ProbeForReadLargeInteger(Timeout);
Timeout = &SafeTimeout;
}
} _SEH_HANDLE {
DPRINT("NtGetPlugPlayEvent() called\n");
/* Function can only be called from user-mode */
- if (KeGetPreviousMode() != UserMode)
+ if (KeGetPreviousMode() == KernelMode)
{
DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
return STATUS_ACCESS_DENIED;
PlugPlayControlClass, Buffer, BufferLength);
/* Function can only be called from user-mode */
- if (KeGetPreviousMode() != UserMode)
+ if (KeGetPreviousMode() == KernelMode)
{
DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
return STATUS_ACCESS_DENIED;
ul = min(ExpNr, RTL_NUMBER_OF(KdbEnterConditions) - 1);
EnterCondition = KdbEnterConditions[ul][FirstChance ? 0 : 1];
if (EnterCondition == KdbDoNotEnter ||
- (EnterCondition == KdbEnterFromUmode && PreviousMode != UserMode) ||
+ (EnterCondition == KdbEnterFromUmode && PreviousMode == KernelMode) ||
(EnterCondition == KdbEnterFromKmode && PreviousMode != KernelMode))
{
EnterConditionMet = FALSE;
}
} else if ((Thread->State == Waiting) &&
- (Thread->WaitMode == UserMode) &&
+ (Thread->WaitMode != KernelMode) &&
(Thread->Alertable)) {
DPRINT("Waking up Thread for User-Mode APC Delivery \n");
/* Now we do the User APCs */
if ((!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])) &&
- (DeliveryMode == UserMode) && (Thread->ApcState.UserApcPending == TRUE)) {
+ (DeliveryMode != KernelMode) && (Thread->ApcState.UserApcPending == TRUE)) {
/* It's not pending anymore */
Thread->ApcState.UserApcPending = FALSE;
TContext.ContextFlags = CONTEXT_FULL;
/* Check the mode */
- if (PreviousMode == UserMode)
+ if (PreviousMode != KernelMode)
{
/* Add Debugger Registers if this is User Mode */
TContext.ContextFlags = TContext.ContextFlags | CONTEXT_DEBUGGER;
if (Action != kdDoNotHandleException)
{
/* See what kind of Exception this is */
- if (PreviousMode == UserMode)
+ if (PreviousMode != KernelMode)
{
/* User mode exception, search the frames if we have to */
if (SearchFrames)
PreviousMode = ((Tf->Cs & 0xffff) == USER_CS) ? (UserMode) : (KernelMode);
DPRINT("Math/Xmm fault happened! (PreviousMode = %s)\n",
- (PreviousMode == UserMode) ? ("UserMode") : ("KernelMode"));
+ (PreviousMode != KernelMode) ? ("UserMode") : ("KernelMode"));
ASSERT(NpxThread == CurrentThread); /* FIXME: Is not always true I think */
Thread->Alerted[AlertMode] = FALSE;
- } else if ((AlertMode == UserMode) && (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))) {
+ } else if ((AlertMode != KernelMode) && (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode]))) {
/* If the mode is User and the Queue isn't empty, set Pending */
Thread->ApcState.UserApcPending = TRUE;
_SEH_TRY {
- ProbeForWrite(SuspendCount,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteUlong(SuspendCount);
} _SEH_HANDLE {
/* Check if parameters are valid */
if(PreviousMode != KernelMode) {
+ Status = STATUS_SUCCESS;
+
_SEH_TRY {
- ProbeForRead(DelayInterval,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
-
/* make a copy on the kernel stack and let DelayInterval point to it so
we don't need to wrap KeDelayExecutionThread in SEH! */
- SafeInterval = *DelayInterval;
+ SafeInterval = ProbeForReadLargeInteger(DelayInterval);
+ DelayInterval = &SafeInterval;
} _SEH_HANDLE {
Status = _SEH_GetExceptionCode();
} _SEH_END;
+
+ if (!NT_SUCCESS(Status))
+ {
+ return Status;
+ }
}
/* Call the Kernel Function */
Status = KeDelayExecutionThread(PreviousMode,
Alertable,
- &SafeInterval);
+ DelayInterval);
/* Return Status */
return Status;
Thread->WaitBlockList = &Thread->WaitBlock[0];
/* Fail if there's an APC Pending */
- if (WaitMode == UserMode && Thread->ApcState.UserApcPending) {
+ if (WaitMode != KernelMode && Thread->ApcState.UserApcPending) {
/* Return the status and increase the pending threads */
ListEntry = (PLIST_ENTRY)STATUS_USER_APC;
/* If there are User APCs Pending, then we can't really be alertable */
} else if ((!IsListEmpty(&CurrentThread->ApcState.ApcListHead[UserMode])) &&
- (WaitMode == UserMode)) {
+ (WaitMode != KernelMode)) {
DPRINT("APCs are Pending\n");
CurrentThread->ApcState.UserApcPending = TRUE;
}
/* If there are User APCs Pending and we are waiting in usermode, then we must notify the caller */
- } else if ((CurrentThread->ApcState.UserApcPending) && (WaitMode == UserMode)) {
+ } else if ((CurrentThread->ApcState.UserApcPending) && (WaitMode != KernelMode)) {
DPRINT("APCs are Pending\n");
*Status = STATUS_USER_APC;
}
{
_SEH_TRY
{
- ProbeForWrite(UnsafeConnectedPortHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(UnsafeConnectedPortHandle);
if (UnsafeMaximumMessageSize != NULL)
{
- ProbeForWrite(UnsafeMaximumMessageSize,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(UnsafeMaximumMessageSize);
}
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForRead(UnsafeConnectDataLength,
- sizeof(ULONG),
- 1);
- ConnectDataLength = *UnsafeConnectDataLength;
+ ConnectDataLength = ProbeForReadUlong(UnsafeConnectDataLength);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForWrite(UnsafeConnectData,
- ConnectDataLength,
- 1);
+ ProbeForWriteUlong(UnsafeConnectData);
RtlCopyMemory(ConnectData,
UnsafeConnectData,
ConnectDataLength);
/* Calculate the number of pages required. */
PageCount = PAGE_ROUND_UP(Mdl->ByteCount + Mdl->ByteOffset) / PAGE_SIZE;
- if (AccessMode == UserMode)
+ if (AccessMode != KernelMode)
{
MEMORY_AREA *Result;
LARGE_INTEGER BoundaryAddressMultiple;
{
return NULL;
}
- if (AccessMode == UserMode)
+ if (AccessMode != KernelMode)
{
/* Throw exception */
ExRaiseStatus(STATUS_ACCESS_VIOLATION);
{
return(Status);
}
- if (PreviousMode == UserMode)
+ if (PreviousMode != KernelMode)
{
_SEH_TRY
{
- ProbeForRead(InitialSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
- SafeInitialSize = *InitialSize;
- ProbeForRead(MaximumSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
- SafeMaximumSize = *MaximumSize;
+ SafeInitialSize = ProbeForReadLargeInteger(InitialSize);
+ SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForRead(MaximumSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
/* make a copy on the stack */
- SafeMaximumSize = *MaximumSize;
+ SafeMaximumSize = ProbeForReadLargeInteger(MaximumSize);
MaximumSize = &SafeMaximumSize;
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForWrite(SectionHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(SectionHandle);
}
_SEH_HANDLE
{
{
if(BaseAddress != NULL)
{
- ProbeForWrite(BaseAddress,
- sizeof(PVOID),
- sizeof(ULONG));
+ ProbeForWritePointer(BaseAddress);
SafeBaseAddress = *BaseAddress;
}
if(SectionOffset != NULL)
{
- ProbeForWrite(SectionOffset,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
+ ProbeForWriteLargeInteger(SectionOffset);
SafeSectionOffset = *SectionOffset;
}
- ProbeForWrite(ViewSize,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(ViewSize);
SafeViewSize = *ViewSize;
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForRead(NewMaximumSize,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
/* make a copy on the stack */
- SafeNewMaximumSize = *NewMaximumSize;
+ SafeNewMaximumSize = ProbeForReadLargeInteger(NewMaximumSize);
NewMaximumSize = &SafeNewMaximumSize;
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForWrite(UnsafeResultLength,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(UnsafeResultLength);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForWrite(UnsafeBaseAddress,
- sizeof(PVOID),
- sizeof(ULONG));
- ProbeForWrite(UnsafeBaseAddress,
- sizeof(ULONG),
- sizeof(ULONG));
- ProbeForWrite(UnsafeOldAccessProtection,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWritePointer(UnsafeBaseAddress);
+ ProbeForWriteUlong(UnsafeNumberOfBytesToProtect);
+ ProbeForWriteUlong(UnsafeOldAccessProtection);
BaseAddress = *UnsafeBaseAddress;
NumberOfBytesToProtect = *UnsafeNumberOfBytesToProtect;
1);
if(NumberOfBytesRead != NULL)
{
- ProbeForWrite(NumberOfBytesRead,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(NumberOfBytesRead);
}
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForWrite(NumberOfBytesWritten,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(NumberOfBytesWritten);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForWrite(DirectoryHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(DirectoryHandle);
}
_SEH_HANDLE
{
ProbeForWrite(Buffer,
BufferLength,
sizeof(WCHAR));
- ProbeForWrite(Context,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(Context);
if(!RestartScan)
{
SkipEntries = *Context;
}
if(ReturnLength != NULL)
{
- ProbeForWrite(ReturnLength,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(ReturnLength);
}
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForWrite(DirectoryHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(DirectoryHandle);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForWrite(TargetHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(TargetHandle);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForWrite(LinkHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(LinkHandle);
}
_SEH_HANDLE
{
{
_SEH_TRY
{
- ProbeForWrite(LinkHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(LinkHandle);
}
_SEH_HANDLE
{
if(ResultLength != NULL)
{
- ProbeForWrite(ResultLength,
- sizeof(ULONG),
- sizeof(ULONG));
+ ProbeForWriteUlong(ResultLength);
}
}
_SEH_HANDLE
if(TimeOut)
{
- ProbeForRead(TimeOut,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
-
/* Make a local copy of the timeout on the stack */
- SafeTimeOut = *TimeOut;
+ SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
TimeOut = &SafeTimeOut;
}
}
{
_SEH_TRY
{
- ProbeForRead(TimeOut,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
/* Make a copy on the stack */
- SafeTimeOut = *TimeOut;
+ SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
TimeOut = &SafeTimeOut;
}
_SEH_HANDLE
{
_SEH_TRY
{
- ProbeForRead(TimeOut,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
/* Make a copy on the stack */
- SafeTimeOut = *TimeOut;
+ SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
TimeOut = &SafeTimeOut;
}
_SEH_HANDLE
CurrentProcess = PsGetCurrentProcess();
/* check for valid buffers */
- if(PreviousMode == UserMode)
+ if(PreviousMode != KernelMode)
{
_SEH_TRY
{
PreviousMode = ExGetPreviousMode();
/* check for valid buffers */
- if(PreviousMode == UserMode)
+ if(PreviousMode != KernelMode)
{
_SEH_TRY
{
PreviousMode = ExGetPreviousMode();
- if(PreviousMode == UserMode)
+ if(PreviousMode != KernelMode)
{
_SEH_TRY
{
ThreadHandle, SuspendCount);
/* Check buffer validity */
- if(SuspendCount && PreviousMode == UserMode) {
+ if(SuspendCount && PreviousMode != KernelMode) {
_SEH_TRY {
* Copy the source string structure to kernel space.
*/
- if(CurrentMode == UserMode)
+ if(CurrentMode != KernelMode)
{
RtlZeroMemory(&Src, sizeof(Src));
PAGED_CODE();
if(CapturedAcl != NULL &&
- (AccessMode == UserMode ||
+ (AccessMode != KernelMode ||
(AccessMode == KernelMode && CaptureIfKernel)))
{
ExFreePool(CapturedAcl);
PAGED_CODE();
if(CapturedSecurityQualityOfService != NULL &&
- (AccessMode == UserMode ||
+ (AccessMode != KernelMode ||
(AccessMode == KernelMode && CaptureIfKernel)))
{
ExFreePool(CapturedSecurityQualityOfService);
and CaptureIfKernelMode that you previously passed to
SeCaptureSecurityDescriptor() in order to avoid memory leaks! */
if(CapturedSecurityDescriptor != NULL &&
- (CurrentMode == UserMode ||
+ (CurrentMode != KernelMode ||
(CurrentMode == KernelMode && CaptureIfKernelMode)))
{
/* only delete the descriptor when SeCaptureSecurityDescriptor() allocated one! */
PAGED_CODE();
if(CapturedSid != NULL &&
- (AccessMode == UserMode ||
+ (AccessMode != KernelMode ||
(AccessMode == KernelMode && CaptureIfKernel)))
{
ExFreePool(CapturedSid);
{
_SEH_TRY
{
- ProbeForWrite(NewTokenHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(NewTokenHandle);
}
_SEH_HANDLE
{
ULONG uLength;
ULONG i;
ULONG nTokenPrivileges = 0;
+ LARGE_INTEGER LocalExpirationTime = {};
KPROCESSOR_MODE PreviousMode;
NTSTATUS Status = STATUS_SUCCESS;
{
_SEH_TRY
{
- ProbeForWrite(TokenHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(TokenHandle);
ProbeForRead(AuthenticationId,
sizeof(LUID),
sizeof(ULONG));
- ProbeForRead(ExpirationTime,
- sizeof(LARGE_INTEGER),
- sizeof(ULONG));
+ LocalExpirationTime = ProbeForReadLargeInteger(ExpirationTime);
ProbeForRead(TokenUser,
sizeof(TOKEN_USER),
sizeof(ULONG));
else
{
nTokenPrivileges = TokenPrivileges->PrivilegeCount;
+ LocalExpirationTime = *ExpirationTime;
}
Status = ZwAllocateLocallyUniqueId(&TokenId);
{
_SEH_TRY
{
- ProbeForWrite(TokenHandle,
- sizeof(HANDLE),
- sizeof(ULONG));
+ ProbeForWriteHandle(TokenHandle);
}
_SEH_HANDLE
{