Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1994 - 1999
  3. Module Name:
  4. uuidsup.cxx
  5. Abstract:
  6. Implements system dependent functions used in creating Uuids.
  7. This file is for Win32 (NT and Chicago) systems.
  8. External functions are:
  9. UuidGlobalMutexRequest
  10. UuidGlobalMutexClear
  11. GetNodeId
  12. UuidGetValues
  13. Note:
  14. WARNING:
  15. Everything in this file is only called from within UuidCreate()
  16. which is already holding the global mutex. Therefore none of
  17. this code is multithread safe. For example, access to the global
  18. Uuid HKEY's is not protected.
  19. Author:
  20. Mario Goertzel (MarioGo) May 23, 1994
  21. Revision History:
  22. --*/
  23. #include <precomp.hxx>
  24. #include <uuidsup.hxx>
  25. RPC_STATUS __RPC_API
  26. UuidGetValues(
  27. OUT UUID_CACHED_VALUES_STRUCT __RPC_FAR *Values
  28. )
  29. /*++
  30. Routine Description:
  31. This routine allocates a block of uuids for UuidCreate to handout.
  32. Arguments:
  33. Values - Set to contain everything needed to allocate a block of uuids.
  34. The following fields will be updated here:
  35. NextTimeLow - Together with LastTimeLow, this denotes the boundaries
  36. of a block of Uuids. The values between NextTimeLow
  37. and LastTimeLow are used in a sequence of Uuids returned
  38. by UuidCreate().
  39. LastTimeLow - See NextTimeLow.
  40. ClockSequence - Clock sequence field in the uuid. This is changed
  41. when the clock is set backward.
  42. Return Value:
  43. RPC_S_OK - We successfully allocated a block of uuids.
  44. RPC_S_OUT_OF_MEMORY - As needed.
  45. --*/
  46. {
  47. NTSTATUS NtStatus;
  48. ULARGE_INTEGER Time;
  49. ULONG Range;
  50. ULONG Sequence;
  51. int Tries = 0;
  52. do {
  53. NtStatus = NtAllocateUuids(&Time, &Range, &Sequence, (char *) &Values->NodeId[0]);
  54. if (NtStatus == STATUS_RETRY)
  55. {
  56. Sleep(1);
  57. }
  58. Tries++;
  59. if (Tries == 20)
  60. {
  61. #ifdef DEBUGRPC
  62. PrintToDebugger("Rpc: NtAllocateUuids retried 20 times!\n");
  63. ASSERT(Tries < 20);
  64. #endif
  65. NtStatus = STATUS_UNSUCCESSFUL;
  66. }
  67. } while(NtStatus == STATUS_RETRY);
  68. if (!NT_SUCCESS(NtStatus))
  69. {
  70. return(RPC_S_OUT_OF_MEMORY);
  71. }
  72. // NtAllocateUuids keeps time in SYSTEM_TIME format which is 100ns ticks since
  73. // Jan 1, 1601. UUIDs use time in 100ns ticks since Oct 15, 1582.
  74. // 17 Days in Oct + 30 (Nov) + 31 (Dec) + 18 years and 5 leap days.
  75. Time.QuadPart += (unsigned __int64) (1000*1000*10) // seconds
  76. * (unsigned __int64) (60 * 60 * 24) // days
  77. * (unsigned __int64) (17+30+31+365*18+5); // # of days
  78. ASSERT(Range);
  79. Values->ClockSeqHiAndReserved =
  80. RPC_UUID_RESERVED | (((unsigned char) (Sequence >> 8))
  81. & (unsigned char) RPC_UUID_CLOCK_SEQ_HI_MASK);
  82. Values->ClockSeqLow = (unsigned char) (Sequence & 0x00FF);
  83. // The order of these assignments is important
  84. Values->Time.QuadPart = Time.QuadPart + (Range - 1);
  85. Values->AllocatedCount = Range;
  86. if ((Values->NodeId[0] & 0x80) == 0)
  87. {
  88. return(RPC_S_OK);
  89. }
  90. return (RPC_S_UUID_LOCAL_ONLY);
  91. }