diff --git a/reactos/ntoskrnl/ex/time.c b/reactos/ntoskrnl/ex/time.c index 78936e064d7..9fe8420c591 100644 --- a/reactos/ntoskrnl/ex/time.c +++ b/reactos/ntoskrnl/ex/time.c @@ -48,9 +48,7 @@ ULONG ExpTimerResolutionCount = 0; *--*/ BOOLEAN NTAPI -ExAcquireTimeRefreshLock( - IN BOOLEAN Wait - ) +ExAcquireTimeRefreshLock(IN BOOLEAN Wait) { /* Block APCs */ KeEnterCriticalRegion(); @@ -82,9 +80,7 @@ ExAcquireTimeRefreshLock( *--*/ VOID NTAPI -ExReleaseTimeRefreshLock( - VOID - ) +ExReleaseTimeRefreshLock(VOID) { /* Release the lock and re-enable APCs */ ExReleaseResourceLite(&ExpTimeRefreshLock); @@ -478,4 +474,92 @@ ExSystemTimeToLocalTime(PLARGE_INTEGER SystemTime, LocalTime->QuadPart = SystemTime->QuadPart - ExpTimeZoneBias.QuadPart; } +/* + * @implemented + */ +NTSTATUS +NTAPI +NtQueryTimerResolution(OUT PULONG MinimumResolution, + OUT PULONG MaximumResolution, + OUT PULONG ActualResolution) +{ + KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); + + /* Check if the call came from user mode */ + if (PreviousMode != KernelMode) + { + _SEH2_TRY + { + /* Probe the parameters */ + ProbeForWriteUlong(MinimumResolution); + ProbeForWriteUlong(MaximumResolution); + ProbeForWriteUlong(ActualResolution); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Return the exception code */ + _SEH2_YIELD(return _SEH2_GetExceptionCode()); + } + _SEH2_END; + } + + /* + * Set the parameters to the actual values. + * + * NOTE: + * MinimumResolution corresponds to the biggest time increment and + * MaximumResolution corresponds to the smallest time increment. + */ + *MinimumResolution = KeMaximumIncrement; + *MaximumResolution = KeMinimumIncrement; + *ActualResolution = KeTimeIncrement; + + /* Return success */ + return STATUS_SUCCESS; +} + +/* + * @implemented + */ +NTSTATUS +NTAPI +NtSetTimerResolution(IN ULONG DesiredResolution, + IN BOOLEAN SetResolution, + OUT PULONG CurrentResolution) +{ + KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); + PEPROCESS Process = PsGetCurrentProcess(); + ULONG NewResolution; + + /* Check if the call came from user mode */ + if (PreviousMode != KernelMode) + { + _SEH2_TRY + { + /* Probe the parameter */ + ProbeForWriteUlong(CurrentResolution); + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + /* Return the exception code */ + _SEH2_YIELD(return _SEH2_GetExceptionCode()); + } + _SEH2_END; + } + + /* Set and return the new resolution */ + NewResolution = ExSetTimerResolution(DesiredResolution, SetResolution); + *CurrentResolution = NewResolution; + + if (SetResolution) + { + /* Set the flag that the resolution has been changed */ + Process->SetTimerResolution = TRUE; + } + + /* Return success if the process changed its timer resolution */ + if (Process->SetTimerResolution) return STATUS_SUCCESS; + else return STATUS_TIMER_RESOLUTION_NOT_SET; +} + /* EOF */ diff --git a/reactos/ntoskrnl/ke/clock.c b/reactos/ntoskrnl/ke/clock.c index 5d3fdf00911..aaed4d14677 100644 --- a/reactos/ntoskrnl/ke/clock.c +++ b/reactos/ntoskrnl/ke/clock.c @@ -236,56 +236,4 @@ KeSetTimeIncrement(IN ULONG MaxIncrement, KiTickOffset = MaxIncrement; } -NTSTATUS -NTAPI -NtQueryTimerResolution(OUT PULONG MinimumResolution, - OUT PULONG MaximumResolution, - OUT PULONG ActualResolution) -{ - KPROCESSOR_MODE PreviousMode = ExGetPreviousMode(); - - /* Check if the call came from user mode */ - if (PreviousMode != KernelMode) - { - _SEH2_TRY - { - /* Probe the parameters */ - ProbeForWriteUlong(MinimumResolution); - ProbeForWriteUlong(MaximumResolution); - ProbeForWriteUlong(ActualResolution); - - /* Try to set the parameters to the actual values */ - *MinimumResolution = KeMinimumIncrement; - *MaximumResolution = KeMaximumIncrement; - *ActualResolution = KeTimeIncrement; - } - _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - /* Return the exception code */ - _SEH2_YIELD(return _SEH2_GetExceptionCode()); - } - _SEH2_END; - } - else - { - /* The call came from kernel mode. Use the pointers directly */ - *MinimumResolution = KeMinimumIncrement; - *MaximumResolution = KeMaximumIncrement; - *ActualResolution = KeTimeIncrement; - } - - /* Return success */ - return STATUS_SUCCESS; -} - -NTSTATUS -NTAPI -NtSetTimerResolution(IN ULONG DesiredResolution, - IN BOOLEAN SetResolution, - OUT PULONG CurrentResolution) -{ - UNIMPLEMENTED; - return STATUS_NOT_IMPLEMENTED; -} - /* EOF */