merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / ntoskrnl / se / luid.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/se/luid.c
6 * PURPOSE: Security manager
7 *
8 * PROGRAMMERS: No programmer listed.
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #include <internal/debug.h>
15
16 /* GLOBALS *******************************************************************/
17
18 static LARGE_INTEGER LuidIncrement;
19 static LARGE_INTEGER LuidValue;
20
21 /* FUNCTIONS *****************************************************************/
22
23 VOID INIT_FUNCTION
24 SepInitLuid(VOID)
25 {
26 LUID DummyLuidValue = SYSTEM_LUID;
27
28 LuidValue.u.HighPart = DummyLuidValue.HighPart;
29 LuidValue.u.LowPart = DummyLuidValue.LowPart;
30 LuidIncrement.QuadPart = 1;
31 }
32
33
34 NTSTATUS
35 ExpAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
36 {
37 LARGE_INTEGER NewLuid, PrevLuid;
38
39 /* atomically increment the luid */
40 do
41 {
42 PrevLuid = (volatile LARGE_INTEGER)LuidValue;
43 NewLuid = RtlLargeIntegerAdd(PrevLuid,
44 LuidIncrement);
45 } while(ExfInterlockedCompareExchange64(&LuidValue.QuadPart,
46 &NewLuid.QuadPart,
47 &PrevLuid.QuadPart) != PrevLuid.QuadPart);
48
49 LocallyUniqueId->LowPart = NewLuid.u.LowPart;
50 LocallyUniqueId->HighPart = NewLuid.u.HighPart;
51
52 return STATUS_SUCCESS;
53 }
54
55
56 /*
57 * @implemented
58 */
59 NTSTATUS STDCALL
60 NtAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
61 {
62 LUID NewLuid;
63 KPROCESSOR_MODE PreviousMode;
64 NTSTATUS Status = STATUS_SUCCESS;
65
66 PAGED_CODE();
67
68 PreviousMode = ExGetPreviousMode();
69
70 if(PreviousMode != KernelMode)
71 {
72 _SEH_TRY
73 {
74 ProbeForWrite(LocallyUniqueId,
75 sizeof(LUID),
76 sizeof(ULONG));
77 }
78 _SEH_HANDLE
79 {
80 Status = _SEH_GetExceptionCode();
81 }
82 _SEH_END;
83
84 if(!NT_SUCCESS(Status))
85 {
86 return Status;
87 }
88 }
89
90 Status = ExpAllocateLocallyUniqueId(&NewLuid);
91
92 _SEH_TRY
93 {
94 *LocallyUniqueId = NewLuid;
95 }
96 _SEH_HANDLE
97 {
98 Status = _SEH_GetExceptionCode();
99 }
100 _SEH_END;
101
102 return Status;
103 }
104
105 /* EOF */