ReactOS 0.4.15-dev-7961-gdcf9eb0
cmsysini.c File Reference
#include "ntoskrnl.h"
#include "debug.h"
Include dependency graph for cmsysini.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI CmpLinkKeyToHive (_In_z_ PCWSTR LinkKeyName, _In_z_ PCWSTR TargetKeyName)
 
VOID NTAPI CmpDeleteKeyObject (PVOID DeletedObject)
 
VOID NTAPI CmpCloseKeyObject (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
 
NTSTATUS NTAPI CmpQueryKeyName (IN PVOID ObjectBody, IN BOOLEAN HasName, IN OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
 
NTSTATUS NTAPI CmpInitHiveFromFile (IN PCUNICODE_STRING HiveName, IN ULONG HiveFlags, OUT PCMHIVE *Hive, IN OUT PBOOLEAN New, IN ULONG CheckFlags)
 
NTSTATUS NTAPI CmpSetSystemValues (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
static NTSTATUS CmpCreateHardwareProfile (HANDLE ControlSetHandle)
 
NTSTATUS NTAPI CmpCreateControlSet (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
NTSTATUS NTAPI CmpLinkHiveToMaster (IN PUNICODE_STRING LinkName, IN HANDLE RootDirectory, IN PCMHIVE RegistryHive, IN BOOLEAN Allocate, IN PSECURITY_DESCRIPTOR SecurityDescriptor)
 
BOOLEAN NTAPI CmpInitializeSystemHive (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
NTSTATUS NTAPI CmpCreateObjectTypes (VOID)
 
BOOLEAN NTAPI CmpCreateRootNode (IN PHHIVE Hive, IN PCWSTR Name, OUT PHCELL_INDEX Index)
 
BOOLEAN NTAPI CmpCreateRegistryRoot (VOID)
 
static PCWSTR CmpGetRegistryPath (VOID)
 
static VOID CmpHasAlternateHiveDiverged (_In_ PCUNICODE_STRING FileName, _In_ PCMHIVE CmMainmHive, _In_ HANDLE AlternateHandle, _Out_ PBOOLEAN Diverged)
 Checks if the primary and alternate backing hive are the same, by determining the time stamp of both hives.
 
 _Function_class_ (KSTART_ROUTINE)
 
VOID NTAPI CmpInitializeHiveList (VOID)
 
BOOLEAN NTAPI CmInitSystem1 (VOID)
 
PUNICODE_STRING *NTAPI CmGetSystemDriverList (VOID)
 
VOID NTAPI CmpLockRegistryExclusive (VOID)
 
VOID NTAPI CmpLockRegistry (VOID)
 
BOOLEAN NTAPI CmpTestRegistryLock (VOID)
 
BOOLEAN NTAPI CmpTestRegistryLockExclusive (VOID)
 
VOID NTAPI CmpLockHiveFlusherExclusive (IN PCMHIVE Hive)
 
VOID NTAPI CmpLockHiveFlusherShared (IN PCMHIVE Hive)
 
VOID NTAPI CmpUnlockHiveFlusher (IN PCMHIVE Hive)
 
BOOLEAN NTAPI CmpTestHiveFlusherLockShared (IN PCMHIVE Hive)
 
BOOLEAN NTAPI CmpTestHiveFlusherLockExclusive (IN PCMHIVE Hive)
 
VOID NTAPI CmpUnlockRegistry (VOID)
 
VOID NTAPI CmpAcquireTwoKcbLocksExclusiveByKey (IN ULONG ConvKey1, IN ULONG ConvKey2)
 
VOID NTAPI CmpReleaseTwoKcbLockByKey (IN ULONG ConvKey1, IN ULONG ConvKey2)
 
VOID NTAPI CmShutdownSystem (VOID)
 
VOID NTAPI CmpSetVersionData (VOID)
 

Variables

POBJECT_TYPE CmpKeyObjectType
 
PCMHIVE CmiVolatileHive
 
LIST_ENTRY CmpHiveListHead
 
ERESOURCE CmpRegistryLock
 
KGUARDED_MUTEX CmpSelfHealQueueLock
 
LIST_ENTRY CmpSelfHealQueueListHead
 
KEVENT CmpLoadWorkerEvent
 
LONG CmpLoadWorkerIncrement
 
PEPROCESS CmpSystemProcess
 
PVOID CmpRegistryLockCallerCaller
 
PVOID CmpRegistryLockCaller
 
BOOLEAN CmpFlushOnLockRelease
 
BOOLEAN CmpSpecialBootCondition
 
BOOLEAN CmpNoWrite = TRUE
 
BOOLEAN CmpWasSetupBoot
 
BOOLEAN CmpProfileLoaded
 
BOOLEAN CmpNoVolatileCreates
 
ULONG CmpTraceLevel = 0
 
BOOLEAN HvShutdownComplete = FALSE
 
LONG CmpFlushStarveWriters
 
BOOLEAN CmFirstTime
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmsysini.c.

Function Documentation

◆ _Function_class_()

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 1261 of file cmsysini.c.

1265{
1266 WCHAR FileBuffer[64], RegBuffer[64];
1267 PCWSTR ConfigPath;
1268 UNICODE_STRING TempName, FileName, RegName;
1269 ULONG i, ErrorResponse, WorkerCount, Length;
1270 USHORT FileStart;
1271 ULONG PrimaryDisposition, SecondaryDisposition, ClusterSize;
1272 PCMHIVE CmHive;
1273 HANDLE PrimaryHandle = NULL, AlternateHandle = NULL;
1275 PVOID ErrorParameters;
1276 BOOLEAN HasDiverged;
1277 PAGED_CODE();
1278
1279 /* Get the hive index, make sure it makes sense */
1280 i = PtrToUlong(StartContext);
1282
1283 /* We were started */
1285
1286 /* Build the file name and registry name strings */
1287 RtlInitEmptyUnicodeString(&FileName, FileBuffer, sizeof(FileBuffer));
1288 RtlInitEmptyUnicodeString(&RegName, RegBuffer, sizeof(RegBuffer));
1289
1290 /* Now build the system root path */
1291 ConfigPath = CmpGetRegistryPath();
1292 RtlInitUnicodeString(&TempName, ConfigPath);
1294 FileStart = FileName.Length;
1295
1296 /* And build the registry root path */
1297 RtlInitUnicodeString(&TempName, L"\\REGISTRY\\");
1298 RtlAppendUnicodeStringToString(&RegName, &TempName);
1299
1300 /* Build the base name */
1301 RtlInitUnicodeString(&TempName, CmpMachineHiveList[i].BaseName);
1302 RtlAppendUnicodeStringToString(&RegName, &TempName);
1303
1304 /* Check if this is a child of the root */
1305 if (RegName.Buffer[RegName.Length / sizeof(WCHAR) - 1] == OBJ_NAME_PATH_SEPARATOR)
1306 {
1307 /* Then setup the whole name */
1309 RtlAppendUnicodeStringToString(&RegName, &TempName);
1310 }
1311
1312 /* Now add the rest of the file name */
1314 FileName.Length = FileStart;
1316 if (!CmpMachineHiveList[i].CmHive)
1317 {
1318 /* We need to allocate a new hive structure */
1320
1321 /* Load the hive file */
1323 CmpMachineHiveList[i].HHiveFlags,
1324 &CmHive,
1327 if (!NT_SUCCESS(Status) ||
1328 (!CmpShareSystemHives && !CmHive->FileHandles[HFILE_TYPE_LOG]))
1329 {
1330 /*
1331 * We failed, or could not get a log file (unless
1332 * the hive is shared), raise a hard error.
1333 */
1334 ErrorParameters = &FileName;
1336 1,
1337 1,
1338 (PULONG_PTR)&ErrorParameters,
1339 OptionOk,
1340 &ErrorResponse);
1341 }
1342
1343 /* Set the hive flags and newly allocated hive pointer */
1344 CmHive->Flags = CmpMachineHiveList[i].CmHiveFlags;
1345 CmpMachineHiveList[i].CmHive2 = CmHive;
1346 }
1347 else
1348 {
1349 /* We already have a hive, is it volatile? */
1350 CmHive = CmpMachineHiveList[i].CmHive;
1351 if (!(CmHive->Hive.HiveFlags & HIVE_VOLATILE))
1352 {
1353 /* It's now, open the hive file and log */
1355 L".ALT",
1356 &PrimaryHandle,
1357 &AlternateHandle,
1358 &PrimaryDisposition,
1359 &SecondaryDisposition,
1360 TRUE,
1361 TRUE,
1362 FALSE,
1363 &ClusterSize);
1364 if (!NT_SUCCESS(Status) || !AlternateHandle)
1365 {
1366 /* Couldn't open the hive or its alternate file, raise a hard error */
1367 ErrorParameters = &FileName;
1369 1,
1370 1,
1371 (PULONG_PTR)&ErrorParameters,
1372 OptionOk,
1373 &ErrorResponse);
1374
1375 /* And bugcheck for posterity's sake */
1376 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 9, 0, i, Status);
1377 }
1378
1379 /* Save the file handles. This should remove our sync hacks */
1380 /*
1381 * FIXME: Any hive that relies on the alternate hive for recovery purposes
1382 * will only get an alternate hive. As a result, the LOG file would never
1383 * get synced each time a write is done to the hive. In the future it would
1384 * be best to adapt the code so that a primary hive can use a LOG and ALT
1385 * hives at the same time.
1386 */
1387 CmHive->FileHandles[HFILE_TYPE_ALTERNATE] = AlternateHandle;
1388 CmHive->FileHandles[HFILE_TYPE_PRIMARY] = PrimaryHandle;
1389
1390 /* Allow lazy flushing since the handles are there -- remove sync hacks */
1391 //ASSERT(CmHive->Hive.HiveFlags & HIVE_NOLAZYFLUSH);
1392 CmHive->Hive.HiveFlags &= ~HIVE_NOLAZYFLUSH;
1393
1394 /* Get the real size of the hive */
1395 Length = CmHive->Hive.Storage[Stable].Length + HBLOCK_SIZE;
1396
1397 /* Check if the cluster size doesn't match */
1398 if (CmHive->Hive.Cluster != ClusterSize)
1399 {
1400 DPRINT1("FIXME: Support for CmHive->Hive.Cluster (%lu) != ClusterSize (%lu) is unimplemented!\n",
1401 CmHive->Hive.Cluster, ClusterSize);
1402 }
1403
1404 /* Set the file size */
1405 DPRINT("FIXME: Should set file size: %lu\n", Length);
1406 //if (!CmpFileSetSize((PHHIVE)CmHive, HFILE_TYPE_PRIMARY, Length, Length))
1407 //{
1408 /* This shouldn't fail */
1409 //ASSERT(FALSE);
1410 //}
1411
1412 /* FreeLdr has recovered the hive with a log, we must do a flush */
1413 if (CmHive->Hive.BaseBlock->BootRecover == HBOOT_BOOT_RECOVERED_BY_HIVE_LOG)
1414 {
1415 DPRINT1("FreeLdr recovered the hive (hive 0x%p)\n", CmHive);
1416 RtlSetAllBits(&CmHive->Hive.DirtyVector);
1417 CmHive->Hive.DirtyCount = CmHive->Hive.DirtyVector.SizeOfBitMap;
1418 HvSyncHive((PHHIVE)CmHive);
1419 }
1420 else
1421 {
1422 /*
1423 * Check whether the both primary and alternate hives are the same,
1424 * or that the primary or alternate were created for the first time.
1425 * Do a write against the alternate hive in these cases.
1426 */
1428 CmHive,
1429 AlternateHandle,
1430 &HasDiverged);
1431 if (HasDiverged ||
1432 PrimaryDisposition == FILE_CREATED ||
1433 SecondaryDisposition == FILE_CREATED)
1434 {
1435 if (!HvWriteAlternateHive((PHHIVE)CmHive))
1436 {
1437 DPRINT1("Failed to write to alternate hive\n");
1438 goto Exit;
1439 }
1440 }
1441 }
1442
1443 /* Finally, set our allocated hive to the same hive we've had */
1444 CmpMachineHiveList[i].CmHive2 = CmHive;
1445 ASSERT(CmpMachineHiveList[i].CmHive == CmpMachineHiveList[i].CmHive2);
1446 }
1447 }
1448
1449Exit:
1450 /* We're done */
1452
1453 /* Check if we're the last worker */
1455 if (WorkerCount == CM_NUMBER_OF_MACHINE_HIVES)
1456 {
1457 /* Signal the event */
1459 }
1460
1461 /* Kill the thread */
1463}
#define PAGED_CODE()
unsigned char BOOLEAN
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
DWORD ClusterSize
Definition: format.c:67
#define CM_NUMBER_OF_MACHINE_HIVES
Definition: cm.h:118
HIVE_LIST_ENTRY CmpMachineHiveList[]
Definition: cmdata.c:41
BOOLEAN CmpShareSystemHives
Definition: cmdata.c:58
#define CM_CHECK_REGISTRY_PURGE_VOLATILES
Definition: cmlib.h:229
BOOLEAN CMAPI HvSyncHive(PHHIVE RegistryHive)
BOOLEAN CMAPI HvWriteAlternateHive(_In_ PHHIVE RegistryHive)
Writes data to an alternate registry hive. An alternate hive is usually backed up by a primary hive....
Definition: hivewrt.c:634
KEVENT CmpLoadWorkerEvent
Definition: cmsysini.c:21
static VOID CmpHasAlternateHiveDiverged(_In_ PCUNICODE_STRING FileName, _In_ PCMHIVE CmMainmHive, _In_ HANDLE AlternateHandle, _Out_ PBOOLEAN Diverged)
Checks if the primary and alternate backing hive are the same, by determining the time stamp of both ...
Definition: cmsysini.c:1213
static PCWSTR CmpGetRegistryPath(VOID)
Definition: cmsysini.c:1172
NTSTATUS NTAPI CmpInitHiveFromFile(IN PCUNICODE_STRING HiveName, IN ULONG HiveFlags, OUT PCMHIVE *Hive, IN OUT PBOOLEAN New, IN ULONG CheckFlags)
Definition: cmsysini.c:289
LONG CmpLoadWorkerIncrement
Definition: cmsysini.c:22
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PtrToUlong(u)
Definition: config.h:107
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
struct _FileName FileName
Definition: fatprocs.h:896
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS NTAPI NtRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:551
@ Stable
Definition: hivedata.h:127
#define HBLOCK_SIZE
Definition: hivedata.h:42
#define HFILE_TYPE_ALTERNATE
Definition: hivedata.h:36
#define HFILE_TYPE_LOG
Definition: hivedata.h:34
#define HIVE_VOLATILE
Definition: hivedata.h:23
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
#define HBOOT_BOOT_RECOVERED_BY_HIVE_LOG
Definition: hivedata.h:95
NTSYSAPI void WINAPI RtlSetAllBits(PRTL_BITMAP)
#define ASSERT(a)
Definition: mode.c:44
@ OptionOk
Definition: extypes.h:187
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FILE_CREATED
Definition: nt_native.h:770
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI CmpOpenHiveFiles(IN PCUNICODE_STRING BaseName, IN PCWSTR Extension OPTIONAL, OUT PHANDLE Primary, OUT PHANDLE Log, OUT PULONG PrimaryDisposition, OUT PULONG LogDisposition, IN BOOLEAN CreateAllowed, IN BOOLEAN MarkAsSystemHive, IN BOOLEAN NoBuffering, OUT PULONG ClusterSize OPTIONAL)
Definition: cminit.c:273
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1145
#define STATUS_CANNOT_LOAD_REGISTRY_FILE
Definition: ntstatus.h:668
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
static void Exit(void)
Definition: sock.c:1330
Definition: cmlib.h:316
BOOLEAN ThreadStarted
Definition: cm.h:416
PCMHIVE CmHive
Definition: cm.h:411
PCMHIVE CmHive2
Definition: cm.h:414
BOOLEAN Allocate
Definition: cm.h:417
BOOLEAN ThreadFinished
Definition: cm.h:415
ULONG CmHiveFlags
Definition: cm.h:413
uint32_t * PULONG_PTR
Definition: typedefs.h:65
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t ULONG
Definition: typedefs.h:59
_In_opt_ PALLOCATE_FUNCTION Allocate
Definition: exfuncs.h:814
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ CmGetSystemDriverList()

