diff --git a/reactos/boot/freeldr/freeldr/CMakeLists.txt b/reactos/boot/freeldr/freeldr/CMakeLists.txt index 0800a9b53ba..8b8b721b688 100644 --- a/reactos/boot/freeldr/freeldr/CMakeLists.txt +++ b/reactos/boot/freeldr/freeldr/CMakeLists.txt @@ -112,8 +112,7 @@ if(ARCH MATCHES i386) arch/i386/xboxmem.c arch/i386/xboxrtc.c arch/i386/xboxvideo.c - arch/i386/ntsetup.c - arch/i386/wlmemory.c + arch/i386/winldr.c windows/headless.c disk/scsiport.c) if(NOT MSVC) @@ -141,8 +140,7 @@ elseif(ARCH MATCHES amd64) arch/i386/pcmem.c arch/i386/pcrtc.c arch/i386/pcvideo.c - arch/amd64/ntsetup.c - arch/amd64/wlmemory.c) + arch/amd64/winldr.c) else() #TBD endif() diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c b/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c deleted file mode 100644 index b6048e792d6..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/amd64/ntsetup.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * PROJECT: EFI Windows Loader - * LICENSE: GPL - See COPYING in the top level directory - * FILE: freeldr/windows/i386/ntsetup.c - * PURPOSE: i386-specific setup for Windows boot - * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org) - */ - -/* INCLUDES ***************************************************************/ - -#include -#include - -// this is needed for new IDT filling -#if 0 -extern ULONG_PTR i386DivideByZero; -extern ULONG_PTR i386DebugException; -extern ULONG_PTR i386NMIException; -extern ULONG_PTR i386Breakpoint; -extern ULONG_PTR i386Overflow; -extern ULONG_PTR i386BoundException; -extern ULONG_PTR i386InvalidOpcode; -extern ULONG_PTR i386FPUNotAvailable; -extern ULONG_PTR i386DoubleFault; -extern ULONG_PTR i386CoprocessorSegment; -extern ULONG_PTR i386InvalidTSS; -extern ULONG_PTR i386SegmentNotPresent; -extern ULONG_PTR i386StackException; -extern ULONG_PTR i386GeneralProtectionFault; -extern ULONG_PTR i386PageFault; // exc 14 -extern ULONG_PTR i386CoprocessorError; // exc 16 -extern ULONG_PTR i386AlignmentCheck; // exc 17 -#endif - -/* FUNCTIONS **************************************************************/ - -// Last step before going virtual -void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock, - PVOID *GdtIdt, - ULONG *PcrBasePage, - ULONG *TssBasePage) -{ - ULONG TssSize; - ULONG TssPages; - ULONG_PTR Pcr = 0; - ULONG_PTR Tss = 0; - ULONG BlockSize, NumPages; - - LoaderBlock->u.I386.CommonDataArea = (PVOID)DbgPrint; // HACK - LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA; - - /* Allocate 2 pages for PCR */ - Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage); - *PcrBasePage = Pcr >> MM_PAGE_SHIFT; - RtlZeroMemory((PVOID)Pcr, 2 * MM_PAGE_SIZE); - - if (Pcr == 0) - { - UiMessageBox("Can't allocate PCR\n"); - return; - } - - /* Allocate TSS */ - TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1); - TssPages = TssSize / MM_PAGE_SIZE; - - Tss = (ULONG_PTR)MmAllocateMemoryWithType(TssSize, LoaderMemoryData); - - *TssBasePage = Tss >> MM_PAGE_SHIFT; - - /* Allocate space for new GDT + IDT */ - BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here? - NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT; - *GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData); - - if (*GdtIdt == NULL) - { - UiMessageBox("Can't allocate pages for GDT+IDT!\n"); - return; - } - - /* Zero newly prepared GDT+IDT */ - RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT); -} diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c b/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c similarity index 91% rename from reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c rename to reactos/boot/freeldr/freeldr/arch/amd64/winldr.c index 7ec5f249ac3..2d4086e1b09 100644 --- a/reactos/boot/freeldr/freeldr/arch/amd64/wlmemory.c +++ b/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c @@ -23,8 +23,8 @@ PHARDWARE_PTE PxeBase; //PHARDWARE_PTE HalPageTable; PVOID GdtIdt; -ULONG PcrBasePage; -ULONG TssBasePage; +ULONG_PTR PcrBasePage; +ULONG_PTR TssBasePage; /* FUNCTIONS **************************************************************/ @@ -152,6 +152,8 @@ MempMapRangeOfPages(ULONG64 VirtualAddress, ULONG64 PhysicalAddress, ULONG cPage { if (!MempMapSinglePage(VirtualAddress, PhysicalAddress)) { + DPRINTM(DPRINT_WINDOWS, "Failed to map page %ld from %p to %p\n", + i, (PVOID)VirtualAddress, (PVOID)PhysicalAddress); return i; } VirtualAddress += PAGE_SIZE; @@ -172,7 +174,8 @@ MempSetupPaging(IN ULONG StartPage, StartPage * PAGE_SIZE, NumberOfPages) != NumberOfPages) { - DPRINTM(DPRINT_WINDOWS,"Failed to map pages 1\n"); + DPRINTM(DPRINT_WINDOWS,"Failed to map pages %ld, %ld\n", + StartPage, NumberOfPages); return FALSE; } @@ -181,7 +184,8 @@ MempSetupPaging(IN ULONG StartPage, StartPage * PAGE_SIZE, NumberOfPages) != NumberOfPages) { - DPRINTM(DPRINT_WINDOWS,"Failed to map pages 2\n"); + DPRINTM(DPRINT_WINDOWS,"Failed to map pages %ld, %ld\n", + StartPage, NumberOfPages); return FALSE; } @@ -227,7 +231,7 @@ WinLdrpMapApic() } BOOLEAN -WinLdrMapSpecialPages(ULONG PcrBasePage) +WinLdrMapSpecialPages() { /* Map the PCR page */ if (!MempMapSinglePage(KIP0PCRADDRESS, PcrBasePage * PAGE_SIZE)) @@ -350,10 +354,8 @@ WinLdrSetProcessorContext(void) DPRINTM(DPRINT_WINDOWS, "leave WinLdrSetProcessorContext\n"); } -WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock) +void WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock) { - ULONG TssSize; - ULONG_PTR KernelStack; ULONG_PTR Pcr = 0; ULONG_PTR Tss = 0; ULONG BlockSize, NumPages; @@ -382,24 +384,25 @@ WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock) /* Allocate space for new GDT + IDT */ BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here? NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT; - *GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData); - - if (*GdtIdt == NULL) + GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData); + if (GdtIdt == NULL) { UiMessageBox("Can't allocate pages for GDT+IDT!\n"); return; } /* Zero newly prepared GDT+IDT */ - RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT); + RtlZeroMemory(GdtIdt, NumPages << MM_PAGE_SHIFT); - /* Write initial context information */ - LoaderBlock->KernelStack = (ULONG_PTR)KernelStack; - LoaderBlock->KernelStack += KERNEL_STACK_SIZE; - LoaderBlock->Prcb = (ULONG_PTR)&Pcr->Prcb; - LoaderBlock->Process = (ULONG_PTR)PdrPage->InitialProcess; - LoaderBlock->Thread = (ULONG_PTR)PdrPage->InitialThread; + // Before we start mapping pages, create a block of memory, which will contain + // PDE and PTEs + if (MempAllocatePageTables() == FALSE) + { + // FIXME: bugcheck + } + /* Map stuff like PCR, KI_USER_SHARED_DATA and Apic */ + WinLdrMapSpecialPages(); } diff --git a/reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c b/reactos/boot/freeldr/freeldr/arch/arm/winldr.c similarity index 100% rename from reactos/boot/freeldr/freeldr/arch/arm/wlmemory.c rename to reactos/boot/freeldr/freeldr/arch/arm/winldr.c diff --git a/reactos/boot/freeldr/freeldr/arch/i386/ntsetup.c b/reactos/boot/freeldr/freeldr/arch/i386/ntsetup.c deleted file mode 100644 index c8275f3e063..00000000000 --- a/reactos/boot/freeldr/freeldr/arch/i386/ntsetup.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * PROJECT: EFI Windows Loader - * LICENSE: GPL - See COPYING in the top level directory - * FILE: freeldr/windows/i386/ntsetup.c - * PURPOSE: i386-specific setup for Windows boot - * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org) - */ - -/* INCLUDES ***************************************************************/ - -#include -#include - -// this is needed for new IDT filling -#if 0 -extern ULONG_PTR i386DivideByZero; -extern ULONG_PTR i386DebugException; -extern ULONG_PTR i386NMIException; -extern ULONG_PTR i386Breakpoint; -extern ULONG_PTR i386Overflow; -extern ULONG_PTR i386BoundException; -extern ULONG_PTR i386InvalidOpcode; -extern ULONG_PTR i386FPUNotAvailable; -extern ULONG_PTR i386DoubleFault; -extern ULONG_PTR i386CoprocessorSegment; -extern ULONG_PTR i386InvalidTSS; -extern ULONG_PTR i386SegmentNotPresent; -extern ULONG_PTR i386StackException; -extern ULONG_PTR i386GeneralProtectionFault; -extern ULONG_PTR i386PageFault; // exc 14 -extern ULONG_PTR i386CoprocessorError; // exc 16 -extern ULONG_PTR i386AlignmentCheck; // exc 17 -#endif - -/* FUNCTIONS **************************************************************/ -#if 0 -// Last step before going virtual -void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock, - PVOID *GdtIdt, - ULONG *PcrBasePage, - ULONG *TssBasePage) -{ - ULONG TssSize; - //ULONG TssPages; - ULONG_PTR Pcr = 0; - ULONG_PTR Tss = 0; - ULONG BlockSize, NumPages; - - LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support - LoaderBlock->u.I386.MachineType = MACHINE_TYPE_ISA; - - /* Allocate 2 pages for PCR */ - Pcr = (ULONG_PTR)MmAllocateMemoryWithType(2 * MM_PAGE_SIZE, LoaderStartupPcrPage); - *PcrBasePage = Pcr >> MM_PAGE_SHIFT; - - if (Pcr == 0) - { - UiMessageBox("Can't allocate PCR\n"); - return; - } - - /* Allocate TSS */ - TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1); - //TssPages = TssSize / MM_PAGE_SIZE; - - Tss = (ULONG_PTR)MmAllocateMemoryWithType(TssSize, LoaderMemoryData); - - *TssBasePage = Tss >> MM_PAGE_SHIFT; - - /* Allocate space for new GDT + IDT */ - BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here? - NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT; - *GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE, LoaderMemoryData); - - if (*GdtIdt == NULL) - { - UiMessageBox("Can't allocate pages for GDT+IDT!\n"); - return; - } - - /* Zero newly prepared GDT+IDT */ - RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT); -} -#endif diff --git a/reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c b/reactos/boot/freeldr/freeldr/arch/i386/winldr.c similarity index 100% rename from reactos/boot/freeldr/freeldr/arch/i386/wlmemory.c rename to reactos/boot/freeldr/freeldr/arch/i386/winldr.c diff --git a/reactos/boot/freeldr/freeldr/cmdline.c b/reactos/boot/freeldr/freeldr/cmdline.c index 7032457da29..d75c63d8db7 100644 --- a/reactos/boot/freeldr/freeldr/cmdline.c +++ b/reactos/boot/freeldr/freeldr/cmdline.c @@ -21,14 +21,14 @@ VOID CmdLineParse(IN PCHAR CmdLine) { PCHAR End, Setting; - ULONG Length, Offset = 0; + ULONG_PTR Length, Offset = 0; // // Set defaults // CmdLineInfo.DefaultOperatingSystem = NULL; CmdLineInfo.TimeOut = -1; - + // // Get timeout // @@ -49,14 +49,14 @@ CmdLineParse(IN PCHAR CmdLine) Setting += sizeof("defaultos=") + sizeof(ANSI_NULL); End = strstr(Setting, " "); if (End) Length = End - Setting; else Length = sizeof(DefaultOs); - + // // Copy the default OS // strncpy(DefaultOs, Setting, Length); CmdLineInfo.DefaultOperatingSystem = DefaultOs; } - + // // Get ramdisk base address // @@ -66,7 +66,7 @@ CmdLineParse(IN PCHAR CmdLine) sizeof(ANSI_NULL), NULL, 0); - + // // Get ramdisk size // diff --git a/reactos/boot/freeldr/freeldr/debug.c b/reactos/boot/freeldr/freeldr/debug.c index 4e5ad6c2a8d..b7b8a5c25a8 100644 --- a/reactos/boot/freeldr/freeldr/debug.c +++ b/reactos/boot/freeldr/freeldr/debug.c @@ -32,15 +32,13 @@ #if defined (DEBUG_ALL) ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_MEMORY | DPRINT_FILESYSTEM | DPRINT_UI | DPRINT_DISK | DPRINT_CACHE | DPRINT_REACTOS | - DPRINT_LINUX | DPRINT_HWDETECT | DPRINT_PELOADER; + DPRINT_LINUX | DPRINT_HWDETECT | DPRINT_PELOADER | DPRINT_WINDOWS; #elif defined (DEBUG_INIFILE) ULONG DebugPrintMask = DPRINT_INIFILE; #elif defined (DEBUG_REACTOS) ULONG DebugPrintMask = DPRINT_REACTOS | DPRINT_REGISTRY; #elif defined (DEBUG_CUSTOM) -ULONG DebugPrintMask = DPRINT_WARNING | - DPRINT_UI | DPRINT_CACHE | DPRINT_REACTOS | - DPRINT_LINUX; +ULONG DebugPrintMask = DPRINT_WARNING | DPRINT_WINDOWS; #else //#elif defined (DEBUG_NONE) ULONG DebugPrintMask = 0; #endif diff --git a/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild b/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild index e8c8fa2526c..1151ce5d2c8 100644 --- a/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild +++ b/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild @@ -41,8 +41,7 @@ xboxmem.c xboxrtc.c xboxvideo.c - ntsetup.c - wlmemory.c + winldr.c @@ -71,8 +70,7 @@ loader.c - ntsetup.c - wlmemory.c + winldr.c hardware.c @@ -93,7 +91,7 @@ - wlmemory.c + winldr.c diff --git a/reactos/boot/freeldr/freeldr/fs/ext2.c b/reactos/boot/freeldr/freeldr/fs/ext2.c index 00d07641bc4..3a0648d2ab7 100644 --- a/reactos/boot/freeldr/freeldr/fs/ext2.c +++ b/reactos/boot/freeldr/freeldr/fs/ext2.c @@ -118,7 +118,7 @@ PEXT2_FILE_INFO Ext2OpenFile(PCSTR FileName) PEXT2_FILE_INFO FileHandle; CHAR SymLinkPath[EXT2_NAME_LEN]; CHAR FullPath[EXT2_NAME_LEN * 2]; - ULONG Index; + ULONG_PTR Index; DPRINTM(DPRINT_FILESYSTEM, "Ext2OpenFile() FileName = %s\n", FileName); diff --git a/reactos/boot/freeldr/freeldr/fs/fat.c b/reactos/boot/freeldr/freeldr/fs/fat.c index 53e3beb8568..863ce504377 100644 --- a/reactos/boot/freeldr/freeldr/fs/fat.c +++ b/reactos/boot/freeldr/freeldr/fs/fat.c @@ -650,7 +650,7 @@ static BOOLEAN FatXSearchDirectoryBufferForFile(PFAT_VOLUME_INFO Volume, PVOID D { ULONG EntryCount; ULONG CurrentEntry; - ULONG FileNameLen; + SIZE_T FileNameLen; FATX_DIRENTRY OurDirEntry; PFATX_DIRENTRY DirEntry = &OurDirEntry; diff --git a/reactos/boot/freeldr/freeldr/include/fs/ext2.h b/reactos/boot/freeldr/freeldr/include/fs/ext2.h index 3458e7dc94a..579729387a4 100644 --- a/reactos/boot/freeldr/freeldr/include/fs/ext2.h +++ b/reactos/boot/freeldr/freeldr/include/fs/ext2.h @@ -183,7 +183,7 @@ typedef struct ext2_dirent EXT2_DIR_ENTRY, *PEXT2_DIR_ENTRY; #define LOG2_BLOCK_SIZE(sb) (sb->log2_block_size + 10) /* The size of an ext2 block in bytes. */ -#define EXT2_BLOCK_SIZE(sb) (1 << LOG2_BLOCK_SIZE(sb)) +#define EXT2_BLOCK_SIZE(sb) (((SIZE_T)1) << LOG2_BLOCK_SIZE(sb)) /* The revision level. */ #define EXT2_REVISION(sb) (sb->revision_level) diff --git a/reactos/boot/freeldr/freeldr/include/mm.h b/reactos/boot/freeldr/freeldr/include/mm.h index 8d325191bcd..eb38ff78982 100644 --- a/reactos/boot/freeldr/freeldr/include/mm.h +++ b/reactos/boot/freeldr/freeldr/include/mm.h @@ -117,7 +117,7 @@ VOID MmFreeMemory(PVOID MemoryPointer); PVOID MmAllocateMemoryAtAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType); PVOID MmAllocateHighestMemoryBelowAddress(ULONG MemorySize, PVOID DesiredAddress, TYPE_OF_MEMORY MemoryType); -PVOID MmHeapAlloc(ULONG MemorySize); +PVOID MmHeapAlloc(SIZE_T MemorySize); VOID MmHeapFree(PVOID MemoryPointer); #define ExAllocatePool(pool, size) MmHeapAlloc(size) diff --git a/reactos/boot/freeldr/freeldr/inffile/inffile.c b/reactos/boot/freeldr/freeldr/inffile/inffile.c index 8d83fa89648..350261546ea 100644 --- a/reactos/boot/freeldr/freeldr/inffile/inffile.c +++ b/reactos/boot/freeldr/freeldr/inffile/inffile.c @@ -320,7 +320,7 @@ InfpAddKeyToLine (PINFCACHELINE Line, if (Line->Key != NULL) return NULL; - Line->Key = (PCHAR)MmHeapAlloc (strlen (Key) + 1); + Line->Key = MmHeapAlloc(strlen(Key) + 1); if (Line->Key == NULL) return NULL; @@ -431,7 +431,7 @@ __inline static int is_eol( struct parser *parser, const CHAR *ptr ) /* push data from current token start up to pos into the current token */ static int push_token( struct parser *parser, const CHAR *pos ) { - unsigned int len = pos - parser->start; + SIZE_T len = pos - parser->start; const CHAR *src = parser->start; CHAR *dst = parser->token + parser->token_len; diff --git a/reactos/boot/freeldr/freeldr/inifile/inifile.c b/reactos/boot/freeldr/freeldr/inifile/inifile.c index 0f9638e67c1..ac633b33757 100644 --- a/reactos/boot/freeldr/freeldr/inifile/inifile.c +++ b/reactos/boot/freeldr/freeldr/inifile/inifile.c @@ -93,7 +93,7 @@ ULONG IniGetSectionSettingNameSize(ULONG_PTR SectionId, ULONG SettingIndex) return 0; // Return the size of the string plus 1 for the null-terminator - return (strlen(SectionItem->ItemName) + 1); + return (ULONG)(strlen(SectionItem->ItemName) + 1); } ULONG IniGetSectionSettingValueSize(ULONG_PTR SectionId, ULONG SettingIndex) @@ -106,7 +106,7 @@ ULONG IniGetSectionSettingValueSize(ULONG_PTR SectionId, ULONG SettingIndex) return 0; // Return the size of the string plus 1 for the null-terminator - return (strlen(SectionItem->ItemValue) + 1); + return (ULONG)(strlen(SectionItem->ItemValue) + 1); } BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize) diff --git a/reactos/boot/freeldr/freeldr/reactos/registry.c b/reactos/boot/freeldr/freeldr/reactos/registry.c index db72f33f329..cd8e074a0f9 100644 --- a/reactos/boot/freeldr/freeldr/reactos/registry.c +++ b/reactos/boot/freeldr/freeldr/reactos/registry.c @@ -27,774 +27,731 @@ static FRLDRHKEY RootKey; VOID RegInitializeRegistry (VOID) { - /* Create root key */ - RootKey = (FRLDRHKEY) MmHeapAlloc (sizeof(KEY)); + /* Create root key */ + RootKey = MmHeapAlloc(sizeof(KEY)); - InitializeListHead (&RootKey->SubKeyList); - InitializeListHead (&RootKey->ValueList); - InitializeListHead (&RootKey->KeyList); + InitializeListHead(&RootKey->SubKeyList); + InitializeListHead(&RootKey->ValueList); + InitializeListHead(&RootKey->KeyList); - RootKey->SubKeyCount = 0; - RootKey->ValueCount = 0; + RootKey->SubKeyCount = 0; + RootKey->ValueCount = 0; - RootKey->NameSize = 4; - RootKey->Name = MmHeapAlloc (4); - wcscpy (RootKey->Name, L"\\"); + RootKey->NameSize = 4; + RootKey->Name = MmHeapAlloc(4); + wcscpy (RootKey->Name, L"\\"); - RootKey->DataType = 0; - RootKey->DataSize = 0; - RootKey->Data = NULL; + RootKey->DataType = 0; + RootKey->DataSize = 0; + RootKey->Data = NULL; - /* Create 'SYSTEM' key */ - RegCreateKey (RootKey, - L"Registry\\Machine\\SYSTEM", - NULL); + /* Create 'SYSTEM' key */ + RegCreateKey (RootKey, + L"Registry\\Machine\\SYSTEM", + NULL); } LONG RegInitCurrentControlSet(BOOLEAN LastKnownGood) { - WCHAR ControlSetKeyName[80]; - FRLDRHKEY SelectKey; - FRLDRHKEY SystemKey; - FRLDRHKEY ControlSetKey; - FRLDRHKEY LinkKey; - ULONG CurrentSet = 0; - ULONG DefaultSet = 0; - ULONG LastKnownGoodSet = 0; - ULONG DataSize; - LONG Error; + WCHAR ControlSetKeyName[80]; + FRLDRHKEY SelectKey; + FRLDRHKEY SystemKey; + FRLDRHKEY ControlSetKey; + FRLDRHKEY LinkKey; + ULONG CurrentSet = 0; + ULONG DefaultSet = 0; + ULONG LastKnownGoodSet = 0; + ULONG DataSize; + LONG Error; - Error = RegOpenKey(NULL, - L"\\Registry\\Machine\\SYSTEM\\Select", - &SelectKey); - if (Error != ERROR_SUCCESS) + Error = RegOpenKey(NULL, + L"\\Registry\\Machine\\SYSTEM\\Select", + &SelectKey); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegOpenKey() failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegOpenKey() failed (Error %u)\n", (int)Error); + return Error; } - DataSize = sizeof(ULONG); - Error = RegQueryValue(SelectKey, - L"Default", - NULL, - (PUCHAR)&DefaultSet, - &DataSize); - if (Error != ERROR_SUCCESS) + DataSize = sizeof(ULONG); + Error = RegQueryValue(SelectKey, + L"Default", + NULL, + (PUCHAR)&DefaultSet, + &DataSize); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); + return Error; } - DataSize = sizeof(ULONG); - Error = RegQueryValue(SelectKey, - L"LastKnownGood", - NULL, - (PUCHAR)&LastKnownGoodSet, - &DataSize); - if (Error != ERROR_SUCCESS) + DataSize = sizeof(ULONG); + Error = RegQueryValue(SelectKey, + L"LastKnownGood", + NULL, + (PUCHAR)&LastKnownGoodSet, + &DataSize); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegQueryValue('Default') failed (Error %u)\n", (int)Error); + return Error; } - CurrentSet = (LastKnownGood == TRUE) ? LastKnownGoodSet : DefaultSet; - wcscpy(ControlSetKeyName, L"ControlSet"); - switch(CurrentSet) + CurrentSet = (LastKnownGood == TRUE) ? LastKnownGoodSet : DefaultSet; + wcscpy(ControlSetKeyName, L"ControlSet"); + switch(CurrentSet) { - case 1: - wcscat(ControlSetKeyName, L"001"); - break; - case 2: - wcscat(ControlSetKeyName, L"002"); - break; - case 3: - wcscat(ControlSetKeyName, L"003"); - break; - case 4: - wcscat(ControlSetKeyName, L"004"); - break; - case 5: - wcscat(ControlSetKeyName, L"005"); - break; + case 1: + wcscat(ControlSetKeyName, L"001"); + break; + case 2: + wcscat(ControlSetKeyName, L"002"); + break; + case 3: + wcscat(ControlSetKeyName, L"003"); + break; + case 4: + wcscat(ControlSetKeyName, L"004"); + break; + case 5: + wcscat(ControlSetKeyName, L"005"); + break; } - Error = RegOpenKey(NULL, - L"\\Registry\\Machine\\SYSTEM", - &SystemKey); - if (Error != ERROR_SUCCESS) + Error = RegOpenKey(NULL, + L"\\Registry\\Machine\\SYSTEM", + &SystemKey); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegOpenKey(SystemKey) failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegOpenKey(SystemKey) failed (Error %lu)\n", Error); + return Error; } - Error = RegOpenKey(SystemKey, - ControlSetKeyName, - &ControlSetKey); - if (Error != ERROR_SUCCESS) + Error = RegOpenKey(SystemKey, + ControlSetKeyName, + &ControlSetKey); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegOpenKey(ControlSetKey) failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegOpenKey(ControlSetKey) failed (Error %lu)\n", Error); + return Error; } - Error = RegCreateKey(SystemKey, - L"CurrentControlSet", - &LinkKey); - if (Error != ERROR_SUCCESS) + Error = RegCreateKey(SystemKey, + L"CurrentControlSet", + &LinkKey); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegCreateKey(LinkKey) failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegCreateKey(LinkKey) failed (Error %lu)\n", Error); + return Error; } - Error = RegSetValue(LinkKey, - NULL, - REG_LINK, - (PCHAR)&ControlSetKey, - sizeof(PVOID)); - if (Error != ERROR_SUCCESS) + Error = RegSetValue(LinkKey, + NULL, + REG_LINK, + (PCHAR)&ControlSetKey, + sizeof(PVOID)); + if (Error != ERROR_SUCCESS) { - DPRINTM(DPRINT_REGISTRY, "RegSetValue(LinkKey) failed (Error %u)\n", (int)Error); - return(Error); + DPRINTM(DPRINT_REGISTRY, "RegSetValue(LinkKey) failed (Error %lu)\n", Error); + return Error; } - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegCreateKey(FRLDRHKEY ParentKey, - PCWSTR KeyName, - PFRLDRHKEY Key) + PCWSTR KeyName, + PFRLDRHKEY Key) { - PLIST_ENTRY Ptr; - FRLDRHKEY SearchKey = NULL; - FRLDRHKEY CurrentKey; - FRLDRHKEY NewKey; - PWCHAR p; - PCWSTR name; - int subkeyLength; - int stringLength; - ULONG NameSize; - int CmpResult; + PLIST_ENTRY Ptr; + FRLDRHKEY SearchKey = NULL; + FRLDRHKEY CurrentKey; + FRLDRHKEY NewKey; + PWCHAR p; + PCWSTR name; + int subkeyLength; + int stringLength; + ULONG NameSize; + int CmpResult; - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - if (*KeyName == L'\\') + if (*KeyName == L'\\') { - KeyName++; - CurrentKey = RootKey; + KeyName++; + CurrentKey = RootKey; } - else if (ParentKey == NULL) + else if (ParentKey == NULL) { - CurrentKey = RootKey; + CurrentKey = RootKey; } - else + else { - CurrentKey = ParentKey; + CurrentKey = ParentKey; } - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; + CurrentKey = (FRLDRHKEY)CurrentKey->Data; } - while (*KeyName != 0) + while (*KeyName != 0) { - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - if (*KeyName == L'\\') - KeyName++; - p = wcschr(KeyName, L'\\'); - if ((p != NULL) && (p != KeyName)) - { - subkeyLength = p - KeyName; - stringLength = subkeyLength + 1; - name = KeyName; - } - else - { - subkeyLength = wcslen(KeyName); - stringLength = subkeyLength; - name = KeyName; - } - NameSize = (subkeyLength + 1) * sizeof(WCHAR); + if (*KeyName == L'\\') + KeyName++; + p = wcschr(KeyName, L'\\'); + if ((p != NULL) && (p != KeyName)) + { + subkeyLength = p - KeyName; + stringLength = subkeyLength + 1; + name = KeyName; + } + else + { + subkeyLength = wcslen(KeyName); + stringLength = subkeyLength; + name = KeyName; + } + NameSize = (subkeyLength + 1) * sizeof(WCHAR); - Ptr = CurrentKey->SubKeyList.Flink; - CmpResult = 1; - while (Ptr != &CurrentKey->SubKeyList) - { - DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); + Ptr = CurrentKey->SubKeyList.Flink; + CmpResult = 1; + while (Ptr != &CurrentKey->SubKeyList) + { + DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); - SearchKey = CONTAINING_RECORD(Ptr, - KEY, - KeyList); - DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); - DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); - CmpResult = _wcsnicmp(SearchKey->Name, name, subkeyLength); - if (CmpResult == 0 && SearchKey->NameSize == NameSize) - break; - else if (CmpResult == -1) - break; + SearchKey = CONTAINING_RECORD(Ptr, KEY, KeyList); + DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); + DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); + CmpResult = _wcsnicmp(SearchKey->Name, name, subkeyLength); - Ptr = Ptr->Flink; - } + if (CmpResult == 0 && SearchKey->NameSize == NameSize) break; + else if (CmpResult == -1) break; - if (CmpResult != 0) - { - /* no key found -> create new subkey */ - NewKey = (FRLDRHKEY)MmHeapAlloc(sizeof(KEY)); - if (NewKey == NULL) - return(ERROR_OUTOFMEMORY); + Ptr = Ptr->Flink; + } - InitializeListHead(&NewKey->SubKeyList); - InitializeListHead(&NewKey->ValueList); + if (CmpResult != 0) + { + /* no key found -> create new subkey */ + NewKey = MmHeapAlloc(sizeof(KEY)); + if (NewKey == NULL) return ERROR_OUTOFMEMORY; - NewKey->SubKeyCount = 0; - NewKey->ValueCount = 0; + InitializeListHead(&NewKey->SubKeyList); + InitializeListHead(&NewKey->ValueList); - NewKey->DataType = 0; - NewKey->DataSize = 0; - NewKey->Data = NULL; + NewKey->SubKeyCount = 0; + NewKey->ValueCount = 0; - InsertTailList(Ptr, &NewKey->KeyList); - CurrentKey->SubKeyCount++; + NewKey->DataType = 0; + NewKey->DataSize = 0; + NewKey->Data = NULL; - NewKey->NameSize = NameSize; - NewKey->Name = (PWCHAR)MmHeapAlloc(NewKey->NameSize); - if (NewKey->Name == NULL) - return(ERROR_OUTOFMEMORY); - memcpy(NewKey->Name, name, NewKey->NameSize - sizeof(WCHAR)); - NewKey->Name[subkeyLength] = 0; + InsertTailList(Ptr, &NewKey->KeyList); + CurrentKey->SubKeyCount++; - DPRINTM(DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey); - DPRINTM(DPRINT_REGISTRY, "NewKey '%S' Length %d\n", NewKey->Name, NewKey->NameSize); + NewKey->NameSize = NameSize; + NewKey->Name = (PWCHAR)MmHeapAlloc(NewKey->NameSize); + if (NewKey->Name == NULL) return ERROR_OUTOFMEMORY; - CurrentKey = NewKey; - } - else - { - CurrentKey = SearchKey; + memcpy(NewKey->Name, name, NewKey->NameSize - sizeof(WCHAR)); + NewKey->Name[subkeyLength] = 0; - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) - { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; - } - } + DPRINTM(DPRINT_REGISTRY, "NewKey 0x%x\n", NewKey); + DPRINTM(DPRINT_REGISTRY, "NewKey '%S' Length %d\n", NewKey->Name, NewKey->NameSize); - KeyName = KeyName + stringLength; + CurrentKey = NewKey; + } + else + { + CurrentKey = SearchKey; + + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) + { + CurrentKey = (FRLDRHKEY)CurrentKey->Data; + } + } + + KeyName = KeyName + stringLength; } - if (Key != NULL) - *Key = CurrentKey; + if (Key != NULL) *Key = CurrentKey; - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegDeleteKey(FRLDRHKEY Key, - PCWSTR Name) + PCWSTR Name) { + if (wcschr(Name, L'\\') != NULL) return ERROR_INVALID_PARAMETER; - if (wcschr(Name, L'\\') != NULL) - return(ERROR_INVALID_PARAMETER); - - - - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegEnumKey(FRLDRHKEY Key, - ULONG Index, - PWCHAR Name, - ULONG* NameSize) + ULONG Index, + PWCHAR Name, + ULONG* NameSize) { - PLIST_ENTRY Ptr; - FRLDRHKEY SearchKey; - ULONG Count = 0; - ULONG Size; + PLIST_ENTRY Ptr; + FRLDRHKEY SearchKey; + ULONG Count = 0; + ULONG Size; - Ptr = Key->SubKeyList.Flink; - while (Ptr != &Key->SubKeyList) + Ptr = Key->SubKeyList.Flink; + while (Ptr != &Key->SubKeyList) { - if (Index == Count) - break; + if (Index == Count) break; - Count++; - Ptr = Ptr->Flink; + Count++; + Ptr = Ptr->Flink; } - if (Ptr == &Key->SubKeyList) - return(ERROR_NO_MORE_ITEMS); + if (Ptr == &Key->SubKeyList) return ERROR_NO_MORE_ITEMS; - SearchKey = CONTAINING_RECORD(Ptr, - KEY, - KeyList); + SearchKey = CONTAINING_RECORD(Ptr, KEY, KeyList); - DPRINTM(DPRINT_REGISTRY, "Name '%S' Length %d\n", SearchKey->Name, SearchKey->NameSize); + DPRINTM(DPRINT_REGISTRY, "Name '%S' Length %d\n", SearchKey->Name, SearchKey->NameSize); - Size = min(SearchKey->NameSize, *NameSize); - *NameSize = Size; - memcpy(Name, SearchKey->Name, Size); + Size = min(SearchKey->NameSize, *NameSize); + *NameSize = Size; + memcpy(Name, SearchKey->Name, Size); - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegOpenKey(FRLDRHKEY ParentKey, - PCWSTR KeyName, - PFRLDRHKEY Key) + PCWSTR KeyName, + PFRLDRHKEY Key) { - PLIST_ENTRY Ptr; - FRLDRHKEY SearchKey = NULL; - FRLDRHKEY CurrentKey; - PWCHAR p; - PCWSTR name; - int subkeyLength; - int stringLength; - ULONG NameSize; + PLIST_ENTRY Ptr; + FRLDRHKEY SearchKey = NULL; + FRLDRHKEY CurrentKey; + PWCHAR p; + PCWSTR name; + int subkeyLength; + int stringLength; + ULONG NameSize; - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - *Key = NULL; + *Key = NULL; - if (*KeyName == L'\\') + if (*KeyName == L'\\') { - KeyName++; - CurrentKey = RootKey; + KeyName++; + CurrentKey = RootKey; } - else if (ParentKey == NULL) + else if (ParentKey == NULL) { - CurrentKey = RootKey; + CurrentKey = RootKey; } - else + else { - CurrentKey = ParentKey; + CurrentKey = ParentKey; } - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; + CurrentKey = (FRLDRHKEY)CurrentKey->Data; } - while (*KeyName != 0) + while (*KeyName != 0) { - DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); + DPRINTM(DPRINT_REGISTRY, "KeyName '%S'\n", KeyName); - if (*KeyName == L'\\') - KeyName++; - p = wcschr(KeyName, L'\\'); - if ((p != NULL) && (p != KeyName)) - { - subkeyLength = p - KeyName; - stringLength = subkeyLength + 1; - name = KeyName; - } - else - { - subkeyLength = wcslen(KeyName); - stringLength = subkeyLength; - name = KeyName; - } - NameSize = (subkeyLength + 1) * sizeof(WCHAR); + if (*KeyName == L'\\') KeyName++; + p = wcschr(KeyName, L'\\'); + if ((p != NULL) && (p != KeyName)) + { + subkeyLength = p - KeyName; + stringLength = subkeyLength + 1; + name = KeyName; + } + else + { + subkeyLength = wcslen(KeyName); + stringLength = subkeyLength; + name = KeyName; + } + NameSize = (subkeyLength + 1) * sizeof(WCHAR); - Ptr = CurrentKey->SubKeyList.Flink; - while (Ptr != &CurrentKey->SubKeyList) - { - DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); + Ptr = CurrentKey->SubKeyList.Flink; + while (Ptr != &CurrentKey->SubKeyList) + { + DPRINTM(DPRINT_REGISTRY, "Ptr 0x%x\n", Ptr); - SearchKey = CONTAINING_RECORD(Ptr, - KEY, - KeyList); + SearchKey = CONTAINING_RECORD(Ptr, KEY, KeyList); - DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); - DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); + DPRINTM(DPRINT_REGISTRY, "SearchKey 0x%x\n", SearchKey); + DPRINTM(DPRINT_REGISTRY, "Searching '%S'\n", SearchKey->Name); - if (SearchKey->NameSize == NameSize && - _wcsnicmp(SearchKey->Name, name, subkeyLength) == 0) - break; + if (SearchKey->NameSize == NameSize && + _wcsnicmp(SearchKey->Name, name, subkeyLength) == 0) break; - Ptr = Ptr->Flink; - } + Ptr = Ptr->Flink; + } - if (Ptr == &CurrentKey->SubKeyList) - { - return(ERROR_PATH_NOT_FOUND); - } - else - { - CurrentKey = SearchKey; + if (Ptr == &CurrentKey->SubKeyList) + { + return ERROR_PATH_NOT_FOUND; + } + else + { + CurrentKey = SearchKey; - /* Check whether current key is a link */ - if (CurrentKey->DataType == REG_LINK) - { - CurrentKey = (FRLDRHKEY)CurrentKey->Data; - } - } + /* Check whether current key is a link */ + if (CurrentKey->DataType == REG_LINK) + { + CurrentKey = (FRLDRHKEY)CurrentKey->Data; + } + } - KeyName = KeyName + stringLength; + KeyName = KeyName + stringLength; } - if (Key != NULL) - *Key = CurrentKey; + if (Key != NULL) + *Key = CurrentKey; - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegSetValue(FRLDRHKEY Key, - PCWSTR ValueName, - ULONG Type, - PCSTR Data, - ULONG DataSize) + PCWSTR ValueName, + ULONG Type, + PCSTR Data, + ULONG DataSize) { - PLIST_ENTRY Ptr; - PVALUE Value = NULL; + PLIST_ENTRY Ptr; + PVALUE Value = NULL; - DPRINTM(DPRINT_REGISTRY, "Key 0x%p, ValueName '%S', Type %ld, Data 0x%p, DataSize %ld\n", - Key, ValueName, Type, Data, DataSize); + DPRINTM(DPRINT_REGISTRY, "Key 0x%p, ValueName '%S', Type %ld, Data 0x%p, DataSize %ld\n", + Key, ValueName, Type, Data, DataSize); - if ((ValueName == NULL) || (*ValueName == 0)) + if ((ValueName == NULL) || (*ValueName == 0)) { - /* set default value */ - if ((Key->Data != NULL) && (Key->DataSize > sizeof(PUCHAR))) - { - MmHeapFree(Key->Data); - } + /* set default value */ + if ((Key->Data != NULL) && (Key->DataSize > sizeof(PUCHAR))) + { + MmHeapFree(Key->Data); + } - if (DataSize <= sizeof(PUCHAR)) - { - Key->DataSize = DataSize; - Key->DataType = Type; - memcpy(&Key->Data, Data, DataSize); - } - else - { - Key->Data = MmHeapAlloc(DataSize); - Key->DataSize = DataSize; - Key->DataType = Type; - memcpy(Key->Data, Data, DataSize); - } + if (DataSize <= sizeof(PUCHAR)) + { + Key->DataSize = DataSize; + Key->DataType = Type; + memcpy(&Key->Data, Data, DataSize); + } + else + { + Key->Data = MmHeapAlloc(DataSize); + Key->DataSize = DataSize; + Key->DataType = Type; + memcpy(Key->Data, Data, DataSize); + } } - else + else { - /* set non-default value */ - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); + /* set non-default value */ + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); - DPRINTM(DPRINT_REGISTRY, "Value->Name '%S'\n", Value->Name); + DPRINTM(DPRINT_REGISTRY, "Value->Name '%S'\n", Value->Name); - if (_wcsicmp(Value->Name, ValueName) == 0) - break; + if (_wcsicmp(Value->Name, ValueName) == 0) break; - Ptr = Ptr->Flink; - } + Ptr = Ptr->Flink; + } - if (Ptr == &Key->ValueList) - { - /* add new value */ - DPRINTM(DPRINT_REGISTRY, "No value found - adding new value\n"); + if (Ptr == &Key->ValueList) + { + /* add new value */ + DPRINTM(DPRINT_REGISTRY, "No value found - adding new value\n"); - Value = (PVALUE)MmHeapAlloc(sizeof(VALUE)); - if (Value == NULL) - return(ERROR_OUTOFMEMORY); + Value = (PVALUE)MmHeapAlloc(sizeof(VALUE)); + if (Value == NULL) return ERROR_OUTOFMEMORY; - InsertTailList(&Key->ValueList, &Value->ValueList); - Key->ValueCount++; + InsertTailList(&Key->ValueList, &Value->ValueList); + Key->ValueCount++; - Value->NameSize = (wcslen(ValueName)+1)*sizeof(WCHAR); - Value->Name = (PWCHAR)MmHeapAlloc(Value->NameSize); - if (Value->Name == NULL) - return(ERROR_OUTOFMEMORY); - wcscpy(Value->Name, ValueName); - Value->DataType = REG_NONE; - Value->DataSize = 0; - Value->Data = NULL; - } + Value->NameSize = (wcslen(ValueName)+1) * sizeof(WCHAR); + Value->Name = MmHeapAlloc(Value->NameSize); + if (Value->Name == NULL) return ERROR_OUTOFMEMORY; + wcscpy(Value->Name, ValueName); + Value->DataType = REG_NONE; + Value->DataSize = 0; + Value->Data = NULL; + } - /* set new value */ - if ((Value->Data != NULL) && (Value->DataSize > sizeof(PUCHAR))) - { - MmHeapFree(Value->Data); - } + /* set new value */ + if ((Value->Data != NULL) && (Value->DataSize > sizeof(PUCHAR))) + { + MmHeapFree(Value->Data); + } - if (DataSize <= sizeof(PUCHAR)) - { - Value->DataSize = DataSize; - Value->DataType = Type; - memcpy(&Value->Data, Data, DataSize); - } - else - { - Value->Data = MmHeapAlloc(DataSize); - if (Value->Data == NULL) - return(ERROR_OUTOFMEMORY); - Value->DataType = Type; - Value->DataSize = DataSize; - memcpy(Value->Data, Data, DataSize); - } + if (DataSize <= sizeof(PUCHAR)) + { + Value->DataSize = DataSize; + Value->DataType = Type; + memcpy(&Value->Data, Data, DataSize); + } + else + { + Value->Data = MmHeapAlloc(DataSize); + if (Value->Data == NULL) return ERROR_OUTOFMEMORY; + Value->DataType = Type; + Value->DataSize = DataSize; + memcpy(Value->Data, Data, DataSize); + } } - return(ERROR_SUCCESS); + return(ERROR_SUCCESS); } LONG RegQueryValue(FRLDRHKEY Key, - PCWSTR ValueName, - ULONG* Type, - PUCHAR Data, - ULONG* DataSize) + PCWSTR ValueName, + ULONG* Type, + PUCHAR Data, + ULONG* DataSize) { - ULONG Size; - PLIST_ENTRY Ptr; - PVALUE Value = NULL; + ULONG Size; + PLIST_ENTRY Ptr; + PVALUE Value = NULL; - if ((ValueName == NULL) || (*ValueName == 0)) + if ((ValueName == NULL) || (*ValueName == 0)) { - /* query default value */ - if (Key->Data == NULL) - return(ERROR_INVALID_PARAMETER); + /* query default value */ + if (Key->Data == NULL) return ERROR_INVALID_PARAMETER; - if (Type != NULL) - *Type = Key->DataType; - if ((Data != NULL) && (DataSize != NULL)) - { - if (Key->DataSize <= sizeof(PUCHAR)) - { - Size = min(Key->DataSize, *DataSize); - memcpy(Data, &Key->Data, Size); - *DataSize = Size; - } - else - { - Size = min(Key->DataSize, *DataSize); - memcpy(Data, Key->Data, Size); - *DataSize = Size; - } - } - else if ((Data == NULL) && (DataSize != NULL)) - { - *DataSize = Key->DataSize; - } + if (Type != NULL) + *Type = Key->DataType; + if ((Data != NULL) && (DataSize != NULL)) + { + if (Key->DataSize <= sizeof(PUCHAR)) + { + Size = min(Key->DataSize, *DataSize); + memcpy(Data, &Key->Data, Size); + *DataSize = Size; + } + else + { + Size = min(Key->DataSize, *DataSize); + memcpy(Data, Key->Data, Size); + *DataSize = Size; + } + } + else if ((Data == NULL) && (DataSize != NULL)) + { + *DataSize = Key->DataSize; + } } - else + else { - /* query non-default value */ - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); + /* query non-default value */ + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); - DPRINTM(DPRINT_REGISTRY, "Searching for '%S'. Value name '%S'\n", ValueName, Value->Name); + DPRINTM(DPRINT_REGISTRY, "Searching for '%S'. Value name '%S'\n", ValueName, Value->Name); - if (_wcsicmp(Value->Name, ValueName) == 0) - break; + if (_wcsicmp(Value->Name, ValueName) == 0) break; - Ptr = Ptr->Flink; - } + Ptr = Ptr->Flink; + } - if (Ptr == &Key->ValueList) - return(ERROR_INVALID_PARAMETER); + if (Ptr == &Key->ValueList) return ERROR_INVALID_PARAMETER; - if (Type != NULL) - *Type = Value->DataType; - if ((Data != NULL) && (DataSize != NULL)) - { - if (Value->DataSize <= sizeof(PUCHAR)) - { - Size = min(Value->DataSize, *DataSize); - memcpy(Data, &Value->Data, Size); - *DataSize = Size; - } - else - { - Size = min(Value->DataSize, *DataSize); - memcpy(Data, Value->Data, Size); - *DataSize = Size; - } - } - else if ((Data == NULL) && (DataSize != NULL)) - { - *DataSize = Value->DataSize; - } + if (Type != NULL) *Type = Value->DataType; + if ((Data != NULL) && (DataSize != NULL)) + { + if (Value->DataSize <= sizeof(PUCHAR)) + { + Size = min(Value->DataSize, *DataSize); + memcpy(Data, &Value->Data, Size); + *DataSize = Size; + } + else + { + Size = min(Value->DataSize, *DataSize); + memcpy(Data, Value->Data, Size); + *DataSize = Size; + } + } + else if ((Data == NULL) && (DataSize != NULL)) + { + *DataSize = Value->DataSize; + } } - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegDeleteValue(FRLDRHKEY Key, - PCWSTR ValueName) + PCWSTR ValueName) { - PLIST_ENTRY Ptr; - PVALUE Value = NULL; + PLIST_ENTRY Ptr; + PVALUE Value = NULL; - if ((ValueName == NULL) || (*ValueName == 0)) + if ((ValueName == NULL) || (*ValueName == 0)) { - /* delete default value */ - if (Key->Data != NULL) - MmFreeMemory(Key->Data); - Key->Data = NULL; - Key->DataSize = 0; - Key->DataType = 0; + /* delete default value */ + if (Key->Data != NULL) MmFreeMemory(Key->Data); + Key->Data = NULL; + Key->DataSize = 0; + Key->DataType = 0; } - else + else { - /* delete non-default value */ - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) - { - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); - if (_wcsicmp(Value->Name, ValueName) == 0) - break; + /* delete non-default value */ + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) + { + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); + if (_wcsicmp(Value->Name, ValueName) == 0) break; - Ptr = Ptr->Flink; - } + Ptr = Ptr->Flink; + } - if (Ptr == &Key->ValueList) - return(ERROR_INVALID_PARAMETER); + if (Ptr == &Key->ValueList) return ERROR_INVALID_PARAMETER; - /* delete value */ - Key->ValueCount--; - if (Value->Name != NULL) - MmFreeMemory(Value->Name); - Value->Name = NULL; - Value->NameSize = 0; + /* delete value */ + Key->ValueCount--; + if (Value->Name != NULL) MmFreeMemory(Value->Name); + Value->Name = NULL; + Value->NameSize = 0; - if (Value->DataSize > sizeof(PUCHAR)) - { - if (Value->Data != NULL) - MmFreeMemory(Value->Data); - } - Value->Data = NULL; - Value->DataSize = 0; - Value->DataType = 0; + if (Value->DataSize > sizeof(PUCHAR)) + { + if (Value->Data != NULL) MmFreeMemory(Value->Data); + } + Value->Data = NULL; + Value->DataSize = 0; + Value->DataType = 0; - RemoveEntryList(&Value->ValueList); - MmFreeMemory(Value); + RemoveEntryList(&Value->ValueList); + MmFreeMemory(Value); } - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } LONG RegEnumValue(FRLDRHKEY Key, - ULONG Index, - PWCHAR ValueName, - ULONG* NameSize, - ULONG* Type, - PUCHAR Data, - ULONG* DataSize) + ULONG Index, + PWCHAR ValueName, + ULONG* NameSize, + ULONG* Type, + PUCHAR Data, + ULONG* DataSize) { - PLIST_ENTRY Ptr; - PVALUE Value; - ULONG Count = 0; + PLIST_ENTRY Ptr; + PVALUE Value; + ULONG Count = 0; - if (Key->Data != NULL) + if (Key->Data != NULL) { - if (Index > 0) - { - Index--; - } - else - { - /* enumerate default value */ - if (ValueName != NULL) - *ValueName = 0; - if (Type != NULL) - *Type = Key->DataType; - if (Data != NULL) + if (Index > 0) { - if (Key->DataSize <= sizeof(PUCHAR)) + Index--; + } + else + { + /* enumerate default value */ + if (ValueName != NULL) *ValueName = 0; + if (Type != NULL) *Type = Key->DataType; + if (Data != NULL) { - memcpy(Data, &Key->Data, min(Key->DataSize, *DataSize)); + if (Key->DataSize <= sizeof(PUCHAR)) + { + memcpy(Data, &Key->Data, min(Key->DataSize, *DataSize)); + } + else + { + memcpy(Data, Key->Data, min(Key->DataSize, *DataSize)); + } } - else - { - memcpy(Data, Key->Data, min(Key->DataSize, *DataSize)); - } - } - if (DataSize != NULL) - *DataSize = min(Key->DataSize, *DataSize); - return(ERROR_SUCCESS); - } + if (DataSize != NULL) *DataSize = min(Key->DataSize, *DataSize); + + return ERROR_SUCCESS; + } } - Ptr = Key->ValueList.Flink; - while (Ptr != &Key->ValueList) + Ptr = Key->ValueList.Flink; + while (Ptr != &Key->ValueList) { - if (Index == Count) - break; + if (Index == Count) break; - Count++; - Ptr = Ptr->Flink; + Count++; + Ptr = Ptr->Flink; } - if (Ptr == &Key->ValueList) - return(ERROR_NO_MORE_ITEMS); + if (Ptr == &Key->ValueList) return ERROR_NO_MORE_ITEMS; - Value = CONTAINING_RECORD(Ptr, - VALUE, - ValueList); + Value = CONTAINING_RECORD(Ptr, VALUE, ValueList); - /* enumerate non-default value */ - if (ValueName != NULL) - memcpy(ValueName, Value->Name, min(Value->NameSize, *NameSize)); - if (Type != NULL) - *Type = Value->DataType; - - if (Data != NULL) + /* enumerate non-default value */ + if (ValueName != NULL) { - if (Value->DataSize <= sizeof(PUCHAR)) + memcpy(ValueName, Value->Name, min(Value->NameSize, *NameSize)); + } + if (Type != NULL) *Type = Value->DataType; + + if (Data != NULL) + { + if (Value->DataSize <= sizeof(PUCHAR)) { - memcpy(Data, &Value->Data, min(Value->DataSize, *DataSize)); + memcpy(Data, &Value->Data, min(Value->DataSize, *DataSize)); } - else + else { - memcpy(Data, Value->Data, min(Value->DataSize, *DataSize)); + memcpy(Data, Value->Data, min(Value->DataSize, *DataSize)); } } - if (DataSize != NULL) - *DataSize = min(Value->DataSize, *DataSize); + if (DataSize != NULL) *DataSize = min(Value->DataSize, *DataSize); - return(ERROR_SUCCESS); + return ERROR_SUCCESS; } ULONG RegGetSubKeyCount (FRLDRHKEY Key) { - return Key->SubKeyCount; + return Key->SubKeyCount; } ULONG RegGetValueCount (FRLDRHKEY Key) { - if (Key->DataSize != 0) - return Key->ValueCount + 1; + if (Key->DataSize != 0) return Key->ValueCount + 1; - return Key->ValueCount; + return Key->ValueCount; } /* EOF */ diff --git a/reactos/boot/freeldr/freeldr/windows/winldr.c b/reactos/boot/freeldr/freeldr/windows/winldr.c index 143da3a8514..9c08d22cb1f 100644 --- a/reactos/boot/freeldr/freeldr/windows/winldr.c +++ b/reactos/boot/freeldr/freeldr/windows/winldr.c @@ -628,7 +628,7 @@ LoadAndBootWindowsCommon( /* Do the machine specific initialization */ WinLdrSetupMachineDependent(LoaderBlock); - /* Turn on paging mode of CPU */ + /* Map pages and create memory descriptors */ WinLdrSetupMemoryLayout(LoaderBlock); /* Save final value of LoaderPagesSpanned */ @@ -640,6 +640,9 @@ LoadAndBootWindowsCommon( DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", KiSystemStartup, LoaderBlockVA); + // Zero KI_USER_SHARED_DATA page + memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); + WinLdrpDumpMemoryDescriptors(LoaderBlockVA); WinLdrpDumpBootDriver(LoaderBlockVA); WinLdrpDumpArcDisks(LoaderBlockVA); diff --git a/reactos/boot/freeldr/freeldr/windows/wlmemory.c b/reactos/boot/freeldr/freeldr/windows/wlmemory.c index 34c66f2ac12..40053dab4b6 100644 --- a/reactos/boot/freeldr/freeldr/windows/wlmemory.c +++ b/reactos/boot/freeldr/freeldr/windows/wlmemory.c @@ -324,9 +324,6 @@ WinLdrSetupMemoryLayout(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock) MempDump(); #endif - // Zero KI_USER_SHARED_DATA page - memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); - return TRUE; } diff --git a/reactos/boot/freeldr/freeldr/windows/wlregistry.c b/reactos/boot/freeldr/freeldr/windows/wlregistry.c index a6b9adb28af..8cf7e34bcfa 100644 --- a/reactos/boot/freeldr/freeldr/windows/wlregistry.c +++ b/reactos/boot/freeldr/freeldr/windows/wlregistry.c @@ -11,7 +11,7 @@ #include #include -// The only global var here, used to mark mem pages as NLS in WinLdrTurnOnPaging() +// The only global var here, used to mark mem pages as NLS in WinLdrSetupMemoryLayout() ULONG TotalNLSSize = 0; BOOLEAN WinLdrGetNLSNames(LPSTR AnsiName,