From 756ab632ca0bc5bfdccb7932da20a7b7d2665f97 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Tue, 22 Feb 2005 22:19:14 +0000 Subject: [PATCH] added more irql checks svn path=/trunk/; revision=13720 --- reactos/ntoskrnl/ex/callback.c | 6 +++++ reactos/ntoskrnl/ex/event.c | 14 +++++++++++ reactos/ntoskrnl/ex/evtpair.c | 20 +++++++++++++++ reactos/ntoskrnl/ex/mutant.c | 46 ++++++++++++++++++++-------------- reactos/ntoskrnl/ex/profile.c | 8 ++++++ reactos/ntoskrnl/ex/rundown.c | 14 ++++++++++- reactos/ntoskrnl/ex/sem.c | 8 ++++++ reactos/ntoskrnl/ex/sysinfo.c | 10 ++++++++ reactos/ntoskrnl/ex/time.c | 4 +++ reactos/ntoskrnl/ex/timer.c | 41 ++++++++++++++++++++++-------- reactos/ntoskrnl/ex/uuid.c | 4 +++ reactos/ntoskrnl/rtl/capture.c | 40 ----------------------------- 12 files changed, 145 insertions(+), 70 deletions(-) diff --git a/reactos/ntoskrnl/ex/callback.c b/reactos/ntoskrnl/ex/callback.c index 3496b017b65..918d766ffb7 100644 --- a/reactos/ntoskrnl/ex/callback.c +++ b/reactos/ntoskrnl/ex/callback.c @@ -171,6 +171,8 @@ ExCreateCallback( PINT_CALLBACK_OBJECT Callback; NTSTATUS Status; HANDLE Handle; + + PAGED_CODE(); /* Open a handle to the callback if it exists */ if (ObjectAttributes->ObjectName) @@ -346,6 +348,8 @@ ExRegisterCallback( PINT_CALLBACK_OBJECT CallbackObject = (PINT_CALLBACK_OBJECT)OpaqueCallbackObject; PCALLBACK_REGISTRATION CallbackRegistration = NULL; KIRQL OldIrql; + + PAGED_CODE(); /* Create reference to Callback Object */ ObReferenceObject (CallbackObject); @@ -411,6 +415,8 @@ ExUnregisterCallback( PCALLBACK_REGISTRATION CallbackRegistration; PINT_CALLBACK_OBJECT CallbackObject; KIRQL OldIrql; + + PAGED_CODE(); /* Convert Handle to valid Structure Pointer */ CallbackRegistration = (PCALLBACK_REGISTRATION) CallbackRegistrationHandle; diff --git a/reactos/ntoskrnl/ex/event.c b/reactos/ntoskrnl/ex/event.c index 352d1af5238..4db20f50ba5 100644 --- a/reactos/ntoskrnl/ex/event.c +++ b/reactos/ntoskrnl/ex/event.c @@ -88,6 +88,8 @@ NtClearEvent(IN HANDLE EventHandle) PKEVENT Event; NTSTATUS Status; + PAGED_CODE(); + Status = ObReferenceObjectByHandle(EventHandle, EVENT_MODIFY_STATE, ExEventObjectType, @@ -118,6 +120,8 @@ NtCreateEvent(OUT PHANDLE EventHandle, PKEVENT Event; HANDLE hEvent; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -195,6 +199,8 @@ NtOpenEvent(OUT PHANDLE EventHandle, KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + DPRINT("NtOpenEvent(0x%x, 0x%x, 0x%x)\n", EventHandle, DesiredAccess, ObjectAttributes); PreviousMode = ExGetPreviousMode(); @@ -254,6 +260,8 @@ NtPulseEvent(IN HANDLE EventHandle, PKEVENT Event; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); DPRINT("NtPulseEvent(EventHandle 0%x PreviousState 0%x)\n", EventHandle, PreviousState); @@ -322,6 +330,8 @@ NtQueryEvent(IN HANDLE EventHandle, PKEVENT Event; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -395,6 +405,8 @@ NtResetEvent(IN HANDLE EventHandle, PKEVENT Event; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); DPRINT("NtResetEvent(EventHandle 0%x PreviousState 0%x)\n", EventHandle, PreviousState); @@ -460,6 +472,8 @@ NtSetEvent(IN HANDLE EventHandle, PKEVENT Event; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); DPRINT("NtSetEvent(EventHandle 0%x PreviousState 0%x)\n", EventHandle, PreviousState); diff --git a/reactos/ntoskrnl/ex/evtpair.c b/reactos/ntoskrnl/ex/evtpair.c index 4e3794194c6..15b05e6bbc3 100644 --- a/reactos/ntoskrnl/ex/evtpair.c +++ b/reactos/ntoskrnl/ex/evtpair.c @@ -95,6 +95,8 @@ NtCreateEventPair(OUT PHANDLE EventPairHandle, KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(PreviousMode == UserMode) @@ -168,6 +170,8 @@ NtOpenEventPair(OUT PHANDLE EventPairHandle, HANDLE hEventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -221,6 +225,8 @@ NtSetHighEventPair(IN HANDLE EventPairHandle) PKEVENT_PAIR EventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); DPRINT("NtSetHighEventPair(EventPairHandle %x)\n", EventPairHandle); @@ -252,6 +258,8 @@ NtSetHighWaitLowEventPair(IN HANDLE EventPairHandle) PKEVENT_PAIR EventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); DPRINT("NtSetHighWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle); @@ -289,6 +297,8 @@ NtSetLowEventPair(IN HANDLE EventPairHandle) PKEVENT_PAIR EventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); DPRINT("NtSetLowEventPair(EventPairHandle %x)\n", EventPairHandle); @@ -320,6 +330,8 @@ NtSetLowWaitHighEventPair(IN HANDLE EventPairHandle) PKEVENT_PAIR EventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); DPRINT("NtSetLowWaitHighEventPair(EventPairHandle %x)\n", EventPairHandle); @@ -357,6 +369,8 @@ NtWaitLowEventPair(IN HANDLE EventPairHandle) PKEVENT_PAIR EventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); DPRINT("NtWaitLowEventPair(EventPairHandle %x)\n", EventPairHandle); @@ -390,6 +404,8 @@ NtWaitHighEventPair(IN HANDLE EventPairHandle) PKEVENT_PAIR EventPair; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); DPRINT("NtWaitHighEventPair(EventPairHandle %x)\n", EventPairHandle); @@ -436,6 +452,8 @@ NtSetLowWaitHighThread( NTSTATUS Status; KIRQL Irql; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(!Thread->EventPair) @@ -489,6 +507,8 @@ NtSetHighWaitLowThread( PKEVENT_PAIR EventPair; NTSTATUS Status; KIRQL Irql; + + PAGED_CODE(); Thread = PsGetCurrentThread(); diff --git a/reactos/ntoskrnl/ex/mutant.c b/reactos/ntoskrnl/ex/mutant.c index 0852e0075ab..f6a2d4b36c7 100644 --- a/reactos/ntoskrnl/ex/mutant.c +++ b/reactos/ntoskrnl/ex/mutant.c @@ -104,27 +104,29 @@ NtCreateMutant(OUT PHANDLE MutantHandle, PKMUTEX Mutant; NTSTATUS Status = STATUS_SUCCESS; - PreviousMode = ExGetPreviousMode(); + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); - if(PreviousMode == UserMode) - { - _SEH_TRY - { - ProbeForWrite(MutantHandle, - sizeof(HANDLE), - sizeof(ULONG)); - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; + if(PreviousMode == UserMode) + { + _SEH_TRY + { + ProbeForWrite(MutantHandle, + sizeof(HANDLE), + sizeof(ULONG)); + } + _SEH_HANDLE + { + Status = _SEH_GetExceptionCode(); + } + _SEH_END; - if(!NT_SUCCESS(Status)) - { - return Status; - } - } + if(!NT_SUCCESS(Status)) + { + return Status; + } + } Status = ObCreateObject(PreviousMode, ExMutantObjectType, @@ -177,6 +179,8 @@ NtOpenMutant(OUT PHANDLE MutantHandle, HANDLE hMutant; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); DPRINT("NtOpenMutant(0x%x, 0x%x, 0x%x)\n", MutantHandle, DesiredAccess, ObjectAttributes); @@ -240,6 +244,8 @@ NtQueryMutant(IN HANDLE MutantHandle, PKMUTANT Mutant; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -311,6 +317,8 @@ NtReleaseMutant(IN HANDLE MutantHandle, PKMUTANT Mutant; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); DPRINT("NtReleaseMutant(MutantHandle 0%x PreviousCount 0%x)\n", MutantHandle, PreviousCount); diff --git a/reactos/ntoskrnl/ex/profile.c b/reactos/ntoskrnl/ex/profile.c index 645dfcb8ccd..863add88d9e 100644 --- a/reactos/ntoskrnl/ex/profile.c +++ b/reactos/ntoskrnl/ex/profile.c @@ -109,6 +109,8 @@ NtCreateProfile(OUT PHANDLE ProfileHandle, OBJECT_ATTRIBUTES ObjectAttributes; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(BufferSize == 0) @@ -271,6 +273,8 @@ NtQueryIntervalProfile(IN KPROFILE_SOURCE ProfileSource, KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(PreviousMode != KernelMode) @@ -329,6 +333,8 @@ NtStartProfile(IN HANDLE ProfileHandle) KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); Status = ObReferenceObjectByHandle(ProfileHandle, @@ -353,6 +359,8 @@ NtStopProfile(IN HANDLE ProfileHandle) KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); Status = ObReferenceObjectByHandle(ProfileHandle, diff --git a/reactos/ntoskrnl/ex/rundown.c b/reactos/ntoskrnl/ex/rundown.c index 19b3f0911ac..baf8a38248b 100644 --- a/reactos/ntoskrnl/ex/rundown.c +++ b/reactos/ntoskrnl/ex/rundown.c @@ -41,6 +41,8 @@ ExAcquireRundownProtectionEx ( { ULONG_PTR PrevCount, Current; + PAGED_CODE(); + Count <<= EX_RUNDOWN_COUNT_SHIFT; /* Loop until successfully incremented the counter */ @@ -74,6 +76,8 @@ ExInitializeRundownProtection ( IN PEX_RUNDOWN_REF RunRef ) { + PAGED_CODE(); + /* Set the count to zero */ RunRef->Count = 0; } @@ -87,6 +91,8 @@ ExReInitializeRundownProtection ( IN PEX_RUNDOWN_REF RunRef ) { + PAGED_CODE(); + /* Reset the count */ #ifdef _WIN64 InterlockedExchangeAdd64((LONGLONG*)&RunRef->Count, 0LL); @@ -106,6 +112,8 @@ ExReleaseRundownProtectionEx ( IN ULONG Count ) { + PAGED_CODE(); + Count <<= EX_RUNDOWN_COUNT_SHIFT; for (;;) @@ -200,7 +208,9 @@ ExRundownCompleted ( IN PEX_RUNDOWN_REF RunRef ) { - /* mark the */ + PAGED_CODE(); + + /* mark the counter as active */ #ifdef _WIN64 InterlockedExchange64((LONGLONG*)&RunRef->Count, (LONGLONG)EX_RUNDOWN_ACTIVE); #else @@ -220,6 +230,8 @@ ExWaitForRundownProtectionRelease ( ULONG_PTR PrevCount, NewPtr, PrevPtr; RUNDOWN_DESCRIPTOR RundownDescriptor; + PAGED_CODE(); + PrevCount = RunRef->Count; if (PrevCount != 0 && !(PrevCount & EX_RUNDOWN_ACTIVE)) diff --git a/reactos/ntoskrnl/ex/sem.c b/reactos/ntoskrnl/ex/sem.c index 64c8f7d23d5..274ce8aed1d 100644 --- a/reactos/ntoskrnl/ex/sem.c +++ b/reactos/ntoskrnl/ex/sem.c @@ -91,6 +91,8 @@ NtCreateSemaphore(OUT PHANDLE SemaphoreHandle, HANDLE hSemaphore; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -167,6 +169,8 @@ NtOpenSemaphore(OUT PHANDLE SemaphoreHandle, HANDLE hSemaphore; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -227,6 +231,8 @@ NtQuerySemaphore(IN HANDLE SemaphoreHandle, PKSEMAPHORE Semaphore; KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -299,6 +305,8 @@ NtReleaseSemaphore(IN HANDLE SemaphoreHandle, PKSEMAPHORE Semaphore; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(PreviousCount != NULL && PreviousMode == UserMode) diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index de9efb57168..2efe7292c20 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -101,6 +101,8 @@ NtQuerySystemEnvironmentValue (IN PUNICODE_STRING VariableName, KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(PreviousMode != KernelMode) @@ -245,6 +247,8 @@ NtSetSystemEnvironmentValue (IN PUNICODE_STRING VariableName, ANSI_STRING AName, AValue; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); @@ -1371,6 +1375,8 @@ NtQuerySystemInformation (IN SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation; NTSTATUS Status; NTSTATUS FStatus; + + PAGED_CODE(); /* DPRINT("NtQuerySystemInformation Start. Class:%d\n", SystemInformationClass ); @@ -1448,6 +1454,8 @@ NtSetSystemInformation ( IN ULONG SystemInformationLength ) { + PAGED_CODE(); + /* * If called from user mode, check * possible unsafe arguments. @@ -1496,6 +1504,8 @@ NtFlushInstructionCache ( IN UINT NumberOfBytesToFlush ) { + PAGED_CODE(); + __asm__("wbinvd\n"); return STATUS_SUCCESS; } diff --git a/reactos/ntoskrnl/ex/time.c b/reactos/ntoskrnl/ex/time.c index 93cc43f5124..b8ca5046dcb 100644 --- a/reactos/ntoskrnl/ex/time.c +++ b/reactos/ntoskrnl/ex/time.c @@ -151,6 +151,8 @@ NtSetSystemTime(IN PLARGE_INTEGER SystemTime, KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + PAGED_CODE(); + PreviousMode = ExGetPreviousMode(); if(PreviousMode != KernelMode) @@ -233,6 +235,8 @@ NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime) { KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); PreviousMode = ExGetPreviousMode(); diff --git a/reactos/ntoskrnl/ex/timer.c b/reactos/ntoskrnl/ex/timer.c index 0a0234a061e..fa0a2540d3d 100644 --- a/reactos/ntoskrnl/ex/timer.c +++ b/reactos/ntoskrnl/ex/timer.c @@ -209,12 +209,16 @@ NtCancelTimer(IN HANDLE TimerHandle, OUT PBOOLEAN CurrentState OPTIONAL) { PETIMER Timer; - KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); - NTSTATUS Status = STATUS_SUCCESS; + KPROCESSOR_MODE PreviousMode; BOOLEAN State; KIRQL OldIrql; - BOOLEAN KillTimer = FALSE; PETHREAD TimerThread; + BOOLEAN KillTimer = FALSE; + NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); DPRINT("NtCancelTimer(0x%x, 0x%x)\n", TimerHandle, CurrentState); @@ -319,8 +323,12 @@ NtCreateTimer(OUT PHANDLE TimerHandle, { PETIMER Timer; HANDLE hTimer; - KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); + KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); DPRINT("NtCreateTimer(Handle: %x, Type: %d)\n", TimerHandle, TimerType); @@ -398,8 +406,12 @@ NtOpenTimer(OUT PHANDLE TimerHandle, IN POBJECT_ATTRIBUTES ObjectAttributes) { HANDLE hTimer; - KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); + KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); DPRINT("NtOpenTimer(TimerHandle: %x)\n", TimerHandle); @@ -452,9 +464,13 @@ NtQueryTimer(IN HANDLE TimerHandle, OUT PULONG ReturnLength OPTIONAL) { PETIMER Timer; - KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); + KPROCESSOR_MODE PreviousMode; NTSTATUS Status = STATUS_SUCCESS; PTIMER_BASIC_INFORMATION BasicInfo = (PTIMER_BASIC_INFORMATION)TimerInformation; + + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); DPRINT("NtQueryTimer(TimerHandle: %x, Class: %d)\n", TimerHandle, TimerInformationClass); @@ -522,13 +538,18 @@ NtSetTimer(IN HANDLE TimerHandle, { PETIMER Timer; KIRQL OldIrql; - BOOLEAN KillTimer = FALSE; BOOLEAN State; - KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); - PETHREAD CurrentThread = PsGetCurrentThread(); - NTSTATUS Status = STATUS_SUCCESS; + KPROCESSOR_MODE PreviousMode; + PETHREAD CurrentThread; LARGE_INTEGER TimerDueTime; PETHREAD TimerThread; + BOOLEAN KillTimer = FALSE; + NTSTATUS Status = STATUS_SUCCESS; + + PAGED_CODE(); + + PreviousMode = ExGetPreviousMode(); + CurrentThread = PsGetCurrentThread(); DPRINT("NtSetTimer(TimerHandle: %x, DueTime: %d, Apc: %x, Period: %d)\n", TimerHandle, DueTime->QuadPart, TimerApcRoutine, Period); diff --git a/reactos/ntoskrnl/ex/uuid.c b/reactos/ntoskrnl/ex/uuid.c index 8cdac4f657f..1db7a2a123b 100644 --- a/reactos/ntoskrnl/ex/uuid.c +++ b/reactos/ntoskrnl/ex/uuid.c @@ -223,6 +223,8 @@ NtAllocateUuids(OUT PULARGE_INTEGER Time, ULARGE_INTEGER IntTime; ULONG IntRange; NTSTATUS Status; + + PAGED_CODE(); ExAcquireFastMutex(&UuidMutex); @@ -278,6 +280,8 @@ NtAllocateUuids(OUT PULARGE_INTEGER Time, NTSTATUS STDCALL NtSetUuidSeed(IN PUCHAR Seed) { + PAGED_CODE(); + RtlCopyMemory(UuidSeed, Seed, SEED_BUFFER_SIZE); diff --git a/reactos/ntoskrnl/rtl/capture.c b/reactos/ntoskrnl/rtl/capture.c index c001291b15e..8eb7529d5b6 100644 --- a/reactos/ntoskrnl/rtl/capture.c +++ b/reactos/ntoskrnl/rtl/capture.c @@ -125,46 +125,6 @@ RtlReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, } } -NTSTATUS -RtlCaptureAnsiString(PANSI_STRING Dest, - PANSI_STRING UnsafeSrc) -{ - PANSI_STRING Src; - NTSTATUS Status; - - /* - * Copy the source string structure to kernel space. - */ - Status = MmCopyFromCaller(&Src, UnsafeSrc, sizeof(ANSI_STRING)); - if (!NT_SUCCESS(Status)) - { - return(Status); - } - - /* - * Initialize the destination string. - */ - Dest->Length = Src->Length; - Dest->MaximumLength = Src->MaximumLength; - Dest->Buffer = ExAllocatePool(NonPagedPool, Dest->MaximumLength); - if (Dest->Buffer == NULL) - { - return(Status); - } - - /* - * Copy the source string to kernel space. - */ - Status = MmCopyFromCaller(Dest->Buffer, Src->Buffer, Dest->Length); - if (!NT_SUCCESS(Status)) - { - ExFreePool(Dest->Buffer); - return(Status); - } - - return(STATUS_SUCCESS); -} - /* * @unimplemented */