PUNICODE_STRING *NTAPI CmGetSystemDriverList ( VOID  )

Definition at line 1839 of file cmsysini.c.

1840{
1841 LIST_ENTRY DriverList;
1844 PCM_KEY_BODY KeyBody;
1845 PHHIVE Hive;
1846 HCELL_INDEX RootCell, ControlCell;
1849 PLIST_ENTRY NextEntry;
1850 ULONG i;
1851 PUNICODE_STRING* ServicePath = NULL;
1852 BOOLEAN Success, AutoSelect;
1854 PAGED_CODE();
1855
1856 /* Initialize the driver list */
1857 InitializeListHead(&DriverList);
1858
1859 /* Open the system hive key */
1860 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System");
1862 &KeyName,
1864 NULL,
1865 NULL);
1867 if (!NT_SUCCESS(Status)) return NULL;
1868
1869 /* Reference the key object to get the root hive/cell to access directly */
1873 KernelMode,
1874 (PVOID*)&KeyBody,
1875 NULL);
1876 if (!NT_SUCCESS(Status))
1877 {
1878 /* Fail */
1880 return NULL;
1881 }
1882
1883 /* Do all this under the registry lock */
1885
1886 /* Get the hive and key cell */
1887 Hive = KeyBody->KeyControlBlock->KeyHive;
1888 RootCell = KeyBody->KeyControlBlock->KeyCell;
1889
1890 /* Open the current control set key */
1891 RtlInitUnicodeString(&KeyName, L"Current");
1892 ControlCell = CmpFindControlSet(Hive, RootCell, &KeyName, &AutoSelect);
1893 if (ControlCell == HCELL_NIL) goto EndPath;
1894
1895 /* Find all system drivers */
1896 Success = CmpFindDrivers(Hive, ControlCell, SystemLoad, NULL, &DriverList);
1897 if (!Success) goto EndPath;
1898
1899 /* Sort by group/tag */
1900 if (!CmpSortDriverList(Hive, ControlCell, &DriverList)) goto EndPath;
1901
1902 /* Remove circular dependencies (cycles) and sort */
1903 if (!CmpResolveDriverDependencies(&DriverList)) goto EndPath;
1904
1905 /* Loop the list to count drivers */
1906 for (i = 0, NextEntry = DriverList.Flink;
1907 NextEntry != &DriverList;
1908 i++, NextEntry = NextEntry->Flink);
1909
1910 /* Allocate the array */
1911 ServicePath = ExAllocatePool(NonPagedPool, (i + 1) * sizeof(PUNICODE_STRING));
1912 if (!ServicePath) KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 2, 1, 0, 0);
1913
1914 /* Loop the driver list */
1915 for (i = 0, NextEntry = DriverList.Flink;
1916 NextEntry != &DriverList;
1917 i++, NextEntry = NextEntry->Flink)
1918 {
1919 /* Get the entry */
1921
1922 /* Allocate the path for the caller */
1923 ServicePath[i] = ExAllocatePool(NonPagedPool, sizeof(UNICODE_STRING));
1924 if (!ServicePath[i])
1925 {
1926 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 2, 1, 0, 0);
1927 }
1928
1929 /* Duplicate the registry path */
1931 &DriverEntry->RegistryPath,
1932 ServicePath[i]);
1933 if (!NT_SUCCESS(Status))
1934 {
1935 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 2, 1, 0, 0);
1936 }
1937 }
1938
1939 /* Terminate the list */
1940 ServicePath[i] = NULL;
1941
1942EndPath:
1943 /* Free the driver list if we had one */
1944 if (!IsListEmpty(&DriverList)) CmpFreeDriverList(Hive, &DriverList);
1945
1946 /* Unlock the registry */
1948
1949 /* Close the key handle and dereference the object, then return the path */
1950 ObDereferenceObject(KeyBody);
1952 return ServicePath;
1953}
BOOLEAN NTAPI CmpFindDrivers(_In_ PHHIVE Hive, _In_ HCELL_INDEX ControlSet, _In_ SERVICE_LOAD_TYPE LoadType, _In_opt_ PCWSTR BootFileSystem, _Inout_ PLIST_ENTRY DriverListHead)
Enumerates all drivers within the given control set and load type, present in the "Services" sub-key,...
Definition: cmboot.c:679
BOOLEAN NTAPI CmpResolveDriverDependencies(_Inout_ PLIST_ENTRY DriverListHead)
Removes potential circular dependencies (cycles) and sorts the driver list.
Definition: cmboot.c:1030
HCELL_INDEX NTAPI CmpFindControlSet(_In_ PHHIVE SystemHive, _In_ HCELL_INDEX RootCell, _In_ PCUNICODE_STRING SelectKeyName, _Out_ PBOOLEAN AutoSelect)
Finds the corresponding "HKLM\SYSTEM\ControlSetXXX" system control set registry key,...
Definition: cmboot.c:84
BOOLEAN NTAPI CmpSortDriverList(_In_ PHHIVE Hive, _In_ HCELL_INDEX ControlSet, _Inout_ PLIST_ENTRY DriverListHead)
Sorts the driver list, according to the drivers' group load ordering.
Definition: cmboot.c:902
VOID NTAPI CmpFreeDriverList(_In_ PHHIVE Hive, _Inout_ PLIST_ENTRY DriverListHead)
Empties the driver list and frees all allocated driver nodes in it.
Definition: cmboot.c:1224
VOID NTAPI CmpLockRegistryExclusive(VOID)
Definition: cmsysini.c:1957
VOID NTAPI CmpUnlockRegistry(VOID)
Definition: cmsysini.c:2056
POBJECT_TYPE CmpKeyObjectType
Definition: cmsysini.c:15
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ Success
Definition: eventcreate.c:712
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
#define HCELL_NIL
Definition: hivedata.h:110
ULONG HCELL_INDEX
Definition: hivedata.h:105
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS WINAPI RtlDuplicateUnicodeString(int, const UNICODE_STRING *, UNICODE_STRING *)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
Definition: arc.h:246
struct _CM_KEY_CONTROL_BLOCK * KeyControlBlock
Definition: cm.h:234
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static int Link(const char **args)
Definition: vfdcmd.c:2414
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
BOOL WINAPI EndPath(_In_ HDC)
@ SystemLoad
Definition: cmtypes.h:997
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by IopInitializeSystemDrivers().

◆ CmInitSystem1()

BOOLEAN NTAPI CmInitSystem1 ( VOID  )

Definition at line 1621 of file cmsysini.c.

