- Fix KiDispatchException to unmask KI_EXCEPTION_INTERNAL when setting the exception...
[reactos.git] / reactos / ntoskrnl / ke / config.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ke/config.c
5 * PURPOSE: Configuration Tree Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <internal/debug.h>
14
15 /* FUNCTIONS *****************************************************************/
16
17 /*
18 * @implemented
19 */
20 PCONFIGURATION_COMPONENT_DATA
21 NTAPI
22 INIT_FUNCTION
23 KeFindConfigurationEntry(IN PCONFIGURATION_COMPONENT_DATA Child,
24 IN CONFIGURATION_CLASS Class,
25 IN CONFIGURATION_TYPE Type,
26 IN PULONG ComponentKey OPTIONAL)
27 {
28 /* Start Search at Root */
29 return KeFindConfigurationNextEntry(Child,
30 Class,
31 Type,
32 ComponentKey,
33 NULL);
34 }
35
36 /*
37 * @implemented
38 */
39 PCONFIGURATION_COMPONENT_DATA
40 NTAPI
41 INIT_FUNCTION
42 KeFindConfigurationNextEntry(IN PCONFIGURATION_COMPONENT_DATA Child,
43 IN CONFIGURATION_CLASS Class,
44 IN CONFIGURATION_TYPE Type,
45 IN PULONG ComponentKey OPTIONAL,
46 IN PCONFIGURATION_COMPONENT_DATA *NextLink)
47 {
48 ULONG Key = 0;
49 ULONG Mask = 0;
50 PCONFIGURATION_COMPONENT_DATA Sibling;
51 PCONFIGURATION_COMPONENT_DATA ReturnEntry;
52
53 /* If we did get a key, then use it instead */
54 if (ComponentKey)
55 {
56 Key = *ComponentKey;
57 Mask = -1;
58 }
59
60 /* Loop the Components until we find a a match */
61 while (Child)
62 {
63 /* Check if we are starting somewhere already */
64 if (*NextLink)
65 {
66 /* If we've found the place where we started, clear and continue */
67 if (Child == *NextLink) *NextLink = NULL;
68 }
69 else
70 {
71 /* Try to get a match */
72 if ((Child->ComponentEntry.Class) == Class &&
73 (Child->ComponentEntry.Type) == Type &&
74 (Child->ComponentEntry.Key & Mask) == Key)
75 {
76 /* Match found */
77 return Child;
78 }
79 }
80
81 /* Now we've also got to lookup the siblings */
82 Sibling = Child->Sibling;
83 while (Sibling)
84 {
85 /* Check if we are starting somewhere already */
86 if (*NextLink)
87 {
88 /* If we've found the place where we started, clear and continue */
89 if (Sibling == *NextLink) *NextLink = NULL;
90 }
91 else
92 {
93 /* Try to get a match */
94 if ((Sibling->ComponentEntry.Class == Class) &&
95 (Sibling->ComponentEntry.Type == Type) &&
96 (Sibling->ComponentEntry.Key & Mask) == Key)
97 {
98 /* Match found */
99 return Sibling;
100 }
101 }
102
103 /* We've got to check if the Sibling has a Child as well */
104 if (Sibling->Child)
105 {
106 /* We're just going to call ourselves again */
107 ReturnEntry = KeFindConfigurationNextEntry(Sibling->Child,
108 Class,
109 Type,
110 ComponentKey,
111 NextLink);
112 if (ReturnEntry) return ReturnEntry;
113 }
114
115 /* Next Sibling */
116 Sibling = Sibling->Sibling;
117 }
118
119 /* Next Child */
120 Child = Child->Child;
121 }
122
123 /* If we got here, nothign was found */
124 return NULL;
125 }
126