ReactOS  0.4.14-dev-115-g4576127
uuid.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for uuid.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define SEED_BUFFER_SIZE   6
 
#define TICKS_PER_CLOCK_TICK   1000
 
#define SECSPERDAY   86400
 
#define TICKSPERSEC   10000000
 
#define SECS_15_OCT_1582_TO_1601   ((17 + 30 + 31 + 365 * 18 + 5) * SECSPERDAY)
 
#define TICKS_15_OCT_1582_TO_1601   ((ULONGLONG)SECS_15_OCT_1582_TO_1601 * TICKSPERSEC)
 
#define TIME_FRAME   10000
 
#define VALUE_BUFFER_SIZE   20
 

Functions

BOOLEAN INIT_FUNCTION NTAPI ExpUuidInitialization (VOID)
 
static NTSTATUS ExpUuidLoadSequenceNumber (PULONG Sequence)
 
static NTSTATUS ExpUuidSaveSequenceNumber (PULONG Sequence)
 
static VOID ExpUuidSaveSequenceNumberIf (VOID)
 
static NTSTATUS ExpAllocateUuids (PULARGE_INTEGER Time, PULONG Range, PULONG Sequence)
 
static NTSTATUS ExpUuidGetValues (PUUID_CACHED_VALUES_STRUCT CachedValues)
 
BOOLEAN INIT_FUNCTION NTAPI ExLuidInitialization (VOID)
 
VOID NTAPI ExAllocateLocallyUniqueId (OUT LUID *LocallyUniqueId)
 
NTSTATUS NTAPI NtAllocateLocallyUniqueId (OUT LUID *LocallyUniqueId)
 
NTSTATUS NTAPI ExUuidCreate (OUT UUID *Uuid)
 
NTSTATUS NTAPI NtAllocateUuids (OUT PULARGE_INTEGER Time, OUT PULONG Range, OUT PULONG Sequence, OUT PUCHAR Seed)
 
NTSTATUS NTAPI NtSetUuidSeed (IN PUCHAR Seed)
 

Variables

FAST_MUTEX ExpUuidLock
 
LARGE_INTEGER ExpUuidLastTimeAllocated
 
ULONG ExpUuidSequenceNumber = 0
 
BOOLEAN ExpUuidSequenceNumberValid
 
BOOLEAN ExpUuidSequenceNumberNotSaved = FALSE
 
UUID_CACHED_VALUES_STRUCT ExpUuidCachedValues = {0ULL, 0xFFFFFFFF, 0, 0, { 0x80, 0x6E, 0x6F, 0x6E, 0x69, 0x63}}
 
BOOLEAN ExpUuidCacheValid = FALSE
 
ULONG ExpLuidIncrement = 1
 
LARGE_INTEGER ExpLuid = {{0x3e9, 0x0}}
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file uuid.c.

◆ SECS_15_OCT_1582_TO_1601

#define SECS_15_OCT_1582_TO_1601   ((17 + 30 + 31 + 365 * 18 + 5) * SECSPERDAY)

Definition at line 26 of file uuid.c.

◆ SECSPERDAY

#define SECSPERDAY   86400

Definition at line 22 of file uuid.c.

◆ SEED_BUFFER_SIZE

#define SEED_BUFFER_SIZE   6

Definition at line 17 of file uuid.c.

◆ TICKS_15_OCT_1582_TO_1601

#define TICKS_15_OCT_1582_TO_1601   ((ULONGLONG)SECS_15_OCT_1582_TO_1601 * TICKSPERSEC)

Definition at line 27 of file uuid.c.

◆ TICKS_PER_CLOCK_TICK

#define TICKS_PER_CLOCK_TICK   1000

Definition at line 21 of file uuid.c.

◆ TICKSPERSEC

#define TICKSPERSEC   10000000

Definition at line 23 of file uuid.c.

◆ TIME_FRAME

#define TIME_FRAME   10000

Definition at line 30 of file uuid.c.

◆ VALUE_BUFFER_SIZE

#define VALUE_BUFFER_SIZE   20

Definition at line 72 of file uuid.c.

Function Documentation

◆ ExAllocateLocallyUniqueId()

VOID NTAPI ExAllocateLocallyUniqueId ( OUT LUID LocallyUniqueId)

Definition at line 340 of file uuid.c.