1622{
1627 PCMHIVE HardwareHive;
1629 PAGED_CODE();
1630
1631 /* Check if this is PE-boot */
1632 if (InitIsWinPEMode)
1633 {
1634 /* Set the registry in PE mode and load the system hives in shared mode */
1637 }
1638
1639 /* Initialize the hive list and lock */
1643
1644 /* Initialize registry lock */
1646
1647 /* Initialize the cache */
1649
1650 /* Initialize allocation and delayed dereferencing */
1654
1655 /* Initialize callbacks */
1657
1658 /* Initialize self healing */
1661
1662 /* Save the current process and lock the registry */
1664
1665 /* Create the key object types */
1667 if (!NT_SUCCESS(Status))
1668 {
1669 /* Bugcheck */
1670 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 1, Status, 0);
1671 }
1672
1673 /* Build the master hive */
1678 NULL,
1679 NULL,
1680 NULL,
1681 NULL,
1682 NULL,
1683 NULL,
1685 if (!NT_SUCCESS(Status))
1686 {
1687 /* Bugcheck */
1688 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 2, Status, 0);
1689 }
1690
1691 /* Create the \REGISTRY key node */
1692 if (!CmpCreateRegistryRoot())
1693 {
1694 /* Bugcheck */
1695 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 3, 0, 0);
1696 }
1697
1698 /* Create the default security descriptor */
1700
1701 /* Create '\Registry\Machine' key */
1702 RtlInitUnicodeString(&KeyName, L"\\REGISTRY\\MACHINE");
1704 &KeyName,
1706 NULL,
1711 0,
1712 NULL,
1713 0,
1714 NULL);
1715 if (!NT_SUCCESS(Status))
1716 {
1717 /* Bugcheck */
1718 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 5, Status, 0);
1719 }
1720
1721 /* Close the handle */
1723
1724 /* Create '\Registry\User' key */
1725 RtlInitUnicodeString(&KeyName, L"\\REGISTRY\\USER");
1727 &KeyName,
1729 NULL,
1734 0,
1735 NULL,
1736 0,
1737 NULL);
1738 if (!NT_SUCCESS(Status))
1739 {
1740 /* Bugcheck */
1741 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 6, Status, 0);
1742 }
1743
1744 /* Close the handle */
1746
1747 /* After this point, do not allow creating keys in the master hive */
1749
1750 /* Initialize the system hive */
1752 {
1753 /* Bugcheck */
1754 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 7, 0, 0);
1755 }
1756
1757 /* Create the 'CurrentControlSet' link */
1759 if (!NT_SUCCESS(Status))
1760 {
1761 /* Bugcheck */
1762 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 8, Status, 0);
1763 }
1764
1765 /* Create the hardware hive */
1766 Status = CmpInitializeHive(&HardwareHive,
1770 NULL,
1771 NULL,
1772 NULL,
1773 NULL,
1774 NULL,
1775 NULL,
1777 if (!NT_SUCCESS(Status))
1778 {
1779 /* Bugcheck */
1780 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 11, Status, 0);
1781 }
1782
1783 /* Add the hive to the hive list */
1784 CmpMachineHiveList[0].CmHive = HardwareHive;
1785
1786 /* Attach it to the machine key */
1787 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\HARDWARE");
1789 NULL,
1790 HardwareHive,
1791 TRUE,
1793 if (!NT_SUCCESS(Status))
1794 {
1795 /* Bugcheck */
1796 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 12, Status, 0);
1797 }
1798
1799 /* Add to HiveList key */
1800 CmpAddToHiveFileList(HardwareHive);
1801
1802 /* Free the security descriptor */
1804
1805 /* Fill out the Hardware key with the ARC Data from the Loader */
1807 if (!NT_SUCCESS(Status))
1808 {
1809 /* Bugcheck */
1810 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 13, Status, 0);
1811 }
1812
1813 /* Initialize machine-dependent information into the registry */
1815 if (!NT_SUCCESS(Status))
1816 {
1817 /* Bugcheck */
1818 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 14, Status, 0);
1819 }
1820
1821 /* Initialize volatile registry settings */
1823 if (!NT_SUCCESS(Status))
1824 {
1825 /* Bugcheck */
1826 KeBugCheckEx(CONFIG_INITIALIZATION_FAILED, 1, 15, Status, 0);
1827 }
1828
1829 /* Free the load options */
1831
1832 /* If we got here, all went well */
1833 return TRUE;
1834}
NTSTATUS NTAPI CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: cmhardwr.c:21
VOID NTAPI CmpInitCmPrivateAlloc(VOID)
Definition: cmalloc.c:29
VOID NTAPI CmpInitCmPrivateDelayAlloc(VOID)
Definition: cmalloc.c:44
NTSTATUS NTAPI CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: cmconfig.c:329
EX_PUSH_LOCK CmpHiveListHeadLock
Definition: cmdata.c:39
EX_PUSH_LOCK CmpLoadHiveLock
Definition: cmdata.c:39
BOOLEAN CmpMiniNTBoot
Definition: cmdata.c:60
UNICODE_STRING CmpLoadOptions
Definition: cmdata.c:55
VOID NTAPI CmpInitDelayDerefKCBEngine(VOID)
Definition: cmdelay.c:268
VOID NTAPI CmpInitCallback(VOID)
Definition: cmhook.c:38
NTSTATUS NTAPI CmpAddToHiveFileList(IN PCMHIVE Hive)
Definition: cmhvlist.c:130
VOID NTAPI CmpInitializeCache(VOID)
Definition: cmkcbncb.c:26
#define CM_CHECK_REGISTRY_DONT_PURGE_VOLATILES
Definition: cmlib.h:228
#define TAG_CM
Definition: cmlib.h:212
#define TAG_CMSD
Definition: cmlib.h:215
BOOLEAN NTAPI CmpCreateRegistryRoot(VOID)
Definition: cmsysini.c:1070
ERESOURCE CmpRegistryLock
Definition: cmsysini.c:18
NTSTATUS NTAPI CmpLinkHiveToMaster(IN PUNICODE_STRING LinkName, IN HANDLE RootDirectory, IN PCMHIVE RegistryHive, IN BOOLEAN Allocate, IN PSECURITY_DESCRIPTOR SecurityDescriptor)
Definition: cmsysini.c:802
PEPROCESS CmpSystemProcess
Definition: cmsysini.c:23
NTSTATUS NTAPI CmpCreateObjectTypes(VOID)
Definition: cmsysini.c:980
NTSTATUS NTAPI CmpCreateControlSet(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: cmsysini.c:528
BOOLEAN NTAPI CmpInitializeSystemHive(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: cmsysini.c:869
BOOLEAN CmpNoVolatileCreates
Definition: cmsysini.c:34
PCMHIVE CmiVolatileHive
Definition: cmsysini.c:16
LIST_ENTRY CmpHiveListHead
Definition: cmsysini.c:17
LIST_ENTRY CmpSelfHealQueueListHead
Definition: cmsysini.c:20
KGUARDED_MUTEX CmpSelfHealQueueLock
Definition: cmsysini.c:19
NTSTATUS NTAPI CmpSetSystemValues(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: cmsysini.c:401
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define ExInitializePushLock
Definition: ex.h:1013
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
#define HINIT_CREATE
Definition: hivedata.h:13
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KEY_WRITE
Definition: nt_native.h:1031
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
NTSTATUS NTAPI CmpInitializeHive(_Out_ PCMHIVE *CmHive, _In_ ULONG OperationType, _In_ ULONG HiveFlags, _In_ ULONG FileType, _In_opt_ PVOID HiveData, _In_ HANDLE Primary, _In_ HANDLE Log, _In_ HANDLE External, _In_ HANDLE Alternate, _In_opt_ PCUNICODE_STRING FileName, _In_ ULONG CheckFlags)
Definition: cminit.c:19
PSECURITY_DESCRIPTOR NTAPI CmpHiveRootSecurityDescriptor(VOID)
Definition: cmse.c:21
BOOLEAN InitIsWinPEMode
Definition: init.c:72
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by Phase1InitializationDiscard().

◆ CmpAcquireTwoKcbLocksExclusiveByKey()

VOID NTAPI CmpAcquireTwoKcbLocksExclusiveByKey ( IN ULONG  ConvKey1,
IN ULONG  ConvKey2 
)

Definition at line 2079 of file cmsysini.c.

2081{
2082 ULONG Index1, Index2;
2083
2084 /* Sanity check */
2086
2087 /* Get hash indexes */
2088 Index1 = GET_HASH_INDEX(ConvKey1);
2089 Index2 = GET_HASH_INDEX(ConvKey2);
2090
2091 /* See which one is highest */
2092 if (Index1 < Index2)
2093 {
2094 /* Grab them in the proper order */
2097 }
2098 else
2099 {
2100 /* Grab the second one first, then the first */
2102 if (Index1 != Index2) CmpAcquireKcbLockExclusiveByKey(ConvKey1);
2103 }
2104}
FORCEINLINE VOID CmpAcquireKcbLockExclusiveByKey(IN ULONG ConvKey)
Definition: cm_x.h:126
#define GET_HASH_INDEX(ConvKey)
Definition: cm_x.h:24
#define CMP_ASSERT_REGISTRY_LOCK()
Definition: cm_x.h:52

Referenced by CmDeleteKey(), CmpCreateKeyControlBlock(), and NtUnloadKey2().

◆ CmpCloseKeyObject()

VOID NTAPI CmpCloseKeyObject ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  Object,
IN ACCESS_MASK  GrantedAccess,
IN ULONG  ProcessHandleCount,
IN ULONG  SystemHandleCount 
)

Definition at line 162 of file cmsysini.c.

167{
169 PAGED_CODE();
170
171 /* Don't do anything if we're not the last handle */
172 if (SystemHandleCount > 1) return;
173
174 /* Make sure we're a valid key body */
175 if (KeyBody->Type == CM_KEY_BODY_TYPE)
176 {
177 /* Don't do anything if we don't have a notify block */
178 if (!KeyBody->NotifyBlock) return;
179
180 /* This shouldn't happen yet */
181 ASSERT(FALSE);
182 }
183}
struct _CM_KEY_BODY * PCM_KEY_BODY
#define CM_KEY_BODY_TYPE
Definition: cm.h:64
ULONG Type
Definition: cm.h:233
struct _CM_NOTIFY_BLOCK * NotifyBlock
Definition: cm.h:235
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

Referenced by CmpCreateObjectTypes().

◆ CmpCreateControlSet()

NTSTATUS NTAPI CmpCreateControlSet ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 528 of file cmsysini.c.

529{
530 UNICODE_STRING ConfigName = RTL_CONSTANT_STRING(L"Control\\IDConfigDB");
531 UNICODE_STRING SelectName =
532 RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\Select");
535 CHAR ValueInfoBuffer[128];
537 WCHAR UnicodeBuffer[128];
538 HANDLE SelectHandle = NULL;
540 HANDLE ConfigHandle = NULL;
541 HANDLE ProfileHandle = NULL;
542 HANDLE ParentHandle = NULL;
543 ULONG ControlSet, HwProfile;
546 PLOADER_PARAMETER_EXTENSION LoaderExtension;
547 PAGED_CODE();
548
549 /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
550 if (LoaderBlock->RegistryBase == NULL)
551 {
552 /* Build the ControlSet001 key */
554 L"\\Registry\\Machine\\System\\ControlSet001");
556 &KeyName,
558 NULL,
559 NULL);
563 0,
564 NULL,
565 0,
566 &Disposition);
567 if (!NT_SUCCESS(Status))
568 {
569 DPRINT1("Failed to create ControlSet001 key: 0x%lx\n", Status);
570 goto Cleanup;
571 }
572
573 /* Create the Hardware Profile keys */
575 if (!NT_SUCCESS(Status))
576 {
577 DPRINT1("Failed to create Hardware profile keys: 0x%lx\n", Status);
578 goto Cleanup;
579 }
580
581 /* Use hard-coded setting */
582 ControlSet = 1;
583 }
584 else
585 {
586 /* Open the select key */
588 &SelectName,
590 NULL,
591 NULL);
592 Status = NtOpenKey(&SelectHandle, KEY_READ, &ObjectAttributes);
593 if (!NT_SUCCESS(Status))
594 {
595 DPRINT1("Failed to open select key: 0x%lx\n", Status);
596 goto Cleanup;
597 }
598
599 /* Open the current value */
600 RtlInitUnicodeString(&KeyName, L"Current");
601 Status = NtQueryValueKey(SelectHandle,
602 &KeyName,
604 ValueInfoBuffer,
605 sizeof(ValueInfoBuffer),
606 &ResultLength);
607 if (!NT_SUCCESS(Status))
608 {
609 DPRINT1("Failed to open the Current value: 0x%lx\n", Status);
610 goto Cleanup;
611 }
612
613 /* Get the actual value pointer, and get the control set ID */
614 ValueInfo = (PKEY_VALUE_FULL_INFORMATION)ValueInfoBuffer;
615 ControlSet = *(PULONG)((PUCHAR)ValueInfo + ValueInfo->DataOffset);
616 }
617
618 /* Create the current control set key */
620 L"\\Registry\\Machine\\System\\CurrentControlSet");
622 &KeyName,
624 NULL,
625 NULL);
629 0,
630 NULL,
632 &Disposition);
633 if (!NT_SUCCESS(Status))
634 goto Cleanup;
635
636 /* Sanity check */
638
639 /* Initialize the target link name */
640 Status = RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
641 L"\\Registry\\Machine\\System\\ControlSet%03ld",
642 ControlSet);
643 if (!NT_SUCCESS(Status))
644 goto Cleanup;
645
646 RtlInitUnicodeString(&KeyName, UnicodeBuffer);
647
648 /* Set the value */
651 0,
652 REG_LINK,
653 KeyName.Buffer,
654 KeyName.Length);
655 if (!NT_SUCCESS(Status))
656 goto Cleanup;
657
658 /* Get the configuration database key */
660 &ConfigName,
662 KeyHandle,
663 NULL);
664 Status = NtOpenKey(&ConfigHandle, KEY_READ, &ObjectAttributes);
665
666 /* Check if we don't have one */
667 if (!NT_SUCCESS(Status))
668 {
669 /* Cleanup and exit */
671 goto Cleanup;
672 }
673
674 /* ReactOS Hack: Hard-code current to 001 for SetupLdr */
675 if (LoaderBlock->RegistryBase == NULL)
676 {
677 HwProfile = 0;
678 }
679 else
680 {
681 /* Now get the current config */
682 RtlInitUnicodeString(&KeyName, L"CurrentConfig");
683 Status = NtQueryValueKey(ConfigHandle,
684 &KeyName,
686 ValueInfoBuffer,
687 sizeof(ValueInfoBuffer),
688 &ResultLength);
689
690 /* Set pointer to buffer */
691 ValueInfo = (PKEY_VALUE_FULL_INFORMATION)ValueInfoBuffer;
692
693 /* Check if we failed or got a non DWORD-value */
694 if (!NT_SUCCESS(Status) || (ValueInfo->Type != REG_DWORD))
695 {
697 goto Cleanup;
698 }
699
700 /* Get the hadware profile */
701 HwProfile = *(PULONG)((PUCHAR)ValueInfo + ValueInfo->DataOffset);
702 }
703
704 /* Open the hardware profile key */
706 L"\\Registry\\Machine\\System\\CurrentControlSet"
707 L"\\Hardware Profiles");
709 &KeyName,
711 NULL,
712 NULL);
713 Status = NtOpenKey(&ParentHandle, KEY_READ, &ObjectAttributes);
714 if (!NT_SUCCESS(Status))
715 {
716 /* Exit and clean up */
718 goto Cleanup;
719 }
720
721 /* Build the profile name */
722 RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
723 L"%04ld", HwProfile);
724 RtlInitUnicodeString(&KeyName, UnicodeBuffer);
725
726 /* Open the associated key */
728 &KeyName,
730 ParentHandle,
731 NULL);
732 Status = NtOpenKey(&ProfileHandle,
735 if (!NT_SUCCESS(Status))
736 {
737 /* Cleanup and exit */
739 goto Cleanup;
740 }
741
742 /* Check if we have a loader block extension */
743 LoaderExtension = LoaderBlock->Extension;
744 if (LoaderExtension)
745 {
746 DPRINT("ReactOS doesn't support NTLDR Profiles yet!\n");
747 }
748
749 /* Create the current hardware profile key */
751 L"\\Registry\\Machine\\System\\CurrentControlSet\\"
752 L"Hardware Profiles\\Current");
754 &KeyName,
756 NULL,
757 NULL);
761 0,
762 NULL,
764 &Disposition);
765 if (NT_SUCCESS(Status))
766 {
767 /* Sanity check */
769
770 /* Create the profile name */
771 RtlStringCbPrintfW(UnicodeBuffer, sizeof(UnicodeBuffer),
772 L"\\Registry\\Machine\\System\\CurrentControlSet\\"
773 L"Hardware Profiles\\%04ld",
774 HwProfile);
775 RtlInitUnicodeString(&KeyName, UnicodeBuffer);
776
777 /* Set it */
780 0,
781 REG_LINK,
782 KeyName.Buffer,
783 KeyName.Length);
784 }
785
787
788Cleanup:
789 /* Close every opened handle */
790 if (SelectHandle) NtClose(SelectHandle);
792 if (ConfigHandle) NtClose(ConfigHandle);
793 if (ProfileHandle) NtClose(ProfileHandle);
794 if (ParentHandle) NtClose(ParentHandle);
795
796 DPRINT("CmpCreateControlSet() done\n");
797 return Status;
798}
UNICODE_STRING CmSymbolicLinkValueName
Definition: cmdata.c:52
static NTSTATUS CmpCreateHardwareProfile(HANDLE ControlSetHandle)
Definition: cmsysini.c:456
static const WCHAR Cleanup[]
Definition: register.c:80
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI NTSTATUS NTAPI NtSetValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN ULONG TitleIndex OPTIONAL, IN ULONG Type, IN PVOID Data, IN ULONG DataSize)
Definition: ntapi.c:859
@ KeyValueFullInformation
Definition: nt_native.h:1181
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_CREATE_LINK
Definition: nt_native.h:1063
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define REG_LINK
Definition: nt_native.h:1500
#define KEY_CREATE_LINK
Definition: nt_native.h:1021
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
struct _KEY_VALUE_FULL_INFORMATION * PKEY_VALUE_FULL_INFORMATION
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define REG_DWORD
Definition: sdbapi.c:596
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
char CHAR
Definition: xmlstorage.h:175

