xref: /reactos/ntoskrnl/include/internal/cm.h (revision 09dde2cf)
1 /*
2  * PROJECT:         ReactOS Kernel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            ntoskrnl/include/internal/cm.h
5  * PURPOSE:         Internal header for the Configuration Manager
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 #pragma once
10 
11 #include <cmlib.h>
12 #include <cmreslist.h>
13 #include "cmboot.h"
14 
15 //
16 // Define this if you want debugging support
17 //
18 #define _CM_DEBUG_                                      0x00
19 
20 //
21 // These define the Debug Masks Supported
22 //
23 #define CM_HANDLE_DEBUG                                 0x01
24 #define CM_NAMESPACE_DEBUG                              0x02
25 #define CM_SECURITY_DEBUG                               0x04
26 #define CM_REFERENCE_DEBUG                              0x08
27 #define CM_CALLBACK_DEBUG                               0x10
28 
29 //
30 // Debug/Tracing support
31 //
32 #if _CM_DEBUG_
33 #ifdef NEW_DEBUG_SYSTEM_IMPLEMENTED // enable when Debug Filters are implemented
34 #define CMTRACE DbgPrintEx
35 #else
36 #define CMTRACE(x, ...)                                 \
37     if (x & CmpTraceLevel) DbgPrint(__VA_ARGS__)
38 #endif
39 #else
40 #define CMTRACE(x, fmt, ...) DPRINT(fmt, ##__VA_ARGS__)
41 #endif
42 
43 //
44 // CM_KEY_CONTROL_BLOCK Signatures
45 //
46 #define CM_KCB_SIGNATURE                                'bKmC'
47 #define CM_KCB_INVALID_SIGNATURE                        '4FmC'
48 
49 //
50 // CM_KEY_CONTROL_BLOCK ExtFlags
51 //
52 #define CM_KCB_NO_SUBKEY                                0x01
53 #define CM_KCB_SUBKEY_ONE                               0x02
54 #define CM_KCB_SUBKEY_HINT                              0x04
55 #define CM_KCB_SYM_LINK_FOUND                           0x08
56 #define CM_KCB_KEY_NON_EXIST                            0x10
57 #define CM_KCB_NO_DELAY_CLOSE                           0x20
58 #define CM_KCB_INVALID_CACHED_INFO                      0x40
59 #define CM_KCB_READ_ONLY_KEY                            0x80
60 
61 //
62 // CM_KEY_BODY Types
63 //
64 #define CM_KEY_BODY_TYPE                                0x6B793032  // 'ky02'
65 
66 //
67 // Number of various lists and hashes
68 //
69 #if 0 // See sdk/lib/cmlib/cmlib.h
70 #define CMP_SECURITY_HASH_LISTS                         64
71 #endif
72 #define CMP_MAX_CALLBACKS                               100
73 
74 //
75 // Hashing Constants
76 //
77 #define CMP_HASH_IRRATIONAL                             314159269
78 #define CMP_HASH_PRIME                                  1000000007
79 
80 //
81 // CmpCreateKeyControlBlock Flags
82 //
83 #define CMP_CREATE_FAKE_KCB                             0x1
84 #define CMP_LOCK_HASHES_FOR_KCB                         0x2
85 
86 //
87 // CmpDoCreate and CmpDoOpen flags
88 //
89 #define CMP_CREATE_KCB_KCB_LOCKED                       0x2
90 #define CMP_OPEN_KCB_NO_CREATE                          0x4
91 
92 //
93 // EnlistKeyBodyWithKCB Flags
94 //
95 #define CMP_ENLIST_KCB_LOCKED_SHARED                    0x1
96 #define CMP_ENLIST_KCB_LOCKED_EXCLUSIVE                 0x2
97 
98 //
99 // Unload Flags
100 //
101 #define CMP_UNLOCK_KCB_LOCKED                    0x1
102 #define CMP_UNLOCK_REGISTRY_LOCKED               0x2
103 
104 //
105 // Maximum size of Value Cache
106 //
107 #define MAXIMUM_CACHED_DATA                             (2 * PAGE_SIZE)
108 
109 //
110 // Hives to load on startup
111 //
112 #define CM_NUMBER_OF_MACHINE_HIVES                      6
113 
114 //
115 // Number of items that can fit inside an Allocation Page
116 //
117 #define CM_KCBS_PER_PAGE                                \
118     ((PAGE_SIZE - FIELD_OFFSET(CM_ALLOC_PAGE, AllocPage)) / sizeof(CM_KEY_CONTROL_BLOCK))
119 #define CM_DELAYS_PER_PAGE                              \
120     ((PAGE_SIZE - FIELD_OFFSET(CM_ALLOC_PAGE, AllocPage)) / sizeof(CM_DELAY_ALLOC))
121 
122 //
123 // Value Search Results
124 //
125 typedef enum _VALUE_SEARCH_RETURN_TYPE
126 {
127     SearchSuccess,
128     SearchNeedExclusiveLock,
129     SearchFail
130 } VALUE_SEARCH_RETURN_TYPE;
131 
132 //
133 // Key Hash
134 //
135 typedef struct _CM_KEY_HASH
136 {
137     ULONG ConvKey;
138     struct _CM_KEY_HASH *NextHash;
139     PHHIVE KeyHive;
140     HCELL_INDEX KeyCell;
141 } CM_KEY_HASH, *PCM_KEY_HASH;
142 
143 //
144 // Key Hash Table Entry
145 //
146 typedef struct _CM_KEY_HASH_TABLE_ENTRY
147 {
148     EX_PUSH_LOCK Lock;
149     PKTHREAD Owner;
150     PCM_KEY_HASH Entry;
151 } CM_KEY_HASH_TABLE_ENTRY, *PCM_KEY_HASH_TABLE_ENTRY;
152 
153 //
154 // Name Hash
155 //
156 typedef struct _CM_NAME_HASH
157 {
158     ULONG ConvKey;
159     struct _CM_NAME_HASH *NextHash;
160     USHORT NameLength;
161     WCHAR Name[ANYSIZE_ARRAY];
162 } CM_NAME_HASH, *PCM_NAME_HASH;
163 
164 //
165 // Name Hash Table Entry
166 //
167 typedef struct _CM_NAME_HASH_TABLE_ENTRY
168 {
169     EX_PUSH_LOCK Lock;
170     PCM_NAME_HASH Entry;
171 } CM_NAME_HASH_TABLE_ENTRY, *PCM_NAME_HASH_TABLE_ENTRY;
172 
173 //
174 // Key Security Cache
175 //
176 typedef struct _CM_KEY_SECURITY_CACHE
177 {
178     HCELL_INDEX Cell;
179     ULONG ConvKey;
180     LIST_ENTRY List;
181     ULONG DescriptorLength;
182     SECURITY_DESCRIPTOR_RELATIVE Descriptor;
183 } CM_KEY_SECURITY_CACHE, *PCM_KEY_SECURITY_CACHE;
184 
185 //
186 // Key Security Cache Entry
187 //
188 typedef struct _CM_KEY_SECURITY_CACHE_ENTRY
189 {
190     HCELL_INDEX Cell;
191     PCM_KEY_SECURITY_CACHE CachedSecurity;
192 } CM_KEY_SECURITY_CACHE_ENTRY, *PCM_KEY_SECURITY_CACHE_ENTRY;
193 
194 //
195 // Cached Child List
196 //
197 typedef struct _CACHED_CHILD_LIST
198 {
199     ULONG Count;
200     union
201     {
202         ULONG ValueList;
203         struct _CM_KEY_CONTROL_BLOCK *RealKcb;
204     };
205 } CACHED_CHILD_LIST, *PCACHED_CHILD_LIST;
206 
207 //
208 // Index Hint Block
209 //
210 typedef struct _CM_INDEX_HINT_BLOCK
211 {
212     ULONG Count;
213     ULONG HashKey[ANYSIZE_ARRAY];
214 } CM_INDEX_HINT_BLOCK, *PCM_INDEX_HINT_BLOCK;
215 
216 //
217 // Key Body
218 //
219 typedef struct _CM_KEY_BODY
220 {
221     ULONG Type;
222     struct _CM_KEY_CONTROL_BLOCK *KeyControlBlock;
223     struct _CM_NOTIFY_BLOCK *NotifyBlock;
224     HANDLE ProcessID;
225     LIST_ENTRY KeyBodyList;
226 } CM_KEY_BODY, *PCM_KEY_BODY;
227 
228 //
229 // Name Control Block (NCB)
230 //
231 typedef struct _CM_NAME_CONTROL_BLOCK
232 {
233     BOOLEAN Compressed;
234     USHORT RefCount;
235     union
236     {
237         CM_NAME_HASH NameHash;
238         struct
239         {
240             ULONG ConvKey;
241             PCM_KEY_HASH NextHash;
242             USHORT NameLength;
243             WCHAR Name[ANYSIZE_ARRAY];
244         };
245     };
246 } CM_NAME_CONTROL_BLOCK, *PCM_NAME_CONTROL_BLOCK;
247 
248 //
249 // Key Control Block (KCB)
250 //
251 typedef struct _CM_KEY_CONTROL_BLOCK
252 {
253     ULONG Signature;
254     ULONG RefCount;
255     struct
256     {
257         ULONG ExtFlags:8;
258         ULONG PrivateAlloc:1;
259         ULONG Delete:1;
260         ULONG DelayedCloseIndex:12;
261         ULONG TotalLevels:10;
262     };
263     union
264     {
265         CM_KEY_HASH KeyHash;
266         struct
267         {
268             ULONG ConvKey;
269             PCM_KEY_HASH NextHash;
270             PHHIVE KeyHive;
271             HCELL_INDEX KeyCell;
272         };
273     };
274     struct _CM_KEY_CONTROL_BLOCK *ParentKcb;
275     PCM_NAME_CONTROL_BLOCK NameBlock;
276     PCM_KEY_SECURITY_CACHE CachedSecurity;
277     CACHED_CHILD_LIST ValueCache;
278     union
279     {
280         PCM_INDEX_HINT_BLOCK IndexHint;
281         ULONG HashKey;
282         ULONG SubKeyCount;
283     };
284     union
285     {
286         LIST_ENTRY KeyBodyListHead;
287         LIST_ENTRY FreeListEntry;
288     };
289     PCM_KEY_BODY KeyBodyArray[4];
290     PVOID DelayCloseEntry;
291     LARGE_INTEGER KcbLastWriteTime;
292     USHORT KcbMaxNameLen;
293     USHORT KcbMaxValueNameLen;
294     ULONG KcbMaxValueDataLen;
295     struct
296     {
297          ULONG KcbUserFlags : 4;
298          ULONG KcbVirtControlFlags : 4;
299          ULONG KcbDebug : 8;
300          ULONG Flags : 16;
301     };
302     ULONG InDelayClose;
303 } CM_KEY_CONTROL_BLOCK, *PCM_KEY_CONTROL_BLOCK;
304 
305 //
306 // Notify Block
307 //
308 typedef struct _CM_NOTIFY_BLOCK
309 {
310     LIST_ENTRY HiveList;
311     LIST_ENTRY PostList;
312     PCM_KEY_CONTROL_BLOCK KeyControlBlock;
313     PCM_KEY_BODY KeyBody;
314     ULONG Filter:29;
315     ULONG WatchTree:30;
316     ULONG NotifyPending:31;
317 } CM_NOTIFY_BLOCK, *PCM_NOTIFY_BLOCK;
318 
319 //
320 // Re-map Block
321 //
322 typedef struct _CM_CELL_REMAP_BLOCK
323 {
324     HCELL_INDEX OldCell;
325     HCELL_INDEX NewCell;
326 } CM_CELL_REMAP_BLOCK, *PCM_CELL_REMAP_BLOCK;
327 
328 //
329 // Allocation Page
330 //
331 typedef struct _CM_ALLOC_PAGE
332 {
333     ULONG FreeCount;
334     ULONG Reserved;
335     PVOID AllocPage;
336 } CM_ALLOC_PAGE, *PCM_ALLOC_PAGE;
337 
338 //
339 // Allocation Page Entry
340 //
341 typedef struct _CM_DELAY_ALLOC
342 {
343     LIST_ENTRY ListEntry;
344     PCM_KEY_CONTROL_BLOCK Kcb;
345 } CM_DELAY_ALLOC, *PCM_DELAY_ALLOC;
346 
347 //
348 // Delayed Close Entry
349 //
350 typedef struct _CM_DELAYED_CLOSE_ENTRY
351 {
352     LIST_ENTRY DelayedLRUList;
353     PCM_KEY_CONTROL_BLOCK KeyControlBlock;
354 } CM_DELAYED_CLOSE_ENTRY, *PCM_DELAYED_CLOSE_ENTRY;
355 
356 //
357 // Delayed KCB Dereference Entry
358 //
359 typedef struct _CM_DELAY_DEREF_KCB_ITEM
360 {
361     LIST_ENTRY ListEntry;
362     PCM_KEY_CONTROL_BLOCK Kcb;
363 } CM_DELAY_DEREF_KCB_ITEM, *PCM_DELAY_DEREF_KCB_ITEM;
364 
365 //
366 // Cached Value Index
367 //
368 typedef struct _CM_CACHED_VALUE_INDEX
369 {
370     HCELL_INDEX CellIndex;
371     union
372     {
373         CELL_DATA CellData;
374         ULONG_PTR List[ANYSIZE_ARRAY];
375     } Data;
376 } CM_CACHED_VALUE_INDEX, *PCM_CACHED_VALUE_INDEX;
377 
378 //
379 // Cached Value
380 //
381 typedef struct _CM_CACHED_VALUE
382 {
383     USHORT DataCacheType;
384     USHORT ValueKeySize;
385     ULONG HashKey;
386     CM_KEY_VALUE KeyValue;
387 } CM_CACHED_VALUE, *PCM_CACHED_VALUE;
388 
389 //
390 // Hive List Entry
391 //
392 typedef struct _HIVE_LIST_ENTRY
393 {
394     PWSTR Name;
395     PWSTR BaseName;
396     PCMHIVE CmHive;
397     ULONG HHiveFlags;
398     ULONG CmHiveFlags;
399     PCMHIVE CmHive2;
400     BOOLEAN ThreadFinished;
401     BOOLEAN ThreadStarted;
402     BOOLEAN Allocate;
403 } HIVE_LIST_ENTRY, *PHIVE_LIST_ENTRY;
404 
405 //
406 // Parse context for Key Object
407 //
408 typedef struct _CM_PARSE_CONTEXT
409 {
410     ULONG TitleIndex;
411     UNICODE_STRING Class;
412     ULONG CreateOptions;
413     ULONG Disposition;
414     CM_KEY_REFERENCE ChildHive;
415     HANDLE PredefinedHandle;
416     BOOLEAN CreateLink;
417     BOOLEAN CreateOperation;
418     PCMHIVE OriginatingPoint;
419 } CM_PARSE_CONTEXT, *PCM_PARSE_CONTEXT;
420 
421 //
422 // MultiFunction Adapter Recognizer Structure
423 //
424 typedef struct _CMP_MF_TYPE
425 {
426     PCHAR Identifier;
427     USHORT InterfaceType;
428     USHORT Count;
429 } CMP_MF_TYPE, *PCMP_MF_TYPE;
430 
431 //
432 // System Control Vector
433 //
434 typedef struct _CM_SYSTEM_CONTROL_VECTOR
435 {
436     PWCHAR KeyPath;
437     PWCHAR ValueName;
438     PVOID Buffer;
439     PULONG BufferLength;
440     PULONG Type;
441 } CM_SYSTEM_CONTROL_VECTOR, *PCM_SYSTEM_CONTROL_VECTOR;
442 
443 //
444 // Structure for CmpQueryValueDataFromCache
445 //
446 typedef struct _KEY_VALUE_INFORMATION
447 {
448     union
449     {
450         KEY_VALUE_BASIC_INFORMATION KeyValueBasicInformation;
451         KEY_VALUE_FULL_INFORMATION KeyValueFullInformation;
452         KEY_VALUE_PARTIAL_INFORMATION KeyValuePartialInformation;
453         KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 KeyValuePartialInformationAlign64;
454     };
455 } KEY_VALUE_INFORMATION, *PKEY_VALUE_INFORMATION;
456 
457 typedef struct _KEY_INFORMATION
458 {
459     union
460     {
461         KEY_BASIC_INFORMATION KeyBasicInformation;
462         KEY_FULL_INFORMATION KeyFullInformation;
463         KEY_NODE_INFORMATION KeyNodeInformation;
464     };
465 } KEY_INFORMATION, *PKEY_INFORMATION;
466 
467 ///////////////////////////////////////////////////////////////////////////////
468 //
469 // BUGBUG Old Hive Stuff for Temporary Support
470 //
471 NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2);
472 ///////////////////////////////////////////////////////////////////////////////
473 
474 //
475 // Mapped View Hive Functions
476 //
477 VOID
478 NTAPI
479 CmpInitHiveViewList(
480     IN PCMHIVE Hive
481 );
482 
483 VOID
484 NTAPI
485 CmpDestroyHiveViewList(
486     IN PCMHIVE Hive
487 );
488 
489 //
490 // Security Cache Functions
491 //
492 VOID
493 NTAPI
494 CmpInitSecurityCache(
495     IN PCMHIVE Hive
496 );
497 
498 VOID
499 NTAPI
500 CmpDestroySecurityCache(
501     IN PCMHIVE Hive
502 );
503 
504 //
505 // Value Cache Functions
506 //
507 VALUE_SEARCH_RETURN_TYPE
508 NTAPI
509 CmpFindValueByNameFromCache(
510     IN PCM_KEY_CONTROL_BLOCK Kcb,
511     IN PCUNICODE_STRING Name,
512     OUT PCM_CACHED_VALUE **CachedValue,
513     OUT ULONG *Index,
514     OUT PCM_KEY_VALUE *Value,
515     OUT BOOLEAN *ValueIsCached,
516     OUT PHCELL_INDEX CellToRelease
517 );
518 
519 VALUE_SEARCH_RETURN_TYPE
520 NTAPI
521 CmpQueryKeyValueData(
522     IN PCM_KEY_CONTROL_BLOCK Kcb,
523     IN PCM_CACHED_VALUE *CachedValue,
524     IN PCM_KEY_VALUE ValueKey,
525     IN BOOLEAN ValueIsCached,
526     IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
527     IN PVOID KeyValueInformation,
528     IN ULONG Length,
529     OUT PULONG ResultLength,
530     OUT PNTSTATUS Status
531 );
532 
533 VALUE_SEARCH_RETURN_TYPE
534 NTAPI
535 CmpGetValueListFromCache(
536     IN PCM_KEY_CONTROL_BLOCK Kcb,
537     OUT PCELL_DATA *CellData,
538     OUT BOOLEAN *IndexIsCached,
539     OUT PHCELL_INDEX ValueListToRelease
540 );
541 
542 VALUE_SEARCH_RETURN_TYPE
543 NTAPI
544 CmpGetValueKeyFromCache(
545     IN PCM_KEY_CONTROL_BLOCK Kcb,
546     IN PCELL_DATA CellData,
547     IN ULONG Index,
548     OUT PCM_CACHED_VALUE **CachedValue,
549     OUT PCM_KEY_VALUE *Value,
550     IN BOOLEAN IndexIsCached,
551     OUT BOOLEAN *ValueIsCached,
552     OUT PHCELL_INDEX CellToRelease
553 );
554 
555 VALUE_SEARCH_RETURN_TYPE
556 NTAPI
557 CmpCompareNewValueDataAgainstKCBCache(
558     IN PCM_KEY_CONTROL_BLOCK Kcb,
559     IN PUNICODE_STRING ValueName,
560     IN ULONG Type,
561     IN PVOID Data,
562     IN ULONG DataSize
563 );
564 
565 //
566 // Registry Validation Functions
567 //
568 ULONG
569 NTAPI
570 CmCheckRegistry(
571     IN PCMHIVE Hive,
572     IN ULONG Flags
573 );
574 
575 //
576 // Hive List Routines
577 //
578 BOOLEAN
579 NTAPI
580 CmpGetHiveName(
581     IN  PCMHIVE Hive,
582     OUT PUNICODE_STRING HiveName
583 );
584 
585 NTSTATUS
586 NTAPI
587 CmpAddToHiveFileList(
588     IN PCMHIVE Hive
589 );
590 
591 VOID
592 NTAPI
593 CmpRemoveFromHiveFileList(
594     IN PCMHIVE Hive
595 );
596 
597 //
598 // Quota Routines
599 //
600 VOID
601 NTAPI
602 CmpSetGlobalQuotaAllowed(
603     VOID
604 );
605 
606 //
607 // Notification Routines
608 //
609 VOID
610 NTAPI
611 CmpReportNotify(
612     IN PCM_KEY_CONTROL_BLOCK Kcb,
613     IN PHHIVE Hive,
614     IN HCELL_INDEX Cell,
615     IN ULONG Filter
616 );
617 
618 VOID
619 NTAPI
620 CmpFlushNotify(
621     IN PCM_KEY_BODY KeyBody,
622     IN BOOLEAN LockHeld
623 );
624 
625 CODE_SEG("INIT")
626 VOID
627 NTAPI
628 CmpInitCallback(
629     VOID
630 );
631 
632 //
633 // KCB Cache/Delay Routines
634 //
635 CODE_SEG("INIT")
636 VOID
637 NTAPI
638 CmpInitializeCache(
639     VOID
640 );
641 
642 CODE_SEG("INIT")
643 VOID
644 NTAPI
645 CmpInitCmPrivateDelayAlloc(
646     VOID
647 );
648 
649 CODE_SEG("INIT")
650 VOID
651 NTAPI
652 CmpInitCmPrivateAlloc(
653     VOID
654 );
655 
656 CODE_SEG("INIT")
657 VOID
658 NTAPI
659 CmpInitDelayDerefKCBEngine(
660     VOID
661 );
662 
663 //
664 // Key Object Routines
665 //
666 VOID
667 NTAPI
668 CmpCloseKeyObject(
669     IN PEPROCESS Process OPTIONAL,
670     IN PVOID Object,
671     IN ACCESS_MASK GrantedAccess,
672     IN ULONG ProcessHandleCount,
673     IN ULONG SystemHandleCount
674 );
675 
676 VOID
677 NTAPI
678 CmpDeleteKeyObject(
679     IN PVOID Object
680 );
681 
682 NTSTATUS
683 NTAPI
684 CmpParseKey(
685     IN PVOID ParseObject,
686     IN PVOID ObjectType,
687     IN OUT PACCESS_STATE AccessState,
688     IN KPROCESSOR_MODE AccessMode,
689     IN ULONG Attributes,
690     IN OUT PUNICODE_STRING CompleteName,
691     IN OUT PUNICODE_STRING RemainingName,
692     IN OUT PVOID Context OPTIONAL,
693     IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
694     OUT PVOID *Object
695 );
696 
697 NTSTATUS
698 NTAPI
699 CmpSecurityMethod(
700     IN PVOID Object,
701     IN SECURITY_OPERATION_CODE OperationType,
702     IN PSECURITY_INFORMATION SecurityInformation,
703     IN PSECURITY_DESCRIPTOR SecurityDescriptor,
704     IN OUT PULONG CapturedLength,
705     IN OUT PSECURITY_DESCRIPTOR *ObjectSecurityDescriptor,
706     IN POOL_TYPE PoolType,
707     IN PGENERIC_MAPPING GenericMapping
708 );
709 
710 NTSTATUS
711 NTAPI
712 CmpQueryKeyName(
713     IN PVOID Object,
714     IN BOOLEAN HasObjectName,
715     OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
716     IN ULONG Length,
717     OUT PULONG ReturnLength,
718     IN KPROCESSOR_MODE AccessMode
719 );
720 
721 //
722 // Hive Routines
723 //
724 NTSTATUS
725 NTAPI
726 CmpInitializeHive(
727     OUT PCMHIVE *CmHive,
728     IN ULONG OperationType,
729     IN ULONG HiveFlags,
730     IN ULONG FileType,
731     IN PVOID HiveData OPTIONAL,
732     IN HANDLE Primary,
733     IN HANDLE Log,
734     IN HANDLE External,
735     IN PCUNICODE_STRING FileName OPTIONAL,
736     IN ULONG CheckFlags
737 );
738 
739 NTSTATUS
740 NTAPI
741 CmpDestroyHive(
742     IN PCMHIVE CmHive
743 );
744 
745 PSECURITY_DESCRIPTOR
746 NTAPI
747 CmpHiveRootSecurityDescriptor(
748     VOID
749 );
750 
751 NTSTATUS
752 NTAPI
753 CmpLinkHiveToMaster(
754     IN PUNICODE_STRING LinkName,
755     IN HANDLE RootDirectory,
756     IN PCMHIVE CmHive,
757     IN BOOLEAN Allocate,
758     IN PSECURITY_DESCRIPTOR SecurityDescriptor
759 );
760 
761 NTSTATUS
762 NTAPI
763 CmpOpenHiveFiles(
764     IN PCUNICODE_STRING BaseName,
765     IN PCWSTR Extension OPTIONAL,
766     OUT PHANDLE Primary,
767     OUT PHANDLE Log,
768     OUT PULONG PrimaryDisposition,
769     OUT PULONG LogDisposition,
770     IN BOOLEAN CreateAllowed,
771     IN BOOLEAN MarkAsSystemHive,
772     IN BOOLEAN NoBuffering,
773     OUT PULONG ClusterSize OPTIONAL
774 );
775 
776 VOID
777 NTAPI
778 CmpCloseHiveFiles(
779     IN PCMHIVE Hive
780 );
781 
782 NTSTATUS
783 NTAPI
784 CmpInitHiveFromFile(
785     IN PCUNICODE_STRING HiveName,
786     IN ULONG HiveFlags,
787     OUT PCMHIVE *Hive,
788     IN OUT PBOOLEAN New,
789     IN ULONG CheckFlags
790 );
791 
792 VOID
793 NTAPI
794 CmpInitializeHiveList(
795     VOID
796 );
797 
798 //
799 // Registry Utility Functions
800 //
801 BOOLEAN
802 NTAPI
803 CmpTestRegistryLockExclusive(
804     VOID
805 );
806 
807 BOOLEAN
808 NTAPI
809 CmpTestRegistryLock(
810     VOID
811 );
812 
813 VOID
814 NTAPI
815 CmpLockRegistryExclusive(
816     VOID
817 );
818 
819 VOID
820 NTAPI
821 CmpLockRegistry(
822     VOID
823 );
824 
825 VOID
826 NTAPI
827 CmpUnlockRegistry(
828     VOID
829 );
830 
831 VOID
832 NTAPI
833 CmpLockHiveFlusherExclusive(
834     IN PCMHIVE Hive
835 );
836 
837 VOID
838 NTAPI
839 CmpLockHiveFlusherShared(
840     IN PCMHIVE Hive
841 );
842 
843 BOOLEAN
844 NTAPI
845 CmpTestHiveFlusherLockExclusive(
846     IN PCMHIVE Hive
847 );
848 
849 BOOLEAN
850 NTAPI
851 CmpTestHiveFlusherLockShared(
852     IN PCMHIVE Hive
853 );
854 
855 VOID
856 NTAPI
857 CmpUnlockHiveFlusher(
858     IN PCMHIVE Hive
859 );
860 
861 //
862 // Delay Functions
863 //
864 PVOID
865 NTAPI
866 CmpAllocateDelayItem(
867     VOID
868 );
869 
870 VOID
871 NTAPI
872 CmpFreeDelayItem(
873     PVOID Entry
874 );
875 
876 VOID
877 NTAPI
878 CmpDelayDerefKeyControlBlock(
879     IN PCM_KEY_CONTROL_BLOCK Kcb
880 );
881 
882 VOID
883 NTAPI
884 CmpAddToDelayedClose(
885     IN PCM_KEY_CONTROL_BLOCK Kcb,
886     IN BOOLEAN LockHeldExclusively
887 );
888 
889 VOID
890 NTAPI
891 CmpArmDelayedCloseTimer(
892     VOID
893 );
894 
895 VOID
896 NTAPI
897 CmpRemoveFromDelayedClose(IN PCM_KEY_CONTROL_BLOCK Kcb);
898 
899 CODE_SEG("INIT")
900 VOID
901 NTAPI
902 CmpInitializeDelayedCloseTable(
903     VOID
904 );
905 
906 //
907 // KCB Functions
908 //
909 PCM_KEY_CONTROL_BLOCK
910 NTAPI
911 CmpCreateKeyControlBlock(
912     IN PHHIVE Hive,
913     IN HCELL_INDEX Index,
914     IN PCM_KEY_NODE Node,
915     IN PCM_KEY_CONTROL_BLOCK Parent,
916     IN ULONG Flags,
917     IN PUNICODE_STRING KeyName
918 );
919 
920 PCM_KEY_CONTROL_BLOCK
921 NTAPI
922 CmpAllocateKeyControlBlock(
923     VOID
924 );
925 
926 VOID
927 NTAPI
928 CmpFreeKeyControlBlock(
929     IN PCM_KEY_CONTROL_BLOCK Kcb
930 );
931 
932 VOID
933 NTAPI
934 CmpRemoveKeyControlBlock(
935     IN PCM_KEY_CONTROL_BLOCK Kcb
936 );
937 
938 VOID
939 NTAPI
940 CmpCleanUpKcbValueCache(
941     IN PCM_KEY_CONTROL_BLOCK Kcb
942 );
943 
944 VOID
945 NTAPI
946 CmpCleanUpKcbCacheWithLock(
947     IN PCM_KEY_CONTROL_BLOCK Kcb,
948     IN BOOLEAN LockHeldExclusively
949 );
950 
951 VOID
952 NTAPI
953 CmpCleanUpSubKeyInfo(
954     IN PCM_KEY_CONTROL_BLOCK Kcb
955 );
956 
957 PUNICODE_STRING
958 NTAPI
959 CmpConstructName(
960     IN PCM_KEY_CONTROL_BLOCK Kcb
961 );
962 
963 BOOLEAN
964 NTAPI
965 CmpReferenceKeyControlBlock(
966     IN PCM_KEY_CONTROL_BLOCK Kcb
967 );
968 
969 VOID
970 NTAPI
971 CmpDereferenceKeyControlBlockWithLock(
972     IN PCM_KEY_CONTROL_BLOCK Kcb,
973     IN BOOLEAN LockHeldExclusively
974 );
975 
976 VOID
977 NTAPI
978 CmpDereferenceKeyControlBlock(
979     IN PCM_KEY_CONTROL_BLOCK Kcb
980 );
981 
982 VOID
983 NTAPI
984 EnlistKeyBodyWithKCB(
985     IN PCM_KEY_BODY KeyObject,
986     IN ULONG Flags
987 );
988 
989 VOID
990 NTAPI
991 DelistKeyBodyFromKCB(
992     IN PCM_KEY_BODY KeyBody,
993     IN BOOLEAN LockHeld
994 );
995 
996 VOID
997 NTAPI
998 CmpAcquireTwoKcbLocksExclusiveByKey(
999     IN ULONG ConvKey1,
1000     IN ULONG ConvKey2
1001 );
1002 
1003 VOID
1004 NTAPI
1005 CmpReleaseTwoKcbLockByKey(
1006     IN ULONG ConvKey1,
1007     IN ULONG ConvKey2
1008 );
1009 
1010 VOID
1011 NTAPI
1012 CmpFlushNotifiesOnKeyBodyList(
1013     IN PCM_KEY_CONTROL_BLOCK Kcb,
1014     IN BOOLEAN LockHeld
1015 );
1016 
1017 //
1018 // Parse Routines
1019 //
1020 BOOLEAN
1021 NTAPI
1022 CmpGetNextName(
1023     IN OUT PUNICODE_STRING RemainingName,
1024     OUT PUNICODE_STRING NextName,
1025     OUT PBOOLEAN LastName
1026 );
1027 
1028 //
1029 // Command Routines (Flush, Open, Close, Init);
1030 //
1031 BOOLEAN
1032 NTAPI
1033 CmpDoFlushAll(
1034     IN BOOLEAN ForceFlush
1035 );
1036 
1037 VOID
1038 NTAPI
1039 CmpShutdownWorkers(
1040     VOID
1041 );
1042 
1043 VOID
1044 NTAPI
1045 CmpCmdInit(
1046     IN BOOLEAN SetupBoot
1047 );
1048 
1049 NTSTATUS
1050 NTAPI
1051 CmpCmdHiveOpen(
1052     IN POBJECT_ATTRIBUTES FileAttributes,
1053     IN PSECURITY_CLIENT_CONTEXT ImpersonationContext,
1054     IN OUT PBOOLEAN Allocate,
1055     OUT PCMHIVE *NewHive,
1056     IN ULONG CheckFlags
1057 );
1058 
1059 VOID
1060 NTAPI
1061 CmpLazyFlush(
1062     VOID
1063 );
1064 
1065 //
1066 // Open/Create Routines
1067 //
1068 NTSTATUS
1069 NTAPI
1070 CmpDoCreate(
1071     IN PHHIVE Hive,
1072     IN HCELL_INDEX Cell,
1073     IN PACCESS_STATE AccessState,
1074     IN PUNICODE_STRING Name,
1075     IN KPROCESSOR_MODE AccessMode,
1076     IN PCM_PARSE_CONTEXT Context,
1077     IN PCM_KEY_CONTROL_BLOCK ParentKcb,
1078     OUT PVOID *Object
1079 );
1080 
1081 NTSTATUS
1082 NTAPI
1083 CmpCreateLinkNode(
1084     IN PHHIVE Hive,
1085     IN HCELL_INDEX Cell,
1086     IN PACCESS_STATE AccessState,
1087     IN UNICODE_STRING Name,
1088     IN KPROCESSOR_MODE AccessMode,
1089     IN ULONG CreateOptions,
1090     IN PCM_PARSE_CONTEXT Context,
1091     IN PCM_KEY_CONTROL_BLOCK ParentKcb,
1092     OUT PVOID *Object
1093 );
1094 
1095 //
1096 // Boot Routines
1097 //
1098 CODE_SEG("INIT")
1099 VOID
1100 NTAPI
1101 CmGetSystemControlValues(
1102     IN PVOID SystemHiveData,
1103     IN PCM_SYSTEM_CONTROL_VECTOR ControlVector
1104 );
1105 
1106 NTSTATUS
1107 NTAPI
1108 CmpSaveBootControlSet(
1109     IN USHORT ControlSet
1110 );
1111 
1112 //
1113 // Hardware Configuration Routines
1114 //
1115 CODE_SEG("INIT")
1116 NTSTATUS
1117 NTAPI
1118 CmpInitializeRegistryNode(
1119     IN PCONFIGURATION_COMPONENT_DATA CurrentEntry,
1120     IN HANDLE NodeHandle,
1121     OUT PHANDLE NewHandle,
1122     IN INTERFACE_TYPE InterfaceType,
1123     IN ULONG BusNumber,
1124     IN PUSHORT DeviceIndexTable
1125 );
1126 
1127 NTSTATUS
1128 NTAPI
1129 CmpInitializeMachineDependentConfiguration(
1130     IN PLOADER_PARAMETER_BLOCK LoaderBlock
1131 );
1132 
1133 CODE_SEG("INIT")
1134 NTSTATUS
1135 NTAPI
1136 CmpInitializeHardwareConfiguration(
1137     IN PLOADER_PARAMETER_BLOCK LoaderBlock
1138 );
1139 
1140 //
1141 // Wrapper Routines
1142 //
1143 NTSTATUS
1144 NTAPI
1145 CmpCreateEvent(
1146     IN EVENT_TYPE EventType,
1147     OUT PHANDLE EventHandle,
1148     OUT PKEVENT *Event
1149 );
1150 
1151 PVOID
1152 NTAPI
1153 CmpAllocate(
1154     IN SIZE_T Size,
1155     IN BOOLEAN Paged,
1156     IN ULONG Tag
1157 );
1158 
1159 VOID
1160 NTAPI
1161 CmpFree(
1162     IN PVOID Ptr,
1163     IN ULONG Quota
1164 );
1165 
1166 BOOLEAN
1167 NTAPI
1168 CmpFileRead(
1169     IN PHHIVE RegistryHive,
1170     IN ULONG FileType,
1171     IN OUT PULONG FileOffset,
1172     OUT PVOID Buffer,
1173     IN SIZE_T BufferLength
1174 );
1175 
1176 BOOLEAN
1177 NTAPI
1178 CmpFileWrite(
1179     IN PHHIVE RegistryHive,
1180     IN ULONG FileType,
1181     IN OUT PULONG FileOffset,
1182     IN PVOID Buffer,
1183     IN SIZE_T BufferLength
1184 );
1185 
1186 BOOLEAN
1187 NTAPI
1188 CmpFileSetSize(
1189     IN PHHIVE RegistryHive,
1190     IN ULONG FileType,
1191     IN ULONG FileSize,
1192     IN ULONG OldFileSize
1193 );
1194 
1195 BOOLEAN
1196 NTAPI
1197 CmpFileFlush(
1198    IN PHHIVE RegistryHive,
1199    IN ULONG FileType,
1200    IN OUT PLARGE_INTEGER FileOffset,
1201    IN ULONG Length
1202 );
1203 
1204 //
1205 // Configuration Manager side of Registry System Calls
1206 //
1207 NTSTATUS
1208 NTAPI
1209 CmEnumerateValueKey(
1210     IN PCM_KEY_CONTROL_BLOCK Kcb,
1211     IN ULONG Index,
1212     IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
1213     IN PVOID KeyValueInformation,
1214     IN ULONG Length,
1215     IN PULONG ResultLength);
1216 
1217 NTSTATUS
1218 NTAPI
1219 CmSetValueKey(
1220     IN PCM_KEY_CONTROL_BLOCK Kcb,
1221     IN PUNICODE_STRING ValueName,
1222     IN ULONG Type,
1223     IN PVOID Data,
1224     IN ULONG DataSize);
1225 
1226 NTSTATUS
1227 NTAPI
1228 CmQueryKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
1229     IN KEY_INFORMATION_CLASS KeyInformationClass,
1230     IN PVOID KeyInformation,
1231     IN ULONG Length,
1232     IN PULONG ResultLength
1233 );
1234 
1235 NTSTATUS
1236 NTAPI
1237 CmEnumerateKey(IN PCM_KEY_CONTROL_BLOCK Kcb,
1238     IN ULONG Index,
1239     IN KEY_INFORMATION_CLASS KeyInformationClass,
1240     IN PVOID KeyInformation,
1241     IN ULONG Length,
1242     IN PULONG ResultLength
1243 );
1244 
1245 NTSTATUS
1246 NTAPI
1247 CmDeleteKey(
1248     IN PCM_KEY_BODY KeyBody
1249 );
1250 
1251 NTSTATUS
1252 NTAPI
1253 CmFlushKey(
1254     IN PCM_KEY_CONTROL_BLOCK Kcb,
1255     IN BOOLEAN EclusiveLock
1256 );
1257 
1258 NTSTATUS
1259 NTAPI
1260 CmDeleteValueKey(
1261     IN PCM_KEY_CONTROL_BLOCK Kcb,
1262     IN UNICODE_STRING ValueName
1263 );
1264 
1265 NTSTATUS
1266 NTAPI
1267 CmQueryValueKey(
1268     IN PCM_KEY_CONTROL_BLOCK Kcb,
1269     IN UNICODE_STRING ValueName,
1270     IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
1271     IN PVOID KeyValueInformation,
1272     IN ULONG Length,
1273     IN PULONG ResultLength
1274 );
1275 
1276 NTSTATUS
1277 NTAPI
1278 CmLoadKey(
1279     IN POBJECT_ATTRIBUTES TargetKey,
1280     IN POBJECT_ATTRIBUTES SourceFile,
1281     IN ULONG Flags,
1282     IN PCM_KEY_BODY KeyBody
1283 );
1284 
1285 NTSTATUS
1286 NTAPI
1287 CmUnloadKey(
1288     IN PCM_KEY_CONTROL_BLOCK Kcb,
1289     IN ULONG Flags
1290 );
1291 
1292 ULONG
1293 NTAPI
1294 CmpEnumerateOpenSubKeys(
1295     IN PCM_KEY_CONTROL_BLOCK RootKcb,
1296     IN BOOLEAN RemoveEmptyCacheEntries,
1297     IN BOOLEAN DereferenceOpenedEntries
1298 );
1299 
1300 HCELL_INDEX
1301 NTAPI
1302 CmpCopyCell(
1303     IN PHHIVE SourceHive,
1304     IN HCELL_INDEX SourceCell,
1305     IN PHHIVE DestinationHive,
1306     IN HSTORAGE_TYPE StorageType
1307 );
1308 
1309 NTSTATUS
1310 NTAPI
1311 CmpDeepCopyKey(
1312     IN PHHIVE SourceHive,
1313     IN HCELL_INDEX SrcKeyCell,
1314     IN PHHIVE DestinationHive,
1315     IN HSTORAGE_TYPE StorageType,
1316     OUT PHCELL_INDEX DestKeyCell OPTIONAL
1317 );
1318 
1319 NTSTATUS
1320 NTAPI
1321 CmSaveKey(
1322     IN PCM_KEY_CONTROL_BLOCK Kcb,
1323     IN HANDLE FileHandle,
1324     IN ULONG Flags
1325 );
1326 
1327 NTSTATUS
1328 NTAPI
1329 CmSaveMergedKeys(
1330     IN PCM_KEY_CONTROL_BLOCK HighKcb,
1331     IN PCM_KEY_CONTROL_BLOCK LowKcb,
1332     IN HANDLE FileHandle
1333 );
1334 
1335 //
1336 // Startup and Shutdown
1337 //
1338 CODE_SEG("INIT")
1339 BOOLEAN
1340 NTAPI
1341 CmInitSystem1(
1342     VOID
1343 );
1344 
1345 VOID
1346 NTAPI
1347 CmShutdownSystem(
1348     VOID
1349 );
1350 
1351 VOID
1352 NTAPI
1353 CmSetLazyFlushState(
1354     IN BOOLEAN Enable
1355 );
1356 
1357 VOID
1358 NTAPI
1359 CmpSetVersionData(
1360     VOID
1361 );
1362 
1363 //
1364 // Driver List Routines
1365 //
1366 CODE_SEG("INIT")
1367 PUNICODE_STRING*
1368 NTAPI
1369 CmGetSystemDriverList(
1370     VOID
1371 );
1372 
1373 //
1374 // Global variables accessible from all of Cm
1375 //
1376 extern ULONG CmpTraceLevel;
1377 extern BOOLEAN CmpSpecialBootCondition;
1378 extern BOOLEAN CmpFlushOnLockRelease;
1379 extern BOOLEAN CmpShareSystemHives;
1380 extern BOOLEAN CmpMiniNTBoot;
1381 extern BOOLEAN CmpNoVolatileCreates;
1382 extern EX_PUSH_LOCK CmpHiveListHeadLock, CmpLoadHiveLock;
1383 extern LIST_ENTRY CmpHiveListHead;
1384 extern POBJECT_TYPE CmpKeyObjectType;
1385 extern ERESOURCE CmpRegistryLock;
1386 extern PCM_KEY_HASH_TABLE_ENTRY CmpCacheTable;
1387 extern PCM_NAME_HASH_TABLE_ENTRY CmpNameCacheTable;
1388 extern KGUARDED_MUTEX CmpDelayedCloseTableLock;
1389 extern CMHIVE CmControlHive;
1390 extern WCHAR CmDefaultLanguageId[];
1391 extern ULONG CmDefaultLanguageIdLength;
1392 extern ULONG CmDefaultLanguageIdType;
1393 extern WCHAR CmInstallUILanguageId[];
1394 extern ULONG CmInstallUILanguageIdLength;
1395 extern ULONG CmInstallUILanguageIdType;
1396 extern ULONG CmNtGlobalFlag;
1397 extern LANGID PsInstallUILanguageId;
1398 extern LANGID PsDefaultUILanguageId;
1399 extern CM_SYSTEM_CONTROL_VECTOR CmControlVector[];
1400 extern ULONG CmpConfigurationAreaSize;
1401 extern PCM_FULL_RESOURCE_DESCRIPTOR CmpConfigurationData;
1402 extern UNICODE_STRING CmTypeName[];
1403 extern UNICODE_STRING CmClassName[];
1404 extern CMP_MF_TYPE CmpMultifunctionTypes[];
1405 extern USHORT CmpUnknownBusCount;
1406 extern ULONG CmpTypeCount[MaximumType + 1];
1407 extern HIVE_LIST_ENTRY CmpMachineHiveList[];
1408 extern UNICODE_STRING CmSymbolicLinkValueName;
1409 extern UNICODE_STRING CmpSystemStartOptions;
1410 extern UNICODE_STRING CmpLoadOptions;
1411 extern BOOLEAN CmSelfHeal;
1412 extern BOOLEAN CmpSelfHeal;
1413 extern ULONG CmpBootType;
1414 extern HANDLE CmpRegistryRootHandle;
1415 extern BOOLEAN ExpInTextModeSetup;
1416 extern BOOLEAN InitIsWinPEMode;
1417 extern ULONG CmpHashTableSize;
1418 extern ULONG CmpDelayedCloseSize, CmpDelayedCloseIndex;
1419 extern BOOLEAN CmpNoWrite;
1420 extern BOOLEAN CmpForceForceFlush;
1421 extern BOOLEAN CmpWasSetupBoot;
1422 extern BOOLEAN CmpProfileLoaded;
1423 extern PCMHIVE CmiVolatileHive;
1424 extern LIST_ENTRY CmiKeyObjectListHead;
1425 extern BOOLEAN CmpHoldLazyFlush;
1426 
1427 //
1428 // Inlined functions
1429 //
1430 #include "cm_x.h"
1431