341 {
342  /* Atomically increment the luid */
343  *(LONG64*)LocallyUniqueId = InterlockedExchangeAdd64(&ExpLuid.QuadPart,
345 }
LARGE_INTEGER ExpLuid
Definition: uuid.c:48
int64_t LONG64
Definition: typedefs.h:66
#define InterlockedExchangeAdd64
Definition: interlocked.h:186
LONGLONG QuadPart
Definition: typedefs.h:112
ULONG ExpLuidIncrement
Definition: uuid.c:47

Referenced by NtAdjustPrivilegesToken(), NtAllocateLocallyUniqueId(), NtSetInformationToken(), SeCreateAccessStateEx(), SepCreateToken(), and SepDuplicateToken().

◆ ExLuidInitialization()

BOOLEAN INIT_FUNCTION NTAPI ExLuidInitialization ( VOID  )

Definition at line 330 of file uuid.c.

331 {
332  return TRUE;
333 }
#define TRUE
Definition: types.h:120

Referenced by SepInitializationPhase0().

◆ ExpAllocateUuids()

static NTSTATUS ExpAllocateUuids ( PULARGE_INTEGER  Time,
PULONG  Range,
PULONG  Sequence 
)
static

Definition at line 202 of file uuid.c.

205 {
207  LARGE_INTEGER Counter, Frequency, CurrentTime, TimeDiff, ClockDiff;
208 
209  PAGED_CODE();
210 
211  /* Initialize sequence number */
213  {
214  /* Try to load sequence number */
216  if (NT_SUCCESS(Status))
217  {
219  }
220  else
221  {
222  /* If we cannot, generate a "true" random */
225  }
226 
227  /* It's valid and to be saved */
230  }
231 
232  KeQuerySystemTime(&CurrentTime);
233  TimeDiff.QuadPart = CurrentTime.QuadPart - ExpUuidLastTimeAllocated.QuadPart;
234  /* If time went backwards, change sequence (see RFC example) */
235  if (TimeDiff.QuadPart < 0)
236  {
238  TimeDiff.QuadPart = 2 * TIME_FRAME;
239 
240  /* It's to be saved */
243  }
244 
245  if (TimeDiff.QuadPart == 0)
246  {
247  return STATUS_RETRY;
248  }
249 
250  /* If time diff > 0.1ms, squash it to reduce it to keep our clock resolution */
251  if (TimeDiff.HighPart > 0 || TimeDiff.QuadPart > TICKS_PER_CLOCK_TICK * TIME_FRAME)
252  {
254  }
255 
256  if (TimeDiff.HighPart < 0 || TimeDiff.QuadPart <= TIME_FRAME)
257  {
258  *Range = TimeDiff.QuadPart;
259  ClockDiff.QuadPart = 0LL;
260  }
261  else
262  {
263  *Range = TIME_FRAME;
264  ClockDiff.QuadPart = TimeDiff.QuadPart - TIME_FRAME;
265  --ClockDiff.HighPart;
266  }
267 
268  Time->QuadPart = CurrentTime.QuadPart - *Range - ClockDiff.QuadPart;
269  ExpUuidLastTimeAllocated.QuadPart = CurrentTime.QuadPart - ClockDiff.QuadPart;
270  *Sequence = ExpUuidSequenceNumber;
271 
272  return STATUS_SUCCESS;
273 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
#define TRUE
Definition: types.h:120
#define LL
Definition: tui.h:85
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
LARGE_INTEGER ExpUuidLastTimeAllocated
Definition: uuid.c:41
#define TIME_FRAME
Definition: uuid.c:30
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG ExpUuidSequenceNumber
Definition: uuid.c:42
ULONG LowPart
Definition: typedefs.h:104
Definition: range.c:43
Status
Definition: gdiplustypes.h:24
#define TICKS_PER_CLOCK_TICK
Definition: uuid.c:21
BOOLEAN ExpUuidSequenceNumberNotSaved
Definition: uuid.c:44
static LARGE_INTEGER Frequency
Definition: clock.c:41
static LARGE_INTEGER Counter
Definition: clock.c:43
#define STATUS_RETRY
Definition: udferr_usr.h:182
static NTSTATUS ExpUuidLoadSequenceNumber(PULONG Sequence)
Definition: uuid.c:74
#define ULONG_PTR
Definition: config.h:101
BOOLEAN ExpUuidSequenceNumberValid
Definition: uuid.c:43
return STATUS_SUCCESS
Definition: btrfs.c:2966
static PLARGE_INTEGER Time
Definition: time.c:105
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by ExpUuidGetValues(), and NtAllocateUuids().

◆ ExpUuidGetValues()

static NTSTATUS ExpUuidGetValues ( PUUID_CACHED_VALUES_STRUCT  CachedValues)
static

Definition at line 281 of file uuid.c.

282 {
285  ULONG Range;
286  ULONG Sequence;
287 
288  PAGED_CODE();
289 
290  /* Allocate UUIDs */
291  Status = ExpAllocateUuids(&Time, &Range, &Sequence);
292  if (Status == STATUS_RETRY)
293  {
294  return Status;
295  }
296 
297  if (!NT_SUCCESS(Status))
298  {
299  return STATUS_NO_MEMORY;
300  }
301 
302  /* We need at least one UUID */
303  ASSERT(Range != 0);
304 
305  /* Set up our internal cache
306  * See format_uuid_v1 in RFC4122 for magic values
307  */
308  CachedValues->ClockSeqLow = Sequence;
309  CachedValues->ClockSeqHiAndReserved = (Sequence & 0x3F00) >> 8;
310  CachedValues->ClockSeqHiAndReserved |= 0x80;
311  CachedValues->AllocatedCount = Range;
312 
313  /*
314  * Time is relative to UUID time
315  * And we set last time range for all the possibly
316  * returnable UUID
317  */
319  CachedValues->Time = Time.QuadPart + (Range - 1);
320 
321  return STATUS_SUCCESS;
322 }
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
struct tagRange Range
#define TICKS_15_OCT_1582_TO_1601
Definition: uuid.c:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: range.c:43
Status
Definition: gdiplustypes.h:24
static NTSTATUS ExpAllocateUuids(PULARGE_INTEGER Time, PULONG Range, PULONG Sequence)
Definition: uuid.c:202
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define STATUS_RETRY
Definition: udferr_usr.h:182
unsigned int ULONG
Definition: retypes.h:1
UCHAR ClockSeqHiAndReserved
Definition: ex.h:174
return STATUS_SUCCESS
Definition: btrfs.c:2966
static PLARGE_INTEGER Time
Definition: time.c:105
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by ExUuidCreate().

◆ ExpUuidInitialization()

BOOLEAN INIT_FUNCTION NTAPI ExpUuidInitialization ( VOID  )

Definition at line 58 of file uuid.c.

59 {
61 
64 
65  return TRUE;
66 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define TRUE
Definition: types.h:120
FAST_MUTEX ExpUuidLock
Definition: uuid.c:40
LARGE_INTEGER ExpUuidLastTimeAllocated
Definition: uuid.c:41
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
BOOLEAN ExpUuidSequenceNumberValid
Definition: uuid.c:43

Referenced by ExpInitSystemPhase1().

◆ ExpUuidLoadSequenceNumber()

static NTSTATUS ExpUuidLoadSequenceNumber ( PULONG  Sequence)
static

Definition at line 74 of file uuid.c.

75 {
76  UCHAR ValueBuffer[VALUE_BUFFER_SIZE];
83 
84  PAGED_CODE();
85 
86  RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\Microsoft\\Rpc");
87  RtlInitUnicodeString(&ValueName, L"UuidSequenceNumber");
88 
90  &KeyName,
92  NULL,
93  NULL);
95  if (!NT_SUCCESS(Status))
96  {
97  DPRINT("ZwOpenKey() failed (Status %lx)\n", Status);
98  return Status;
99  }
100 
101  ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer;
102  Status = ZwQueryValueKey(KeyHandle,
103  &ValueName,
105  ValueBuffer,
107  &ValueLength);
109  if (!NT_SUCCESS(Status))
110  {
111  DPRINT("ZwQueryValueKey() failed (Status %lx)\n", Status);
112  return Status;
113  }
114 
115  if (ValueInfo->Type != REG_DWORD || ValueInfo->DataLength != sizeof(DWORD))
116  {
117  return STATUS_UNSUCCESSFUL;
118  }
119 
120  *Sequence = *((PULONG)ValueInfo->Data);
121 
122  DPRINT("Loaded sequence %lx\n", *Sequence);
123 
124  return STATUS_SUCCESS;
125 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define VALUE_BUFFER_SIZE
Definition: uuid.c:72
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
unsigned long DWORD
Definition: ntddk_ex.h:95
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
_In_ GUID _In_ PVOID _In_ ULONG ValueLength
Definition: hubbusif.h:311
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define REG_DWORD
Definition: sdbapi.c:596
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by ExpAllocateUuids().

◆ ExpUuidSaveSequenceNumber()

static NTSTATUS ExpUuidSaveSequenceNumber ( PULONG  Sequence)
static

Definition at line 132 of file uuid.c.

133 {
138 
139  PAGED_CODE();
140 
141  RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Software\\Microsoft\\Rpc");
142  RtlInitUnicodeString(&ValueName, L"UuidSequenceNumber");
143 
145  &KeyName,
147  NULL,
148  NULL);
149  Status = ZwOpenKey(&KeyHandle,
152  if (!NT_SUCCESS(Status))
153  {
154  DPRINT("ZwOpenKey() failed (Status %lx)\n", Status);
155  return Status;
156  }
157 
158  Status = ZwSetValueKey(KeyHandle,
159  &ValueName,
160  0,
161  REG_DWORD,
162  Sequence,
163  sizeof(ULONG));
165  if (!NT_SUCCESS(Status))
166  {
167  DPRINT("ZwSetValueKey() failed (Status %lx)\n", Status);
168  }
169 
170  return Status;
171 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_DWORD
Definition: sdbapi.c:596
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by ExpUuidSaveSequenceNumberIf().

◆ ExpUuidSaveSequenceNumberIf()

static VOID ExpUuidSaveSequenceNumberIf ( VOID  )
static

Definition at line 179 of file uuid.c.

180 {
182 
183  PAGED_CODE();
184 
185  /* Only save sequence if it has to */
187  {
189  if (NT_SUCCESS(Status))
190  {
192  }
193  }
194 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
static NTSTATUS ExpUuidSaveSequenceNumber(PULONG Sequence)
Definition: uuid.c:132
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG ExpUuidSequenceNumber
Definition: uuid.c:42
Status
Definition: gdiplustypes.h:24
BOOLEAN ExpUuidSequenceNumberNotSaved
Definition: uuid.c:44

Referenced by ExUuidCreate(), and NtAllocateUuids().

◆ ExUuidCreate()

NTSTATUS NTAPI ExUuidCreate ( OUT UUID Uuid)

Definition at line 385 of file uuid.c.

386 {
388  LONG AllocatedCount;
390  BOOLEAN Valid;
391 
392  PAGED_CODE();
393 
395  /* Loop until we have an UUID to return */
396  while (TRUE)
397  {
398  /* Try to gather node values */
399  do
400  {
402 
403  RtlCopyMemory(&Uuid->Data4[0],
406  Valid = ExpUuidCacheValid;
408  }
409  /* Loop till we can do it without being disturbed */
411 
412  /* We have more than an allocated UUID left, that's OK to return! */
413  if (AllocatedCount >= 0)
414  {
415  break;
416  }
417 
418  /*
419  * Here, we're out of UUIDs, we need to allocate more
420  * We need to be alone to do it, so lock the mutex
421  */
424  {
425  /* If allocation fails, bail out! */
427  if (Status != STATUS_SUCCESS)
428  {
430  return Status;
431  }
432 
433  /* Save our current sequence if changed */
435  }
437  }
438 
439  /*
440  * Once here, we've got an UUID to return
441  * But, if our init wasn't sane, then, make
442  * sure it's only used locally
443  */
444  if (!Valid)
445  {
447  }
448 
449  /* Set our timestamp - see RFC4211 */
450  Time.QuadPart -= AllocatedCount;
451  Uuid->Data1 = Time.LowPart;
452  Uuid->Data2 = Time.HighPart;
453  /* We also set the bit for GUIDv1 */
454  Uuid->Data3 = ((Time.HighPart >> 16) & 0x0FFF) | 0x1000;
455 
456  return Status;
457 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN ExpUuidCacheValid
Definition: uuid.c:46
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
FAST_MUTEX ExpUuidLock
Definition: uuid.c:40
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
static VOID ExpUuidSaveSequenceNumberIf(VOID)
Definition: uuid.c:179
static NTSTATUS ExpUuidGetValues(PUUID_CACHED_VALUES_STRUCT CachedValues)
Definition: uuid.c:281
#define InterlockedDecrement
Definition: armddk.h:52
ULONG LowPart
Definition: typedefs.h:104
Status
Definition: gdiplustypes.h:24
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
UUID_CACHED_VALUES_STRUCT ExpUuidCachedValues
Definition: uuid.c:45
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define SEED_BUFFER_SIZE
Definition: uuid.c:17
static PLARGE_INTEGER Time
Definition: time.c:105
#define RPC_NT_UUID_LOCAL_ONLY
Definition: ntstatus.h:162
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by ChanMgrCreateChannel(), CreateNewVolumeName(), CreateNoDriveLetterEntry(), Ext2InitializeVcb(), IntCreateNewRegistryPath(), and START_TEST().

◆ NtAllocateLocallyUniqueId()

NTSTATUS NTAPI NtAllocateLocallyUniqueId ( OUT LUID LocallyUniqueId)

Definition at line 353 of file uuid.c.

354 {
356  PAGED_CODE();
357 
358  /* Probe if user mode */
360  if (PreviousMode != KernelMode)
361  {
362  _SEH2_TRY
363  {
364  ProbeForWrite(LocallyUniqueId,
365  sizeof(LUID),
366  sizeof(ULONG));
367  }
369  {
371  }
372  _SEH2_END;
373  }
374 
375  /* Do the allocation */
376  ExAllocateLocallyUniqueId(LocallyUniqueId);
377  return STATUS_SUCCESS;
378 }
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_SEH2_END
Definition: create.c:4424
VOID NTAPI ExAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
Definition: uuid.c:340
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AllocateLocallyUniqueId(), and LsaApLogonUserEx2().

◆ NtAllocateUuids()

NTSTATUS NTAPI NtAllocateUuids ( OUT PULARGE_INTEGER  Time,
OUT PULONG  Range,
OUT PULONG  Sequence,
OUT PUCHAR  Seed 
)

Definition at line 464 of file uuid.c.

468 {
469  ULARGE_INTEGER IntTime;
470  ULONG IntRange, IntSequence;
473 
474  PAGED_CODE();
475 
476  /* Probe if user mode */
478  if (PreviousMode != KernelMode)
479  {
480  _SEH2_TRY
481  {
483  sizeof(ULARGE_INTEGER),
484  sizeof(ULONG));
485 
487  sizeof(ULONG),
488  sizeof(ULONG));
489 
490  ProbeForWrite(Sequence,
491  sizeof(ULONG),
492  sizeof(ULONG));
493 
494  ProbeForWrite(Seed,
496  sizeof(UCHAR));
497  }
499  {
501  }
502  _SEH2_END;
503  }
504 
505  /* During allocation we must be alone */
507 
508  Status = ExpAllocateUuids(&IntTime,
509  &IntRange,
510  &IntSequence);
511  if (!NT_SUCCESS(Status))
512  {
514  return Status;
515  }
516 
517  /* If sequence number was changed, save it */
519 
520  /* Allocation done, so we can release */
522 
523  /* Write back UUIDs to caller */
524  _SEH2_TRY
525  {
526  Time->QuadPart = IntTime.QuadPart;
527  *Range = IntRange;
528  *Sequence = IntSequence;
529 
530  RtlCopyMemory(Seed,
533 
535  }
537  {
539  }
540  _SEH2_END;
541 
542  return Status;
543 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
#define PAGED_CODE()
Definition: video.h:57
FAST_MUTEX ExpUuidLock
Definition: uuid.c:40
_SEH2_TRY
Definition: create.c:4250
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static VOID ExpUuidSaveSequenceNumberIf(VOID)
Definition: uuid.c:179
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
unsigned char UCHAR
Definition: xmlstorage.h:181
Definition: range.c:43
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
LONG NTAPI ExSystemExceptionFilter(VOID)
Definition: harderr.c:351
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
static NTSTATUS ExpAllocateUuids(PULARGE_INTEGER Time, PULONG Range, PULONG Sequence)
Definition: uuid.c:202
UUID_CACHED_VALUES_STRUCT ExpUuidCachedValues
Definition: uuid.c:45
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define SEED_BUFFER_SIZE
Definition: uuid.c:17
static PLARGE_INTEGER Time
Definition: time.c:105
LONGLONG QuadPart
Definition: typedefs.h:112

◆ NtSetUuidSeed()

NTSTATUS NTAPI NtSetUuidSeed ( IN PUCHAR  Seed)

Definition at line 551 of file uuid.c.

552 {
554  BOOLEAN GotContext;
557  LUID CallerLuid, SystemLuid = SYSTEM_LUID;
558 
559  PAGED_CODE();
560 
561  /* Should only be done by umode */
563 
564  /* No context to release */
565  GotContext = FALSE;
566  _SEH2_TRY
567  {
568  /* Get our caller context and remember to release it */
570  GotContext = TRUE;
571 
572  /* Get caller access token and its associated ID */
574  Status = SeQueryAuthenticationIdToken(Token, &CallerLuid);
575  if (!NT_SUCCESS(Status))
576  {
578  }
579 
580  /* This call is only allowed for SYSTEM */
581  if (!RtlEqualLuid(&CallerLuid, &SystemLuid))
582  {
584  }
585 
586  /* Check for buffer validity and then copy it to our seed */
587  ProbeForRead(Seed, SEED_BUFFER_SIZE, sizeof(UCHAR));
589 
590  /*
591  * According to RFC 4122, UUID seed is based on MAC addresses
592  * If it is randomly set, then, it must have its multicast be set
593  * to be valid and avoid collisions
594  * Reflect it here
595  */
596  ExpUuidCacheValid = ~(*Seed >> 7) & 1;
597 
599  }
601  {
603  }
604  _SEH2_END;
605 
606  /* Release context if required */
607  if (GotContext)
608  {
610  }
611 
612  return Status;
613 }
VOID NTAPI SeCaptureSubjectContext(OUT PSECURITY_SUBJECT_CONTEXT SubjectContext)
Definition: access.c:301
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
_Inout_ PLIST_ENTRY _In_ PVOID _In_ PSTRING _In_ BOOLEAN _In_ BOOLEAN _In_ ULONG _In_ PFLT_CALLBACK_DATA _In_opt_ PCHECK_FOR_TRAVERSE_ACCESS _In_opt_ PSECURITY_SUBJECT_CONTEXT SubjectContext
Definition: fltkernel.h:2239
VOID NTAPI SeReleaseSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext)
Definition: access.c:360
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define KeGetPreviousMode()
Definition: ketypes.h:1107
LONG NTSTATUS
Definition: precomp.h:26
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
BOOLEAN ExpUuidCacheValid
Definition: uuid.c:46
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
NTSTATUS NTAPI SeQueryAuthenticationIdToken(IN PACCESS_TOKEN Token, OUT PLUID LogonId)
Definition: token.c:1752
#define RtlEqualLuid(Luid1, Luid2)
Definition: rtlfuncs.h:301
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define SeQuerySubjectContextToken(SubjectContext)
Definition: sefuncs.h:583
#define SYSTEM_LUID
Definition: setypes.h:672
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
UUID_CACHED_VALUES_STRUCT ExpUuidCachedValues
Definition: uuid.c:45
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define SEED_BUFFER_SIZE
Definition: uuid.c:17

Referenced by DealWithDeviceEvent().

Variable Documentation

◆ ExpLuid

LARGE_INTEGER ExpLuid = {{0x3e9, 0x0}}

Definition at line 48 of file uuid.c.

Referenced by ExAllocateLocallyUniqueId().

◆ ExpLuidIncrement

ULONG ExpLuidIncrement = 1

Definition at line 47 of file uuid.c.

Referenced by ExAllocateLocallyUniqueId().

◆ ExpUuidCachedValues

UUID_CACHED_VALUES_STRUCT ExpUuidCachedValues = {0ULL, 0xFFFFFFFF, 0, 0, { 0x80, 0x6E, 0x6F, 0x6E, 0x69, 0x63}}

Definition at line 45 of file uuid.c.

Referenced by ExUuidCreate(), NtAllocateUuids(), and NtSetUuidSeed().

◆ ExpUuidCacheValid

BOOLEAN ExpUuidCacheValid = FALSE

Definition at line 46 of file uuid.c.

Referenced by ExUuidCreate(), and NtSetUuidSeed().

◆ ExpUuidLastTimeAllocated

LARGE_INTEGER ExpUuidLastTimeAllocated

Definition at line 41 of file uuid.c.

Referenced by ExpAllocateUuids(), and ExpUuidInitialization().

◆ ExpUuidLock

FAST_MUTEX ExpUuidLock

Definition at line 40 of file uuid.c.

Referenced by ExpUuidInitialization(), ExUuidCreate(), and NtAllocateUuids().

◆ ExpUuidSequenceNumber

ULONG ExpUuidSequenceNumber = 0

Definition at line 42 of file uuid.c.

Referenced by ExpAllocateUuids(), and ExpUuidSaveSequenceNumberIf().

◆ ExpUuidSequenceNumberNotSaved

BOOLEAN ExpUuidSequenceNumberNotSaved = FALSE

Definition at line 44 of file uuid.c.

Referenced by ExpAllocateUuids(), and ExpUuidSaveSequenceNumberIf().

◆ ExpUuidSequenceNumberValid

BOOLEAN ExpUuidSequenceNumberValid

Definition at line 43 of file uuid.c.

Referenced by ExpAllocateUuids(), and ExpUuidInitialization().