Referenced by CmInitSystem1().

◆ CmpCreateHardwareProfile()

static NTSTATUS CmpCreateHardwareProfile ( HANDLE  ControlSetHandle)
static

Definition at line 456 of file cmsysini.c.

457{
460 HANDLE ProfilesHandle = NULL;
461 HANDLE ProfileHandle = NULL;
464
465 DPRINT("CmpCreateHardwareProfile()\n");
466
467 /* Create the Hardware Profiles key */
468 RtlInitUnicodeString(&KeyName, L"Hardware Profiles");
470 &KeyName,
472 ControlSetHandle,
473 NULL);
474 Status = NtCreateKey(&ProfilesHandle,
477 0,
478 NULL,
479 0,
480 &Disposition);
481 if (!NT_SUCCESS(Status))
482 {
483 DPRINT1("Creating the Hardware Profile key failed\n");
484 goto done;
485 }
486
487 /* Sanity check */
489
490 /* Create the 0000 key */
493 &KeyName,
495 ProfilesHandle,
496 NULL);
497 Status = NtCreateKey(&ProfileHandle,
500 0,
501 NULL,
502 0,
503 &Disposition);
504 if (!NT_SUCCESS(Status))
505 {
506 DPRINT1("Creating the Hardware Profile\\0000 key failed\n");
507 goto done;
508 }
509
510 /* Sanity check */
512
513done:
514 if (ProfilesHandle)
515 NtClose(ProfilesHandle);
516
517 if (ProfileHandle)
518 NtClose(ProfileHandle);
519
520 DPRINT("CmpCreateHardwareProfile() done\n");
521
522 return Status;
523}

Referenced by CmpCreateControlSet().

◆ CmpCreateObjectTypes()

NTSTATUS NTAPI CmpCreateObjectTypes ( VOID  )

Definition at line 980 of file cmsysini.c.

981{
982 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
984 GENERIC_MAPPING CmpKeyMapping = {KEY_READ,
985 KEY_WRITE,
988 PAGED_CODE();
989
990 /* Initialize the Key object type */
991 RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
993 ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
994 ObjectTypeInitializer.DefaultPagedPoolCharge = sizeof(CM_KEY_BODY);
995 ObjectTypeInitializer.GenericMapping = CmpKeyMapping;
996 ObjectTypeInitializer.PoolType = PagedPool;
997 ObjectTypeInitializer.ValidAccessMask = KEY_ALL_ACCESS;
998 ObjectTypeInitializer.UseDefaultObject = TRUE;
999 ObjectTypeInitializer.DeleteProcedure = CmpDeleteKeyObject;
1000 ObjectTypeInitializer.ParseProcedure = CmpParseKey;
1001 ObjectTypeInitializer.SecurityProcedure = CmpSecurityMethod;
1002 ObjectTypeInitializer.QueryNameProcedure = CmpQueryKeyName;
1003 ObjectTypeInitializer.CloseProcedure = CmpCloseKeyObject;
1004 ObjectTypeInitializer.SecurityRequired = TRUE;
1005 ObjectTypeInitializer.InvalidAttributes = OBJ_EXCLUSIVE | OBJ_PERMANENT;
1006
1007 /* Create it */
1008 return ObCreateObjectType(&Name, &ObjectTypeInitializer, NULL, &CmpKeyObjectType);
1009}
struct NameRec_ * Name
Definition: cdprocs.h:460
struct _CM_KEY_BODY CM_KEY_BODY
NTSTATUS NTAPI CmpParseKey(IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context OPTIONAL, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
Definition: cmparse.c:1848
VOID NTAPI CmpDeleteKeyObject(PVOID DeletedObject)
Definition: cmsysini.c:112
VOID NTAPI CmpCloseKeyObject(IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
Definition: cmsysini.c:162
NTSTATUS NTAPI CmpQueryKeyName(IN PVOID ObjectBody, IN BOOLEAN HasName, IN OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
Definition: cmsysini.c:187
#define PagedPool
Definition: env_spec_w32.h:308
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
#define OBJ_PERMANENT
Definition: winternl.h:226
#define KEY_EXECUTE
Definition: nt_native.h:1037
NTSTATUS NTAPI CmpSecurityMethod(IN PVOID ObjectBody, IN SECURITY_OPERATION_CODE OperationCode, IN PSECURITY_INFORMATION SecurityInformation, IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN OUT PULONG BufferLength, IN OUT PSECURITY_DESCRIPTOR *OldSecurityDescriptor, IN POOL_TYPE PoolType, IN PGENERIC_MAPPING GenericMapping)
Definition: cmse.c:261
NTSTATUS NTAPI ObCreateObjectType(IN PUNICODE_STRING TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, IN PVOID Reserved, OUT POBJECT_TYPE *ObjectType)
Definition: oblife.c:1136
OB_CLOSE_METHOD CloseProcedure
Definition: obtypes.h:368
OB_SECURITY_METHOD SecurityProcedure
Definition: obtypes.h:371
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
OB_DELETE_METHOD DeleteProcedure
Definition: obtypes.h:369
OB_QUERYNAME_METHOD QueryNameProcedure
Definition: obtypes.h:372
OB_PARSE_METHOD ParseProcedure
Definition: obtypes.h:370
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by CmInitSystem1().

◆ CmpCreateRegistryRoot()

BOOLEAN NTAPI CmpCreateRegistryRoot ( VOID  )

Definition at line 1070 of file cmsysini.c.

1071{
1075 HCELL_INDEX RootIndex;
1077 PCM_KEY_NODE KeyCell;
1080 PAGED_CODE();
1081
1082 /* Setup the root node */
1083 if (!CmpCreateRootNode(&CmiVolatileHive->Hive, L"REGISTRY", &RootIndex))
1084 {
1085 /* We failed */
1086 return FALSE;
1087 }
1088
1089 /* Create '\Registry' key. */
1090 RtlInitUnicodeString(&KeyName, L"\\REGISTRY");
1093 &KeyName,
1095 NULL,
1100 KernelMode,
1101 NULL,
1102 sizeof(CM_KEY_BODY),
1103 0,
1104 0,
1105 (PVOID*)&RootKey);
1107 if (!NT_SUCCESS(Status)) return FALSE;
1108
1109 /* Sanity check, and get the key cell */
1110 ASSERT((&CmiVolatileHive->Hive)->ReleaseCellRoutine == NULL);
1111 KeyCell = (PCM_KEY_NODE)HvGetCell(&CmiVolatileHive->Hive, RootIndex);
1112 if (!KeyCell)
1113 {
1115 return FALSE;
1116 }
1117
1118 /* Create the KCB */
1119 RtlInitUnicodeString(&KeyName, L"\\REGISTRY");
1121 RootIndex,
1122 KeyCell,
1123 NULL,
1124 0,
1125 &KeyName);
1126 if (!Kcb)
1127 {
1129 return FALSE;
1130 }
1131
1132 /* Initialize the object */
1133 RootKey->KeyControlBlock = Kcb;
1134 RootKey->Type = CM_KEY_BODY_TYPE;
1135 RootKey->NotifyBlock = NULL;
1136 RootKey->ProcessID = PsGetCurrentProcessId();
1137 RootKey->KcbLocked = FALSE;
1138
1139 /* Link with KCB */
1141
1142 /* Insert the key into the namespace */
1144 NULL,
1146 0,
1147 NULL,
1149 if (!NT_SUCCESS(Status))
1150 {
1151 return FALSE;
1152 }
1153
1154 /* Reference the key again so that we never lose it */
1156 KEY_READ,
1157 NULL,
1158 KernelMode,
1159 (PVOID*)&RootKey,
1160 NULL);
1161 if (!NT_SUCCESS(Status))
1162 {
1164 return FALSE;
1165 }
1166
1167 /* Completely sucessful */
1168 return TRUE;
1169}
HANDLE CmpRegistryRootHandle
Definition: cmdata.c:69
struct _CM_KEY_NODE * PCM_KEY_NODE
PCM_KEY_CONTROL_BLOCK NTAPI CmpCreateKeyControlBlock(IN PHHIVE Hive, IN HCELL_INDEX Index, IN PCM_KEY_NODE Node, IN PCM_KEY_CONTROL_BLOCK Parent, IN ULONG Flags, IN PUNICODE_STRING KeyName)
Definition: cmkcbncb.c:655
VOID NTAPI EnlistKeyBodyWithKCB(IN PCM_KEY_BODY KeyBody, IN ULONG Flags)
Definition: cmkcbncb.c:1042
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:457
BOOLEAN NTAPI CmpCreateRootNode(IN PHHIVE Hive, IN PCWSTR Name, OUT PHCELL_INDEX Index)
Definition: cmsysini.c:1014
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2935
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:1039
static PMEMKEY RootKey
Definition: registry.c:55
HHIVE Hive
Definition: cmlib.h:317

Referenced by CmInitSystem1().

◆ CmpCreateRootNode()

BOOLEAN NTAPI CmpCreateRootNode ( IN PHHIVE  Hive,
IN PCWSTR  Name,
OUT PHCELL_INDEX  Index 
)

Definition at line 1014 of file cmsysini.c.

1017{
1019 PCM_KEY_NODE KeyCell;
1020 PAGED_CODE();
1021
1022 /* Initialize the node name and allocate it */
1024 *Index = HvAllocateCell(Hive,
1026 CmpNameSize(Hive, &KeyName),
1027 Stable,
1028 HCELL_NIL);
1029 if (*Index == HCELL_NIL) return FALSE;
1030
1031 /* Set the cell index and get the data */
1032 Hive->BaseBlock->RootCell = *Index;
1033 KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, *Index);
1034 if (!KeyCell) return FALSE;
1035
1036 /* Setup the cell */
1038 KeyCell->Flags = KEY_HIVE_ENTRY | KEY_NO_DELETE;
1040 KeyCell->Parent = HCELL_NIL;
1041 KeyCell->SubKeyCounts[Stable] = 0;
1042 KeyCell->SubKeyCounts[Volatile] = 0;
1043 KeyCell->SubKeyLists[Stable] = HCELL_NIL;
1044 KeyCell->SubKeyLists[Volatile] = HCELL_NIL;
1045 KeyCell->ValueList.Count = 0;
1046 KeyCell->ValueList.List = HCELL_NIL;
1047 KeyCell->Security = HCELL_NIL;
1048 KeyCell->Class = HCELL_NIL;
1049 KeyCell->ClassLength = 0;
1050 KeyCell->MaxNameLen = 0;
1051 KeyCell->MaxClassLen = 0;
1052 KeyCell->MaxValueNameLen = 0;
1053 KeyCell->MaxValueDataLen = 0;
1054
1055 /* Copy the name (this will also set the length) */
1056 KeyCell->NameLength = CmpCopyName(Hive, KeyCell->Name, &KeyName);
1057
1058 /* Check if the name was compressed and set the flag if so */
1059 if (KeyCell->NameLength < KeyName.Length)
1060 KeyCell->Flags |= KEY_COMP_NAME;
1061
1062 /* Return success */
1063 HvReleaseCell(Hive, *Index);
1064 return TRUE;
1065}
#define KEY_COMP_NAME
Definition: cmdata.h:35
#define KEY_NO_DELETE
Definition: cmdata.h:33
#define CM_KEY_NODE_SIGNATURE
Definition: cmdata.h:21
#define KEY_HIVE_ENTRY
Definition: cmdata.h:32
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:460
USHORT NTAPI CmpCopyName(IN PHHIVE Hive, OUT PWCHAR Destination, IN PCUNICODE_STRING Source)
Definition: cmname.c:21
USHORT NTAPI CmpNameSize(IN PHHIVE Hive, IN PCUNICODE_STRING Name)
Definition: cmname.c:74
HCELL_INDEX CMAPI HvAllocateCell(PHHIVE RegistryHive, ULONG Size, HSTORAGE_TYPE Storage, IN HCELL_INDEX Vicinity)
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
@ Volatile
Definition: hivedata.h:128
HCELL_INDEX List
Definition: cmdata.h:75
ULONG Count
Definition: cmdata.h:74
USHORT Signature
Definition: cmdata.h:92
HCELL_INDEX Parent
Definition: cmdata.h:96
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:116
HCELL_INDEX SubKeyLists[HTYPE_COUNT]
Definition: cmdata.h:102
ULONG MaxValueNameLen
Definition: cmdata.h:111
ULONG MaxNameLen
Definition: cmdata.h:109
ULONG SubKeyCounts[HTYPE_COUNT]
Definition: cmdata.h:97
HCELL_INDEX Security
Definition: cmdata.h:107
USHORT NameLength
Definition: cmdata.h:114
USHORT ClassLength
Definition: cmdata.h:115
ULONG MaxClassLen
Definition: cmdata.h:110
HCELL_INDEX Class
Definition: cmdata.h:108
ULONG MaxValueDataLen
Definition: cmdata.h:112
CHILD_LIST ValueList
Definition: cmdata.h:103
USHORT Flags
Definition: cmdata.h:93
LARGE_INTEGER LastWriteTime
Definition: cmdata.h:94
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by CmpCreateRegistryRoot().

