Add missing processor architecture cases
[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 #if defined (ALLOC_PRAGMA)
17 #pragma alloc_text(INIT, SepInitLuid)
18 #endif
19
20
21 /* GLOBALS *******************************************************************/
22
23 static LARGE_INTEGER LuidIncrement;
24 static LARGE_INTEGER LuidValue;
25
26 /* FUNCTIONS *****************************************************************/
27
28 VOID
29 INIT_FUNCTION
30 NTAPI
31 SepInitLuid(VOID)
32 {
33 LUID DummyLuidValue = SYSTEM_LUID;
34
35 LuidValue.u.HighPart = DummyLuidValue.HighPart;
36 LuidValue.u.LowPart = DummyLuidValue.LowPart;
37 LuidIncrement.QuadPart = 1;
38 }
39
40
41 NTSTATUS
42 NTAPI
43 ExpAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
44 {
45 LARGE_INTEGER NewLuid, PrevLuid;
46
47 /* atomically increment the luid */
48 do
49 {
50 PrevLuid = LuidValue;
51 NewLuid = RtlLargeIntegerAdd(PrevLuid,
52 LuidIncrement);
53 } while(ExfInterlockedCompareExchange64(&LuidValue.QuadPart,
54 &NewLuid.QuadPart,
55 &PrevLuid.QuadPart) != PrevLuid.QuadPart);
56
57 LocallyUniqueId->LowPart = NewLuid.u.LowPart;
58 LocallyUniqueId->HighPart = NewLuid.u.HighPart;
59
60 return STATUS_SUCCESS;
61 }
62
63
64 /*
65 * @implemented
66 */
67 NTSTATUS STDCALL
68 NtAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
69 {
70 LUID NewLuid;
71 KPROCESSOR_MODE PreviousMode;
72 NTSTATUS Status = STATUS_SUCCESS;
73
74 PAGED_CODE();
75
76 PreviousMode = ExGetPreviousMode();
77
78 if(PreviousMode != KernelMode)
79 {
80 _SEH_TRY
81 {
82 ProbeForWrite(LocallyUniqueId,
83 sizeof(LUID),
84 sizeof(ULONG));
85 }
86 _SEH_HANDLE
87 {
88 Status = _SEH_GetExceptionCode();
89 }
90 _SEH_END;
91
92 if(!NT_SUCCESS(Status))
93 {
94 return Status;
95 }
96 }
97
98 Status = ExpAllocateLocallyUniqueId(&NewLuid);
99
100 _SEH_TRY
101 {
102 *LocallyUniqueId = NewLuid;
103 }
104 _SEH_HANDLE
105 {
106 Status = _SEH_GetExceptionCode();
107 }
108 _SEH_END;
109
110 return Status;
111 }
112
113 /* EOF */