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.

137 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. luid.c
  5. Abstract:
  6. This module implements the NT locally unique identifier services.
  7. Author:
  8. Jim Kelly (JimK) 7-June-1990
  9. Revision History:
  10. --*/
  11. #include "exp.h"
  12. //
  13. // Global variables needed to support locally unique IDs.
  14. //
  15. //
  16. // The first 1000 values are reserved for static definition. This
  17. // value can be increased with later releases with no adverse impact.
  18. //
  19. // N.B. The LUID source always refers to the "next" allocatable LUID.
  20. //
  21. LARGE_INTEGER ExpLuid = {1001,0};
  22. const LARGE_INTEGER ExpLuidIncrement = {1,0};
  23. #ifdef ALLOC_PRAGMA
  24. #pragma alloc_text(INIT, ExLuidInitialization)
  25. #pragma alloc_text(PAGE, NtAllocateLocallyUniqueId)
  26. #endif
  27. BOOLEAN
  28. ExLuidInitialization (
  29. VOID
  30. )
  31. /*++
  32. Routine Description:
  33. This function initializes the locally unique identifier allocation.
  34. NOTE: THE LUID ALLOCATION SERVICES ARE NEEDED BY SECURITY IN PHASE 0
  35. SYSTEM INITIALIZATION. FOR THIS REASON, LUID INITIALIZATION IS
  36. PERFORMED AS PART OF PHASE 0 SECURITY INITIALIZATION.
  37. Arguments:
  38. None.
  39. Return Value:
  40. A value of TRUE is returned if the initialization is successfully
  41. completed. Otherwise, a value of FALSE is returned.
  42. --*/
  43. {
  44. return TRUE;
  45. }
  46. NTSTATUS
  47. NtAllocateLocallyUniqueId (
  48. OUT PLUID Luid
  49. )
  50. /*++
  51. Routine Description:
  52. This function returns an LUID value that is unique since the system
  53. was last rebooted. It is unique on the system it is generated on
  54. only (not network wide).
  55. There are no restrictions on who can allocate LUIDs. The LUID space
  56. is large enough that this will never present a problem. If one LUID
  57. is allocated every 100ns, they will not be exhausted for roughly
  58. 15,000 years (100ns * 2^63).
  59. Arguments:
  60. Luid - Supplies the address of a variable that will receive the
  61. new LUID.
  62. Return Value:
  63. STATUS_SUCCESS is returned if the service is successfully executed.
  64. STATUS_ACCESS_VIOLATION is returned if the output parameter for the
  65. LUID cannot be written.
  66. --*/
  67. {
  68. KPROCESSOR_MODE PreviousMode;
  69. //
  70. // Establish an exception handler and attempt to write the Luid
  71. // to the specified variable. If the write attempt fails, then return
  72. // the exception code as the service status. Otherwise return success
  73. // as the service status.
  74. //
  75. try {
  76. //
  77. // Get previous processor mode and probe argument if necessary.
  78. //
  79. PreviousMode = KeGetPreviousMode();
  80. if (PreviousMode != KernelMode) {
  81. ProbeForWriteSmallStructure((PVOID)Luid, sizeof(LUID), sizeof(ULONG));
  82. }
  83. //
  84. // Allocate and store a locally unique Id.
  85. //
  86. ExAllocateLocallyUniqueId(Luid);
  87. } except (ExSystemExceptionFilter()) {
  88. return GetExceptionCode();
  89. }
  90. return STATUS_SUCCESS;
  91. }