◆ CmpDeleteKeyObject()

VOID NTAPI CmpDeleteKeyObject ( PVOID  DeletedObject)

Definition at line 112 of file cmsysini.c.

113{
114 PCM_KEY_BODY KeyBody = (PCM_KEY_BODY)DeletedObject;
116 REG_KEY_HANDLE_CLOSE_INFORMATION KeyHandleCloseInfo;
117 REG_POST_OPERATION_INFORMATION PostOperationInfo;
119 PAGED_CODE();
120
121 /* First off, prepare the handle close information callback */
122 PostOperationInfo.Object = KeyBody;
123 KeyHandleCloseInfo.Object = KeyBody;
125 &KeyHandleCloseInfo);
126 if (!NT_SUCCESS(Status))
127 {
128 /* If we failed, notify the post routine */
129 PostOperationInfo.Status = Status;
131 return;
132 }
133
134 /* Acquire hive lock */
136
137 /* Make sure this is a valid key body */
138 if (KeyBody->Type == CM_KEY_BODY_TYPE)
139 {
140 /* Get the KCB */
141 Kcb = KeyBody->KeyControlBlock;
142 if (Kcb)
143 {
144 /* Delist the key */
145 DelistKeyBodyFromKCB(KeyBody, KeyBody->KcbLocked);
146
147 /* Dereference the KCB */
149 }
150 }
151
152 /* Release the registry lock */
154
155 /* Do the post callback */
156 PostOperationInfo.Status = STATUS_SUCCESS;
158}
VOID NTAPI CmpDelayDerefKeyControlBlock(IN PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cmdelay.c:286
NTSTATUS CmiCallRegisteredCallbacks(IN REG_NOTIFY_CLASS Argument1, IN PVOID Argument2)
Definition: cmhook.c:59
VOID NTAPI DelistKeyBodyFromKCB(IN PCM_KEY_BODY KeyBody, IN BOOLEAN LockHeld)
Definition: cmkcbncb.c:1100
VOID NTAPI CmpLockRegistry(VOID)
Definition: cmsysini.c:1970
BOOLEAN KcbLocked
Definition: cm.h:240
Definition: cmtypes.h:858
PVOID Object
Definition: cmtypes.h:859
NTSTATUS Status
Definition: cmtypes.h:860
@ RegNtPreKeyHandleClose
Definition: cmtypes.h:655
@ RegNtPostKeyHandleClose
Definition: cmtypes.h:666

Referenced by CmpCreateObjectTypes().

◆ CmpGetRegistryPath()

static PCWSTR CmpGetRegistryPath ( VOID  )
static

Definition at line 1172 of file cmsysini.c.

1173{
1174 PCWSTR ConfigPath;
1175
1176 /* Check if we are booted in setup */
1177 if (!ExpInTextModeSetup)
1178 {
1179 ConfigPath = L"\\SystemRoot\\System32\\Config\\";
1180 }
1181 else
1182 {
1183 ConfigPath = L"\\SystemRoot\\";
1184 }
1185
1186 DPRINT1("CmpGetRegistryPath: ConfigPath = '%S'\n", ConfigPath);
1187
1188 return ConfigPath;
1189}
BOOLEAN ExpInTextModeSetup
Definition: init.c:69

Referenced by _Function_class_(), and CmpInitializeHiveList().

◆ CmpHasAlternateHiveDiverged()

static VOID CmpHasAlternateHiveDiverged ( _In_ PCUNICODE_STRING  FileName,
_In_ PCMHIVE  CmMainmHive,
_In_ HANDLE  AlternateHandle,
_Out_ PBOOLEAN  Diverged 
)
static

Checks if the primary and alternate backing hive are the same, by determining the time stamp of both hives.

Parameters
[in]FileNameA pointer to a string containing the file name of the primary hive.
[in]CmMainmHiveA pointer to a CM hive descriptor associated with the primary hive.
[in]AlternateHandleA handle to a file that represents the alternate hive.
[in]DivergedA pointer to a boolean value, if both hives are the same it returns TRUE. Otherwise it returns FALSE.

Definition at line 1213 of file cmsysini.c.

1218{
1219 PHHIVE Hive, AlternateHive;
1221 PCMHIVE CmiAlternateHive;
1222
1223 /* Assume it has not diverged */
1224 *Diverged = FALSE;
1225
1226 /* Initialize the SYSTEM alternate hive */
1227 Status = CmpInitializeHive(&CmiAlternateHive,
1228 HINIT_FILE,
1229 0,
1231 NULL,
1232 AlternateHandle,
1233 NULL,
1234 NULL,
1235 NULL,
1236 FileName,
1238 if (!NT_SUCCESS(Status))
1239 {
1240 /* Assume it has diverged... */
1241 DPRINT1("Failed to initialize the alternate hive to check for diversion (Status 0x%lx)\n", Status);
1242 *Diverged = TRUE;
1243 return;
1244 }
1245
1246 /*
1247 * Check the timestamp of both hives. If they do not match they
1248 * have diverged, the kernel has to synchronize the both hives.
1249 */
1250 Hive = &CmMainmHive->Hive;
1251 AlternateHive = &CmiAlternateHive->Hive;
1252 if (AlternateHive->BaseBlock->TimeStamp.QuadPart !=
1254 {
1255 *Diverged = TRUE;
1256 }
1257
1258 CmpDestroyHive(CmiAlternateHive);
1259}
#define HINIT_FILE
Definition: hivedata.h:15
NTSTATUS NTAPI CmpDestroyHive(IN PCMHIVE CmHive)
Definition: cminit.c:242
LARGE_INTEGER TimeStamp
Definition: hivedata.h:151
PHBASE_BLOCK BaseBlock
Definition: hivedata.h:328
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by _Function_class_().

◆ CmpInitHiveFromFile()

NTSTATUS NTAPI CmpInitHiveFromFile ( IN PCUNICODE_STRING  HiveName,
IN ULONG  HiveFlags,
OUT PCMHIVE Hive,
IN OUT PBOOLEAN  New,
IN ULONG  CheckFlags 
)

Definition at line 289 of file cmsysini.c.

294{
295 ULONG HiveDisposition, LogDisposition;
299 PCMHIVE NewHive;
300 PAGED_CODE();
301
302 /* Assume failure */
303 *Hive = NULL;
304
305 /* Open or create the hive files */
306 Status = CmpOpenHiveFiles(HiveName,
307 L".LOG",
308 &FileHandle,
309 &LogHandle,
310 &HiveDisposition,
311 &LogDisposition,
312 *New,
313 FALSE,
314 TRUE,
315 NULL);
316 if (!NT_SUCCESS(Status)) return Status;
317
318 /* Check if we have a log handle */
320
321 /* Check if we created or opened the hive */
322 if (HiveDisposition == FILE_CREATED)
323 {
324 /* Do a create operation */
326 *New = TRUE;
327 }
328 else
329 {
330 /* Open it as a file */
332 *New = FALSE;
333 }
334
335 /* Check if the system hives are opened in shared mode */
337 {
338 /* Then force using the primary hive */
340 if (LogHandle)
341 {
342 /* Get rid of the log handle */
344 LogHandle = NULL;
345 }
346 }
347
348 /* Check if we're too late */
350 {
351 /* Fail */
354 return STATUS_TOO_LATE;
355 }
356
357 /* Initialize the hive */
358 Status = CmpInitializeHive(&NewHive,
359 Operation,
360 HiveFlags,
361 FileType,
362 NULL,
364 LogHandle,
365 NULL,
366 NULL,
367 HiveName,
368 CheckFlags);
369 if (!NT_SUCCESS(Status))
370 {
371 /* Fail */
374 return Status;
375 }
376
377 /* Success, return hive */
378 *Hive = NewHive;
379
380 /* Duplicate the hive name */
382 HiveName->Length,
383 TAG_CM);
384 if (NewHive->FileFullPath.Buffer)
385 {
386 /* Copy the string */
388 HiveName->Buffer,
389 HiveName->Length);
390 NewHive->FileFullPath.Length = HiveName->Length;
391 NewHive->FileFullPath.MaximumLength = HiveName->Length;
392 }
393
394 /* Return success */
395 return STATUS_SUCCESS;
396}
BOOLEAN HvShutdownComplete
Definition: cmsysini.c:36
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
FP_OP Operation
Definition: fpcontrol.c:150
_In_ UINT _Out_ PNDIS_HANDLE LogHandle
Definition: ndis.h:5382
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define STATUS_TOO_LATE
Definition: ntstatus.h:626
#define New(t)
Definition: rtf.h:1086
UNICODE_STRING FileFullPath
Definition: cmlib.h:333
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ WDFDEVICE _In_ WDF_SPECIAL_FILE_TYPE FileType
Definition: wdfdevice.h:2741

Referenced by _Function_class_(), and CmpCmdHiveOpen().

◆ CmpInitializeHiveList()

VOID NTAPI CmpInitializeHiveList ( VOID  )

Definition at line 1467 of file cmsysini.c.

1468{
1469 WCHAR FileBuffer[64], RegBuffer[64];
1470 PCWSTR ConfigPath;
1471 UNICODE_STRING TempName, FileName, RegName;
1472 HANDLE Thread;
1474 ULONG i;
1475 USHORT RegStart;
1477
1478 PAGED_CODE();
1479
1480 /* Reenable hive writes now */
1481 CmpNoWrite = FALSE;
1482
1483 /* Build the file name and registry name strings */
1484 RtlInitEmptyUnicodeString(&FileName, FileBuffer, sizeof(FileBuffer));
1485 RtlInitEmptyUnicodeString(&RegName, RegBuffer, sizeof(RegBuffer));
1486
1487 /* Now build the system root path */
1488 ConfigPath = CmpGetRegistryPath();
1489 RtlInitUnicodeString(&TempName, ConfigPath);
1491
1492 /* And build the registry root path */
1493 RtlInitUnicodeString(&TempName, L"\\REGISTRY\\");
1494 RtlAppendUnicodeStringToString(&RegName, &TempName);
1495 RegStart = RegName.Length;
1496
1497 /* Setup the event to synchronize workers */
1499
1500 /* Enter special boot condition */
1502
1503 /* Create the SD for the root hives */
1505
1506 /* Loop every hive we care about */
1507 for (i = 0; i < CM_NUMBER_OF_MACHINE_HIVES; i++)
1508 {
1509 /* Make sure the list is set up */
1511
1512 /* Load this root hive as volatile, if opened in shared mode */
1515
1516 /* Create a thread to handle this hive */
1519 NULL,
1520 0,
1521 NULL,
1522 CmpLoadHiveThread,
1523 UlongToPtr(i));
1524 if (NT_SUCCESS(Status))
1525 {
1526 /* We don't care about the handle -- the thread self-terminates */
1527 ZwClose(Thread);
1528 }
1529 else
1530 {
1531 /* Can't imagine this happening */
1532 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 9, 3, i, Status);
1533 }
1534 }
1535
1536 /* Make sure we've reached the end of the list */
1538
1539 /* Wait for hive loading to finish */
1541 Executive,
1542 KernelMode,
1543 FALSE,
1544 NULL);
1545
1546 /* Exit the special boot condition and make sure all workers completed */
1549
1550 /* Loop hives again */
1551 for (i = 0; i < CM_NUMBER_OF_MACHINE_HIVES; i++)
1552 {
1553 /* Make sure the thread ran and finished */
1554 ASSERT(CmpMachineHiveList[i].ThreadFinished == TRUE);
1555 ASSERT(CmpMachineHiveList[i].ThreadStarted == TRUE);
1556
1557 /* Check if this was a new hive */
1558 if (!CmpMachineHiveList[i].CmHive)
1559 {
1560 /* Make sure we allocated something */
1561 ASSERT(CmpMachineHiveList[i].CmHive2 != NULL);
1562
1563 /* Build the base name */
1564 RegName.Length = RegStart;
1565 RtlInitUnicodeString(&TempName, CmpMachineHiveList[i].BaseName);
1566 RtlAppendUnicodeStringToString(&RegName, &TempName);
1567
1568 /* Check if this is a child of the root */
1569 if (RegName.Buffer[RegName.Length / sizeof(WCHAR) - 1] == OBJ_NAME_PATH_SEPARATOR)
1570 {
1571 /* Then setup the whole name */
1573 RtlAppendUnicodeStringToString(&RegName, &TempName);
1574 }
1575
1576 /* Now link the hive to its master */
1577 Status = CmpLinkHiveToMaster(&RegName,
1578 NULL,
1579 CmpMachineHiveList[i].CmHive2,
1582 if (Status != STATUS_SUCCESS)
1583 {
1584 /* Linking needs to work */
1585 KeBugCheckEx(CONFIG_LIST_FAILED, 11, Status, i, (ULONG_PTR)&RegName);
1586 }
1587
1588 /* Check if we had to allocate a new hive */
1590 {
1591 /* Sync the new hive */
1592 //HvSyncHive((PHHIVE)(CmpMachineHiveList[i].CmHive2));
1593 }
1594 }
1595
1596 /* Check if we created a new hive */
1597 if (CmpMachineHiveList[i].CmHive2)
1598 {
1599 /* Add to HiveList key */
1601 }
1602 }
1603
1604 /* Get rid of the SD */
1606
1607 /* Link SECURITY to SAM */
1608 CmpLinkKeyToHive(L"\\Registry\\Machine\\Security\\SAM",
1609 L"\\Registry\\Machine\\SAM\\SAM");
1610
1611 /* Link S-1-5-18 to .Default */
1613 CmpLinkKeyToHive(L"\\Registry\\User\\S-1-5-18",
1614 L"\\Registry\\User\\.Default");
1616}
BOOLEAN NTAPI CmpLinkKeyToHive(_In_z_ PCWSTR LinkKeyName, _In_z_ PCWSTR TargetKeyName)
Definition: cmsysini.c:45
BOOLEAN CmpSpecialBootCondition
Definition: cmsysini.c:26
BOOLEAN CmpNoWrite
Definition: cmsysini.c:30
#define UlongToPtr(u)
Definition: config.h:106
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
@ SynchronizationEvent
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
ULONG HHiveFlags
Definition: cm.h:412
uint32_t ULONG_PTR
Definition: typedefs.h:65
@ Executive
Definition: ketypes.h:415

