1. /*++
  2. Copyright (c) 1989-2001 Microsoft Corporation
  3. Module Name:
  4. systime.c
  5. Abstract:
  6. This module implements the NT system time services.
  7. --*/
  8. #include "exp.h"
  9. //
  10. // Guards against multiple threads attempting to set the system time.
  11. //
  12. INITIALIZED_CRITICAL_SECTION(ExpTimeRefreshLock);
  13. NTSTATUS
  14. NtSetSystemTime (
  15. IN PLARGE_INTEGER SystemTime,
  16. OUT PLARGE_INTEGER PreviousTime OPTIONAL
  17. )
  18. /*++
  19. Routine Description:
  20. This function sets the current system time and optionally returns the
  21. previous system time.
  22. Arguments:
  23. SystemTime - Supplies a pointer to the new value for the system time.
  24. PreviousTime - Supplies an optional pointer to a variable that receives
  25. the previous system time.
  26. Return Value:
  27. STATUS_SUCCESS is returned if the service is successfully executed.
  28. STATUS_ACCESS_VIOLATION is returned if the input parameter for the
  29. system time cannot be read or the output parameter for the system
  30. time cannot be written.
  31. STATUS_INVALID_PARAMETER is returned if the input system time is negative.
  32. --*/
  33. {
  34. LARGE_INTEGER CurrentTime;
  35. LARGE_INTEGER NewTime;
  36. TIME_FIELDS TimeFields;
  37. PAGED_CODE();
  38. RtlEnterCriticalSectionAndRegion(&ExpTimeRefreshLock);
  39. //
  40. // Get the new system time and check to ensure that the value is
  41. // positive and resonable. If the new system time is negative, then
  42. // return an invalid parameter status.
  43. //
  44. NewTime = *SystemTime;
  45. if ((NewTime.HighPart < 0) || (NewTime.HighPart > 0x20000000)) {
  46. RtlLeaveCriticalSectionAndRegion(&ExpTimeRefreshLock);
  47. return STATUS_INVALID_PARAMETER;
  48. }
  49. //
  50. // Set the system time, and capture the previous system time in a
  51. // local variable, then store the local variable in the previous time
  52. // variable if it is specified. This is required so that faults can
  53. // be prevented from happening in the set time routine.
  54. //
  55. KeSetSystemTime(&NewTime, &CurrentTime);
  56. RtlTimeToTimeFields(&NewTime, &TimeFields);
  57. HalSetRealTimeClock(&TimeFields);
  58. if (ARGUMENT_PRESENT(PreviousTime)) {
  59. *PreviousTime = CurrentTime;
  60. }
  61. //
  62. // Mark the CMOS data as valid.
  63. //
  64. HalMarkCmosValid();
  65. RtlLeaveCriticalSectionAndRegion(&ExpTimeRefreshLock);
  66. return STATUS_SUCCESS;
  67. }

systime.h