Referenced by CmpCmdInit().

◆ CmpInitializeSystemHive()

BOOLEAN NTAPI CmpInitializeSystemHive ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 869 of file cmsysini.c.

870{
871 static const UNICODE_STRING HiveName = RTL_CONSTANT_STRING(L"SYSTEM");
872 PVOID HiveBase;
880
881 PAGED_CODE();
882
883 /* Setup the ansi string */
884 RtlInitAnsiString(&LoadString, LoaderBlock->LoadOptions);
885
886 /* Allocate the unicode buffer */
887 Length = LoadString.Length * sizeof(WCHAR) + sizeof(UNICODE_NULL);
889 if (!Buffer)
890 {
891 /* Fail */
892 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO, 3, 1, (ULONG_PTR)LoaderBlock, 0);
893 }
894
895 /* Setup the unicode string */
896 RtlInitEmptyUnicodeString(&CmpLoadOptions, Buffer, (USHORT)Length);
897
898 /* Add the load options and null-terminate */
900 if (!NT_SUCCESS(Status))
901 {
902 return FALSE;
903 }
904
906 CmpLoadOptions.Length += sizeof(WCHAR);
907
908 /* Get the System Hive base address */
909 HiveBase = LoaderBlock->RegistryBase;
910
912 HiveBase ? HINIT_MEMORY : HINIT_CREATE,
915 HiveBase,
916 NULL,
917 NULL,
918 NULL,
919 NULL,
920 &HiveName,
922 if (!NT_SUCCESS(Status))
923 {
924 return FALSE;
925 }
926
927 /* Set the hive filename */
928 if (!RtlCreateUnicodeString(&SystemHive->FileFullPath, L"\\SystemRoot\\System32\\Config\\SYSTEM"))
929 return FALSE;
930
931 /* Load the system hive as volatile, if opened in shared mode */
932 if (HiveBase && CmpShareSystemHives)
934
935 /* Save the boot type */
937
938 /* Are we in self-healing mode? */
939 if (!CmSelfHeal)
940 {
941 /* Disable self-healing internally and check if boot type wanted it */
944 {
945 /* We're disabled, so bugcheck */
946 KeBugCheckEx(BAD_SYSTEM_CONFIG_INFO,
947 3,
948 3,
950 0);
951 }
952 }
953
954 /* Create the default security descriptor */
956
957 /* Attach it to the system key */
958 /* Let CmpLinkHiveToMaster allocate a new hive if we got none from the LoaderBlock. */
959 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\SYSTEM");
961 NULL,
963 !HiveBase,
965
966 /* Free the security descriptor */
968 if (!NT_SUCCESS(Status)) return FALSE;
969
970 /* Add the hive to the hive list */
972
973 /* Success! */
974 return TRUE;
975}
PHHIVE SystemHive
Definition: registry.c:33
Definition: bufpool.h:45
ULONG CmpBootType
Definition: cmdata.c:62
BOOLEAN CmpSelfHeal
Definition: cmdata.c:64
BOOLEAN CmSelfHeal
Definition: cmdata.c:63
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define HINIT_MEMORY
Definition: hivedata.h:14
#define HBOOT_TYPE_SELF_HEAL
Definition: hivedata.h:89
#define HIVE_NOLAZYFLUSH
Definition: hivedata.h:24
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define UNICODE_NULL
ULONG BootType
Definition: hivedata.h:186
ULONG HiveFlags
Definition: hivedata.h:347
#define LoadString
Definition: winuser.h:5819

Referenced by CmInitSystem1().

◆ CmpLinkHiveToMaster()

NTSTATUS NTAPI CmpLinkHiveToMaster ( IN PUNICODE_STRING  LinkName,
IN HANDLE  RootDirectory,
IN PCMHIVE  RegistryHive,
IN BOOLEAN  Allocate,
IN PSECURITY_DESCRIPTOR  SecurityDescriptor 
)

Definition at line 802 of file cmsysini.c.

807{
810 CM_PARSE_CONTEXT ParseContext = {0};
812 PCM_KEY_BODY KeyBody;
813 PAGED_CODE();
814
815 /* Setup the object attributes */
817 LinkName,
821
822 /* Setup the parse context */
823 ParseContext.CreateLink = TRUE;
824 ParseContext.CreateOperation = TRUE;
825 ParseContext.ChildHive.KeyHive = &RegistryHive->Hive;
826
827 /* Check if we have a root keycell or if we need to create it */
828 if (Allocate)
829 {
830 /* Create it */
831 ParseContext.ChildHive.KeyCell = HCELL_NIL;
832 }
833 else
834 {
835 /* We have one */
836 ParseContext.ChildHive.KeyCell = RegistryHive->Hive.BaseBlock->RootCell;
837 }
838
839 /* Create the link node */
843 NULL,
845 (PVOID)&ParseContext,
846 &KeyHandle);
847 if (!NT_SUCCESS(Status)) return Status;
848
849 /* Mark the hive as clean */
850 RegistryHive->Hive.DirtyFlag = FALSE;
851
852 /* ReactOS Hack: Keep alive */
854 0,
857 (PVOID*)&KeyBody,
858 NULL);
860
861 /* Close the extra handle */
863 return STATUS_SUCCESS;
864}
WCHAR RootDirectory[MAX_PATH]
Definition: format.c:74
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
NTSTATUS NTAPI ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN OUT PVOID ParseContext, OUT PHANDLE Handle)
Definition: obhandle.c:2532
PHHIVE KeyHive
Definition: cmdata.h:84
HCELL_INDEX KeyCell
Definition: cmdata.h:83
CM_KEY_REFERENCE ChildHive
Definition: cm.h:438
BOOLEAN CreateLink
Definition: cm.h:440
BOOLEAN CreateOperation
Definition: cm.h:441

Referenced by CmInitSystem1(), CmLoadKey(), CmpInitializeHiveList(), and CmpInitializeSystemHive().

◆ CmpLinkKeyToHive()

BOOLEAN NTAPI CmpLinkKeyToHive ( _In_z_ PCWSTR  LinkKeyName,
_In_z_ PCWSTR  TargetKeyName 
)

Definition at line 45 of file cmsysini.c.

48{
52 HANDLE LinkKeyHandle;
54
55 PAGED_CODE();
56
57 /* Initialize the object attributes */
58 RtlInitUnicodeString(&KeyName, LinkKeyName);
60 &KeyName,
62 NULL,
63 NULL);
64
65 /* Create the link key */
66 Status = ZwCreateKey(&LinkKeyHandle,
69 0,
70 NULL,
73 if (!NT_SUCCESS(Status))
74 {
75 DPRINT1("CM: CmpLinkKeyToHive: couldn't create %S, Status = 0x%lx\n",
76 LinkKeyName, Status);
77 return FALSE;
78 }
79
80 /* Check if the new key was actually created */
82 {
83 DPRINT1("CM: CmpLinkKeyToHive: %S already exists!\n", LinkKeyName);
84 ZwClose(LinkKeyHandle);
85 return FALSE;
86 }
87
88 /* Set the target key name as link target */
89 RtlInitUnicodeString(&KeyName, TargetKeyName);
90 Status = ZwSetValueKey(LinkKeyHandle,
92 0,
94 KeyName.Buffer,
95 KeyName.Length);
96
97 /* Close the link key handle */
98 ObCloseHandle(LinkKeyHandle, KernelMode);
99
100 if (!NT_SUCCESS(Status))
101 {
102 DPRINT1("CM: CmpLinkKeyToHive: couldn't create symbolic link for %S, Status = 0x%lx\n",
103 TargetKeyName, Status);
104 return FALSE;
105 }
106
107 return TRUE;
108}
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379

Referenced by CmpInitializeHiveList(), and RegInitializeRegistry().

◆ CmpLockHiveFlusherExclusive()

VOID NTAPI CmpLockHiveFlusherExclusive ( IN PCMHIVE  Hive)

Definition at line 2006 of file cmsysini.c.

2007{
2008 /* Lock the flusher. We should already be in a critical section */
2010 ASSERT((ExIsResourceAcquiredShared(Hive->FlusherLock) == 0) &&
2011 (ExIsResourceAcquiredExclusiveLite(Hive->FlusherLock) == 0));
2012 ExAcquireResourceExclusiveLite(Hive->FlusherLock, TRUE);
2013}
#define CMP_ASSERT_REGISTRY_LOCK_OR_LOADING(h)
Definition: cm_x.h:59
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1624
#define ExIsResourceAcquiredShared
Definition: exfuncs.h:348

Referenced by CmFlushKey(), CmLoadKey(), CmpDoFlushAll(), and CmpUnlinkHiveFromMaster().

◆ CmpLockHiveFlusherShared()

VOID NTAPI CmpLockHiveFlusherShared ( IN PCMHIVE  Hive)

Definition at line 2017 of file cmsysini.c.

2018{
2019 /* Lock the flusher. We should already be in a critical section */
2021 ASSERT((ExIsResourceAcquiredShared(Hive->FlusherLock) == 0) &&
2022 (ExIsResourceAcquiredExclusiveLite(Hive->FlusherLock) == 0));
2023 ExAcquireResourceSharedLite(Hive->FlusherLock, TRUE);
2024}
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621

Referenced by CmDeleteKey(), CmDeleteValueKey(), CmpCreateLinkNode(), CmpDoCreate(), and CmSetValueKey().

◆ CmpLockRegistry()

VOID NTAPI CmpLockRegistry ( VOID  )

Definition at line 1970 of file cmsysini.c.

1971{
1972 /* Enter a critical region */
1974
1975 /* Check if we have to starve writers */
1977 {
1978 /* Starve exlusive waiters */
1980 }
1981 else
1982 {
1983 /* Just grab the lock */
1985 }
1986}
LONG CmpFlushStarveWriters
Definition: cmlazy.c:27
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1068

Referenced by _Function_class_(), CmDeleteKey(), CmDeleteValueKey(), CmEnumerateKey(), CmEnumerateValueKey(), CmLoadKey(), CmpBuildHashStackAndLookupCache(), CmpDeleteKeyObject(), CmpQueryKeyName(), CmpSecurityMethod(), CmQueryKey(), CmQueryValueKey(), CmSaveKey(), CmSaveMergedKeys(), CmSetValueKey(), NtFlushKey(), and NtUnloadKey2().

◆ CmpLockRegistryExclusive()

VOID NTAPI CmpLockRegistryExclusive ( VOID  )

Definition at line 1957 of file cmsysini.c.

1958{
1959 /* Enter a critical region and lock the registry */
1962
1963 /* Sanity check */
1966}
PVOID CmpRegistryLockCallerCaller
Definition: cmsysini.c:24
PVOID CmpRegistryLockCaller
Definition: cmsysini.c:24
NTSYSAPI VOID NTAPI RtlGetCallersAddress(_Out_ PVOID *CallersAddress, _Out_ PVOID *CallersCaller)
Definition: except.c:22

Referenced by _Function_class_(), CmGetSystemDriverList(), CmLoadKey(), CmShutdownSystem(), NtInitializeRegistry(), NtQueryOpenSubKeys(), and NtUnloadKey2().

◆ CmpQueryKeyName()

NTSTATUS NTAPI CmpQueryKeyName ( IN PVOID  ObjectBody,
IN BOOLEAN  HasName,
IN OUT POBJECT_NAME_INFORMATION  ObjectNameInfo,
IN ULONG  Length,
OUT PULONG  ReturnLength,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 187 of file cmsysini.c.

193{
197 PCM_KEY_BODY KeyBody = (PCM_KEY_BODY)ObjectBody;
199
200 /* Acquire hive lock */
202
203 /* Lock KCB shared */
205
206 /* Check if it's a deleted block */
207 if (Kcb->Delete)
208 {
209 /* Release the locks */
212
213 /* Let the caller know it's deleted */
214 return STATUS_KEY_DELETED;
215 }
216
217 /* Get the name */
219
220 /* Release the locks */
223
224 /* Check if we got the name */
226
227 /* Set the returned length */
228 *ReturnLength = KeyName->Length + sizeof(OBJECT_NAME_INFORMATION) + sizeof(WCHAR);
229
230 /* Calculate amount of bytes to copy into the buffer */
231 BytesToCopy = KeyName->Length + sizeof(WCHAR);
232
233 /* Check if the provided buffer is too small to fit even anything */
234 if ((Length <= sizeof(OBJECT_NAME_INFORMATION)) ||
235 ((Length < *ReturnLength) && (BytesToCopy < sizeof(WCHAR))))
236 {
237 /* Free the buffer allocated by CmpConstructName */
239
240 /* Return buffer length failure without writing anything there because nothing fits */
242 }
243
244 /* Check if the provided buffer can be partially written */
245 if (Length < *ReturnLength)
246 {
247 /* Yes, indicate so in the return status */
249
250 /* Calculate amount of bytes which the provided buffer could handle */
252 }
253
254 /* Remove the null termination character from the size */
255 BytesToCopy -= sizeof(WCHAR);
256
257 /* Fill in the result */
259 {
260 /* Return data to user */
261 ObjectNameInfo->Name.Buffer = (PWCHAR)(ObjectNameInfo + 1);
262 ObjectNameInfo->Name.MaximumLength = KeyName->Length;
263 ObjectNameInfo->Name.Length = KeyName->Length;
264
265 /* Copy string content*/
266 RtlCopyMemory(ObjectNameInfo->Name.Buffer,
267 KeyName->Buffer,
269
270 /* Null terminate it */
271 ObjectNameInfo->Name.Buffer[BytesToCopy / sizeof(WCHAR)] = UNICODE_NULL;
272 }
274 {
275 /* Get the status */
277 }
278 _SEH2_END;
279
280 /* Free the buffer allocated by CmpConstructName */
282
283 /* Return status */
284 return Status;
285}
#define CmpAcquireKcbLockShared(k)
Definition: cm_x.h:145
FORCEINLINE VOID CmpReleaseKcbLock(PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cm_x.h:185
PUNICODE_STRING NTAPI CmpConstructName(IN PCM_KEY_CONTROL_BLOCK Kcb)
Definition: cmkcbncb.c:897
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3168
struct _OBJECT_NAME_INFORMATION OBJECT_NAME_INFORMATION
#define STATUS_KEY_DELETED
Definition: ntstatus.h:613
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by CmpCreateObjectTypes().

◆ CmpReleaseTwoKcbLockByKey()

VOID NTAPI CmpReleaseTwoKcbLockByKey ( IN ULONG  ConvKey1,
IN ULONG  ConvKey2 
)

Definition at line 2108 of file cmsysini.c.

2110{
2111 ULONG Index1, Index2;
2112
2113 /* Sanity check */
2115
2116 /* Get hash indexes */
2117 Index1 = GET_HASH_INDEX(ConvKey1);
2118 Index2 = GET_HASH_INDEX(ConvKey2);
2121
2122 /* See which one is highest */
2123 if (Index1 < Index2)
2124 {
2125 /* Grab them in the proper order */
2128 CmpReleaseKcbLockByKey(ConvKey2);
2129 CmpReleaseKcbLockByKey(ConvKey1);
2130 }
2131 else
2132 {
2133 /* Release the first one first, then the second */
2134 if (Index1 != Index2)
2135 {
2138 CmpReleaseKcbLockByKey(ConvKey1);
2139 }
2140 CmpReleaseKcbLockByKey(ConvKey2);
2141 }
2142}
#define GET_HASH_ENTRY(Table, ConvKey)
Definition: cm_x.h:26
FORCEINLINE VOID CmpReleaseKcbLockByKey(ULONG ConvKey)
Definition: cm_x.h:195
PCM_KEY_HASH_TABLE_ENTRY CmpCacheTable
Definition: cmkcbncb.c:18
BOOLEAN NTAPI CmpTestRegistryLockExclusive(VOID)
Definition: cmsysini.c:1998
#define KeGetCurrentThread
Definition: hal.h:55
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ OwnerSize PSID Owner
Definition: rtlfuncs.h:1597

Referenced by CmDeleteKey(), CmpCreateKeyControlBlock(), CmUnloadKey(), and NtUnloadKey2().

◆ CmpSetSystemValues()

NTSTATUS NTAPI CmpSetSystemValues ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 401 of file cmsysini.c.

402{
407
408 ASSERT(LoaderBlock != NULL);
409
410 /* Setup attributes for loader options */
412 L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\"
413 L"Control");
415 &KeyName,
417 NULL,
418 NULL);
420 if (!NT_SUCCESS(Status))
421 return Status;
422
423 /* Setup the value for the system start options */
424 RtlInitUnicodeString(&KeyName, L"SystemStartOptions");
426 &KeyName,
427 0,
428 REG_SZ,
431 if (!NT_SUCCESS(Status))
432 goto Quit;
433
434 /* Setup the value for the system boot device in ARC format */
435 RtlInitUnicodeString(&KeyName, L"SystemBootDevice");
436 RtlCreateUnicodeStringFromAsciiz(&ValueName, LoaderBlock->ArcBootDeviceName);
438 &KeyName,
439 0,
440 REG_SZ,
441 ValueName.Buffer,
442 ValueName.Length);
443
444 /* Free the temporary string */
446
447Quit:
448 /* Close the key and return */
450 return Status;
451}
#define REG_SZ
Definition: layer.c:22
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

Referenced by CmInitSystem1().

◆ CmpSetVersionData()

VOID NTAPI CmpSetVersionData ( VOID  )

Definition at line 2182 of file cmsysini.c.

2183{
2189 ANSI_STRING TempString;
2190 HANDLE SoftwareKeyHandle = NULL;
2191 HANDLE MicrosoftKeyHandle = NULL;
2192 HANDLE WindowsNtKeyHandle = NULL;
2193 HANDLE CurrentVersionKeyHandle = NULL;
2194 WCHAR Buffer[128]; // Buffer large enough to contain a full ULONG in decimal
2195 // representation, and the full 'CurrentType' string.
2196
2197 /*
2198 * Open the 'HKLM\Software\Microsoft\Windows NT\CurrentVersion' key
2199 * (create the intermediate subkeys if needed).
2200 */
2201
2202 RtlInitUnicodeString(&KeyName, L"\\REGISTRY\\MACHINE\\SOFTWARE");
2204 &KeyName,
2206 NULL,
2207 NULL);
2208 Status = NtCreateKey(&SoftwareKeyHandle,
2211 0,
2212 NULL,
2213 0,
2214 NULL);
2215 if (!NT_SUCCESS(Status))
2216 {
2217 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
2218 return;
2219 }
2220
2221 RtlInitUnicodeString(&KeyName, L"Microsoft");
2223 &KeyName,
2225 SoftwareKeyHandle,
2226 NULL);
2227 Status = NtCreateKey(&MicrosoftKeyHandle,
2230 0,
2231 NULL,
2232 0,
2233 NULL);
2234 if (!NT_SUCCESS(Status))
2235 {
2236 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
2237 goto Quit;
2238 }
2239
2240 RtlInitUnicodeString(&KeyName, L"Windows NT");
2242 &KeyName,
2244 MicrosoftKeyHandle,
2245 NULL);
2246 Status = NtCreateKey(&WindowsNtKeyHandle,
2249 0,
2250 NULL,
2251 0,
2252 NULL);
2253 if (!NT_SUCCESS(Status))
2254 {
2255 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
2256 goto Quit;
2257 }
2258
2259 RtlInitUnicodeString(&KeyName, L"CurrentVersion");
2261 &KeyName,
2263 WindowsNtKeyHandle,
2264 NULL);
2265 Status = NtCreateKey(&CurrentVersionKeyHandle,
2268 0,
2269 NULL,
2270 0,
2271 NULL);
2272 if (!NT_SUCCESS(Status))
2273 {
2274 DPRINT1("Failed to create key %wZ (Status: %08lx)\n", &KeyName, Status);
2275 goto Quit;
2276 }
2277
2278 /* Set the 'CurrentVersion' value */
2279 RtlInitUnicodeString(&ValueName, L"CurrentVersion");
2280 NtSetValueKey(CurrentVersionKeyHandle,
2281 &ValueName,
2282 0,
2283 REG_SZ,
2285 CmVersionString.Length + sizeof(WCHAR));
2286
2287 /* Set the 'CurrentBuildNumber' value */
2288 RtlInitUnicodeString(&ValueName, L"CurrentBuildNumber");
2289 RtlInitEmptyUnicodeString(&ValueData, Buffer, sizeof(Buffer));
2291 NtSetValueKey(CurrentVersionKeyHandle,
2292 &ValueName,
2293 0,
2294 REG_SZ,
2295 ValueData.Buffer,
2296 ValueData.Length + sizeof(WCHAR));
2297
2298 /* Set the 'BuildLab' value */
2299 RtlInitUnicodeString(&ValueName, L"BuildLab");
2300 RtlInitAnsiString(&TempString, NtBuildLab);
2302 if (NT_SUCCESS(Status))
2303 {
2304 NtSetValueKey(CurrentVersionKeyHandle,
2305 &ValueName,
2306 0,
2307 REG_SZ,
2308 ValueData.Buffer,
2309 ValueData.Length + sizeof(WCHAR));
2310 }
2311
2312 /* Set the 'CurrentType' value */
2313 RtlInitUnicodeString(&ValueName, L"CurrentType");
2315 L"%s %s",
2316#ifdef CONFIG_SMP
2317 L"Multiprocessor"
2318#else
2319 L"Uniprocessor"
2320#endif
2321 ,
2322#if (DBG == 1)
2323 L"Checked"
2324#else
2325 L"Free"
2326#endif
2327 );
2329 NtSetValueKey(CurrentVersionKeyHandle,
2330 &ValueName,
2331 0,
2332 REG_SZ,
2333 ValueData.Buffer,
2334 ValueData.Length + sizeof(WCHAR));
2335
2336 /* Set the 'CSDVersion' value */
2337 RtlInitUnicodeString(&ValueName, L"CSDVersion");
2338 if (CmCSDVersionString.Length != 0)
2339 {
2340 NtSetValueKey(CurrentVersionKeyHandle,
2341 &ValueName,
2342 0,
2343 REG_SZ,
2345 CmCSDVersionString.Length + sizeof(WCHAR));
2346 }
2347 else
2348 {
2349 NtDeleteValueKey(CurrentVersionKeyHandle, &ValueName);
2350 }
2351
2352 /* Set the 'CSDBuildNumber' value */
2353 RtlInitUnicodeString(&ValueName, L"CSDBuildNumber");
2354 if (CmNtSpBuildNumber != 0)
2355 {
2356 RtlInitEmptyUnicodeString(&ValueData, Buffer, sizeof(Buffer));
2358 NtSetValueKey(CurrentVersionKeyHandle,
2359 &ValueName,
2360 0,
2361 REG_SZ,
2362 ValueData.Buffer,
2363 ValueData.Length + sizeof(WCHAR));
2364 }
2365 else
2366 {
2367 NtDeleteValueKey(CurrentVersionKeyHandle, &ValueName);
2368 }
2369
2370 /* Set the 'SystemRoot' value */
2371 RtlInitUnicodeString(&ValueName, L"SystemRoot");
2372 NtSetValueKey(CurrentVersionKeyHandle,
2373 &ValueName,
2374 0,
2375 REG_SZ,
2377 NtSystemRoot.Length + sizeof(WCHAR));
2378
2379Quit:
2380 /* Close the keys */
2381 if (CurrentVersionKeyHandle != NULL)
2382 NtClose(CurrentVersionKeyHandle);
2383
2384 if (WindowsNtKeyHandle != NULL)
2385 NtClose(WindowsNtKeyHandle);
2386
2387 if (MicrosoftKeyHandle != NULL)
2388 NtClose(MicrosoftKeyHandle);
2389
2390 if (SoftwareKeyHandle != NULL)
2391 NtClose(SoftwareKeyHandle);
2392}
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
#define DBG(x)
Definition: moztest.c:12
NTSYSAPI NTSTATUS NTAPI NtDeleteValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName)
Definition: ntapi.c:1014
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
#define KEY_SET_VALUE
Definition: nt_native.h:1017
UNICODE_STRING NtSystemRoot
Definition: init.c:76
CHAR NtBuildLab[]
Definition: init.c:64
UNICODE_STRING CmVersionString
Definition: init.c:61
ULONG CmNtSpBuildNumber
Definition: init.c:58
UNICODE_STRING CmCSDVersionString
Definition: init.c:62
ULONG NtBuildNumber
Definition: init.c:50

Referenced by NtInitializeRegistry().

◆ CmpTestHiveFlusherLockExclusive()

BOOLEAN NTAPI CmpTestHiveFlusherLockExclusive ( IN PCMHIVE  Hive)

Definition at line 2048 of file cmsysini.c.

2049{
2050 /* Test the lock */
2051 return !ExIsResourceAcquiredExclusiveLite(Hive->FlusherLock) ? FALSE : TRUE;
2052}

◆ CmpTestHiveFlusherLockShared()

BOOLEAN NTAPI CmpTestHiveFlusherLockShared ( IN PCMHIVE  Hive)

Definition at line 2040 of file cmsysini.c.

2041{
2042 /* Test the lock */
2043 return !ExIsResourceAcquiredSharedLite(Hive->FlusherLock) ? FALSE : TRUE;
2044}
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1663

◆ CmpTestRegistryLock()

BOOLEAN NTAPI CmpTestRegistryLock ( VOID  )

Definition at line 1990 of file cmsysini.c.

1991{
1992 /* Test the lock */
1994}

◆ CmpTestRegistryLockExclusive()

BOOLEAN NTAPI CmpTestRegistryLockExclusive ( VOID  )

Definition at line 1998 of file cmsysini.c.

1999{
2000 /* Test the lock */
2002}

Referenced by CmFlushKey(), and CmpReleaseTwoKcbLockByKey().

◆ CmpUnlockHiveFlusher()

VOID NTAPI CmpUnlockHiveFlusher ( IN PCMHIVE  Hive)

Definition at line 2028 of file cmsysini.c.

2029{
2030 /* Sanity check */
2033
2034 /* Release the lock */
2035 ExReleaseResourceLite(Hive->FlusherLock);
2036}
#define CMP_ASSERT_FLUSH_LOCK(h)
Definition: cm_x.h:282
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822

Referenced by CmDeleteKey(), CmDeleteValueKey(), CmFlushKey(), CmLoadKey(), CmpCreateLinkNode(), CmpDoCreate(), CmpDoFlushAll(), CmpUnlinkHiveFromMaster(), and CmSetValueKey().

◆ CmpUnlockRegistry()

VOID NTAPI CmpUnlockRegistry ( VOID  )

Definition at line 2056 of file cmsysini.c.

2057{
2058 /* Sanity check */
2060
2061 /* Check if we should flush the registry */
2063 {
2064 /* The registry should be exclusively locked for this */
2066
2067 /* Flush the registry */
2070 }
2071
2072 /* Release the lock and leave the critical region */
2075}
#define CMP_ASSERT_EXCLUSIVE_REGISTRY_LOCK()
Definition: cm_x.h:67
BOOLEAN NTAPI CmpDoFlushAll(IN BOOLEAN ForceFlush)
Definition: cmapi.c:81
BOOLEAN CmpFlushOnLockRelease
Definition: cmsysini.c:25
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119

Referenced by _Function_class_(), CmDeleteKey(), CmDeleteValueKey(), CmEnumerateKey(), CmEnumerateValueKey(), CmGetSystemDriverList(), CmLoadKey(), CmpDeleteKeyObject(), CmpParseKey(), CmpQueryKeyName(), CmpSecurityMethod(), CmQueryKey(), CmQueryValueKey(), CmSaveKey(), CmSaveMergedKeys(), CmSetValueKey(), CmShutdownSystem(), CmUnloadKey(), NtFlushKey(), NtInitializeRegistry(), NtQueryOpenSubKeys(), and NtUnloadKey2().

◆ CmShutdownSystem()

VOID NTAPI CmShutdownSystem ( VOID  )

Definition at line 2146 of file cmsysini.c.

2147{
2148 PLIST_ENTRY ListEntry;
2149 PCMHIVE Hive;
2150
2151 /* Kill the workers */
2153
2154 /* Flush all hives */
2157
2158 /* Close all hive files */
2159 ListEntry = CmpHiveListHead.Flink;
2160 while (ListEntry != &CmpHiveListHead)
2161 {
2162 Hive = CONTAINING_RECORD(ListEntry, CMHIVE, HiveList);
2163
2164 CmpCloseHiveFiles(Hive);
2165
2166 ListEntry = ListEntry->Flink;
2167 }
2168
2169 /*
2170 * As we flushed all the hives on the disk,
2171 * tell the system we do not want any further
2172 * registry flushing or syncing at this point
2173 * since we are shutting down the registry anyway.
2174 */
2176
2178}
VOID NTAPI CmpShutdownWorkers(VOID)
Definition: cmlazy.c:437
BOOLEAN CmFirstTime
Definition: ntapi.c:17
VOID NTAPI CmpCloseHiveFiles(IN PCMHIVE Hive)
Definition: cminit.c:644

Referenced by PopGracefulShutdown().

Variable Documentation

◆ CmFirstTime

BOOLEAN CmFirstTime
extern

Definition at line 17 of file ntapi.c.

Referenced by CmShutdownSystem(), and NtInitializeRegistry().

◆ CmiVolatileHive

◆ CmpFlushOnLockRelease

BOOLEAN CmpFlushOnLockRelease

Definition at line 25 of file cmsysini.c.

Referenced by CmpUnlockRegistry().

◆ CmpFlushStarveWriters

LONG CmpFlushStarveWriters
extern

Definition at line 27 of file cmlazy.c.

Referenced by _Function_class_(), CmpLockRegistry(), and CmpLockRegistryExclusive().

◆ CmpHiveListHead

LIST_ENTRY CmpHiveListHead

◆ CmpKeyObjectType

◆ CmpLoadWorkerEvent

KEVENT CmpLoadWorkerEvent

Definition at line 21 of file cmsysini.c.

Referenced by _Function_class_(), and CmpInitializeHiveList().

◆ CmpLoadWorkerIncrement

LONG CmpLoadWorkerIncrement

Definition at line 22 of file cmsysini.c.

Referenced by _Function_class_(), and CmpInitializeHiveList().

◆ CmpNoVolatileCreates

BOOLEAN CmpNoVolatileCreates

Definition at line 34 of file cmsysini.c.

Referenced by CmInitSystem1(), CmpInitializeHiveList(), and CmpParseKey().

◆ CmpNoWrite

◆ CmpProfileLoaded

BOOLEAN CmpProfileLoaded

Definition at line 33 of file cmsysini.c.

Referenced by CmLoadKey().

◆ CmpRegistryLock

◆ CmpRegistryLockCaller

PVOID CmpRegistryLockCaller

Definition at line 24 of file cmsysini.c.

Referenced by CmpLockRegistryExclusive().

◆ CmpRegistryLockCallerCaller

PVOID CmpRegistryLockCallerCaller

Definition at line 24 of file cmsysini.c.

Referenced by CmpLockRegistryExclusive().

◆ CmpSelfHealQueueListHead

LIST_ENTRY CmpSelfHealQueueListHead

Definition at line 20 of file cmsysini.c.

Referenced by CmInitSystem1().

◆ CmpSelfHealQueueLock

KGUARDED_MUTEX CmpSelfHealQueueLock

Definition at line 19 of file cmsysini.c.

Referenced by CmInitSystem1().

◆ CmpSpecialBootCondition

BOOLEAN CmpSpecialBootCondition

Definition at line 26 of file cmsysini.c.

Referenced by CmFlushKey(), and CmpInitializeHiveList().

◆ CmpSystemProcess

PEPROCESS CmpSystemProcess

Definition at line 23 of file cmsysini.c.

Referenced by CmInitSystem1().

◆ CmpTraceLevel

ULONG CmpTraceLevel = 0

Definition at line 35 of file cmsysini.c.

◆ CmpWasSetupBoot

BOOLEAN CmpWasSetupBoot

Definition at line 32 of file cmsysini.c.

Referenced by CmLoadKey(), and CmpCmdInit().

◆ HvShutdownComplete

BOOLEAN HvShutdownComplete = FALSE

Definition at line 36 of file cmsysini.c.

Referenced by CmpInitHiveFromFile(), and CmShutdownSystem().