- most of the churn here is from code and headers imported from trunk.
authorArt Yerkes <art.yerkes@gmail.com>
Mon, 1 Jan 2007 11:32:44 +0000 (11:32 +0000)
committerArt Yerkes <art.yerkes@gmail.com>
Mon, 1 Jan 2007 11:32:44 +0000 (11:32 +0000)
- there are several improvements to freeldr for which ion and fireball are responsible.
- also here is filip's cmlib.
- my changes to freeldr mostly centered around managing the kernel slab and transitioning to the kernel memory
  map.  the new map is built in a new area and installed once we have every page set up.  this is a bit safer
  than the old method.
- the video planes are handed off to ntoskrnl, and some trace macros using the frame buffer are available.
- some hacks are removed.
- current status: LdrInitModuleManagement tries to get the header from hal.dll but fails for some reason.  i
  need to look into it.
- this is a checkpoint, since there's been some interest in seeing how things are progressing.
- you can put any pe-coff powerpc exe (based at 0x80000000) in place of ntoskrnl to test various aspects of
  the boot handoff.  this will be useful for testing our trap handlers and such.
- the toolchain didn't produce correct executables in all cases before, and didn't differentiate rva32 and
  rel32, causing some things to be linked wrong.  so far, the current toolchain (20061231) links correctly,
  using R_PPC_UADDR32 as a surrogate for rva32, since it's never produced by gcc.
- some earlyboot video tracing is in ntoskrnl so i can peek around a bit.

svn path=/branches/powerpc/; revision=25259

38 files changed:
reactos/ReactOS-ppc.rbuild
reactos/boot/freeldr/bootsect/ofwboot.s
reactos/boot/freeldr/freeldr/arch/powerpc/mach.c
reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c
reactos/boot/freeldr/freeldr/arch/powerpc/mmu.c
reactos/boot/freeldr/freeldr/freeldr_base.rbuild
reactos/boot/freeldr/freeldr/mm/mm.c
reactos/boot/freeldr/freeldr/reactos/reactos.c
reactos/boot/freeldr/freeldr/windows/peloader.c
reactos/boot/freeldr/freeldr/windows/winldr.c
reactos/boot/freeldr/freeldr/windows/wlmemory.c
reactos/boot/freeldr/freeldr/windows/wlregistry.c
reactos/include/ddk/winddk.h
reactos/include/ndk/powerpc/ketypes.h
reactos/include/psdk/winnt.h
reactos/include/reactos/arc/arc.h
reactos/include/reactos/font.h
reactos/include/reactos/ppcboot.h
reactos/include/reactos/ppcdebug.h [new file with mode: 0644]
reactos/include/reactos/rosldr.h
reactos/lib/cmlib/cmdata.h
reactos/lib/cmlib/cminit.c
reactos/lib/cmlib/cmlib.h
reactos/lib/cmlib/cmlib.mak
reactos/lib/cmlib/hivebin.c
reactos/lib/cmlib/hivecell.c
reactos/lib/cmlib/hivedata.h
reactos/lib/cmlib/hiveinit.c
reactos/lib/cmlib/hivewrt.c
reactos/ntoskrnl/ex/rundown.c
reactos/ntoskrnl/include/internal/ke_x.h
reactos/ntoskrnl/include/internal/ntoskrnl.h
reactos/ntoskrnl/include/internal/powerpc/ke.h
reactos/ntoskrnl/ke/freeldr.c
reactos/ntoskrnl/ke/powerpc/main_asm.S
reactos/ntoskrnl/ke/thrdobj.c
reactos/ntoskrnl/ldr/loader.c
reactos/tools/ppc.lost+found/link-freeldr

index 6653730..d6f73a4 100644 (file)
   <define name="__cdecl__" empty="true" />
   <define name="dllimport" empty="true" />
   <define name="WORDS_BIGENDIAN" empty="true" />
+  <define name="MB_CUR_MAX">1</define>
   <compilerflag>-fshort-wchar</compilerflag>
   <compilerflag>-fsigned-char</compilerflag>
+  <compilerflag>-map</compilerflag>
   <if property="MP" value="1">
     <define name="CONFIG_SMP" value="1" />
   </if>
index 4158d2d..dde2bec 100644 (file)
@@ -86,7 +86,6 @@ zero_registers:
 
        blr
        
-       .org    0x1000
 freeldr_banner:
        .ascii  "ReactOS OpenFirmware Boot Program\r\n\0"
 
@@ -99,7 +98,7 @@ ofw_memory_size:
        .long   0
        .long   0
        
-       .org    0x2000
+       .org    0x1000
 stack:
        .space  0x4000
 
index 5af5522..8ec7817 100644 (file)
@@ -29,7 +29,7 @@ extern ULONG CacheSizeLimit;
 of_proxy ofproxy;
 void *PageDirectoryStart, *PageDirectoryEnd;
 static int chosen_package, stdin_handle, part_handle = -1, kernel_mem = 0;
-int mmu_handle = 0;
+int mmu_handle = 0, FixedMemory = 0;
 BOOLEAN AcpiPresent = FALSE;
 char BootPath[0x100] = { 0 }, BootPart[0x100] = { 0 }, CmdLine[0x100] = { 0 };
 jmp_buf jmp;
@@ -344,9 +344,12 @@ ULONG PpcGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap,
        /* Hack for pearpc */
        if( kernel_mem ) {
            BiosMemoryMap[slots].Length = kernel_mem * 1024;
-           ofw_claim((int)BiosMemoryMap[slots].BaseAddress,
-                     (int)BiosMemoryMap[slots].Length,
-                     0x1000);
+           if( !FixedMemory ) {
+               ofw_claim((int)BiosMemoryMap[slots].BaseAddress,
+                         (int)BiosMemoryMap[slots].Length,
+                         0x1000);
+               FixedMemory = BiosMemoryMap[slots].BaseAddress;
+           }
            total += BiosMemoryMap[slots].Length;
            slots++;
            break;
@@ -520,6 +523,10 @@ void PpcInit( of_proxy the_ofproxy ) {
     ofw_getprop( chosen_package, "mmu",
                 (char *)&mmu_handle_chosen, sizeof(mmu_handle_chosen) );
 
+    ofw_print_string("Found stdin ");
+    ofw_print_number(stdin_handle_chosen);
+    ofw_print_string("\r\n");
+
     stdin_handle = REV(stdin_handle_chosen);
     mmu_handle = REV(mmu_handle_chosen);
 
index 73ff20e..3674383 100644 (file)
@@ -74,6 +74,7 @@ ULONG RaToPa(ULONG p) {
 #define BAT_GRANULARITY             (64 * 1024)
 #define KernelMemorySize            (16 * 1024 * 1024)
 #define KernelEntryPoint            (KernelEntry - KERNEL_BASE_PHYS) + KernelBase
+#define XROUNDUP(x,n)               ((((ULONG)x) + ((n) - 1)) & (~((n) - 1)))
 
 /* Load Address of Next Module */
 ULONG_PTR NextModuleBase = 0;
@@ -165,6 +166,7 @@ AddPageMapping( DIRECTORY_HEADER *TranslationMap,
                ULONG OldVirt) {
     ULONG Phys;
     DIRECTORY_ENTRY *Entry;
+
     if( !TranslationMap->DirectoryPage ||
        TranslationMap->UsedSpace >= ((1<<PFN_SHIFT)/sizeof(DIRECTORY_ENTRY)) )
     {
@@ -190,9 +192,9 @@ FrLdrStartup(ULONG Magic)
 {
     KernelEntryFn KernelEntryAddress = 
        (KernelEntryFn)(KernelEntry + KernelBase);
-    register ULONG_PTR i asm("r4"), j asm("r5") = 0;
-    register DIRECTORY_HEADER *TranslationMap asm("r6") = 
-       MmAllocateMemory(1<<PFN_SHIFT);
+    ULONG_PTR i, j;
+    DIRECTORY_HEADER *TranslationMap = MmAllocateMemory(4<<PFN_SHIFT);
+    ULONG_PTR stack = ((ULONG_PTR)TranslationMap)+(4<<PFN_SHIFT);
     boot_infos_t *LocalBootInfo = (boot_infos_t *)TranslationMap;
     TranslationMap = (DIRECTORY_HEADER *)
        (((PCHAR)&LocalBootInfo[1]) + sizeof(BootDigits));
@@ -202,17 +204,22 @@ FrLdrStartup(ULONG Magic)
     ULONG_PTR KernelVirtAddr, NewMapSdr = 
        (ULONG_PTR)MmAllocateMemory(128*1024);
     DIRECTORY_ENTRY *Entry;
+    LoaderBlock.ArchExtra = (ULONG)LocalBootInfo;
 
-    NewMapSdr = ROUND_UP(NewMapSdr,64*1024);
+    printf("Translation map: %x\n", TranslationMap);
+    NewMapSdr = XROUNDUP(NewMapSdr,64*1024);
     printf("New SDR1 value will be %x\n", NewMapSdr);
 
     memset(TranslationMap,0,sizeof(*TranslationMap));
 
+    printf("Translation map zeroed\n");
     /* Add the page containing the page directory */
-    AddPageMapping( TranslationMap, (ULONG)TranslationMap, 0 );
+    for( i = (ULONG_PTR)TranslationMap; i < stack; i += (1<<PFN_SHIFT) ) {
+       AddPageMapping( TranslationMap, i, 0 );
+    }
 
-    /* Map freeldr space 0xe00000 ... 0xe50000 */
-    for( i = 0xe00000; i < 0xe50000; i += (1<<PFN_SHIFT),j++ ) {
+    /* Map freeldr space 0xe00000 ... 0xe60000 */
+    for( i = 0xe00000; i < 0xe80000; i += (1<<PFN_SHIFT) ) {
        AddPageMapping( TranslationMap, i, 0 );
     }
 
@@ -225,6 +232,7 @@ FrLdrStartup(ULONG Magic)
     }
 
     printf("Built map of %d pages\n", TranslationMap->NumberOfPages);
+    printf("Local boot info at %x\n", LocalBootInfo);
 
     /* 
      * Stuff page table entries for the page containing this code,
@@ -243,11 +251,12 @@ FrLdrStartup(ULONG Magic)
     }
 
     /* Tell them we're booting */
-    DrawNumber(LocalBootInfo,0x1cabba9e,10,100);
+    DrawNumber(LocalBootInfo,(ULONG)&LoaderBlock,10,100);
     DrawNumber(LocalBootInfo,(ULONG)KernelEntryAddress,100,100);
 
     SetSDR1( NewMapSdr );
-    KernelEntryAddress( (void*)LocalBootInfo );
+    KernelEntryAddress( (void*)&LoaderBlock );
+    /* Nothing more */
     while(1);
 }
 
@@ -364,6 +373,12 @@ FrLdrSetupPageDirectory(VOID)
 {
 }
 
+ULONG SignExtend24(ULONG Base, ULONG Delta)
+{
+    Delta = (Base & 0xfffffc) + Delta;
+    return (Base & 0xff000003) | (Delta & 0xfffffc);
+}
+
 /*++
  * FrLdrMapKernel
  * INTERNAL
@@ -402,6 +417,7 @@ FrLdrMapKernel(FILE *KernelImage)
     ULONG_PTR Delta;
     PUSHORT ShortPtr;
     PULONG LongPtr;
+    PLOADER_MODULE ModuleData;
 
     /* Allocate 1024 bytes for PE Header */
     ImageHeader = (PIMAGE_DOS_HEADER)MmAllocateMemory(1024);
@@ -519,6 +535,11 @@ FrLdrMapKernel(FILE *KernelImage)
                     *ShortPtr += HIWORD(Delta);
                     break;
 
+               case IMAGE_REL_BASED_HIGHADJ:
+                   *ShortPtr += 
+                       HIWORD(Delta) + ((LOWORD(Delta) & 0x8000) ? 1 : 0);
+                   break;
+
                 case IMAGE_REL_BASED_LOW:
                     *ShortPtr += LOWORD(Delta);
                     break;
@@ -528,8 +549,13 @@ FrLdrMapKernel(FILE *KernelImage)
                     *LongPtr += Delta;
                     break;
 
+               case IMAGE_REL_BASED_MIPS_JMPADDR:
+                   LongPtr = (PULONG)ShortPtr;
+                   *LongPtr = SignExtend24(*LongPtr,Delta);
+                   break;
+
                default:
-                   printf("Unknown relocation %d\n", *TypeOffset >> 12);
+                   //printf("Unknown relocation %d\n", *TypeOffset >> 12);
                    break;
             }
 
@@ -540,8 +566,13 @@ FrLdrMapKernel(FILE *KernelImage)
         RelocationDir = (PIMAGE_BASE_RELOCATION)((ULONG_PTR)RelocationDir + RelocationDir->SizeOfBlock);
     }
 
+    ModuleData = &reactos_modules[LoaderBlock.ModsCount];
+    ModuleData->ModStart = (ULONG)KernelMemory;
     /* Increase the next Load Base */
     NextModuleBase = ROUND_UP((ULONG)KernelMemory + ImageSize, PAGE_SIZE);
+    ModuleData->ModEnd = NextModuleBase;
+    ModuleData->String = (ULONG)"ntoskrnl.exe";
+    LoaderBlock.ModsCount++;
 
     /* Return Success */
     return TRUE;
@@ -580,6 +611,11 @@ FrLdrLoadModule(FILE *ModuleImage,
     ModuleData->ModStart = NextModuleBase;
     ModuleData->ModEnd = NextModuleBase + LocalModuleSize;
 
+    printf("Module size %x len %x name %s\n", 
+          ModuleData->ModStart,
+          ModuleData->ModEnd - ModuleData->ModStart,
+          ModuleName);
+
     /* Save name */
     strcpy(NameBuffer, ModuleName);
     ModuleData->String = (ULONG_PTR)NameBuffer;
index 363e418..4f4ee70 100644 (file)
@@ -230,7 +230,23 @@ inline int GetSDR1() {
 }
 
 inline void SetSDR1( int sdr ) {
+#if 0
+    int i,j;
+#endif
     __asm__("mtsdr1 3");
+#if 0
+    __asm__("sync");
+    __asm__("isync");
+    __asm__("ptesync");
+    
+    for( i = 0; i < 256; i++ ) {
+       j = i << 12;
+       __asm__("tlbie %0,0" : : "r" (j));
+    }
+    __asm__("eieio");
+    __asm__("tlbsync");
+    __asm__("ptesync");
+#endif
 }
 
 inline int BatHit( int bath, int batl, int virt ) {
@@ -319,12 +335,6 @@ BOOLEAN InsertPageEntry( int virt, int phys, int slot, int _sdr1 ) {
        SetPhys( ptegaddr + (i * 8), ptehi );
        SetPhys( ptegaddr + (i * 8) + 4, ptelo );
 
-       __asm__("ptesync");
-       __asm__("tlbie %0,0" : : "r" (virt));
-       __asm__("eieio");
-       __asm__("tlbsync");
-       __asm__("ptesync");
-
        return TRUE;
     }
 
index be33668..9a64ccd 100644 (file)
@@ -54,6 +54,7 @@
        </directory>
        <directory name="rtl">
                <file>list.c</file>
+               <file>libsupp.c</file>
        </directory>
        <directory name="ui">
                <file>gui.c</file>
index 91fd0bd..b049aee 100644 (file)
@@ -92,8 +92,10 @@ PVOID MmAllocateMemory(ULONG MemorySize)
        if (FreePagesInLookupTable < PagesNeeded)
        {
 #ifdef _M_PPC
+               ULONG ptr;
                printf("Allocating %d bytes directly ...\n", MemorySize);
-               MemPointer = (PVOID)ofw_claim(0,MemorySize,MM_PAGE_SIZE);
+               ptr = ofw_claim(0,MemorySize,MM_PAGE_SIZE);
+               MemPointer = (PVOID)(REV(ptr));
 #endif
                if( !MemPointer ) 
                {
index b04b8bd..c170d89 100644 (file)
@@ -30,8 +30,13 @@ LOADER_MODULE                        reactos_modules[64];            // Array to hold boot module info loaded f
 char                                   reactos_module_strings[64][256];        // Array to hold module names
 unsigned long                  reactos_memory_map_descriptor_size;
 memory_map_t                   reactos_memory_map[32];         // Memory map
-
+ARC_DISK_SIGNATURE      reactos_arc_disk_info[32]; // ARC Disk Information
+char                    reactos_arc_strings[32][256];
+unsigned long           reactos_disk_count = 0;
+CHAR szHalName[255];
+CHAR szBootPath[255];
 static CHAR szLoadingMsg[] = "Loading ReactOS...";
+BOOLEAN FrLdrBootType;
 
 static BOOLEAN
 NTAPI
@@ -123,6 +128,7 @@ LoadKernelSymbols(PCHAR szKernelName, int nPos)
   PROSSYM_INFO RosSymInfo;
   ULONG Size;
   ULONG_PTR Base;
+  //return TRUE;
 
   RosSymInit(&FreeldrCallbacks);
 
@@ -562,14 +568,12 @@ VOID
 LoadAndBootReactOS(PCSTR OperatingSystemName)
 {
        PFILE FilePointer;
-       CHAR  name[1024];
-       CHAR  value[1024];
-       CHAR  SystemPath[1024];
-       CHAR  szKernelName[1024];
-       CHAR  szHalName[1024];
-       CHAR  szFileName[1024];
-       CHAR  szBootPath[256];
-       UINT   i;
+       CHAR name[255];
+       CHAR value[255];
+       CHAR SystemPath[255];
+       CHAR szKernelName[255];
+       CHAR szFileName[255];
+       UINT i;
        CHAR  MsgBuffer[256];
        ULONG SectionId;
 
@@ -595,6 +599,8 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
        UiDrawStatusText("Detecting Hardware...");
     UiDrawProgressBarCenter(1, 100, szLoadingMsg);
 
+    printf("LoadAndBootReactOS\n");
+
        /*
         * Setup multiboot information structure
         */
@@ -602,17 +608,21 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
        LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
        LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
        LoaderBlock.BootDevice = 0xffffffff;
-       LoaderBlock.CommandLine = (unsigned long)reactos_kernel_cmdline;
+       LoaderBlock.CommandLine = (ULONG)reactos_kernel_cmdline;
        LoaderBlock.ModsCount = 0;
-       LoaderBlock.ModsAddr = (unsigned long)reactos_modules;
+       LoaderBlock.ModsAddr = (ULONG)reactos_modules;
+       LoaderBlock.DrivesAddr = (ULONG)reactos_arc_disk_info;
        LoaderBlock.MmapLength = (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP)(PVOID)&reactos_memory_map, 32) * sizeof(memory_map_t);
+       printf("Got memory map length: %d\n", LoaderBlock.MmapLength);
        if (LoaderBlock.MmapLength)
        {
                LoaderBlock.MmapAddr = (unsigned long)&reactos_memory_map;
                LoaderBlock.Flags |= MB_FLAGS_MEM_INFO | MB_FLAGS_MMAP_INFO;
-               reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
+               *((PULONG)(LoaderBlock.MmapAddr - sizeof(ULONG))) = 
+                   reactos_memory_map_descriptor_size = sizeof(memory_map_t); // GetBiosMemoryMap uses a fixed value of 24
                DbgPrint((DPRINT_REACTOS, "memory map length: %d\n", LoaderBlock.MmapLength));
                DbgPrint((DPRINT_REACTOS, "dumping memory map:\n"));
+               printf("memory map length: %d\n", LoaderBlock.MmapLength);
                for (i=0; i<(LoaderBlock.MmapLength/sizeof(memory_map_t)); i++)
                {
                        if (BiosMemoryUsable == reactos_memory_map[i].type &&
@@ -634,6 +644,10 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
                                  reactos_memory_map[i].base_addr_low,
                                  reactos_memory_map[i].length_low,
                                  reactos_memory_map[i].type));
+                       printf("start: %x size: %x type %d\n",
+                                 reactos_memory_map[i].base_addr_low,
+                                 reactos_memory_map[i].length_low,
+                                 reactos_memory_map[i].type);
                }
        }
        DbgPrint((DPRINT_REACTOS, "low_mem = %d\n", LoaderBlock.MemLower));
@@ -679,7 +693,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
        /*
         * Read the optional kernel parameters (if any)
         */
-       if (IniReadSettingByName(SectionId, "Options", value, 1024))
+       if (IniReadSettingByName(SectionId, "Options", value, sizeof(value)))
        {
                strcat(reactos_kernel_cmdline, " ");
                strcat(reactos_kernel_cmdline, value);
@@ -692,6 +706,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
     UiDrawProgressBarCenter(5, 100, szLoadingMsg);
 
        if (AcpiPresent) LoaderBlock.Flags |= MB_FLAGS_ACPI_TABLE;
+    LoaderBlock.DrivesCount = reactos_disk_count;
 
        UiDrawStatusText("Loading...");
 
@@ -715,7 +730,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
         * Find the kernel image name
         * and try to load the kernel off the disk
         */
-       if(IniReadSettingByName(SectionId, "Kernel", value, 1024))
+       if(IniReadSettingByName(SectionId, "Kernel", value, sizeof(value)))
        {
                /*
                 * Set the name and
@@ -739,13 +754,11 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
                strcat(szKernelName, value);
        }
 
-    if (!FrLdrLoadKernel(szKernelName, 5)) return;
-
        /*
         * Find the HAL image name
         * and try to load the kernel off the disk
         */
-       if(IniReadSettingByName(SectionId, "Hal", value, 1024))
+       if(IniReadSettingByName(SectionId, "Hal", value, sizeof(value)))
        {
                /*
                 * Set the name and
@@ -769,19 +782,10 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
                strcat(szHalName, value);
        }
 
-       if (!FrLdrLoadDriver(szHalName, 10))
-               return;
-
-#if 0
-    /* Load bootvid */
-               strcpy(value, "INBV.DLL");
-               strcpy(szHalName, szBootPath);
-               strcat(szHalName, "SYSTEM32\\");
-               strcat(szHalName, value);
+    /* Load the kernel */
+    if (!FrLdrLoadKernel(szKernelName, 5)) return;
+    if (!FrLdrLoadDriver(szHalName, 6)) return;
 
-       if (!FrLdrLoadDriver(szHalName, 10))
-               return;
-#endif
        /*
         * Load the System hive from disk
         */
@@ -820,11 +824,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
        /*
         * Import the loaded system hive
         */
-       if( !RegImportBinaryHive((PCHAR)Base, Size) )
-       {
-           printf("Could not load system hive\n");
-           return;
-       }
+       RegImportBinaryHive((PCHAR)Base, Size);
 
        /*
         * Initialize the 'CurrentControlSet' link
@@ -874,8 +874,7 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
 
 #undef DbgPrint
 ULONG
-__cdecl
-DbgPrint(PCCH Format, ...)
+DbgPrint(const char *Format, ...)
 {
        va_list ap;
        CHAR Buffer[512];
index 9419dd4..1f1e75f 100644 (file)
 \r
 /* FUNCTIONS **************************************************************/\r
 \r
+BOOLEAN\r
+WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
+                        IN PCH DllName,\r
+                        OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry)\r
+{\r
+       return FALSE;\r
+}\r
+\r
+\r
 BOOLEAN\r
 WinLdrScanImportDescriptorTable(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,\r
                                 IN PCCH DirectoryPath,\r
index bef20f4..603965e 100644 (file)
 //#define NDEBUG
 #include <debug.h>
 
+//FIXME: Do a better way to retrieve Arc disk information
+extern ULONG reactos_disk_count;
+extern ARC_DISK_SIGNATURE reactos_arc_disk_info[];
+extern char reactos_arc_strings[32][256];
+
+ARC_DISK_SIGNATURE BldrDiskInfo[32];
+CHAR BldrArcNames[32][256];
+
+BOOLEAN
+WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
+                        IN PCH DllName,
+                        OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry);
+
+// debug stuff
 VOID DumpMemoryAllocMap(VOID);
 VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
+VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock);
+VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock);
+
 
 void InitializeHWConfig(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
 {
@@ -85,6 +102,14 @@ AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
        InitializeListHead(&LoaderBlock->MemoryDescriptorListHead);
        InitializeListHead(&LoaderBlock->BootDriverListHead);
 
+       /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */
+       LoaderBlock->NlsData = MmAllocateMemory(sizeof(NLS_DATA_BLOCK));
+       if (LoaderBlock->NlsData == NULL)
+       {
+               UiMessageBox("Failed to allocate memory for NLS table data!");
+               return;
+       }
+       RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK));
 
        *OutLoaderBlock = LoaderBlock;
 }
@@ -95,11 +120,12 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock)
 {
        //CHAR  Options[] = "/CRASHDEBUG /DEBUGPORT=COM1 /BAUDRATE=115200";
        CHAR    Options[] = "/NODEBUG";
-       CHAR    SystemRoot[] = "\\WINNT";
+       CHAR    SystemRoot[] = "\\WINNT\\";
        CHAR    HalPath[] = "\\";
        CHAR    ArcBoot[] = "multi(0)disk(0)rdisk(1)partition(1)";
        CHAR    ArcHal[] = "multi(0)disk(0)rdisk(1)partition(1)";
 
+       ULONG i;
        PLOADER_PARAMETER_EXTENSION Extension;
 
        LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support
@@ -132,17 +158,31 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock)
        /* Arc devices */
        LoaderBlock->ArcDiskInformation = (PARC_DISK_INFORMATION)MmAllocateMemory(sizeof(ARC_DISK_INFORMATION));
        InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
-       List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
-       LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
 
-       /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */
-       LoaderBlock->NlsData = MmAllocateMemory(sizeof(NLS_DATA_BLOCK));
-       if (LoaderBlock->NlsData == NULL)
+       /* Convert ARC disk information from freeldr to a correct format */
+       for (i = 0; i < reactos_disk_count; i++)
        {
-               UiMessageBox("Failed to allocate memory for NLS table data!");
-               return;
+               PARC_DISK_SIGNATURE ArcDiskInfo;
+
+               /* Get the ARC structure */
+               ArcDiskInfo = &BldrDiskInfo[i];
+
+               /* Copy the data over */
+               ArcDiskInfo->Signature = reactos_arc_disk_info[i].Signature;
+               ArcDiskInfo->CheckSum = reactos_arc_disk_info[i].CheckSum;
+
+               /* Copy the ARC Name */
+               strcpy(BldrArcNames[i], reactos_arc_disk_info[i].ArcName);
+               ArcDiskInfo->ArcName = BldrArcNames[i];
+
+               /* Insert into the list */
+               InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
+                       &ArcDiskInfo->ListEntry);
        }
-       RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK));
+
+       /* Convert the list to virtual address */
+       List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
+       LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
 
        /* Create configuration entries */
        InitializeHWConfig(LoaderBlock);
@@ -224,6 +264,111 @@ void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
        RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT);
 }
 
+BOOLEAN
+WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
+                       LPSTR BootPath,
+                       PUNICODE_STRING FilePath,
+                       ULONG Flags,
+                       PLDR_DATA_TABLE_ENTRY *DriverDTE)
+{
+       CHAR FullPath[1024];
+       CHAR DriverPath[1024];
+       CHAR DllName[1024];
+       PCHAR DriverNamePos;
+       BOOLEAN Status;
+       PVOID DriverBase;
+
+       // Separate the path to file name and directory path
+       sprintf(DriverPath, "%wZ", FilePath);
+       DriverNamePos = strrchr(DriverPath, '\\');
+       if (DriverNamePos != NULL)
+       {
+               // Copy the name
+               strcpy(DllName, DriverNamePos+1);
+
+               // Cut out the name from the path
+               *(DriverNamePos+1) = 0;
+       }
+
+       DbgPrint((DPRINT_WINDOWS, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock));
+
+
+       // Check if driver is already loaded
+       Status = WinLdrCheckForLoadedDll(LoaderBlock, DllName, DriverDTE);
+       if (Status)
+       {
+               // We've got the pointer to its DTE, just return success
+               return TRUE;
+       }
+
+       // It's not loaded, we have to load it
+       sprintf(FullPath,"%s%wZ", BootPath, FilePath);
+       Status = WinLdrLoadImage(FullPath, &DriverBase);
+       if (!Status)
+               return FALSE;
+
+       // Allocate a DTE for it
+       Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE);
+       if (!Status)
+       {
+               DbgPrint((DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n"));
+               return FALSE;
+       }
+
+       // Modify any flags, if needed
+       (*DriverDTE)->Flags |= Flags;
+
+       // Look for any dependencies it may have, and load them too
+       sprintf(FullPath,"%s%s", BootPath, DriverPath);
+       Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE);
+       if (!Status)
+       {
+               DbgPrint((DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n",
+                       FullPath));
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+BOOLEAN
+WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
+                      LPSTR BootPath)
+{
+       PLIST_ENTRY NextBd;
+       PBOOT_DRIVER_LIST_ENTRY BootDriver;
+       BOOLEAN Status;
+
+       // Walk through the boot drivers list
+       NextBd = LoaderBlock->BootDriverListHead.Flink;
+
+       while (NextBd != &LoaderBlock->BootDriverListHead)
+       {
+               BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry);
+
+               //DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
+               //      BootDriver->DataTableEntry, &BootDriver->RegistryPath));
+
+               // Paths are relative (FIXME: Are they always relative?)
+
+               // Load it
+               Status = WinLdrLoadDeviceDriver(LoaderBlock, BootPath, &BootDriver->FilePath,
+                       0, &BootDriver->DataTableEntry);
+
+               // If loading failed - cry loudly
+               //FIXME: Maybe remove it from the list and try to continue?
+               if (!Status)
+               {
+                       UiMessageBox("Can't load boot driver!");
+                       return FALSE;
+               }
+
+               NextBd = BootDriver->ListEntry.Flink;
+       }
+
+       return TRUE;
+}
+
 VOID
 LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
 {
@@ -243,8 +388,6 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
        ULONG PcrBasePage=0;
        ULONG TssBasePage=0;
 
-
-
        //sprintf(MsgBuffer,"Booting Microsoft(R) Windows(R) OS version '%04x' is not implemented yet", OperatingSystemVersion);
        //UiMessageBox(MsgBuffer);
 
@@ -257,6 +400,13 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
                return;
        }
 
+       UiDrawBackdrop();
+       UiDrawStatusText("Detecting Hardware...");
+       UiDrawProgressBarCenter(1, 100, "Loading Windows...");
+
+       //FIXME: This is needed only for MachHwDetect() which performs registry operations!
+       RegInitializeRegistry();
+
        /* Make sure the system path is set in the .ini file */
        if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath)))
        {
@@ -271,6 +421,9 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
                return;
        }
 
+       /* Detect hardware */
+       MachHwDetect();
+
        UiDrawStatusText("Loading...");
 
        /* Try to open system drive */
@@ -331,17 +484,16 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
        if (KdComDTE)
                WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KdComDTE);
 
-       /* Initialize Phase 1 - before NLS */
-       WinLdrInitializePhase1(LoaderBlock);
-
        /* Load Hive, and then NLS data, OEM font, and prepare boot drivers list */
        Status = WinLdrLoadAndScanSystemHive(LoaderBlock, BootPath);
        DbgPrint((DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status));
 
-       /* FIXME: Load OEM HAL font, should be moved to WinLdrLoadAndScanSystemHive() */
-
        /* Load boot drivers */
-       //WinLdrLoadBootDrivers();
+       Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
+       DbgPrint((DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status));
+
+       /* Initialize Phase 1 - no drivers loading anymore */
+       WinLdrInitializePhase1(LoaderBlock);
 
        /* Alloc PCR, TSS, do magic things with the GDT/IDT */
        WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
@@ -361,6 +513,8 @@ LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
                KiSystemStartup, LoaderBlockVA));
 
        WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
+       WinLdrpDumpBootDriver(LoaderBlockVA);
+       WinLdrpDumpArcDisks(LoaderBlockVA);
 
        //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
        //while (1) {};
@@ -394,3 +548,41 @@ WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
                NextMd = MemoryDescriptor->ListEntry.Flink;
        }
 }
+
+VOID
+WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock)
+{
+       PLIST_ENTRY NextBd;
+       PBOOT_DRIVER_LIST_ENTRY BootDriver;
+
+       NextBd = LoaderBlock->BootDriverListHead.Flink;
+
+       while (NextBd != &LoaderBlock->BootDriverListHead)
+       {
+               BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, ListEntry);
+
+               DbgPrint((DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
+                       BootDriver->DataTableEntry, &BootDriver->RegistryPath));
+
+               NextBd = BootDriver->ListEntry.Flink;
+       }
+}
+
+VOID
+WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
+{
+       PLIST_ENTRY NextBd;
+       PARC_DISK_SIGNATURE ArcDisk;
+
+       NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
+
+       while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
+       {
+               ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
+
+               DbgPrint((DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
+                       ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature));
+
+               NextBd = ArcDisk->ListEntry.Flink;
+       }
+}
index 9f6cbc5..7848a3e 100644 (file)
@@ -15,6 +15,8 @@
 #define NDEBUG\r
 #include <debug.h>\r
 \r
+extern ULONG TotalNLSSize;\r
+\r
 // This is needed because headers define wrong one for ReactOS\r
 #undef KIP0PCRADDRESS\r
 #define KIP0PCRADDRESS                      0xffdff000\r
@@ -300,7 +302,7 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
        // Check if it's more than the allowed for OS loader\r
        // if yes - don't map the pages, just add as FirmwareTemporary\r
        //\r
-       if (BasePage + PageCount > LOADER_HIGH_ZONE)\r
+       if (BasePage + PageCount > LOADER_HIGH_ZONE && (Type != LoaderNlsData))\r
        {\r
                Mad[MadCount].MemoryType = LoaderFirmwareTemporary;\r
 \r
@@ -353,24 +355,9 @@ MempAddMemoryBlock(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
        else\r
        {\r
                //\r
-               // Now choose memory type as usual. FIXME!!!\r
+               // Set memory type\r
                //\r
-               if (Type == 0)\r
-               {\r
-                       Mad[MadCount].MemoryType = LoaderFree;\r
-               }\r
-               else if (Type != 0 && Type != 1)\r
-               {\r
-                       Mad[MadCount].MemoryType = LoaderFirmwarePermanent;\r
-               }\r
-               else if (Type == 1)\r
-               {\r
-                       Mad[MadCount].MemoryType = LoaderSystemCode;\r
-               }\r
-               else\r
-               {\r
-                       Mad[MadCount].MemoryType = LoaderFirmwarePermanent;\r
-               }\r
+               Mad[MadCount].MemoryType = Type;\r
 \r
                //\r
                // Add descriptor\r
@@ -397,12 +384,15 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
                    ULONG TssBasePage,\r
                    PVOID GdtIdt)\r
 {\r
-#ifdef _M_IX86\r
        ULONG i, PagesCount;\r
-       ULONG LastPageIndex, LastPageType;\r
+       ULONG LastPageIndex, LastPageType, NtType;\r
        PPAGE_LOOKUP_TABLE_ITEM MemoryMap;\r
        ULONG NoEntries;\r
+#if 0\r
        PKTSS Tss;\r
+#endif\r
+       PVOID NlsBase = VaToPa(((PNLS_DATA_BLOCK)VaToPa(LoaderBlock->NlsData))->AnsiCodePageData);\r
+       ULONG NlsBasePage = (ULONG_PTR)NlsBase >> PAGE_SHIFT;\r
 \r
        //\r
        // Creating a suitable memory map for the Windows can be tricky, so let's\r
@@ -439,7 +429,8 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
                return FALSE;\r
        }\r
 \r
-       DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries\n"));\r
+       DbgPrint((DPRINT_WINDOWS, "Got memory map with %d entries, NlsBasePage 0x%X\n",\r
+               NoEntries, NlsBasePage));\r
 \r
        // Construct a good memory map from what we've got\r
        PagesCount = 1;\r
@@ -447,14 +438,67 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
        LastPageType = MemoryMap[0].PageAllocated;\r
        for(i=1;i<NoEntries;i++)\r
        {\r
-               if (MemoryMap[i].PageAllocated == LastPageType)\r
+               if (MemoryMap[i].PageAllocated == LastPageType &&\r
+                       (i < NlsBasePage || i > NlsBasePage+TotalNLSSize) && (i != NoEntries-1) )\r
                {\r
                        PagesCount++;\r
                }\r
+               else if (i == NlsBasePage)\r
+               {\r
+                       // This is NLS data, map it accordingly\r
+                       // It's VERY important for NT kernel - it calculates size of NLS\r
+                       // tables based on NlsData memory type descriptors!\r
+\r
+                       // Firstly map what we already have (if we have any)\r
+                       // Convert mem types\r
+                       if (LastPageType == 0)\r
+                               NtType = LoaderFree;\r
+                       else if (LastPageType != 0 && LastPageType != 1)\r
+                               NtType = LoaderFirmwarePermanent;\r
+                       else if (LastPageType == 1)\r
+                               NtType = LoaderSystemCode;\r
+                       else\r
+                               NtType = LoaderFirmwarePermanent;\r
+\r
+                       if (PagesCount > 0)\r
+                               MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, NtType);\r
+\r
+                       // Then map nls data\r
+                       MempAddMemoryBlock(LoaderBlock, NlsBasePage, TotalNLSSize, LoaderNlsData);\r
+\r
+                       // skip them\r
+                       i += TotalNLSSize;\r
+\r
+                       // Reset our counter vars\r
+                       LastPageIndex = i;\r
+                       LastPageType = MemoryMap[i].PageAllocated;\r
+                       PagesCount = 1;\r
+\r
+                       continue;\r
+               }\r
                else\r
                {\r
-                       // Add the region\r
-                       MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, LastPageType);\r
+                       // Add the resulting region\r
+\r
+                       // Convert mem types\r
+                       if (LastPageType == 0)\r
+                       {\r
+                               NtType = LoaderFree;\r
+                       }\r
+                       else if (LastPageType != 0 && LastPageType != 1)\r
+                       {\r
+                               NtType = LoaderFirmwarePermanent;\r
+                       }\r
+                       else if (LastPageType == 1)\r
+                       {\r
+                               NtType = LoaderSystemCode;\r
+                       }\r
+                       else\r
+                       {\r
+                               NtType = LoaderFirmwarePermanent;\r
+                       }\r
+\r
+                       MempAddMemoryBlock(LoaderBlock, LastPageIndex, PagesCount, NtType);\r
 \r
                        // Reset our counter vars\r
                        LastPageIndex = i;\r
@@ -480,6 +524,7 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
 \r
        // Page Tables have been setup, make special handling for PCR and TSS\r
        // (which is done in BlSetupFotNt in usual ntldr)\r
+#ifdef _M_IX86\r
        HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].PageFrameNumber = PcrBasePage+1;\r
        HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Valid = 1;\r
        HalPT[(KI_USER_SHARED_DATA - 0xFFC00000) >> MM_PAGE_SHIFT].Write = 1;\r
@@ -493,6 +538,7 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
        //DbgPrint((DPRINT_WINDOWS, "VideoMemoryBase: 0x%X\n", VideoMemoryBase));\r
 \r
        Tss = (PKTSS)(KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));\r
+#endif\r
 \r
        // Fill the memory descriptor list and \r
        //PrepareMemoryDescriptorList();\r
@@ -525,23 +571,29 @@ WinLdrTurnOnPaging(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
        //BS->ExitBootServices(ImageHandle,MapKey);\r
 \r
        // Disable Interrupts\r
-       Ke386DisableInterrupts();\r
+       _disable();\r
 \r
        // Re-initalize EFLAGS\r
+#ifdef _M_IX86\r
        Ke386EraseFlags();\r
+#endif\r
 \r
        // Set the PDBR\r
-       Ke386SetPageTableDirectory((ULONG_PTR)PDE);\r
+#ifdef _M_IX86\r
+       __writecr3((ULONG_PTR)PDE);\r
+#endif\r
 \r
        // Enable paging by modifying CR0\r
-       Ke386SetCr0(Ke386GetCr0() | CR0_PG);\r
+#ifdef _M_IX86\r
+       __writecr0(__readcr0() | CR0_PG);\r
+#endif\r
 \r
        // Set processor context\r
-       WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));\r
+       WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, 0/*KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT)*/);\r
 \r
        // Zero KI_USER_SHARED_DATA page\r
        memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);\r
-#endif\r
+\r
        return TRUE;\r
 }\r
 \r
index 73ec593..6c97762 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
+// The only global var here, used to mark mem pages as NLS in WinLdrTurnOnPaging()
+ULONG TotalNLSSize = 0;
+
+BOOLEAN WinLdrGetNLSNames(LPSTR AnsiName,
+                          LPSTR OemName,
+                          LPSTR LangName);
+
+VOID
+WinLdrScanRegistry(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
+                   IN LPCSTR DirectoryPath);
+
+BOOLEAN
+WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead,
+                      LPWSTR RegistryPath,
+                      LPWSTR ImagePath,
+                      LPWSTR ServiceName);
+
 BOOLEAN
 WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
                   IN LPCSTR DirectoryPath,
@@ -96,6 +113,9 @@ WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
        return TRUE;
 }
 
+
+/* PRIVATE FUNCTIONS ******************************************************/
+
 // Queries registry for those three file names
 BOOLEAN WinLdrGetNLSNames(LPSTR AnsiName,
                           LPSTR OemName,
@@ -315,6 +335,9 @@ WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
                MM_SIZE_TO_PAGES(OemFileSize)  +
                MM_SIZE_TO_PAGES(LanguageFileSize);
 
+       /* Store it for later marking the pages as NlsData type */
+       TotalNLSSize = TotalSize;
+
        NlsDataBase = (ULONG_PTR)MmAllocateMemory(TotalSize*MM_PAGE_SIZE);
 
        if (NlsDataBase == 0)
@@ -401,3 +424,317 @@ Failure:
        UiMessageBox("Error reading NLS file!");
        return FALSE;
 }
+
+VOID
+WinLdrScanRegistry(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
+                   IN LPCSTR DirectoryPath)
+{
+       LONG rc = 0;
+       FRLDRHKEY hGroupKey, hOrderKey, hServiceKey, hDriverKey;
+       WCHAR GroupNameBuffer[512];
+       WCHAR ServiceName[256];
+       ULONG OrderList[128];
+       ULONG BufferSize;
+       ULONG Index;
+       ULONG TagIndex;
+       LPWSTR GroupName;
+
+       ULONG ValueSize;
+       ULONG ValueType;
+       ULONG StartValue;
+       ULONG TagValue;
+       WCHAR DriverGroup[256];
+       ULONG DriverGroupSize;
+
+       CHAR ImagePath[256];
+       WCHAR TempImagePath[256];
+
+       BOOLEAN Status;
+
+       /* get 'service group order' key */
+       rc = RegOpenKey(NULL,
+               L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
+               &hGroupKey);
+       if (rc != ERROR_SUCCESS) {
+
+               DbgPrint((DPRINT_REACTOS, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc));
+               return;
+       }
+
+       /* get 'group order list' key */
+       rc = RegOpenKey(NULL,
+               L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
+               &hOrderKey);
+       if (rc != ERROR_SUCCESS) {
+
+               DbgPrint((DPRINT_REACTOS, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc));
+               return;
+       }
+
+       /* enumerate drivers */
+       rc = RegOpenKey(NULL,
+               L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
+               &hServiceKey);
+       if (rc != ERROR_SUCCESS)  {
+
+               DbgPrint((DPRINT_REACTOS, "Failed to open the 'Services' key (rc %d)\n", (int)rc));
+               return;
+       }
+
+       /* Get the Name Group */
+       BufferSize = sizeof(GroupNameBuffer);
+       rc = RegQueryValue(hGroupKey, L"List", NULL, (PUCHAR)GroupNameBuffer, &BufferSize);
+       DbgPrint((DPRINT_REACTOS, "RegQueryValue(): rc %d\n", (int)rc));
+       if (rc != ERROR_SUCCESS)
+               return;
+       DbgPrint((DPRINT_REACTOS, "BufferSize: %d \n", (int)BufferSize));
+       DbgPrint((DPRINT_REACTOS, "GroupNameBuffer: '%S' \n", GroupNameBuffer));
+
+       /* Loop through each group */
+       GroupName = GroupNameBuffer;
+       while (*GroupName)
+       {
+               DbgPrint((DPRINT_WINDOWS, "Driver group: '%S'\n", GroupName));
+
+               /* Query the Order */
+               BufferSize = sizeof(OrderList);
+               rc = RegQueryValue(hOrderKey, GroupName, NULL, (PUCHAR)OrderList, &BufferSize);
+               if (rc != ERROR_SUCCESS) OrderList[0] = 0;
+
+               /* enumerate all drivers */
+               for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++)
+               {
+                       Index = 0;
+
+                       while (TRUE)
+                       {
+                               /* Get the Driver's Name */
+                               ValueSize = sizeof(ServiceName);
+                               rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
+                               //DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+
+                               /* Makre sure it's valid, and check if we're done */
+                               if (rc == ERROR_NO_MORE_ITEMS)
+                                       break;
+                               if (rc != ERROR_SUCCESS)
+                                       return;
+                               //DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+
+                               /* open driver Key */
+                               rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
+                               if (rc == ERROR_SUCCESS)
+                               {
+                                       /* Read the Start Value */
+                                       ValueSize = sizeof(ULONG);
+                                       rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
+                                       if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
+                                       //DbgPrint((DPRINT_REACTOS, "  Start: %x  \n", (int)StartValue));
+
+                                       /* Read the Tag */
+                                       ValueSize = sizeof(ULONG);
+                                       rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
+                                       if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
+                                       //DbgPrint((DPRINT_REACTOS, "  Tag:   %x  \n", (int)TagValue));
+
+                                       /* Read the driver's group */
+                                       DriverGroupSize = sizeof(DriverGroup);
+                                       rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
+                                       //DbgPrint((DPRINT_REACTOS, "  Group: '%S'  \n", DriverGroup));
+
+                                       /* Make sure it should be started */
+                                       if ((StartValue == 0) &&
+                                               (TagValue == OrderList[TagIndex]) &&
+                                               (_wcsicmp(DriverGroup, GroupName) == 0)) {
+
+                                                       /* Get the Driver's Location */
+                                                       ValueSize = sizeof(TempImagePath);
+                                                       rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
+
+                                                       /* Write the whole path if it suceeded, else prepare to fail */
+                                                       if (rc != ERROR_SUCCESS) {
+                                                               DbgPrint((DPRINT_REACTOS, "  ImagePath: not found\n"));
+                                                               TempImagePath[0] = 0;
+                                                               sprintf(ImagePath, "%s\\system32\\drivers\\%S.sys", DirectoryPath, ServiceName);
+                                                       } else if (TempImagePath[0] != L'\\') {
+                                                               sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath);
+                                                       } else {
+                                                               sprintf(ImagePath, "%S", TempImagePath);
+                                                               DbgPrint((DPRINT_REACTOS, "  ImagePath: '%s'\n", ImagePath));
+                                                       }
+
+                                                       DbgPrint((DPRINT_WINDOWS, "  Adding boot driver: '%s'\n", ImagePath));
+
+                                                       Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead,
+                                                               L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
+                                                               TempImagePath,
+                                                               ServiceName);
+
+                                                       if (!Status)
+                                                               DbgPrint((DPRINT_WINDOWS, " Failed to add boot driver\n"));
+                                       } else
+                                       {
+                                               //DbgPrint((DPRINT_REACTOS, "  Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
+                                               //      ServiceName, StartValue, TagValue, DriverGroup, OrderList[TagIndex], GroupName));
+                                       }
+                               }
+
+                               Index++;
+                       }
+               }
+
+               Index = 0;
+               while (TRUE)
+               {
+                       /* Get the Driver's Name */
+                       ValueSize = sizeof(ServiceName);
+                       rc = RegEnumKey(hServiceKey, Index, ServiceName, &ValueSize);
+
+                       //DbgPrint((DPRINT_REACTOS, "RegEnumKey(): rc %d\n", (int)rc));
+                       if (rc == ERROR_NO_MORE_ITEMS)
+                               break;
+                       if (rc != ERROR_SUCCESS)
+                               return;
+                       //DbgPrint((DPRINT_REACTOS, "Service %d: '%S'\n", (int)Index, ServiceName));
+
+                       /* open driver Key */
+                       rc = RegOpenKey(hServiceKey, ServiceName, &hDriverKey);
+                       if (rc == ERROR_SUCCESS)
+                       {
+                               /* Read the Start Value */
+                               ValueSize = sizeof(ULONG);
+                               rc = RegQueryValue(hDriverKey, L"Start", &ValueType, (PUCHAR)&StartValue, &ValueSize);
+                               if (rc != ERROR_SUCCESS) StartValue = (ULONG)-1;
+                               //DbgPrint((DPRINT_REACTOS, "  Start: %x  \n", (int)StartValue));
+
+                               /* Read the Tag */
+                               ValueSize = sizeof(ULONG);
+                               rc = RegQueryValue(hDriverKey, L"Tag", &ValueType, (PUCHAR)&TagValue, &ValueSize);
+                               if (rc != ERROR_SUCCESS) TagValue = (ULONG)-1;
+                               //DbgPrint((DPRINT_REACTOS, "  Tag:   %x  \n", (int)TagValue));
+
+                               /* Read the driver's group */
+                               DriverGroupSize = sizeof(DriverGroup);
+                               rc = RegQueryValue(hDriverKey, L"Group", NULL, (PUCHAR)DriverGroup, &DriverGroupSize);
+                               //DbgPrint((DPRINT_REACTOS, "  Group: '%S'  \n", DriverGroup));
+
+                               for (TagIndex = 1; TagIndex <= OrderList[0]; TagIndex++) {
+                                       if (TagValue == OrderList[TagIndex]) break;
+                               }
+
+                               if ((StartValue == 0) &&
+                                       (TagIndex > OrderList[0]) &&
+                                       (_wcsicmp(DriverGroup, GroupName) == 0)) {
+
+                                               ValueSize = sizeof(TempImagePath);
+                                               rc = RegQueryValue(hDriverKey, L"ImagePath", NULL, (PUCHAR)TempImagePath, &ValueSize);
+                                               if (rc != ERROR_SUCCESS) {
+                                                       DbgPrint((DPRINT_REACTOS, "  ImagePath: not found\n"));
+                                                       TempImagePath[0] = 0;
+                                                       sprintf(ImagePath, "%ssystem32\\drivers\\%S.sys", DirectoryPath, ServiceName);
+                                               } else if (TempImagePath[0] != L'\\') {
+                                                       sprintf(ImagePath, "%s%S", DirectoryPath, TempImagePath);
+                                               } else {
+                                                       sprintf(ImagePath, "%S", TempImagePath);
+                                                       DbgPrint((DPRINT_REACTOS, "  ImagePath: '%s'\n", ImagePath));
+                                               }
+                                               DbgPrint((DPRINT_WINDOWS, "  Adding boot driver: '%s'\n", ImagePath));
+
+                                               Status = WinLdrAddDriverToList(&LoaderBlock->BootDriverListHead,
+                                                       L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\",
+                                                       TempImagePath,
+                                                       ServiceName);
+
+                                               if (!Status)
+                                                       DbgPrint((DPRINT_WINDOWS, " Failed to add boot driver\n"));
+                               } else
+                               {
+                                       //DbgPrint((DPRINT_REACTOS, "  Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
+                                       //      ServiceName, StartValue, TagValue, DriverGroup, GroupName));
+                               }
+                       }
+
+                       Index++;
+               }
+
+               /* Move to the next group name */
+               GroupName = GroupName + wcslen(GroupName) + 1;
+       }
+}
+
+BOOLEAN
+WinLdrAddDriverToList(LIST_ENTRY *BootDriverListHead,
+                      LPWSTR RegistryPath,
+                      LPWSTR ImagePath,
+                      LPWSTR ServiceName)
+{
+       PBOOT_DRIVER_LIST_ENTRY BootDriverEntry;
+       NTSTATUS Status;
+       ULONG PathLength;
+
+       BootDriverEntry = MmAllocateMemory(sizeof(BOOT_DRIVER_LIST_ENTRY));
+
+       if (!BootDriverEntry)
+               return FALSE;
+
+       // DTE will be filled during actual load of the driver
+       BootDriverEntry->DataTableEntry = NULL;
+
+       // Check - if we have a valid ImagePath, if not - we need to build it
+       // like "System32\\Drivers\\blah.sys"
+       if (ImagePath && (wcslen(ImagePath) > 0))
+       {
+               // Just copy ImagePath to the corresponding field in the structure
+               PathLength = wcslen(ImagePath) * sizeof(WCHAR);
+
+               BootDriverEntry->FilePath.Length = 0;
+               BootDriverEntry->FilePath.MaximumLength = PathLength + sizeof(WCHAR);
+               BootDriverEntry->FilePath.Buffer = MmAllocateMemory(PathLength);
+
+               if (!BootDriverEntry->FilePath.Buffer)
+                       return FALSE;
+
+               Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ImagePath);
+               if (!NT_SUCCESS(Status))
+                       return FALSE;
+       }
+       else
+       {
+               // we have to construct ImagePath ourselves
+               PathLength = wcslen(ServiceName)*sizeof(WCHAR) + sizeof(L"system32\\drivers\\.sys");;
+               BootDriverEntry->FilePath.Length = 0;
+               BootDriverEntry->FilePath.MaximumLength = PathLength+sizeof(WCHAR);
+               BootDriverEntry->FilePath.Buffer = MmAllocateMemory(PathLength);
+
+               if (!BootDriverEntry->FilePath.Buffer)
+                       return FALSE;
+
+               Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L"system32\\drivers\\");
+               if (!NT_SUCCESS(Status))
+                       return FALSE;
+
+               Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, ServiceName);
+               if (!NT_SUCCESS(Status))
+                       return FALSE;
+
+               Status = RtlAppendUnicodeToString(&BootDriverEntry->FilePath, L".sys");
+               if (!NT_SUCCESS(Status))
+                       return FALSE;
+       }
+
+       // Add registry path
+       PathLength = wcslen(RegistryPath)*sizeof(WCHAR);
+       BootDriverEntry->RegistryPath.Length = 0;
+       BootDriverEntry->RegistryPath.MaximumLength = PathLength+sizeof(WCHAR);
+       BootDriverEntry->RegistryPath.Buffer = MmAllocateMemory(PathLength);
+       if (!BootDriverEntry->RegistryPath.Buffer)
+               return FALSE;
+
+       Status = RtlAppendUnicodeToString(&BootDriverEntry->RegistryPath, RegistryPath);
+       if (!NT_SUCCESS(Status))
+               return FALSE;
+
+       // Insert entry at top of the list
+       InsertHeadList(BootDriverListHead, &BootDriverEntry->ListEntry);
+
+       return TRUE;
+}
index 721721b..0a3684e 100644 (file)
 extern "C" {
 #endif
 
+#ifdef __GNUC__
 #include "intrin.h"
+#endif
 
 /*
 ** Definitions specific to this Device Driver Kit
 */
 #define DDKAPI __stdcall
-#define DDKFASTAPI __fastcall
 #define FASTCALL __fastcall
 #define DDKCDECLAPI __cdecl
-
-/* FIXME: REMOVE THIS UNCOMPATIBLE CRUFT!!! */
-//#define NTKERNELAPI
+#ifndef DDKFASTAPI
+#define DDKFASTAPI
+#endif
+#ifndef NTOSAPI
+#define NTOSAPI
+#endif
 
 #ifdef _NTOSKRNL_
-#define NTKERNELAPI 
+/* HACKHACKHACK!!! We shouldn't include this header from ntoskrnl! */
+#define NTKERNELAPI
 #else
 #define NTKERNELAPI DECLSPEC_IMPORT
 #endif
 
-
-#ifndef NTOSAPI
-#define NTOSAPI NTKERNELAPI
-#endif
 #if defined(_NTOSKRNL_)
 #define DECLARE_INTERNAL_OBJECT(x) typedef struct _##x; typedef struct _##x *P##x;
 #define DECLARE_INTERNAL_OBJECT2(x,y) typedef struct _##x; typedef struct _##x *P##y;
@@ -2629,35 +2630,35 @@ typedef NTSTATUS
   IN PDEVICE_CONTROL_COMPLETION  CompletionRoutine);
 
 typedef VOID
-(DDKFASTAPI *pHalExamineMBR)(
+(FASTCALL *pHalExamineMBR)(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  SectorSize,
   IN ULONG  MBRTypeIdentifier,
   OUT PVOID  *Buffer);
 
 typedef VOID
-(DDKFASTAPI *pHalIoAssignDriveLetters)(
+(FASTCALL *pHalIoAssignDriveLetters)(
   IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
   IN PSTRING NtDeviceName,
   OUT PUCHAR NtSystemPath,
   OUT PSTRING NtSystemPathString);
 
 typedef NTSTATUS
-(DDKFASTAPI *pHalIoReadPartitionTable)(
+(FASTCALL *pHalIoReadPartitionTable)(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  SectorSize,
   IN BOOLEAN  ReturnRecognizedPartitions,
   OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer);
 
 typedef NTSTATUS
-(DDKFASTAPI *pHalIoSetPartitionInformation)(
+(FASTCALL *pHalIoSetPartitionInformation)(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  SectorSize,
   IN ULONG  PartitionNumber,
   IN ULONG  PartitionType);
 
 typedef NTSTATUS
-(DDKFASTAPI *pHalIoWritePartitionTable)(
+(FASTCALL *pHalIoWritePartitionTable)(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  SectorSize,
   IN ULONG  SectorsPerTrack,
@@ -2665,12 +2666,12 @@ typedef NTSTATUS
   IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer);
 
 typedef PBUS_HANDLER
-(DDKFASTAPI *pHalHandlerForBus)(
+(FASTCALL *pHalHandlerForBus)(
   IN INTERFACE_TYPE  InterfaceType,
   IN ULONG  BusNumber);
 
 typedef VOID
-(DDKFASTAPI *pHalReferenceBusHandler)(
+(FASTCALL *pHalReferenceBusHandler)(
   IN PBUS_HANDLER  BusHandler);
 
 typedef NTSTATUS
@@ -4183,7 +4184,7 @@ typedef struct _RTL_OSVERSIONINFOEXW {
   UCHAR  wReserved;
 } RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
 
-NTOSAPI
+NTSYSAPI
 ULONGLONG
 DDKAPI
 VerSetConditionMask(
@@ -5080,7 +5081,7 @@ typedef struct _DISK_SIGNATURE {
 } DISK_SIGNATURE, *PDISK_SIGNATURE;
 
 typedef VOID
-(DDKFASTAPI*PTIME_UPDATE_NOTIFY_ROUTINE)(
+(FASTCALL*PTIME_UPDATE_NOTIFY_ROUTINE)(
   IN HANDLE  ThreadId,
   IN KPROCESSOR_MODE  Mode);
 
@@ -5218,9 +5219,9 @@ typedef struct _KFLOATING_SAVE {
 #define PAGE_SIZE                         0x1000
 #define PAGE_SHIFT                        12L
 
-extern NTOSAPI PVOID MmHighestUserAddress;
-extern NTOSAPI PVOID MmSystemRangeStart;
-extern NTOSAPI ULONG_PTR MmUserProbeAddress;
+extern NTKERNELAPI PVOID MmHighestUserAddress;
+extern NTKERNELAPI PVOID MmSystemRangeStart;
+extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
 
 #define MM_HIGHEST_USER_ADDRESS           MmHighestUserAddress
 #define MM_SYSTEM_RANGE_START             MmSystemRangeStart
@@ -5278,36 +5279,36 @@ KeGetCurrentProcessorNumber(VOID)
 #if !defined(__INTERLOCKED_DECLARED)
 #define __INTERLOCKED_DECLARED
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKFASTAPI
+FASTCALL
 InterlockedIncrement(
   IN OUT LONG volatile *Addend);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKFASTAPI
+FASTCALL
 InterlockedDecrement(
   IN OUT LONG volatile *Addend);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKFASTAPI
+FASTCALL
 InterlockedCompareExchange(
   IN OUT LONG volatile *Destination,
   IN LONG  Exchange,
   IN LONG  Comparand);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKFASTAPI
+FASTCALL
 InterlockedExchange(
   IN OUT LONG volatile *Destination,
   IN LONG Value);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKFASTAPI
+FASTCALL
 InterlockedExchangeAdd(
   IN OUT LONG volatile *Addend,
   IN LONG  Value);
@@ -5337,27 +5338,27 @@ InterlockedExchangeAdd(
 
 #endif /* !__INTERLOCKED_DECLARED */
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KefAcquireSpinLockAtDpcLevel(
   IN PKSPIN_LOCK  SpinLock);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KefReleaseSpinLockFromDpcLevel(
   IN PKSPIN_LOCK  SpinLock);
 
 NTHALAPI
 KIRQL
-DDKFASTAPI
+FASTCALL
 KfAcquireSpinLock(
   IN PKSPIN_LOCK SpinLock);
 
 NTHALAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KfReleaseSpinLock(
   IN PKSPIN_LOCK SpinLock,
   IN KIRQL NewIrql);
@@ -5371,7 +5372,10 @@ KfReleaseSpinLock(
 
 #define KeGetDcacheFillSize() 1L
 
-#elif defined(_PPC_)
+#elif defined(_M_PPC)
+
+#define PAGE_SIZE                         0x1000
+#define PAGE_SHIFT                        12L
 
 typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
 
@@ -5444,15 +5448,15 @@ typedef struct _KPCR {
   UCHAR  Number;                /* 51 */
 } KPCR, *PKPCR;                 /* 54 */
 
+#if !defined(__INTERLOCKED_DECLARED)
+#define __INTERLOCKED_DECLARED
+
 NTHALAPI
 KIRQL
 DDKAPI
 KeGetCurrentIrql(
   VOID);
 
-#if !defined(__INTERLOCKED_DECLARED)
-#define __INTERLOCKED_DECLARED
-
 NTOSAPI
 LONG
 DDKFASTAPI
@@ -5505,7 +5509,6 @@ InterlockedExchangeAdd(
  */
 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
   ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
-#define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
 
 #endif /* !__INTERLOCKED_DECLARED */
 
@@ -5560,10 +5563,6 @@ KeGetCurrentProcessorNumber(VOID)
 {
        return 0; // XXX arty fixme
 }
-
-#define PAGE_SIZE                         0x1000
-#define PAGE_SHIFT                        12L
-
 #endif /* _X86_ */
 
 /*
@@ -5694,14 +5693,16 @@ extern BOOLEAN NTSYSAPI NLS_MB_OEM_CODE_PAGE_TAG;
 
 /** Runtime library routines **/
 
-static __inline VOID
+VOID
+FORCEINLINE
 InitializeListHead(
   IN PLIST_ENTRY  ListHead)
 {
   ListHead->Flink = ListHead->Blink = ListHead;
 }
 
-static __inline VOID
+VOID
+FORCEINLINE
 InsertHeadList(
   IN PLIST_ENTRY  ListHead,
   IN PLIST_ENTRY  Entry)
@@ -5714,7 +5715,8 @@ InsertHeadList(
   ListHead->Flink = Entry;
 }
 
-static __inline VOID
+VOID
+FORCEINLINE
 InsertTailList(
   IN PLIST_ENTRY  ListHead,
   IN PLIST_ENTRY  Entry)
@@ -5759,7 +5761,8 @@ InsertTailList(
        (_Entry)->Next = (_ListHead)->Next; \
        (_ListHead)->Next = (_Entry); \
 
-static __inline BOOLEAN
+BOOLEAN
+FORCEINLINE
 RemoveEntryList(
   IN PLIST_ENTRY  Entry)
 {
@@ -5773,7 +5776,8 @@ RemoveEntryList(
   return (OldFlink == OldBlink);
 }
 
-static __inline PLIST_ENTRY
+PLIST_ENTRY
+FORCEINLINE
 RemoveHeadList(
   IN PLIST_ENTRY  ListHead)
 {
@@ -5787,7 +5791,8 @@ RemoveHeadList(
   return Entry;
 }
 
-static __inline PLIST_ENTRY
+PLIST_ENTRY
+FORCEINLINE
 RemoveTailList(
   IN PLIST_ENTRY  ListHead)
 {
@@ -5803,15 +5808,15 @@ RemoveTailList(
 
 #if !defined(_WINBASE_H) || _WIN32_WINNT < 0x0501
 
-NTOSAPI
+NTKERNELAPI
 PSLIST_ENTRY
-DDKFASTAPI
+FASTCALL
 InterlockedPopEntrySList(
   IN PSLIST_HEADER  ListHead);
 
-NTOSAPI
+NTKERNELAPI
 PSLIST_ENTRY
-DDKFASTAPI
+FASTCALL
 InterlockedPushEntrySList(
   IN PSLIST_HEADER  ListHead,
   IN PSLIST_ENTRY  ListEntry);
@@ -5828,9 +5833,9 @@ InterlockedPushEntrySList(
 
 #define InterlockedFlushSList(ListHead) ExInterlockedFlushSList(ListHead)
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlxAnsiStringToUnicodeSize(
   IN PCANSI_STRING  AnsiString);
 
@@ -5840,106 +5845,106 @@ RtlxAnsiStringToUnicodeSize(
   ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR)   \
 )
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlAnsiStringToUnicodeString(
   IN OUT PUNICODE_STRING  DestinationString,
   IN PANSI_STRING  SourceString,
   IN BOOLEAN  AllocateDestinationString);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlAppendUnicodeStringToString(
   IN OUT PUNICODE_STRING  Destination,
   IN PCUNICODE_STRING  Source);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlAppendUnicodeToString(
   IN OUT PUNICODE_STRING  Destination,
   IN PCWSTR  Source);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlAreBitsClear(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  StartingIndex,
   IN ULONG  Length);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlAreBitsSet(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  StartingIndex,
   IN ULONG  Length);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlCharToInteger(
   IN PCSZ  String,
   IN ULONG  Base  OPTIONAL,
   IN OUT PULONG  Value);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlCheckBit(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  BitPosition);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlCheckRegistryKey(
   IN ULONG  RelativeTo,
   IN PWSTR  Path);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlClearAllBits(
   IN PRTL_BITMAP  BitMapHeader);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlClearBit(
   PRTL_BITMAP  BitMapHeader,
   ULONG  BitNumber);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlClearBits(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  StartingIndex,
   IN ULONG  NumberToClear);
 
-NTOSAPI
+NTSYSAPI
 SIZE_T
-DDKAPI
+NTAPI
 RtlCompareMemory(
   IN CONST VOID  *Source1,
   IN CONST VOID  *Source2,
   IN SIZE_T  Length);
 
-NTOSAPI
+NTSYSAPI
 LONG
-DDKAPI
+NTAPI
 RtlCompareString(
   IN PSTRING  String1,
   IN PSTRING  String2,
   BOOLEAN  CaseInSensitive);
 
-NTOSAPI
+NTSYSAPI
 LONG
-DDKAPI
+NTAPI
 RtlCompareUnicodeString(
   IN PCUNICODE_STRING  String1,
   IN PCUNICODE_STRING  String2,
@@ -5956,21 +5961,21 @@ RtlConvertLongToLargeInteger(LONG SignedInteger)
     return Result;
 }
 
-NTOSAPI
+NTSYSAPI
 LUID
-DDKAPI
+NTAPI
 RtlConvertLongToLuid(
   IN LONG  Long);
 
-NTOSAPI
+NTSYSAPI
 LARGE_INTEGER
-DDKAPI
+NTAPI
 RtlConvertUlongToLargeInteger(
   IN ULONG  UnsignedInteger);
 
-NTOSAPI
+NTSYSAPI
 LUID
-DDKAPI
+NTAPI
 RtlConvertUlongToLuid(
   ULONG  Ulong);
 
@@ -5990,45 +5995,45 @@ RtlConvertUlongToLuid(
 #define RtlCopyBytes RtlCopyMemory
 #endif
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlCopyMemory32(
   IN VOID UNALIGNED  *Destination,
   IN CONST VOID UNALIGNED  *Source,
   IN ULONG  Length);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlCopyString(
   IN OUT PSTRING  DestinationString,
   IN PSTRING  SourceString  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlCopyUnicodeString(
   IN OUT PUNICODE_STRING  DestinationString,
   IN PCUNICODE_STRING  SourceString);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlCreateRegistryKey(
   IN ULONG  RelativeTo,
   IN PWSTR  Path);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlCreateSecurityDescriptor(
   IN OUT PSECURITY_DESCRIPTOR  SecurityDescriptor,
   IN ULONG  Revision);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlDeleteRegistryValue(
   IN ULONG  RelativeTo,
   IN PCWSTR  Path,
@@ -6053,17 +6058,17 @@ RtlDeleteRegistryValue(
  */
 #define RtlEqualMemory(Destination, Source, Length) (!memcmp(Destination, Source, Length))
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlEqualString(
   IN PSTRING  String1,
   IN PSTRING  String2,
   IN BOOLEAN  CaseInSensitive);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlEqualUnicodeString(
   IN CONST UNICODE_STRING  *String1,
   IN CONST UNICODE_STRING  *String2,
@@ -6085,178 +6090,178 @@ RtlEqualUnicodeString(
 #define RtlFillBytes RtlFillMemory
 #endif
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindClearBits(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  NumberToFind,
   IN ULONG  HintIndex);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindClearBitsAndSet(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  NumberToFind,
   IN ULONG  HintIndex);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindClearRuns(
   IN PRTL_BITMAP  BitMapHeader,
   OUT PRTL_BITMAP_RUN  RunArray,
   IN ULONG  SizeOfRunArray,
   IN BOOLEAN  LocateLongestRuns);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindFirstRunClear(
   IN PRTL_BITMAP  BitMapHeader,
   OUT PULONG  StartingIndex);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindLastBackwardRunClear(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  FromIndex,
   OUT PULONG  StartingRunIndex);
 
-NTOSAPI
+NTSYSAPI
 CCHAR
-DDKAPI
+NTAPI
 RtlFindLeastSignificantBit(
   IN ULONGLONG  Set);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindLongestRunClear(
   IN PRTL_BITMAP  BitMapHeader,
   OUT PULONG  StartingIndex);
 
-NTOSAPI
+NTSYSAPI
 CCHAR
-DDKAPI
+NTAPI
 RtlFindMostSignificantBit(
   IN ULONGLONG  Set);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindNextForwardRunClear(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  FromIndex,
   OUT PULONG  StartingRunIndex);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindSetBits(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  NumberToFind,
   IN ULONG  HintIndex);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlFindSetBitsAndClear(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  NumberToFind,
   IN ULONG  HintIndex);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlFreeAnsiString(
   IN PANSI_STRING  AnsiString);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlFreeUnicodeString(
   IN PUNICODE_STRING  UnicodeString);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlGetCallersAddress(
   OUT PVOID  *CallersAddress,
   OUT PVOID  *CallersCaller);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlGetVersion(
   IN OUT PRTL_OSVERSIONINFOW  lpVersionInformation);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlGUIDFromString(
   IN PUNICODE_STRING  GuidString,
   OUT GUID  *Guid);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlHashUnicodeString(
   IN CONST UNICODE_STRING  *String,
   IN BOOLEAN  CaseInSensitive,
   IN ULONG  HashAlgorithm,
   OUT PULONG  HashValue);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlInitAnsiString(
   IN OUT PANSI_STRING  DestinationString,
   IN PCSZ  SourceString);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlInitializeBitMap(
   IN PRTL_BITMAP  BitMapHeader,
   IN PULONG  BitMapBuffer,
   IN ULONG  SizeOfBitMap);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlInitString(
   IN OUT PSTRING  DestinationString,
   IN PCSZ  SourceString);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlInitUnicodeString(
   IN OUT PUNICODE_STRING  DestinationString,
   IN PCWSTR  SourceString);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlInt64ToUnicodeString(
   IN ULONGLONG  Value,
   IN ULONG  Base OPTIONAL,
   IN OUT PUNICODE_STRING  String);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlIntegerToUnicodeString(
   IN ULONG  Value,
   IN ULONG  Base  OPTIONAL,
   IN OUT PUNICODE_STRING  String);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlIntPtrToUnicodeString(
   PLONG  Value,
   ULONG  Base  OPTIONAL,
@@ -6270,15 +6275,15 @@ RtlIntPtrToUnicodeString(
 #define RtlIsZeroLuid(_L1) \
   ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlLengthSecurityDescriptor(
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlMapGenericMask(
   IN OUT PACCESS_MASK  AccessMask,
   IN PGENERIC_MAPPING  GenericMapping);
@@ -6292,36 +6297,36 @@ RtlMapGenericMask(
  */
 #define RtlMoveMemory memmove
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlNumberOfClearBits(
   IN PRTL_BITMAP  BitMapHeader);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlNumberOfSetBits(
   IN PRTL_BITMAP  BitMapHeader);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKFASTAPI
+FASTCALL
 RtlPrefetchMemoryNonTemporal(
   IN PVOID  Source,
   IN SIZE_T  Length);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlPrefixUnicodeString(
   IN PCUNICODE_STRING  String1,
   IN PCUNICODE_STRING  String2,
   IN BOOLEAN  CaseInSensitive);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlQueryRegistryValues(
   IN ULONG  RelativeTo,
   IN PCWSTR  Path,
@@ -6353,95 +6358,95 @@ RtlQueryRegistryValues(
         *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
     }
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlRetrieveUshort(
   IN OUT PUSHORT  DestinationAddress,
   IN PUSHORT  SourceAddress);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlSetAllBits(
   IN PRTL_BITMAP  BitMapHeader);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlSetBit(
   PRTL_BITMAP  BitMapHeader,
   ULONG  BitNumber);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlSetBits(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  StartingIndex,
   IN ULONG  NumberToSet);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlSetDaclSecurityDescriptor(
   IN OUT PSECURITY_DESCRIPTOR  SecurityDescriptor,
   IN BOOLEAN  DaclPresent,
   IN PACL  Dacl  OPTIONAL,
   IN BOOLEAN  DaclDefaulted  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlStoreUlong(
   IN PULONG  Address,
   IN ULONG  Value);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlStoreUlonglong(
   IN OUT PULONGLONG  Address,
   ULONGLONG  Value);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlStoreUlongPtr(
   IN OUT PULONG_PTR  Address,
   IN ULONG_PTR  Value);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlStoreUshort(
   IN PUSHORT  Address,
   IN USHORT  Value);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlStringFromGUID(
   IN REFGUID  Guid,
   OUT PUNICODE_STRING  GuidString);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlTestBit(
   IN PRTL_BITMAP  BitMapHeader,
   IN ULONG  BitNumber);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlTimeFieldsToTime(
   IN PTIME_FIELDS  TimeFields,
   IN PLARGE_INTEGER  Time);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlTimeToTimeFields(
   IN PLARGE_INTEGER  Time,
   IN PTIME_FIELDS  TimeFields);
@@ -6462,8 +6467,8 @@ RtlUlonglongByteSwap(
     ((STRING)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
 )
 
-FORCEINLINE
 VOID
+FORCEINLINE
 RtlInitEmptyUnicodeString(OUT PUNICODE_STRING UnicodeString,
                           IN PWSTR Buffer,
                           IN USHORT BufferSize)
@@ -6473,45 +6478,56 @@ RtlInitEmptyUnicodeString(OUT PUNICODE_STRING UnicodeString,
     UnicodeString->Buffer = Buffer;
 }
 
-NTOSAPI
+VOID
+FORCEINLINE
+RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
+                       IN PCHAR Buffer,
+                       IN USHORT BufferSize)
+{
+    AnsiString->Length = 0;
+    AnsiString->MaximumLength = BufferSize;
+    AnsiString->Buffer = Buffer;
+}
+
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlUnicodeStringToAnsiString(
   IN OUT PANSI_STRING  DestinationString,
   IN PCUNICODE_STRING  SourceString,
   IN BOOLEAN  AllocateDestinationString);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlUnicodeStringToInteger(
   IN PCUNICODE_STRING  String,
   IN ULONG  Base  OPTIONAL,
   OUT PULONG  Value);
 
-NTOSAPI
+NTSYSAPI
 WCHAR
-DDKAPI
+NTAPI
 RtlUpcaseUnicodeChar(
   IN WCHAR  SourceCharacter);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlUpcaseUnicodeString(
   IN OUT PUNICODE_STRING  DestinationString  OPTIONAL,
   IN PCUNICODE_STRING  SourceString,
   IN BOOLEAN  AllocateDestinationString);
 
-NTOSAPI
+NTSYSAPI
 CHAR
-DDKAPI
+NTAPI
 RtlUpperChar(
   IN CHAR Character);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 RtlUpperString(
   IN OUT PSTRING  DestinationString,
   IN PSTRING  SourceString);
@@ -6521,46 +6537,46 @@ FASTCALL
 RtlUshortByteSwap(
   IN USHORT  Source);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlValidRelativeSecurityDescriptor(
   IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
   IN ULONG  SecurityDescriptorLength,
   IN SECURITY_INFORMATION  RequiredInformation);
 
-NTOSAPI
+NTSYSAPI
 BOOLEAN
-DDKAPI
+NTAPI
 RtlValidSecurityDescriptor(
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlVerifyVersionInfo(
   IN PRTL_OSVERSIONINFOEXW  VersionInfo,
   IN ULONG  TypeMask,
   IN ULONGLONG  ConditionMask);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlVolumeDeviceToDosName(
   IN PVOID  VolumeDeviceObject,
   OUT PUNICODE_STRING  DosName);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlWalkFrameChain(
   OUT PVOID  *Callers,
   IN ULONG  Count,
   IN ULONG  Flags);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 RtlWriteRegistryValue(
   IN ULONG  RelativeTo,
   IN PCWSTR  Path,
@@ -6569,9 +6585,9 @@ RtlWriteRegistryValue(
   IN PVOID  ValueData,
   IN ULONG  ValueLength);
 
-NTOSAPI
+NTSYSAPI
 ULONG
-DDKAPI
+NTAPI
 RtlxUnicodeStringToAnsiSize(
   IN PCUNICODE_STRING  UnicodeString);
 
@@ -6593,48 +6609,56 @@ RtlxUnicodeStringToAnsiSize(
 
 /* Guarded Mutex routines */
 
+NTKERNELAPI
 VOID
 FASTCALL
 KeAcquireGuardedMutex(
     IN OUT PKGUARDED_MUTEX GuardedMutex
 );
 
+NTKERNELAPI
 VOID
 FASTCALL
 KeAcquireGuardedMutexUnsafe(
     IN OUT PKGUARDED_MUTEX GuardedMutex
 );
 
+NTKERNELAPI
 VOID
 NTAPI
 KeEnterGuardedRegion(
     VOID
 );
 
+NTKERNELAPI
 VOID
 NTAPI
 KeLeaveGuardedRegion(
     VOID
 );
 
+NTKERNELAPI
 VOID
 FASTCALL
 KeInitializeGuardedMutex(
     OUT PKGUARDED_MUTEX GuardedMutex
 );
 
+NTKERNELAPI
 VOID
 FASTCALL
 KeReleaseGuardedMutexUnsafe(
     IN OUT PKGUARDED_MUTEX GuardedMutex
 );
 
+NTKERNELAPI
 VOID
 FASTCALL
 KeReleaseGuardedMutex(
     IN OUT PKGUARDED_MUTEX GuardedMutex
 );
 
+NTKERNELAPI
 BOOLEAN
 FASTCALL
 KeTryToAcquireGuardedMutex(
@@ -6650,28 +6674,28 @@ KeTryToAcquireGuardedMutex(
     KeInitializeEvent(&(_FastMutex)->Gate, SynchronizationEvent, FALSE); \
 }
 
-NTOSAPI
+NTKERNELAPI
 VOID
 FASTCALL
 ExAcquireFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex);
 
-NTOSAPI
+NTKERNELAPI
 VOID
 FASTCALL
 ExReleaseFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex);
 
 #if defined(_NTHAL_) && defined(_X86_)
-NTOSAPI
+NTKERNELAPI
 VOID
 FASTCALL
 ExiAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex);
 
-NTOSAPI
+NTKERNELAPI
 VOID
 FASTCALL
 ExiReleaseFastMutex(IN OUT PFAST_MUTEX FastMutex);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
 FASTCALL
 ExiTryToAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex);
@@ -6682,17 +6706,17 @@ ExiTryToAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex);
 
 #else
 
-NTOSAPI
+NTKERNELAPI
 VOID
 FASTCALL
 ExAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex);
 
-NTOSAPI
+NTKERNELAPI
 VOID
 FASTCALL
 ExReleaseFastMutex(IN OUT PFAST_MUTEX FastMutex);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
 FASTCALL
 ExTryToAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex);
@@ -6700,30 +6724,30 @@ ExTryToAcquireFastMutex(IN OUT PFAST_MUTEX FastMutex);
 
 /** Executive support routines **/
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExAcquireResourceExclusiveLite(
   IN PERESOURCE  Resource,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExAcquireResourceSharedLite(
   IN PERESOURCE  Resource,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExAcquireSharedStarveExclusive(
   IN PERESOURCE  Resource,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExAcquireSharedWaitForExclusive(
   IN PERESOURCE  Resource,
   IN BOOLEAN  Wait);
@@ -6758,17 +6782,17 @@ ExAllocateFromPagedLookasideList(
   return Entry;
 }
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 ExAllocatePoolWithQuotaTag(
   IN POOL_TYPE  PoolType,
   IN SIZE_T  NumberOfBytes,
   IN ULONG  Tag);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 ExAllocatePoolWithTag(
   IN POOL_TYPE  PoolType,
   IN SIZE_T  NumberOfBytes,
@@ -6781,67 +6805,67 @@ ExAllocatePoolWithTag(
 
 #else /* !POOL_TAGGING */
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 ExAllocatePool(
   IN POOL_TYPE  PoolType,
   IN SIZE_T  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 ExAllocatePoolWithQuota(
   IN POOL_TYPE  PoolType,
   IN SIZE_T  NumberOfBytes);
 
 #endif /* POOL_TAGGING */
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 ExAllocatePoolWithTagPriority(
   IN POOL_TYPE  PoolType,
   IN SIZE_T  NumberOfBytes,
   IN ULONG  Tag,
   IN EX_POOL_PRIORITY  Priority);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExConvertExclusiveToSharedLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ExCreateCallback(
   OUT PCALLBACK_OBJECT  *CallbackObject,
   IN POBJECT_ATTRIBUTES  ObjectAttributes,
   IN BOOLEAN  Create,
   IN BOOLEAN  AllowMultipleCallbacks);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExDeleteNPagedLookasideList(
   IN PNPAGED_LOOKASIDE_LIST  Lookaside);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExDeletePagedLookasideList(
   IN PPAGED_LOOKASIDE_LIST  Lookaside);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ExDeleteResourceLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExFreePool(
   IN PVOID  P);
 
@@ -6851,9 +6875,9 @@ ExFreePool(
 #define ExFreePool(P) ExFreePoolWithTag(P, 0)
 #endif
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExFreePoolWithTag(
   IN PVOID  P,
   IN ULONG  Tag);
@@ -6895,35 +6919,35 @@ ExFreeToPagedLookasideList(
  */
 #define ExGetCurrentResourceThread() ((ERESOURCE_THREAD) PsGetCurrentThread())
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 ExGetExclusiveWaiterCount(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 KPROCESSOR_MODE
-DDKAPI
+NTAPI
 ExGetPreviousMode(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 ExGetSharedWaiterCount(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeEvent(
   IN PRKEVENT  Event,
   IN EVENT_TYPE  Type,
   IN BOOLEAN  State);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExInitializeNPagedLookasideList(
   IN PNPAGED_LOOKASIDE_LIST  Lookaside,
   IN PALLOCATE_FUNCTION  Allocate  OPTIONAL,
@@ -6933,9 +6957,9 @@ ExInitializeNPagedLookasideList(
   IN ULONG  Tag,
   IN USHORT  Depth);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExInitializePagedLookasideList(
   IN PPAGED_LOOKASIDE_LIST  Lookaside,
   IN PALLOCATE_FUNCTION  Allocate  OPTIONAL,
@@ -6945,9 +6969,9 @@ ExInitializePagedLookasideList(
   IN ULONG  Tag,
   IN USHORT  Depth);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ExInitializeResourceLite(
   IN PERESOURCE  Resource);
 
@@ -6961,71 +6985,71 @@ ExInitializeResourceLite(
 
 #define ExInitializeSListHead InitializeSListHead
 
-NTOSAPI
+NTKERNELAPI
 LARGE_INTEGER
-DDKAPI
+NTAPI
 ExInterlockedAddLargeInteger(
   IN PLARGE_INTEGER  Addend,
   IN LARGE_INTEGER  Increment,
   IN PKSPIN_LOCK  Lock);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 ExInterlockedAddLargeStatistic(
   IN PLARGE_INTEGER  Addend,
   IN ULONG  Increment);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 ExInterlockedAddUlong(
   IN PULONG  Addend,
   IN ULONG  Increment,
   PKSPIN_LOCK  Lock);
 
-NTOSAPI
+NTKERNELAPI
 LONGLONG
-DDKFASTAPI
+FASTCALL
 ExInterlockedCompareExchange64(
   IN OUT PLONGLONG  Destination,
   IN PLONGLONG  Exchange,
   IN PLONGLONG  Comparand,
   IN PKSPIN_LOCK  Lock);
 
-NTOSAPI
+NTKERNELAPI
 LONGLONG
-DDKFASTAPI
+FASTCALL
 ExfInterlockedCompareExchange64(
   IN OUT LONGLONG volatile  *Destination,
   IN PLONGLONG  Exchange,
   IN PLONGLONG  Comperand);
 
-NTOSAPI
+NTKERNELAPI
 PSINGLE_LIST_ENTRY
-DDKFASTAPI
+FASTCALL
 ExInterlockedFlushSList(
   IN PSLIST_HEADER  ListHead);
 
-NTOSAPI
+NTKERNELAPI
 PLIST_ENTRY
-DDKAPI
+NTAPI
 ExInterlockedInsertHeadList(
   IN PLIST_ENTRY  ListHead,
   IN PLIST_ENTRY  ListEntry,
   IN PKSPIN_LOCK  Lock);
 
-NTOSAPI
+NTKERNELAPI
 PLIST_ENTRY
-DDKAPI
+NTAPI
 ExInterlockedInsertTailList(
   IN PLIST_ENTRY  ListHead,
   IN PLIST_ENTRY  ListEntry,
   IN PKSPIN_LOCK  Lock);
 
-NTOSAPI
+NTKERNELAPI
 PSINGLE_LIST_ENTRY
-DDKAPI
+NTAPI
 ExInterlockedPopEntryList(
   IN PSINGLE_LIST_ENTRY  ListHead,
   IN PKSPIN_LOCK  Lock);
@@ -7040,9 +7064,9 @@ ExInterlockedPopEntryList(
                                    _Lock) \
   InterlockedPopEntrySList(_ListHead)
 
-NTOSAPI
+NTKERNELAPI
 PSINGLE_LIST_ENTRY
-DDKAPI
+NTAPI
 ExInterlockedPushEntryList(
   IN PSINGLE_LIST_ENTRY  ListHead,
   IN PSINGLE_LIST_ENTRY  ListEntry,
@@ -7060,139 +7084,139 @@ ExInterlockedPushEntryList(
                                     _Lock) \
   InterlockedPushEntrySList(_ListHead, _ListEntry)
 
-NTOSAPI
+NTKERNELAPI
 PLIST_ENTRY
-DDKAPI
+NTAPI
 ExInterlockedRemoveHeadList(
   IN PLIST_ENTRY  ListHead,
   IN PKSPIN_LOCK  Lock);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExIsProcessorFeaturePresent(
   IN ULONG  ProcessorFeature);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExIsResourceAcquiredExclusiveLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 USHORT
-DDKAPI
+NTAPI
 ExIsResourceAcquiredLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 ExIsResourceAcquiredSharedLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExLocalTimeToSystemTime(
   IN PLARGE_INTEGER  LocalTime,
   OUT PLARGE_INTEGER  SystemTime);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExNotifyCallback(
   IN PCALLBACK_OBJECT  CallbackObject,
   IN PVOID  Argument1,
   IN PVOID  Argument2);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExRaiseAccessViolation(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExRaiseDatatypeMisalignment(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExRaiseStatus(
   IN NTSTATUS  Status);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 ExRegisterCallback(
   IN PCALLBACK_OBJECT  CallbackObject,
   IN PCALLBACK_FUNCTION  CallbackFunction,
   IN PVOID  CallbackContext);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ExReinitializeResourceLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExReleaseResourceForThreadLite(
   IN PERESOURCE  Resource,
   IN ERESOURCE_THREAD  ResourceThreadId);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 ExReleaseResourceLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExSetResourceOwnerPointer(
   IN PERESOURCE  Resource,
   IN PVOID  OwnerPointer);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 ExSetTimerResolution(
   IN ULONG  DesiredTime,
   IN BOOLEAN  SetResolution);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExSystemTimeToLocalTime(
   IN PLARGE_INTEGER  SystemTime,
   OUT PLARGE_INTEGER  LocalTime);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExTryToAcquireResourceExclusiveLite(
   IN PERESOURCE  Resource);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ExUnregisterCallback(
   IN PVOID  CbRegistration);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ExUuidCreate(
   OUT UUID  *Uuid);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 ExVerifySuite(
   IN SUITE_TYPE  SuiteType);
 
@@ -7211,17 +7235,17 @@ ExVerifySuite(
 
 #endif
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ProbeForRead(
   IN CONST VOID  *Address,
   IN ULONG  Length,
   IN ULONG  Alignment);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ProbeForWrite(
   IN PVOID  Address,
   IN ULONG  Length,
@@ -7231,17 +7255,17 @@ ProbeForWrite(
 
 /** Configuration manager routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 CmRegisterCallback(
   IN PEX_CALLBACK_FUNCTION  Function,
   IN PVOID  Context,
   IN OUT PLARGE_INTEGER  Cookie);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 CmUnRegisterCallback(
   IN LARGE_INTEGER  Cookie);
 
@@ -7249,9 +7273,9 @@ CmUnRegisterCallback(
 
 /** Filesystem runtime library routines **/
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 FsRtlIsTotalDeviceFailure(
   IN NTSTATUS  Status);
 
@@ -7261,13 +7285,13 @@ FsRtlIsTotalDeviceFailure(
 
 NTHALAPI
 BOOLEAN
-DDKAPI
+NTAPI
 HalMakeBeep(
   IN ULONG Frequency);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 HalExamineMBR(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  SectorSize,
@@ -7293,7 +7317,7 @@ IoAllocateAdapterChannel(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 READ_PORT_BUFFER_UCHAR(
   IN PUCHAR  Port,
   IN PUCHAR  Buffer,
@@ -7301,7 +7325,7 @@ READ_PORT_BUFFER_UCHAR(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 READ_PORT_BUFFER_ULONG(
   IN PULONG  Port,
   IN PULONG  Buffer,
@@ -7309,7 +7333,7 @@ READ_PORT_BUFFER_ULONG(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 READ_PORT_BUFFER_USHORT(
   IN PUSHORT  Port,
   IN PUSHORT  Buffer,
@@ -7317,67 +7341,67 @@ READ_PORT_BUFFER_USHORT(
 
 NTHALAPI
 UCHAR
-DDKAPI
+NTAPI
 READ_PORT_UCHAR(
   IN PUCHAR  Port);
 
 NTHALAPI
 ULONG
-DDKAPI
+NTAPI
 READ_PORT_ULONG(
   IN PULONG  Port);
 
 NTHALAPI
 USHORT
-DDKAPI
+NTAPI
 READ_PORT_USHORT(
   IN PUSHORT  Port);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 READ_REGISTER_BUFFER_UCHAR(
   IN PUCHAR  Register,
   IN PUCHAR  Buffer,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 READ_REGISTER_BUFFER_ULONG(
   IN PULONG  Register,
   IN PULONG  Buffer,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 READ_REGISTER_BUFFER_USHORT(
   IN PUSHORT  Register,
   IN PUSHORT  Buffer,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 UCHAR
-DDKAPI
+NTAPI
 READ_REGISTER_UCHAR(
   IN PUCHAR  Register);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 READ_REGISTER_ULONG(
   IN PULONG  Register);
 
-NTOSAPI
+NTKERNELAPI
 USHORT
-DDKAPI
+NTAPI
 READ_REGISTER_USHORT(
   IN PUSHORT  Register);
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_PORT_BUFFER_UCHAR(
   IN PUCHAR  Port,
   IN PUCHAR  Buffer,
@@ -7385,7 +7409,7 @@ WRITE_PORT_BUFFER_UCHAR(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_PORT_BUFFER_ULONG(
   IN PULONG  Port,
   IN PULONG  Buffer,
@@ -7393,7 +7417,7 @@ WRITE_PORT_BUFFER_ULONG(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_PORT_BUFFER_USHORT(
   IN PUSHORT  Port,
   IN PUSHORT  Buffer,
@@ -7401,81 +7425,81 @@ WRITE_PORT_BUFFER_USHORT(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_PORT_UCHAR(
   IN PUCHAR  Port,
   IN UCHAR  Value);
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_PORT_ULONG(
   IN PULONG  Port,
   IN ULONG  Value);
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_PORT_USHORT(
   IN PUSHORT  Port,
   IN USHORT  Value);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_REGISTER_BUFFER_UCHAR(
   IN PUCHAR  Register,
   IN PUCHAR  Buffer,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_REGISTER_BUFFER_ULONG(
   IN PULONG  Register,
   IN PULONG  Buffer,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_REGISTER_BUFFER_USHORT(
   IN PUSHORT  Register,
   IN PUSHORT  Buffer,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_REGISTER_UCHAR(
   IN PUCHAR  Register,
   IN UCHAR  Value);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_REGISTER_ULONG(
   IN PULONG  Register,
   IN ULONG  Value);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 WRITE_REGISTER_USHORT(
   IN PUSHORT  Register,
   IN USHORT  Value);
 
 /** I/O manager routines **/
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoAcquireCancelSpinLock(
   OUT PKIRQL  Irql);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoAcquireRemoveLockEx(
   IN PIO_REMOVE_LOCK  RemoveLock,
   IN OPTIONAL PVOID  Tag  OPTIONAL,
@@ -7512,41 +7536,41 @@ IoAcquireRemoveLockEx(
     } \
 }
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoAllocateController(
   IN PCONTROLLER_OBJECT  ControllerObject,
   IN PDEVICE_OBJECT  DeviceObject,
   IN PDRIVER_CONTROL  ExecutionRoutine,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoAllocateDriverObjectExtension(
   IN PDRIVER_OBJECT  DriverObject,
   IN PVOID  ClientIdentificationAddress,
   IN ULONG  DriverObjectExtensionSize,
   OUT PVOID  *DriverObjectExtension);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 IoAllocateErrorLogEntry(
   IN PVOID  IoObject,
   IN UCHAR  EntrySize);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoAllocateIrp(
   IN CCHAR  StackSize,
   IN BOOLEAN  ChargeQuota);
 
-NTOSAPI
+NTKERNELAPI
 PMDL
-DDKAPI
+NTAPI
 IoAllocateMdl(
   IN PVOID  VirtualAddress,
   IN ULONG  Length,
@@ -7554,9 +7578,9 @@ IoAllocateMdl(
   IN BOOLEAN  ChargeQuota,
   IN OUT PIRP  Irp  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 PIO_WORKITEM
-DDKAPI
+NTAPI
 IoAllocateWorkItem(
   IN PDEVICE_OBJECT  DeviceObject);
 
@@ -7568,24 +7592,24 @@ IoAllocateWorkItem(
 #define IoAssignArcName(_ArcName, _DeviceName) ( \
   IoCreateSymbolicLink((_ArcName), (_DeviceName)))
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoAttachDevice(
   IN PDEVICE_OBJECT  SourceDevice,
   IN PUNICODE_STRING  TargetDevice,
   OUT PDEVICE_OBJECT  *AttachedDevice);
 
-NTOSAPI
+NTKERNELAPI
 PDEVICE_OBJECT
-DDKAPI
+NTAPI
 IoAttachDeviceToDeviceStack(
   IN PDEVICE_OBJECT  SourceDevice,
   IN PDEVICE_OBJECT  TargetDevice);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoBuildAsynchronousFsdRequest(
   IN ULONG  MajorFunction,
   IN PDEVICE_OBJECT  DeviceObject,
@@ -7594,9 +7618,9 @@ IoBuildAsynchronousFsdRequest(
   IN PLARGE_INTEGER  StartingOffset  OPTIONAL,
   IN PIO_STATUS_BLOCK  IoStatusBlock  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoBuildDeviceIoControlRequest(
   IN ULONG  IoControlCode,
   IN PDEVICE_OBJECT  DeviceObject,
@@ -7608,18 +7632,18 @@ IoBuildDeviceIoControlRequest(
   IN PKEVENT  Event,
   OUT PIO_STATUS_BLOCK  IoStatusBlock);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoBuildPartialMdl(
   IN PMDL  SourceMdl,
   IN OUT PMDL  TargetMdl,
   IN PVOID  VirtualAddress,
   IN ULONG  Length);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoBuildSynchronousFsdRequest(
   IN ULONG  MajorFunction,
   IN PDEVICE_OBJECT  DeviceObject,
@@ -7629,9 +7653,9 @@ IoBuildSynchronousFsdRequest(
   IN PKEVENT  Event,
   OUT PIO_STATUS_BLOCK  IoStatusBlock);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKFASTAPI
+FASTCALL
 IofCallDriver(
   IN PDEVICE_OBJECT  DeviceObject,
   IN OUT PIRP  Irp);
@@ -7644,22 +7668,22 @@ IofCallDriver(
  */
 #define IoCallDriver IofCallDriver
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoCancelFileOpen(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PFILE_OBJECT  FileObject);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 IoCancelIrp(
   IN PIRP  Irp);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCheckShareAccess(
   IN ACCESS_MASK  DesiredAccess,
   IN ULONG  DesiredShareAccess,
@@ -7667,9 +7691,9 @@ IoCheckShareAccess(
   IN OUT PSHARE_ACCESS  ShareAccess,
   IN BOOLEAN  Update);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 IofCompleteRequest(
   IN PIRP  Irp,
   IN CCHAR  PriorityBoost);
@@ -7682,9 +7706,9 @@ IofCompleteRequest(
  */
 #define IoCompleteRequest IofCompleteRequest
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoConnectInterrupt(
   OUT PKINTERRUPT  *InterruptObject,
   IN PKSERVICE_ROUTINE  ServiceRoutine,
@@ -7730,15 +7754,15 @@ IoConnectInterrupt(
   _NextIrpSp->Control = 0; \
 }
 
-NTOSAPI
+NTKERNELAPI
 PCONTROLLER_OBJECT
-DDKAPI
+NTAPI
 IoCreateController(
   IN ULONG  Size);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCreateDevice(
   IN PDRIVER_OBJECT  DriverObject,
   IN ULONG  DeviceExtensionSize,
@@ -7748,16 +7772,16 @@ IoCreateDevice(
   IN BOOLEAN  Exclusive,
   OUT PDEVICE_OBJECT  *DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCreateDisk(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PCREATE_DISK  Disk);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCreateFile(
   OUT PHANDLE FileHandle,
   IN ACCESS_MASK DesiredAccess,
@@ -7774,37 +7798,37 @@ IoCreateFile(
   IN PVOID ExtraCreateParameters OPTIONAL,
   IN ULONG Options);
 
-NTOSAPI
+NTKERNELAPI
 PKEVENT
-DDKAPI
+NTAPI
 IoCreateNotificationEvent(
   IN PUNICODE_STRING  EventName,
   OUT PHANDLE  EventHandle);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCreateSymbolicLink(
   IN PUNICODE_STRING  SymbolicLinkName,
   IN PUNICODE_STRING  DeviceName);
 
-NTOSAPI
+NTKERNELAPI
 PKEVENT
-DDKAPI
+NTAPI
 IoCreateSynchronizationEvent(
   IN PUNICODE_STRING  EventName,
   OUT PHANDLE  EventHandle);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCreateUnprotectedSymbolicLink(
   IN PUNICODE_STRING  SymbolicLinkName,
   IN PUNICODE_STRING  DeviceName);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoCsqInitialize(
   PIO_CSQ  Csq,
   IN PIO_CSQ_INSERT_IRP  CsqInsertIrp,
@@ -7814,43 +7838,43 @@ IoCsqInitialize(
   IN PIO_CSQ_RELEASE_LOCK  CsqReleaseLock,
   IN PIO_CSQ_COMPLETE_CANCELED_IRP  CsqCompleteCanceledIrp);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoCsqInsertIrp(
   IN  PIO_CSQ  Csq,
   IN  PIRP  Irp,
   IN  PIO_CSQ_IRP_CONTEXT  Context);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoCsqRemoveIrp(
   IN  PIO_CSQ  Csq,
   IN  PIO_CSQ_IRP_CONTEXT  Context);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoCsqRemoveNextIrp(
   IN PIO_CSQ  Csq,
   IN PVOID  PeekContext);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoDeleteController(
   IN PCONTROLLER_OBJECT  ControllerObject);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoDeleteDevice(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoDeleteSymbolicLink(
   IN PUNICODE_STRING  SymbolicLinkName);
 
@@ -7861,91 +7885,91 @@ IoDeleteSymbolicLink(
  */
 #define IoDeassignArcName IoDeleteSymbolicLink
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoDetachDevice(
   IN OUT PDEVICE_OBJECT  TargetDevice);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoDisconnectInterrupt(
   IN PKINTERRUPT  InterruptObject);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 IoForwardIrpSynchronously(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PIRP  Irp);
 
 #define IoForwardAndCatchIrp IoForwardIrpSynchronously
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoFreeController(
   IN PCONTROLLER_OBJECT  ControllerObject);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoFreeErrorLogEntry(
   PVOID  ElEntry);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoFreeIrp(
   IN PIRP  Irp);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoFreeMdl(
   IN PMDL  Mdl);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoFreeWorkItem(
   IN PIO_WORKITEM  pIOWorkItem);
 
-NTOSAPI
+NTKERNELAPI
 PDEVICE_OBJECT
-DDKAPI
+NTAPI
 IoGetAttachedDevice(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 PDEVICE_OBJECT
-DDKAPI
+NTAPI
 IoGetAttachedDeviceReference(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoGetBootDiskInformation(
   IN OUT PBOOTDISK_INFORMATION  BootDiskInformation,
   IN ULONG  Size);
 
-NTOSAPI
+NTKERNELAPI
 PCONFIGURATION_INFORMATION
-DDKAPI
+NTAPI
 IoGetConfigurationInformation(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 PEPROCESS
-DDKAPI
+NTAPI
 IoGetCurrentProcess(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoGetDeviceInterfaceAlias(
   IN PUNICODE_STRING  SymbolicLinkName,
   IN CONST GUID  *AliasInterfaceClassGuid,
@@ -7953,27 +7977,27 @@ IoGetDeviceInterfaceAlias(
 
 #define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoGetDeviceInterfaces(
   IN CONST GUID  *InterfaceClassGuid,
   IN PDEVICE_OBJECT  PhysicalDeviceObject  OPTIONAL,
   IN ULONG  Flags,
   OUT PWSTR  *SymbolicLinkList);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoGetDeviceObjectPointer(
   IN PUNICODE_STRING  ObjectName,
   IN ACCESS_MASK  DesiredAccess,
   OUT PFILE_OBJECT  *FileObject,
   OUT PDEVICE_OBJECT  *DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoGetDeviceProperty(
   IN PDEVICE_OBJECT  DeviceObject,
   IN DEVICE_REGISTRY_PROPERTY  DeviceProperty,
@@ -7981,30 +8005,30 @@ IoGetDeviceProperty(
   OUT PVOID  PropertyBuffer,
   OUT PULONG  ResultLength);
 
-NTOSAPI
+NTKERNELAPI
 PDEVICE_OBJECT
-DDKAPI
+NTAPI
 IoGetDeviceToVerify(
   IN PETHREAD  Thread);
 
-NTOSAPI
+NTKERNELAPI
 PDMA_ADAPTER
-DDKAPI
+NTAPI
 IoGetDmaAdapter(
   IN PDEVICE_OBJECT  PhysicalDeviceObject,
   IN PDEVICE_DESCRIPTION  DeviceDescription,
   IN OUT PULONG  NumberOfMapRegisters);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 IoGetDriverObjectExtension(
   IN PDRIVER_OBJECT  DriverObject,
   IN PVOID  ClientIdentificationAddress);
 
-NTOSAPI
+NTKERNELAPI
 PGENERIC_MAPPING
-DDKAPI
+NTAPI
 IoGetFileObjectGenericMapping(
   VOID);
 
@@ -8016,34 +8040,34 @@ IoGetFileObjectGenericMapping(
 #define IoGetFunctionCodeFromCtlCode(_ControlCode) \
   (((_ControlCode) >> 2) & 0x00000FFF)
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 IoGetInitialStack(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 PDEVICE_OBJECT
-DDKAPI
+NTAPI
 IoGetRelatedDeviceObject(
   IN PFILE_OBJECT  FileObject);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 IoGetRemainingStackSize(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoGetStackLimits(
   OUT PULONG_PTR  LowLimit,
   OUT PULONG_PTR  HighLimit);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeDpc(
   IN PRKDPC  Dpc,
   IN PKDEFERRED_ROUTINE  DeferredRoutine,
@@ -8061,17 +8085,17 @@ KeInitializeDpc(
     (PKDEFERRED_ROUTINE) (_DpcRoutine), \
     _DeviceObject)
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoInitializeIrp(
   IN OUT PIRP  Irp,
   IN USHORT  PacketSize,
   IN CCHAR  StackSize);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoInitializeRemoveLockEx(
   IN  PIO_REMOVE_LOCK Lock,
   IN  ULONG   AllocateTag,
@@ -8091,30 +8115,30 @@ IoInitializeRemoveLockEx(
   IoInitializeRemoveLockEx(Lock, AllocateTag, MaxLockedMinutes, \
     HighWatermark, sizeof(IO_REMOVE_LOCK))
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoInitializeTimer(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PIO_TIMER_ROUTINE  TimerRoutine,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoInvalidateDeviceRelations(
   IN PDEVICE_OBJECT  DeviceObject,
   IN DEVICE_RELATION_TYPE  Type);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoInvalidateDeviceState(
   IN PDEVICE_OBJECT  PhysicalDeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 IoIs32bitProcess(
   IN PIRP  Irp  OPTIONAL);
 
@@ -8132,16 +8156,16 @@ IoIs32bitProcess(
    ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
    ((Status) == STATUS_WRONG_VOLUME)))
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 IoIsWdmVersionAvailable(
   IN UCHAR  MajorVersion,
   IN UCHAR  MinorVersion);
 
-NTOSAPI
+NTKERNELAPI
 PIRP
-DDKAPI
+NTAPI
 IoMakeAssociatedIrp(
   IN PIRP  Irp,
   IN CCHAR  StackSize);
@@ -8154,9 +8178,9 @@ IoMakeAssociatedIrp(
 #define IoMarkIrpPending(_Irp) \
   (IoGetCurrentIrpStackLocation(_Irp)->Control |= SL_PENDING_RETURNED)
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoOpenDeviceInterfaceRegistryKey(
   IN PUNICODE_STRING  SymbolicLinkName,
   IN ACCESS_MASK  DesiredAccess,
@@ -8166,18 +8190,18 @@ IoOpenDeviceInterfaceRegistryKey(
 #define PLUGPLAY_REGKEY_DRIVER                            2
 #define PLUGPLAY_REGKEY_CURRENT_HWPROFILE                 4
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoOpenDeviceRegistryKey(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  DevInstKeyType,
   IN ACCESS_MASK  DesiredAccess,
   OUT PHANDLE  DevInstRegKey);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoQueryDeviceDescription(
   IN PINTERFACE_TYPE  BusType  OPTIONAL,
   IN PULONG  BusNumber  OPTIONAL,
@@ -8188,82 +8212,82 @@ IoQueryDeviceDescription(
   IN PIO_QUERY_DEVICE_ROUTINE  CalloutRoutine,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoQueueWorkItem(
   IN PIO_WORKITEM  pIOWorkItem,
   IN PIO_WORKITEM_ROUTINE  Routine,
   IN WORK_QUEUE_TYPE  QueueType,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoRaiseHardError(
   IN PIRP  Irp,
   IN PVPB  Vpb  OPTIONAL,
   IN PDEVICE_OBJECT  RealDeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 IoRaiseInformationalHardError(
   IN NTSTATUS  ErrorStatus,
   IN PUNICODE_STRING  String  OPTIONAL,
   IN PKTHREAD  Thread  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReadDiskSignature(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  BytesPerSector,
   OUT PDISK_SIGNATURE  Signature);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReadPartitionTableEx(
   IN PDEVICE_OBJECT  DeviceObject,
   IN struct _DRIVE_LAYOUT_INFORMATION_EX  **PartitionBuffer);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoRegisterBootDriverReinitialization(
   IN PDRIVER_OBJECT  DriverObject,
   IN PDRIVER_REINITIALIZE  DriverReinitializationRoutine,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoRegisterBootDriverReinitialization(
   IN PDRIVER_OBJECT  DriverObject,
   IN PDRIVER_REINITIALIZE  DriverReinitializationRoutine,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoRegisterDeviceInterface(
   IN PDEVICE_OBJECT  PhysicalDeviceObject,
   IN CONST GUID  *InterfaceClassGuid,
   IN PUNICODE_STRING  ReferenceString  OPTIONAL,
   OUT PUNICODE_STRING  SymbolicLinkName);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoRegisterDriverReinitialization(
   IN PDRIVER_OBJECT  DriverObject,
   IN PDRIVER_REINITIALIZE  DriverReinitializationRoutine,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoRegisterPlugPlayNotification(
   IN IO_NOTIFICATION_EVENT_CATEGORY  EventCategory,
   IN ULONG  EventCategoryFlags,
@@ -8273,29 +8297,29 @@ IoRegisterPlugPlayNotification(
   IN PVOID  Context,
   OUT PVOID  *NotificationEntry);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoRegisterShutdownNotification(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoReleaseCancelSpinLock(
   IN KIRQL  Irql);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoReleaseRemoveLockAndWaitEx(
   IN PIO_REMOVE_LOCK  RemoveLock,
   IN PVOID  Tag,
   IN ULONG  RemlockSize);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoReleaseRemoveLockEx(
   IN PIO_REMOVE_LOCK  RemoveLock,
   IN PVOID  Tag,
@@ -8321,16 +8345,16 @@ IoReleaseRemoveLockEx(
                                    _Tag) \
   IoReleaseRemoveLockAndWaitEx(_RemoveLock, _Tag, sizeof(IO_REMOVE_LOCK))
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoRemoveShareAccess(
   IN PFILE_OBJECT  FileObject,
   IN OUT PSHARE_ACCESS  ShareAccess);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReportDetectedDevice(
   IN PDRIVER_OBJECT  DriverObject,
   IN INTERFACE_TYPE  LegacyBusType,
@@ -8341,9 +8365,9 @@ IoReportDetectedDevice(
   IN BOOLEAN  ResourceAssigned,
   IN OUT PDEVICE_OBJECT  *DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReportResourceForDetection(
   IN PDRIVER_OBJECT  DriverObject,
   IN PCM_RESOURCE_LIST  DriverList  OPTIONAL,
@@ -8353,9 +8377,9 @@ IoReportResourceForDetection(
   IN ULONG  DeviceListSize  OPTIONAL,
   OUT PBOOLEAN  ConflictDetected);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReportResourceUsage(
   IN PUNICODE_STRING  DriverClassName  OPTIONAL,
   IN PDRIVER_OBJECT  DriverObject,
@@ -8367,25 +8391,25 @@ IoReportResourceUsage(
   IN BOOLEAN  OverrideConflict,
   OUT PBOOLEAN  ConflictDetected);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReportTargetDeviceChange(
   IN PDEVICE_OBJECT  PhysicalDeviceObject,
   IN PVOID  NotificationStructure);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoReportTargetDeviceChangeAsynchronous(
   IN PDEVICE_OBJECT  PhysicalDeviceObject,
   IN PVOID  NotificationStructure,
   IN PDEVICE_CHANGE_COMPLETE_CALLBACK  Callback  OPTIONAL,
   IN PVOID  Context  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoRequestDeviceEject(
   IN PDEVICE_OBJECT  PhysicalDeviceObject);
 
@@ -8399,9 +8423,9 @@ IoRequestDeviceEject(
 #define IoRequestDpc(DeviceObject, Irp, Context)( \
   KeInsertQueueDpc(&(DeviceObject)->Dpc, (Irp), (Context)))
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoReuseIrp(
   IN OUT PIRP  Irp,
   IN NTSTATUS  Status);
@@ -8446,9 +8470,9 @@ IoReuseIrp(
   if (_InvokeOnCancel) _IrpSp->Control |= SL_INVOKE_ON_CANCEL; \
 }
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoSetCompletionRoutineEx(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PIRP  Irp,
@@ -8458,16 +8482,16 @@ IoSetCompletionRoutineEx(
   IN BOOLEAN  InvokeOnError,
   IN BOOLEAN  InvokeOnCancel);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoSetDeviceInterfaceState(
   IN PUNICODE_STRING  SymbolicLinkName,
   IN BOOLEAN  Enable);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoSetHardErrorOrVerifyDevice(
   IN PIRP  Irp,
   IN PDEVICE_OBJECT  DeviceObject);
@@ -8483,40 +8507,40 @@ IoSetHardErrorOrVerifyDevice(
   (_Irp)->Tail.Overlay.CurrentStackLocation--; \
 }
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoSetPartitionInformationEx(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  PartitionNumber,
   IN struct _SET_PARTITION_INFORMATION_EX  *PartitionInfo);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoSetShareAccess(
   IN ACCESS_MASK  DesiredAccess,
   IN ULONG  DesiredShareAccess,
   IN OUT PFILE_OBJECT  FileObject,
   OUT PSHARE_ACCESS  ShareAccess);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoSetStartIoAttributes(
   IN PDEVICE_OBJECT  DeviceObject,
   IN BOOLEAN  DeferredStartIo,
   IN BOOLEAN  NonCancelable);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoSetSystemPartition(
   IN PUNICODE_STRING  VolumeNameString);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 IoSetThreadHardErrorMode(
   IN BOOLEAN  EnableHardErrors);
 
@@ -8539,100 +8563,100 @@ IoSetThreadHardErrorMode(
   (_Irp)->Tail.Overlay.CurrentStackLocation++; \
 }
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoStartNextPacket(
   IN PDEVICE_OBJECT  DeviceObject,
   IN BOOLEAN  Cancelable);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoStartNextPacketByKey(
   IN PDEVICE_OBJECT  DeviceObject,
   IN BOOLEAN  Cancelable,
   IN ULONG  Key);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoStartPacket(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PIRP  Irp,
   IN PULONG  Key  OPTIONAL,
   IN PDRIVER_CANCEL  CancelFunction  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoStartTimer(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoStopTimer(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoUnregisterPlugPlayNotification(
   IN PVOID  NotificationEntry);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoUnregisterShutdownNotification(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoUpdateShareAccess(
   IN PFILE_OBJECT  FileObject,
   IN OUT PSHARE_ACCESS  ShareAccess);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoVerifyPartitionTable(
   IN PDEVICE_OBJECT  DeviceObject,
   IN BOOLEAN  FixErrors);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoVolumeDeviceToDosName(
   IN  PVOID  VolumeDeviceObject,
   OUT PUNICODE_STRING  DosName);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIAllocateInstanceIds(
   IN GUID  *Guid,
   IN ULONG  InstanceCount,
   OUT ULONG  *FirstInstanceId);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 IoWMIDeviceObjectToProviderId(
   IN PDEVICE_OBJECT  DeviceObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIDeviceObjectToInstanceName(
   IN PVOID  DataBlockObject,
   IN PDEVICE_OBJECT  DeviceObject,
   OUT PUNICODE_STRING  InstanceName);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIExecuteMethod(
   IN PVOID  DataBlockObject,
   IN PUNICODE_STRING  InstanceName,
@@ -8641,51 +8665,51 @@ IoWMIExecuteMethod(
   IN OUT PULONG  OutBufferSize,
   IN OUT  PUCHAR  InOutBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIHandleToInstanceName(
   IN PVOID  DataBlockObject,
   IN HANDLE  FileHandle,
   OUT PUNICODE_STRING  InstanceName);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIOpenBlock(
   IN GUID  *DataBlockGuid,
   IN ULONG  DesiredAccess,
   OUT PVOID  *DataBlockObject);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIQueryAllData(
   IN PVOID  DataBlockObject,
   IN OUT ULONG  *InOutBufferSize,
   OUT PVOID  OutBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIQueryAllDataMultiple(
   IN PVOID  *DataBlockObjectList,
   IN ULONG  ObjectCount,
   IN OUT ULONG  *InOutBufferSize,
   OUT PVOID  OutBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIQuerySingleInstance(
   IN PVOID  DataBlockObject,
   IN PUNICODE_STRING  InstanceName,
   IN OUT ULONG  *InOutBufferSize,
   OUT PVOID OutBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIQuerySingleInstanceMultiple(
   IN PVOID  *DataBlockObjectList,
   IN PUNICODE_STRING  InstanceNames,
@@ -8693,24 +8717,24 @@ IoWMIQuerySingleInstanceMultiple(
   IN OUT ULONG  *InOutBufferSize,
   OUT PVOID  OutBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIRegistrationControl(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  Action);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMISetNotificationCallback(
   IN PVOID  Object,
   IN WMI_NOTIFICATION_CALLBACK  Callback,
   IN PVOID  Context);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMISetSingleInstance(
   IN PVOID  DataBlockObject,
   IN PUNICODE_STRING  InstanceName,
@@ -8718,9 +8742,9 @@ IoWMISetSingleInstance(
   IN ULONG  ValueBufferSize,
   IN PVOID  ValueBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMISetSingleItem(
   IN PVOID  DataBlockObject,
   IN PUNICODE_STRING  InstanceName,
@@ -8729,30 +8753,30 @@ IoWMISetSingleItem(
   IN ULONG  ValueBufferSize,
   IN PVOID  ValueBuffer);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMISuggestInstanceName(
   IN PDEVICE_OBJECT  PhysicalDeviceObject OPTIONAL,
   IN PUNICODE_STRING  SymbolicLinkName OPTIONAL,
   IN BOOLEAN  CombineNames,
   OUT PUNICODE_STRING  SuggestedInstanceName);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWMIWriteEvent(
   IN PVOID  WnodeEventItem);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 IoWriteErrorLogEntry(
   IN PVOID  ElEntry);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 IoWritePartitionTableEx(
   IN PDEVICE_OBJECT  DeviceObject,
   IN struct _DRIVE_LAYOUT_INFORMATION_EX  *PartitionBuffer);
@@ -8763,39 +8787,39 @@ IoWritePartitionTableEx(
 
 NTHALAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KeAcquireInStackQueuedSpinLock(
   IN PKSPIN_LOCK  SpinLock,
   IN PKLOCK_QUEUE_HANDLE  LockHandle);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KeAcquireInStackQueuedSpinLockAtDpcLevel(
   IN PKSPIN_LOCK  SpinLock,
   IN PKLOCK_QUEUE_HANDLE  LockHandle);
 
-NTOSAPI
+NTKERNELAPI
 KIRQL
-DDKAPI
+NTAPI
 KeAcquireInterruptSpinLock(
   IN PKINTERRUPT  Interrupt);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeAreApcsDisabled(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeBugCheck(
   IN ULONG  BugCheckCode);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeBugCheckEx(
   IN ULONG  BugCheckCode,
   IN ULONG_PTR  BugCheckParameter1,
@@ -8803,35 +8827,35 @@ KeBugCheckEx(
   IN ULONG_PTR  BugCheckParameter3,
   IN ULONG_PTR  BugCheckParameter4);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeCancelTimer(
   IN PKTIMER  Timer);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeClearEvent(
   IN PRKEVENT  Event);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KeDelayExecutionThread(
   IN KPROCESSOR_MODE  WaitMode,
   IN BOOLEAN  Alertable,
   IN PLARGE_INTEGER  Interval);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeDeregisterBugCheckCallback(
   IN PKBUGCHECK_CALLBACK_RECORD  CallbackRecord);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeEnterCriticalRegion(
   VOID);
 
@@ -8846,93 +8870,87 @@ KeEnterCriticalRegion(
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 KeFlushWriteBuffer(VOID);
 
-NTOSAPI
+NTKERNELAPI
 PRKTHREAD
-DDKAPI
+NTAPI
 KeGetCurrentThread(
   VOID);
 
-NTOSAPI
-KPROCESSOR_MODE
-DDKAPI
-KeGetPreviousMode(
-  VOID);
-
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 KeGetRecommendedSharedDataAlignment(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeDeviceQueue(
   IN PKDEVICE_QUEUE  DeviceQueue);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeMutex(
   IN PRKMUTEX  Mutex,
   IN ULONG  Level);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeSemaphore(
   IN PRKSEMAPHORE  Semaphore,
   IN LONG  Count,
   IN LONG  Limit);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeSpinLock(
   IN PKSPIN_LOCK  SpinLock);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeTimer(
   IN PKTIMER  Timer);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeInitializeTimerEx(
   IN PKTIMER  Timer,
   IN TIMER_TYPE  Type);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeInsertByKeyDeviceQueue(
   IN PKDEVICE_QUEUE  DeviceQueue,
   IN PKDEVICE_QUEUE_ENTRY  DeviceQueueEntry,
   IN ULONG  SortKey);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeInsertDeviceQueue(
   IN PKDEVICE_QUEUE  DeviceQueue,
   IN PKDEVICE_QUEUE_ENTRY  DeviceQueueEntry);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeInsertQueueDpc(
   IN PRKDPC  Dpc,
   IN PVOID  SystemArgument1,
   IN PVOID  SystemArgument2);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeLeaveCriticalRegion(
   VOID);
 
@@ -8962,78 +8980,78 @@ KeMemoryBarrier(
 
 #endif
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KePulseEvent(
   IN PRKEVENT  Event,
   IN KPRIORITY  Increment,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 ULONGLONG
-DDKAPI
+NTAPI
 KeQueryInterruptTime(
   VOID);
 
 NTHALAPI
 LARGE_INTEGER
-DDKAPI
+NTAPI
 KeQueryPerformanceCounter(
   OUT PLARGE_INTEGER  PerformanceFrequency  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 KPRIORITY
-DDKAPI
+NTAPI
 KeQueryPriorityThread(
   IN PRKTHREAD  Thread);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeQuerySystemTime(
   OUT PLARGE_INTEGER  CurrentTime);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeQueryTickCount(
   OUT PLARGE_INTEGER  TickCount);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 KeQueryTimeIncrement(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeReadStateEvent(
   IN PRKEVENT  Event);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeReadStateMutex(
   IN PRKMUTEX  Mutex);
 
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeReadStateSemaphore(
   IN PRKSEMAPHORE  Semaphore);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeReadStateTimer(
   IN PKTIMER  Timer);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeRegisterBugCheckCallback(
   IN PKBUGCHECK_CALLBACK_RECORD  CallbackRecord,
   IN PKBUGCHECK_CALLBACK_ROUTINE  CallbackRoutine,
@@ -9043,170 +9061,170 @@ KeRegisterBugCheckCallback(
 
 NTHALAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KeReleaseInStackQueuedSpinLock(
   IN PKLOCK_QUEUE_HANDLE  LockHandle);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KeReleaseInStackQueuedSpinLockFromDpcLevel(
   IN PKLOCK_QUEUE_HANDLE  LockHandle);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeReleaseInterruptSpinLock(
   IN PKINTERRUPT  Interrupt,
   IN KIRQL  OldIrql);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeReleaseMutex(
   IN PRKMUTEX  Mutex,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeReleaseSemaphore(
   IN PRKSEMAPHORE  Semaphore,
   IN KPRIORITY  Increment,
   IN LONG  Adjustment,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 PKDEVICE_QUEUE_ENTRY
-DDKAPI
+NTAPI
 KeRemoveByKeyDeviceQueue(
   IN PKDEVICE_QUEUE  DeviceQueue,
   IN ULONG  SortKey);
 
-NTOSAPI
+NTKERNELAPI
 PKDEVICE_QUEUE_ENTRY
-DDKAPI
+NTAPI
 KeRemoveDeviceQueue(
   IN PKDEVICE_QUEUE  DeviceQueue);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeRemoveEntryDeviceQueue(
   IN PKDEVICE_QUEUE  DeviceQueue,
   IN PKDEVICE_QUEUE_ENTRY  DeviceQueueEntry);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeRemoveQueueDpc(
   IN PRKDPC  Dpc);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeResetEvent(
   IN PRKEVENT  Event);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KeRestoreFloatingPointState(
   IN PKFLOATING_SAVE  FloatSave);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeRevertToUserAffinityThread(VOID);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KeSaveFloatingPointState(
   OUT PKFLOATING_SAVE  FloatSave);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeSetBasePriorityThread(
   IN PRKTHREAD  Thread,
   IN LONG  Increment);
 
-NTOSAPI
+NTKERNELAPI
 LONG
-DDKAPI
+NTAPI
 KeSetEvent(
   IN PRKEVENT  Event,
   IN KPRIORITY  Increment,
   IN BOOLEAN  Wait);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeSetImportanceDpc(
   IN PRKDPC  Dpc,
   IN KDPC_IMPORTANCE  Importance);
 
-NTOSAPI
+NTKERNELAPI
 KPRIORITY
-DDKAPI
+NTAPI
 KeSetPriorityThread(
   IN PKTHREAD  Thread,
   IN KPRIORITY  Priority);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeSetSystemAffinityThread(
     IN KAFFINITY Affinity);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeSetTargetProcessorDpc(
   IN PRKDPC  Dpc,
   IN CCHAR  Number);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeSetTimer(
   IN PKTIMER  Timer,
   IN LARGE_INTEGER  DueTime,
   IN PKDPC  Dpc  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeSetTimerEx(
   IN PKTIMER  Timer,
   IN LARGE_INTEGER  DueTime,
   IN LONG  Period  OPTIONAL,
   IN PKDPC  Dpc  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKFASTAPI
+FASTCALL
 KeSetTimeUpdateNotifyRoutine(
   IN PTIME_UPDATE_NOTIFY_ROUTINE  NotifyRoutine);
 
 NTHALAPI
 VOID
-DDKAPI
+NTAPI
 KeStallExecutionProcessor(
   IN ULONG  MicroSeconds);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 KeSynchronizeExecution(
   IN PKINTERRUPT    Interrupt,
   IN PKSYNCHRONIZE_ROUTINE  SynchronizeRoutine,
   IN PVOID  SynchronizeContext);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KeWaitForMultipleObjects(
   IN ULONG  Count,
   IN PVOID  Object[],
@@ -9217,9 +9235,9 @@ KeWaitForMultipleObjects(
   IN PLARGE_INTEGER  Timeout  OPTIONAL,
   IN PKWAIT_BLOCK  WaitBlockArray  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KeWaitForMutexObject(
   IN PRKMUTEX  Mutex,
   IN KWAIT_REASON  WaitReason,
@@ -9227,9 +9245,9 @@ KeWaitForMutexObject(
   IN BOOLEAN  Alertable,
   IN PLARGE_INTEGER  Timeout  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KeWaitForSingleObject(
   IN PVOID  Object,
   IN KWAIT_REASON  WaitReason,
@@ -9311,45 +9329,49 @@ KeRaiseIrqlToSynchLevel(
 
 #else
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 KeLowerIrql(
   IN KIRQL  NewIrql);
 
-NTOSAPI
+NTKERNELAPI
 KIRQL
-DDKAPI
+NTAPI
 KeRaiseIrql(
   IN KIRQL  NewIrql);
 
-NTOSAPI
+NTKERNELAPI
 KIRQL
-DDKAPI
+NTAPI
 KeRaiseIrqlToDpcLevel(
   VOID);
 
+#define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
+#define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
+#define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
+
 #endif
 
 /** Memory manager routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmAdvanceMdl(
   IN PMDL  Mdl,
   IN ULONG  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmAllocateContiguousMemory(
   IN ULONG  NumberOfBytes,
   IN PHYSICAL_ADDRESS  HighestAcceptableAddress);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmAllocateContiguousMemorySpecifyCache(
   IN SIZE_T  NumberOfBytes,
   IN PHYSICAL_ADDRESS  LowestAcceptableAddress,
@@ -9357,37 +9379,37 @@ MmAllocateContiguousMemorySpecifyCache(
   IN PHYSICAL_ADDRESS  BoundaryAddressMultiple  OPTIONAL,
   IN MEMORY_CACHING_TYPE  CacheType);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmAllocateMappingAddress(
   IN SIZE_T  NumberOfBytes,
   IN ULONG  PoolTag);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmAllocateNonCachedMemory(
   IN ULONG  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 PMDL
-DDKAPI
+NTAPI
 MmAllocatePagesForMdl(
   IN PHYSICAL_ADDRESS  LowAddress,
   IN PHYSICAL_ADDRESS  HighAddress,
   IN PHYSICAL_ADDRESS  SkipBytes,
   IN SIZE_T  TotalBytes);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmBuildMdlForNonPagedPool(
   IN OUT PMDL  MemoryDescriptorList);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmCreateSection(
   OUT PVOID *SectionObject,
   IN ACCESS_MASK  DesiredAccess,
@@ -9403,44 +9425,44 @@ typedef enum _MMFLUSH_TYPE {
   MmFlushForWrite
 } MMFLUSH_TYPE;
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 MmFlushImageSection(
   IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
   IN MMFLUSH_TYPE  FlushType);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmFreeContiguousMemory(
   IN PVOID  BaseAddress);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmFreeContiguousMemorySpecifyCache(
   IN PVOID  BaseAddress,
   IN SIZE_T  NumberOfBytes,
   IN MEMORY_CACHING_TYPE  CacheType);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmFreeMappingAddress(
   IN PVOID  BaseAddress,
   IN ULONG  PoolTag);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmFreeNonCachedMemory(
   IN PVOID  BaseAddress,
   IN SIZE_T  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmFreePagesFromMdl(
   IN PMDL  MemoryDescriptorList);
 
@@ -9476,27 +9498,27 @@ MmFreePagesFromMdl(
 #define MmGetMdlVirtualAddress(_Mdl) \
   ((PVOID) ((PCHAR) ((_Mdl)->StartVa) + (_Mdl)->ByteOffset))
 
-NTOSAPI
+NTKERNELAPI
 PHYSICAL_ADDRESS
-DDKAPI
+NTAPI
 MmGetPhysicalAddress(
   IN PVOID  BaseAddress);
 
-NTOSAPI
+NTKERNELAPI
 PPHYSICAL_MEMORY_RANGE
-DDKAPI
+NTAPI
 MmGetPhysicalMemoryRanges(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmGetVirtualForPhysical(
   IN PHYSICAL_ADDRESS  PhysicalAddress);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmMapLockedPagesSpecifyCache(
   IN PMDL  MemoryDescriptorList,
   IN KPROCESSOR_MODE  AccessMode,
@@ -9505,57 +9527,57 @@ MmMapLockedPagesSpecifyCache(
   IN ULONG  BugCheckOnFailure,
   IN MM_PAGE_PRIORITY  Priority);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmMapLockedPagesWithReservedMapping(
   IN PVOID  MappingAddress,
   IN ULONG  PoolTag,
   IN PMDL  MemoryDescriptorList,
   IN MEMORY_CACHING_TYPE  CacheType);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmMapUserAddressesToPage(
   IN PVOID  BaseAddress,
   IN SIZE_T  NumberOfBytes,
   IN PVOID  PageAddress);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmMapVideoDisplay(
   IN PHYSICAL_ADDRESS  PhysicalAddress,
   IN SIZE_T  NumberOfBytes,
   IN MEMORY_CACHING_TYPE  CacheType);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmMapViewInSessionSpace(
   IN PVOID  Section,
   OUT PVOID  *MappedBase,
   IN OUT PSIZE_T  ViewSize);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmMapViewInSystemSpace(
   IN PVOID  Section,
   OUT PVOID  *MappedBase,
   IN PSIZE_T  ViewSize);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmMarkPhysicalMemoryAsBad(
   IN PPHYSICAL_ADDRESS  StartAddress,
   IN OUT PLARGE_INTEGER  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmMarkPhysicalMemoryAsGood(
   IN PPHYSICAL_ADDRESS  StartAddress,
   IN OUT PLARGE_INTEGER  NumberOfBytes);
@@ -9573,9 +9595,9 @@ MmMarkPhysicalMemoryAsGood(
     (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
       KernelMode, MmCached, NULL, FALSE, _Priority)
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmGetSystemRoutineAddress(
   IN PUNICODE_STRING  SystemRoutineName);
 
@@ -9610,39 +9632,39 @@ MmGetSystemRoutineAddress(
   (_MemoryDescriptorList)->ByteCount = (ULONG) _Length; \
 }
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 MmIsAddressValid(
   IN PVOID  VirtualAddress);
 
-NTOSAPI
+NTKERNELAPI
 LOGICAL
-DDKAPI
+NTAPI
 MmIsDriverVerifying(
   IN PDRIVER_OBJECT  DriverObject);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 MmIsThisAnNtAsSystem(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmIsVerifierEnabled(
   OUT PULONG  VerifierFlags);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmLockPagableDataSection(
   IN PVOID  AddressWithinSection);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmLockPagableImageSection(
   IN PVOID  AddressWithinSection);
 
@@ -9653,71 +9675,71 @@ MmLockPagableImageSection(
  */
 #define MmLockPagableCodeSection MmLockPagableDataSection
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmLockPagableSectionByHandle(
   IN PVOID  ImageSectionHandle);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmMapIoSpace(
   IN PHYSICAL_ADDRESS  PhysicalAddress,
   IN ULONG  NumberOfBytes,
   IN MEMORY_CACHING_TYPE  CacheEnable);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmMapLockedPages(
   IN PMDL  MemoryDescriptorList,
   IN KPROCESSOR_MODE  AccessMode);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 MmPageEntireDriver(
   IN PVOID  AddressWithinSection);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmProbeAndLockProcessPages(
   IN OUT PMDL  MemoryDescriptorList,
   IN PEPROCESS  Process,
   IN KPROCESSOR_MODE  AccessMode,
   IN LOCK_OPERATION  Operation);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmProtectMdlSystemAddress(
   IN PMDL  MemoryDescriptorList,
   IN ULONG  NewProtect);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnmapLockedPages(
   IN PVOID  BaseAddress,
   IN PMDL  MemoryDescriptorList);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmUnmapViewInSessionSpace(
   IN PVOID  MappedBase);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmUnmapViewInSystemSpace(
   IN PVOID MappedBase);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnsecureVirtualMemory(
   IN HANDLE  SecureHandle);
 
@@ -9736,78 +9758,78 @@ MmUnsecureVirtualMemory(
   } \
 }
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmProbeAndLockPages(
   IN OUT PMDL  MemoryDescriptorList,
   IN KPROCESSOR_MODE  AccessMode,
   IN LOCK_OPERATION  Operation);
 
-NTOSAPI
+NTKERNELAPI
 MM_SYSTEMSIZE
-DDKAPI
+NTAPI
 MmQuerySystemSize(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 MmRemovePhysicalMemory(
   IN PPHYSICAL_ADDRESS  StartAddress,
   IN OUT PLARGE_INTEGER  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmResetDriverPaging(
   IN PVOID  AddressWithinSection);
 
-NTOSAPI
+NTKERNELAPI
 HANDLE
-DDKAPI
+NTAPI
 MmSecureVirtualMemory(
   IN PVOID  Address,
   IN SIZE_T  Size,
   IN ULONG  ProbeMode);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
-DDKAPI
+NTAPI
 MmSizeOfMdl(
   IN PVOID  Base,
   IN SIZE_T  Length);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnlockPagableImageSection(
   IN PVOID  ImageSectionHandle);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnlockPages(
   IN PMDL  MemoryDescriptorList);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnmapIoSpace(
   IN PVOID  BaseAddress,
   IN SIZE_T  NumberOfBytes);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnmapReservedMapping(
   IN PVOID  BaseAddress,
   IN ULONG  PoolTag,
   IN PMDL  MemoryDescriptorList);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 MmUnmapVideoDisplay(
   IN PVOID  BaseAddress,
   IN SIZE_T  NumberOfBytes);
@@ -9816,25 +9838,25 @@ MmUnmapVideoDisplay(
 
 /** Object manager routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObAssignSecurity(
   IN PACCESS_STATE  AccessState,
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
   IN PVOID  Object,
   IN POBJECT_TYPE  Type);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ObDereferenceSecurityDescriptor(
   PSECURITY_DESCRIPTOR  SecurityDescriptor,
   ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 LONG_PTR
-DDKFASTAPI
+FASTCALL
 ObfDereferenceObject(
   IN PVOID  Object);
 
@@ -9845,17 +9867,17 @@ ObfDereferenceObject(
  */
 #define ObDereferenceObject ObfDereferenceObject
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObGetObjectSecurity(
   IN PVOID  Object,
   OUT PSECURITY_DESCRIPTOR  *SecurityDescriptor,
   OUT PBOOLEAN  MemoryAllocated);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObInsertObject(
   IN PVOID  Object,
   IN PACCESS_STATE  PassedAccessState  OPTIONAL,
@@ -9864,15 +9886,15 @@ ObInsertObject(
   OUT PVOID*  ReferencedObject  OPTIONAL,
   OUT PHANDLE  Handle);
 
-NTOSAPI
+NTKERNELAPI
 LONG_PTR
-DDKFASTAPI
+FASTCALL
 ObfReferenceObject(
   IN PVOID  Object);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObLogSecurityDescriptor(
   IN PSECURITY_DESCRIPTOR  InputSecurityDescriptor,
   OUT PSECURITY_DESCRIPTOR  *OutputSecurityDescriptor,
@@ -9884,15 +9906,15 @@ ObLogSecurityDescriptor(
  */
 #define ObReferenceObject ObfReferenceObject
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ObMakeTemporaryObject(
   IN PVOID  Object);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObOpenObjectByName(
   IN POBJECT_ATTRIBUTES  ObjectAttributes,
   IN POBJECT_TYPE  ObjectType,
@@ -9902,9 +9924,9 @@ ObOpenObjectByName(
   IN OUT PVOID  ParseContext  OPTIONAL,
   OUT PHANDLE  Handle);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObOpenObjectByPointer(
   IN PVOID  Object,
   IN ULONG  HandleAttributes,
@@ -9914,16 +9936,16 @@ ObOpenObjectByPointer(
   IN KPROCESSOR_MODE  AccessMode,
   OUT PHANDLE  Handle);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObQueryObjectAuditingByHandle(
   IN HANDLE  Handle,
   OUT PBOOLEAN  GenerateOnClose);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObReferenceObjectByHandle(
   IN HANDLE  Handle,
   IN ACCESS_MASK  DesiredAccess,
@@ -9932,9 +9954,9 @@ ObReferenceObjectByHandle(
   OUT PVOID  *Object,
   OUT POBJECT_HANDLE_INFORMATION  HandleInformation  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObReferenceObjectByName(
   IN PUNICODE_STRING  ObjectPath,
   IN ULONG  Attributes,
@@ -9945,25 +9967,25 @@ ObReferenceObjectByName(
   IN OUT PVOID  ParseContext  OPTIONAL,
   OUT PVOID  *Object);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ObReferenceObjectByPointer(
   IN PVOID  Object,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_TYPE  ObjectType,
   IN KPROCESSOR_MODE  AccessMode);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ObReferenceSecurityDescriptor(
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
   IN ULONG  Count);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 ObReleaseObjectSecurity(
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
   IN BOOLEAN  MemoryAllocated);
@@ -9972,17 +9994,17 @@ ObReleaseObjectSecurity(
 
 /** Process manager routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsCreateSystemProcess(
   IN PHANDLE  ProcessHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsCreateSystemThread(
   OUT PHANDLE  ThreadHandle,
   IN ULONG  DesiredAccess,
@@ -9998,9 +10020,9 @@ PsCreateSystemThread(
  */
 #define PsGetCurrentProcess IoGetCurrentProcess
 
-NTOSAPI
+NTKERNELAPI
 HANDLE
-DDKAPI
+NTAPI
 PsGetCurrentProcessId(
   VOID);
 
@@ -10011,55 +10033,55 @@ PsGetCurrentProcessId(
 #define PsGetCurrentThread() \
   ((PETHREAD) KeGetCurrentThread())
 
-NTOSAPI
+NTKERNELAPI
 HANDLE
-DDKAPI
+NTAPI
 PsGetCurrentThreadId(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 PsGetVersion(
   PULONG  MajorVersion  OPTIONAL,
   PULONG  MinorVersion  OPTIONAL,
   PULONG  BuildNumber  OPTIONAL,
   PUNICODE_STRING  CSDVersion  OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsRemoveCreateThreadNotifyRoutine(
   IN PCREATE_THREAD_NOTIFY_ROUTINE  NotifyRoutine);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsRemoveLoadImageNotifyRoutine(
   IN PLOAD_IMAGE_NOTIFY_ROUTINE  NotifyRoutine);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsSetCreateProcessNotifyRoutine(
   IN PCREATE_PROCESS_NOTIFY_ROUTINE  NotifyRoutine,
   IN BOOLEAN  Remove);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsSetCreateThreadNotifyRoutine(
   IN PCREATE_THREAD_NOTIFY_ROUTINE  NotifyRoutine);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsSetLoadImageNotifyRoutine(
   IN PLOAD_IMAGE_NOTIFY_ROUTINE  NotifyRoutine);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PsTerminateSystemThread(
   IN NTSTATUS  ExitStatus);
 
@@ -10067,9 +10089,9 @@ PsTerminateSystemThread(
 
 /** Security reference monitor routines **/
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 SeAccessCheck(
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
   IN PSECURITY_SUBJECT_CONTEXT  SubjectSecurityContext,
@@ -10082,9 +10104,9 @@ SeAccessCheck(
   OUT PACCESS_MASK  GrantedAccess,
   OUT PNTSTATUS  AccessStatus);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 SeAssignSecurity(
   IN PSECURITY_DESCRIPTOR  ParentDescriptor  OPTIONAL,
   IN PSECURITY_DESCRIPTOR  ExplicitDescriptor  OPTIONAL,
@@ -10094,9 +10116,9 @@ SeAssignSecurity(
   IN PGENERIC_MAPPING  GenericMapping,
   IN POOL_TYPE  PoolType);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 SeAssignSecurityEx(
   IN PSECURITY_DESCRIPTOR  ParentDescriptor  OPTIONAL,
   IN PSECURITY_DESCRIPTOR  ExplicitDescriptor  OPTIONAL,
@@ -10108,22 +10130,22 @@ SeAssignSecurityEx(
   IN PGENERIC_MAPPING  GenericMapping,
   IN POOL_TYPE  PoolType);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 SeDeassignSecurity(
   IN OUT PSECURITY_DESCRIPTOR  *SecurityDescriptor);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 SeSinglePrivilegeCheck(
   LUID  PrivilegeValue,
   KPROCESSOR_MODE  PreviousMode);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 SeValidSecurityDescriptor(
   IN ULONG  Length,
   IN PSECURITY_DESCRIPTOR  SecurityDescriptor);
@@ -10132,18 +10154,18 @@ SeValidSecurityDescriptor(
 
 /** NtXxx routines **/
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtOpenProcess(
   OUT PHANDLE  ProcessHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes,
   IN PCLIENT_ID  ClientId  OPTIONAL);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtQueryInformationProcess(
   IN HANDLE  ProcessHandle,
   IN PROCESSINFOCLASS  ProcessInformationClass,
@@ -10155,36 +10177,36 @@ NtQueryInformationProcess(
 
 /** NtXxx and ZwXxx routines **/
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwCancelTimer(
   IN HANDLE  TimerHandle,
   OUT PBOOLEAN  CurrentState  OPTIONAL);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtClose(
   IN HANDLE  Handle);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwClose(
   IN HANDLE  Handle);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwCreateDirectoryObject(
   OUT PHANDLE  DirectoryHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtCreateEvent(
   OUT PHANDLE  EventHandle,
   IN ACCESS_MASK  DesiredAccess,
@@ -10192,9 +10214,9 @@ NtCreateEvent(
   IN EVENT_TYPE  EventType,
   IN BOOLEAN  InitialState);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwCreateEvent(
   OUT PHANDLE  EventHandle,
   IN ACCESS_MASK  DesiredAccess,
@@ -10202,9 +10224,9 @@ ZwCreateEvent(
   IN EVENT_TYPE  EventType,
   IN BOOLEAN  InitialState);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwCreateFile(
   OUT PHANDLE  FileHandle,
   IN ACCESS_MASK  DesiredAccess,
@@ -10218,9 +10240,9 @@ ZwCreateFile(
   IN PVOID  EaBuffer  OPTIONAL,
   IN ULONG  EaLength);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwCreateKey(
   OUT PHANDLE  KeyHandle,
   IN ACCESS_MASK  DesiredAccess,
@@ -10230,31 +10252,31 @@ ZwCreateKey(
   IN ULONG  CreateOptions,
   OUT PULONG  Disposition  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwCreateTimer(
   OUT PHANDLE  TimerHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes  OPTIONAL,
   IN TIMER_TYPE  TimerType);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwDeleteKey(
   IN HANDLE  KeyHandle);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwDeleteValueKey(
   IN HANDLE  KeyHandle,
   IN PUNICODE_STRING  ValueName);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtDeviceIoControlFile(
   IN HANDLE  DeviceHandle,
   IN HANDLE  Event  OPTIONAL,
@@ -10267,9 +10289,9 @@ NtDeviceIoControlFile(
   OUT PVOID  OutputBuffer,
   IN ULONG  OutputBufferSize);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwDeviceIoControlFile(
   IN HANDLE  DeviceHandle,
   IN HANDLE  Event  OPTIONAL,
@@ -10282,9 +10304,9 @@ ZwDeviceIoControlFile(
   OUT PVOID  OutputBuffer,
   IN ULONG  OutputBufferSize);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwEnumerateKey(
   IN HANDLE  KeyHandle,
   IN ULONG  Index,
@@ -10293,9 +10315,9 @@ ZwEnumerateKey(
   IN ULONG  Length,
   OUT PULONG  ResultLength);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwEnumerateValueKey(
   IN HANDLE  KeyHandle,
   IN ULONG  Index,
@@ -10304,21 +10326,21 @@ ZwEnumerateValueKey(
   IN ULONG  Length,
   OUT PULONG  ResultLength);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwFlushKey(
   IN HANDLE  KeyHandle);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwMakeTemporaryObject(
   IN HANDLE  Handle);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtMapViewOfSection(
   IN HANDLE  SectionHandle,
   IN HANDLE  ProcessHandle,
@@ -10331,9 +10353,9 @@ NtMapViewOfSection(
   IN ULONG  AllocationType,
   IN ULONG  Protect);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwMapViewOfSection(
   IN HANDLE  SectionHandle,
   IN HANDLE  ProcessHandle,
@@ -10346,9 +10368,9 @@ ZwMapViewOfSection(
   IN ULONG  AllocationType,
   IN ULONG  Protect);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtOpenFile(
   OUT PHANDLE  FileHandle,
   IN ACCESS_MASK  DesiredAccess,
@@ -10357,9 +10379,9 @@ NtOpenFile(
   IN ULONG  ShareAccess,
   IN ULONG  OpenOptions);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwOpenFile(
   OUT PHANDLE  FileHandle,
   IN ACCESS_MASK  DesiredAccess,
@@ -10368,41 +10390,41 @@ ZwOpenFile(
   IN ULONG  ShareAccess,
   IN ULONG  OpenOptions);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwOpenKey(
   OUT PHANDLE  KeyHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwOpenSection(
   OUT PHANDLE  SectionHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwOpenSymbolicLinkObject(
   OUT PHANDLE  LinkHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwOpenTimer(
   OUT PHANDLE  TimerHandle,
   IN ACCESS_MASK  DesiredAccess,
   IN POBJECT_ATTRIBUTES  ObjectAttributes);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwQueryInformationFile(
   IN HANDLE  FileHandle,
   OUT PIO_STATUS_BLOCK  IoStatusBlock,
@@ -10410,9 +10432,9 @@ ZwQueryInformationFile(
   IN ULONG  Length,
   IN FILE_INFORMATION_CLASS  FileInformationClass);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwQueryKey(
   IN HANDLE  KeyHandle,
   IN KEY_INFORMATION_CLASS  KeyInformationClass,
@@ -10420,17 +10442,17 @@ ZwQueryKey(
   IN ULONG  Length,
   OUT PULONG  ResultLength);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwQuerySymbolicLinkObject(
   IN HANDLE  LinkHandle,
   IN OUT PUNICODE_STRING  LinkTarget,
   OUT PULONG  ReturnedLength  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwQueryValueKey(
   IN HANDLE  KeyHandle,
   IN PUNICODE_STRING  ValueName,
@@ -10439,9 +10461,9 @@ ZwQueryValueKey(
   IN ULONG  Length,
   OUT PULONG  ResultLength);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtReadFile(
   IN HANDLE  FileHandle,
   IN HANDLE  Event  OPTIONAL,
@@ -10453,9 +10475,9 @@ NtReadFile(
   IN PLARGE_INTEGER  ByteOffset  OPTIONAL,
   IN PULONG  Key  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwReadFile(
   IN HANDLE  FileHandle,
   IN HANDLE  Event  OPTIONAL,
@@ -10467,23 +10489,23 @@ ZwReadFile(
   IN PLARGE_INTEGER  ByteOffset  OPTIONAL,
   IN PULONG  Key  OPTIONAL);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtSetEvent(
   IN HANDLE  EventHandle,
   OUT PLONG  PreviousState  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwSetEvent(
   IN HANDLE  EventHandle,
   OUT PLONG  PreviousState  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwSetInformationFile(
   IN HANDLE  FileHandle,
   OUT PIO_STATUS_BLOCK  IoStatusBlock,
@@ -10491,18 +10513,18 @@ ZwSetInformationFile(
   IN ULONG  Length,
   IN FILE_INFORMATION_CLASS  FileInformationClass);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwSetInformationThread(
   IN HANDLE  ThreadHandle,
   IN THREADINFOCLASS  ThreadInformationClass,
   IN PVOID  ThreadInformation,
   IN ULONG  ThreadInformationLength);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwSetTimer(
   IN HANDLE  TimerHandle,
   IN PLARGE_INTEGER  DueTime,
@@ -10512,9 +10534,9 @@ ZwSetTimer(
   IN LONG  Period  OPTIONAL,
   OUT PBOOLEAN  PreviousState  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwSetValueKey(
   IN HANDLE  KeyHandle,
   IN PUNICODE_STRING  ValueName,
@@ -10528,39 +10550,39 @@ ZwSetValueKey(
 #define AT_RESERVED                       0x20000000
 #define AT_ROUND_TO_PAGE                  0x40000000
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtUnmapViewOfSection(
   IN HANDLE  ProcessHandle,
   IN PVOID  BaseAddress);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwUnmapViewOfSection(
   IN HANDLE  ProcessHandle,
   IN PVOID  BaseAddress);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtWaitForSingleObject(
   IN HANDLE  ObjectHandle,
   IN BOOLEAN  Alertable,
   IN PLARGE_INTEGER  TimeOut  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwWaitForSingleObject(
   IN HANDLE  ObjectHandle,
   IN BOOLEAN  Alertable,
   IN PLARGE_INTEGER  TimeOut  OPTIONAL);
 
-NTOSAPI
+NTSYSCALLAPI
 NTSTATUS
-DDKAPI
+NTAPI
 NtWriteFile(
   IN HANDLE  FileHandle,
   IN HANDLE  Event  OPTIONAL,
@@ -10572,9 +10594,9 @@ NtWriteFile(
   IN PLARGE_INTEGER  ByteOffset  OPTIONAL,
   IN PULONG  Key  OPTIONAL);
 
-NTOSAPI
+NTSYSAPI
 NTSTATUS
-DDKAPI
+NTAPI
 ZwWriteFile(
   IN HANDLE  FileHandle,
   IN HANDLE  Event  OPTIONAL,
@@ -10590,32 +10612,32 @@ ZwWriteFile(
 
 /** Power management support routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PoCallDriver(
   IN PDEVICE_OBJECT  DeviceObject,
   IN OUT PIRP  Irp);
 
-NTOSAPI
+NTKERNELAPI
 PULONG
-DDKAPI
+NTAPI
 PoRegisterDeviceForIdleDetection(
   IN PDEVICE_OBJECT  DeviceObject,
   IN ULONG  ConservationIdleTime,
   IN ULONG  PerformanceIdleTime,
   IN DEVICE_POWER_STATE  State);
 
-NTOSAPI
+NTKERNELAPI
 PVOID
-DDKAPI
+NTAPI
 PoRegisterSystemState(
   IN PVOID  StateHandle,
   IN EXECUTION_STATE  Flags);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PoRequestPowerIrp(
   IN PDEVICE_OBJECT  DeviceObject,
   IN UCHAR  MinorFunction,
@@ -10624,41 +10646,41 @@ PoRequestPowerIrp(
   IN PVOID  Context,
   OUT PIRP  *Irp OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 PoRequestShutdownEvent(
   OUT PVOID  *Event);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 PoSetDeviceBusy(
   PULONG  IdlePointer);
 
-NTOSAPI
+NTKERNELAPI
 POWER_STATE
-DDKAPI
+NTAPI
 PoSetPowerState(
   IN PDEVICE_OBJECT  DeviceObject,
   IN POWER_STATE_TYPE  Type,
   IN POWER_STATE  State);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 PoSetSystemState(
   IN EXECUTION_STATE  Flags);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 PoStartNextPowerIrp(
   IN PIRP  Irp);
 
-NTOSAPI
+NTKERNELAPI
 VOID
-DDKAPI
+NTAPI
 PoUnregisterSystemState(
   IN PVOID  StateHandle);
 
@@ -10666,9 +10688,9 @@ PoUnregisterSystemState(
 
 /** WMI library support routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 WmiCompleteRequest(
   IN PDEVICE_OBJECT  DeviceObject,
   IN PIRP  Irp,
@@ -10676,9 +10698,9 @@ WmiCompleteRequest(
   IN ULONG  BufferUsed,
   IN CCHAR  PriorityBoost);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 WmiFireEvent(
   IN PDEVICE_OBJECT  DeviceObject,
   IN LPGUID  Guid,
@@ -10686,9 +10708,9 @@ WmiFireEvent(
   IN ULONG  EventDataSize,
   IN PVOID  EventData);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 WmiQueryTraceInformation(
   IN TRACE_INFORMATION_CLASS  TraceInformationClass,
   OUT PVOID  TraceInformation,
@@ -10696,16 +10718,16 @@ WmiQueryTraceInformation(
   OUT PULONG  RequiredLength OPTIONAL,
   IN PVOID  Buffer OPTIONAL);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 WmiSystemControl(
   IN PWMILIB_CONTEXT  WmiLibInfo,
   IN PDEVICE_OBJECT  DeviceObject,
   IN PIRP  Irp,
   OUT PSYSCTL_IRP_DISPOSITION  IrpDisposition);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
 DDKCDECLAPI
 WmiTraceMessage(
@@ -10717,7 +10739,7 @@ WmiTraceMessage(
 
 #if 0
 /* FIXME: Get va_list from where? */
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
 DDKCDECLAPI
 WmiTraceMessageVa(
@@ -10731,15 +10753,15 @@ WmiTraceMessageVa(
 
 /** Kernel debugger routines **/
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KdDisableDebugger(
   VOID);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 KdEnableDebugger(
   VOID);
 
@@ -10748,9 +10770,9 @@ NTAPI
 DbgBreakPoint(
   VOID);
 
-NTOSAPI
+NTSYSAPI
 VOID
-DDKAPI
+NTAPI
 DbgBreakPointWithStatus(
   IN ULONG  Status);
 
@@ -10768,23 +10790,23 @@ DbgPrintEx(
   IN PCCH  Format,
   IN ...);
 
-NTOSAPI
+NTKERNELAPI
 ULONG
 DDKCDECLAPI
 DbgPrintReturnControlC(
   IN PCH  Format,
   IN ...);
 
-NTOSAPI
+NTKERNELAPI
 BOOLEAN
-DDKAPI
+NTAPI
 DbgQueryDebugFilterState(
   IN ULONG  ComponentId,
   IN ULONG  Level);
 
-NTOSAPI
+NTKERNELAPI
 NTSTATUS
-DDKAPI
+NTAPI
 DbgSetDebugFilterState(
   IN ULONG  ComponentId,
   IN ULONG  Level,
@@ -10808,8 +10830,8 @@ DbgSetDebugFilterState(
 
 #if defined(_NTDDK_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
 
-extern NTOSAPI PBOOLEAN KdDebuggerNotPresent;
-extern NTOSAPI PBOOLEAN KdDebuggerEnabled;
+extern NTKERNELAPI PBOOLEAN KdDebuggerNotPresent;
+extern NTKERNELAPI PBOOLEAN KdDebuggerEnabled;
 #define KD_DEBUGGER_ENABLED     *KdDebuggerEnabled
 #define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
 
@@ -10822,53 +10844,6 @@ extern BOOLEAN KdDebuggerEnabled;
 
 #endif
 
-#ifdef __GNUC__
-
-/* Available as intrinsics on MSVC */
-#ifdef _X86_
-static __inline void _disable(void) {__asm__ __volatile__("cli\n");}
-static __inline void _enable(void)  {__asm__ __volatile__("sti\n");}
-
-static __inline ULONG64 __readcr3(void)
-{
-    ULONG_PTR Ret;
-    __asm__ __volatile__("movl %%cr3, %0;\n"
-        :"=r"(Ret));
-    return (ULONG64)Ret;
-}
-
-static __inline ULONG64 __readcr4(void)
-{
-    ULONG_PTR Ret;
-    __asm__ __volatile__("movl %%cr4, %0; \n"
-        :"=r"(Ret));
-    return (ULONG64)Ret;
-}
-#elif defined(_PPC_)
-#ifndef _ENABLE_DISABLE_DEFINED
-#define _ENABLE_DISABLE_DEFINED
-static __inline void _disable(void) {
-       /* Turn off EE bit */
-       __asm__ __volatile__
-               ("mfmsr 3\n\t"
-                "xor 4,5,5\n\t"
-                "addi 4,4,-1\n\t"
-                "and 0,3,4\n\t"
-                "mtmsr 0\n\t"
-                );
-}
-static __inline void _enable(void)  {
-       /* Turn on EE bit */
-       __asm__ __volatile__
-               ("mfmsr 3\n\t"
-                "ori 0,3,0x8000\n\t"
-                "mtmsr 0\n\t"
-                );
-}
-#endif
-#endif /*_X86_*/
-#endif
-
 #ifdef __cplusplus
 }
 #endif
index 180d3b7..9ab555a 100644 (file)
@@ -646,4 +646,6 @@ typedef struct _KEXCEPTION_FRAME
     DOUBLE Fpr31;
 } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
 
+#define KeGetPreviousMode       ExGetPreviousMode
+
 #endif
index ba0828e..7d54e14 100644 (file)
@@ -62,7 +62,7 @@ extern "C" {
 #elif (_MSC_VER)
 #define FORCEINLINE __inline
 #else
-#define FORCEINLINE static __inline
+#define FORCEINLINE static __attribute__((unused))
 #endif
 #endif
 
index 1ebad32..5a1316b 100644 (file)
@@ -65,6 +65,27 @@ typedef struct _MEMORY_ALLOCATION_DESCRIPTOR
     ULONG PageCount;
 } MEMORY_ALLOCATION_DESCRIPTOR, *PMEMORY_ALLOCATION_DESCRIPTOR;
 
+typedef struct _BOOT_DRIVER_LIST_ENTRY
+{
+    LIST_ENTRY ListEntry;
+    UNICODE_STRING FilePath;
+    UNICODE_STRING RegistryPath;
+    struct _LDR_DATA_TABLE_ENTRY *DataTableEntry;
+} BOOT_DRIVER_LIST_ENTRY, *PBOOT_DRIVER_LIST_ENTRY;
+
+typedef struct _ARC_DISK_SIGNATURE
+{
+    LIST_ENTRY ListEntry;
+    ULONG Signature;
+    PCHAR ArcName;
+    ULONG CheckSum;
+    BOOLEAN ValidPartitionTable;
+    BOOLEAN xInt13;
+    BOOLEAN IsGpt;
+    BOOLEAN Reserved;
+    CHAR GptSignature[16];
+} ARC_DISK_SIGNATURE, *PARC_DISK_SIGNATURE;
+
 typedef struct _CONFIGURATION_COMPONENT
 {
     CONFIGURATION_CLASS Class;
@@ -268,6 +289,11 @@ typedef struct _I386_LOADER_BLOCK
     ULONG Reserved;
 } I386_LOADER_BLOCK, *PI386_LOADER_BLOCK;
 
+typedef struct _POWERPC_LOADER_BLOCK
+{
+    PVOID BootInfo;
+} POWERPC_LOADER_BLOCK, *PPOWERPC_LOADER_BLOCK;
+
 //
 // Loader Parameter Block
 //
@@ -298,6 +324,7 @@ typedef struct _LOADER_PARAMETER_BLOCK
         I386_LOADER_BLOCK I386;
         ALPHA_LOADER_BLOCK Alpha;
         IA64_LOADER_BLOCK Ia64;
+       POWERPC_LOADER_BLOCK PowerPC;
     } u;
 } LOADER_PARAMETER_BLOCK, *PLOADER_PARAMETER_BLOCK;
 
index 1dd1eb8..4ea53e7 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _ARCH_POWERPC_FONT_H
 #define _ARCH_POWERPC_FONT_H
 
-font_char BootDigits[16] = {
+font_char BootDigits[37] = {
     " XXXXX  "
     "X     X "
     "X  x  X "
@@ -113,6 +113,146 @@ font_char BootDigits[16] = {
     " X      "
     " X      "
     " X      "
+    "        ",
+    "  XXXX  "
+    " X    X "
+    " X      "
+    " X   XX "
+    " X    X "
+    "  XXXXX "
+    "        ",
+    " X    X "
+    " X    X "
+    " XXXXXX "
+    " X    X "
+    " X    X "
+    " X    X "
+    "        ",
+    "  XXXX  "
+    "   XX   "
+    "   XX   "
+    "   XX   "
+    "   XX   "
+    "  XXXX  "
+    "        ",
+    "      X "
+    "      X "
+    "      X "
+    "      X "
+    " X    X "
+    "  XXXX  "
+    "        ",
+    " X    X "
+    " X   X  "
+    " X  X   "
+    " XXXX   "
+    " X   X  "
+    " X    X "
+    "        ",
+    " X      "
+    " X      "
+    " X      "
+    " X      "
+    " X      "
+    " XXXXXX "
+    "        ",
+    "  X  X  "
+    " X XX X "
+    " X XX X "
+    " X    X "
+    " X    X "
+    " X    X "
+    "        ",
+    " X    X "
+    " XX   X "
+    " X X  X "
+    " X  X X "
+    " X   XX "
+    " X    X "
+    "        ",
+    "  XXXX  "
+    " X    X "
+    " X    X "
+    " X    X "
+    " X    X "
+    "  XXXX  "
+    "        ",
+    " XXXXX  "
+    " X    X "
+    " X    X "
+    " XXXXX  "
+    " X      "
+    " X      "
+    "        ",
+    "  XXXX  "
+    " X    X "
+    " X    X "
+    " X  X X "
+    " X  XXX "
+    "  XXXXX "
+    "        ",
+    " XXXXX  "
+    " X    X "
+    " X    X "
+    " XXXXX  "
+    " X    X "
+    " X    X "
+    "        ",
+    "  XXXXX "
+    " X      "
+    "  XXXX  "
+    "      X "
+    "      X "
+    " XXXXX  "
+    "        ",
+    " XXXXXX "
+    "   XX   "
+    "   XX   "
+    "   XX   "
+    "   XX   "
+    "   XX   "
+    "        ",
+    " X    X "
+    " X    X "
+    " X    X "
+    " X    X "
+    " X    X "
+    "  XXXX  "
+    "        ",
+    " X    X "
+    " X    X "
+    " X    X "
+    " X    X "
+    "  X  X  "
+    "   XX   "
+    "        ",
+    " X    X "
+    " X    X "
+    " X    X "
+    " X XX X "
+    " X XX X "
+    "  X  X  "
+    "        ",
+    " X    X "
+    "  X  X  "
+    "   XX   "
+    "  X  X  "
+    " X    X "
+    " X    X "
+    "        ",
+    " X    X "
+    " X    X "
+    "  X  X  "
+    "   XX   "
+    "   XX   "
+    "   XX   "
+    "        ",
+    " XXXXXX "
+    "     X  "
+    "    X   "
+    "   X    "
+    "  X     "
+    " XXXXXX "
     "        "
 };
 
index 460af14..8dc39c2 100644 (file)
@@ -3,6 +3,7 @@
 
 typedef char font_char[57];
 typedef struct _boot_infos_t {
+    void *loaderBlock;
     int dispDeviceRect[4];
     int dispDeviceRowBytes;
     int dispDeviceDepth;
diff --git a/reactos/include/reactos/ppcdebug.h b/reactos/include/reactos/ppcdebug.h
new file mode 100644 (file)
index 0000000..0b665a3
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _PPCDEBUG_H
+#define _PPCDEBUG_H
+
+#include "ppcboot.h"
+
+extern struct _boot_infos_t *BootInfo;
+extern void DrawNumber(struct _boot_infos_t *, unsigned long, int, int);
+extern void DrawString(struct _boot_infos_t *, const char *, int, int);
+#define TRACEXY(x,y) do { \
+  unsigned long _x_ = (unsigned long)(x), _y_ = (unsigned long)(y); \
+  __asm__("ori 0,0,0"); \
+  DrawNumber(BootInfo, __LINE__, 10, 160); \
+  DrawString(BootInfo, __FILE__, 100, 160); \
+  DrawNumber(BootInfo, _x_, 400, 160); \
+  DrawNumber(BootInfo, _y_, 490, 160); \
+} while(0)
+#define TRACEX(x) TRACEXY(x,0)
+#define TRACE TRACEX(0)
+
+#endif//_PPCDEBUG_H
index 3e456e2..732a32b 100644 (file)
@@ -42,6 +42,7 @@ typedef struct _ROS_LOADER_PARAMETER_BLOCK
     ULONG PageDirectoryStart;\r
     ULONG PageDirectoryEnd;\r
     ULONG KernelBase;\r
+    ULONG ArchExtra;\r
 } ROS_LOADER_PARAMETER_BLOCK, *PROS_LOADER_PARAMETER_BLOCK;\r
 \r
 extern ULONG MmFreeLdrMemHigher, MmFreeLdrMemLower;\r
index fb6b711..d0266ee 100644 (file)
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#ifndef CMLIB_CMDATA_H
-#define CMLIB_CMDATA_H
-
-#define  REG_INIT_BLOCK_LIST_SIZE      32
-#define  REG_INIT_HASH_TABLE_SIZE      3
-#define  REG_EXTEND_HASH_TABLE_SIZE    4
-#define  REG_VALUE_LIST_CELL_MULTIPLE  4
-
-#define  REG_KEY_CELL_ID               0x6b6e
-#define  REG_HASH_TABLE_CELL_ID        0x666c
-#define  REG_VALUE_CELL_ID             0x6b76
-#define  REG_SECURITY_CELL_ID          0x6b73
-
-#ifndef _CM_
-
-#include <pshpack1.h>
-
-typedef struct _CM_VIEW_OF_FILE
-{
-    LIST_ENTRY LRUViewList;
-    LIST_ENTRY PinViewList;
-    ULONG FileOffset;
-    ULONG Size;
-    PULONG ViewAddress;
-    PVOID Bcb;
-    ULONG UseCount;
-} CM_VIEW_OF_FILE, *PCM_VIEW_OF_FILE;
-
-typedef struct _CHILD_LIST
-{
-    ULONG Count;
-    HCELL_INDEX List;
-} CHILD_LIST, *PCHILD_LIST;
-
-typedef struct _CM_KEY_NODE
-{
-   /* Key cell identifier "kn" (0x6b6e) */
-   USHORT Id;
-
-   /* Flags */
-   USHORT Flags;
-
-   /* Time of last flush */
-   LARGE_INTEGER LastWriteTime;
-
-   ULONG Spare;
-
-   /* BlockAddress offset of parent key cell */
-   HCELL_INDEX Parent;
-
-   /* Count of sub keys for the key in this key cell (stable & volatile) */
-   ULONG SubKeyCounts[HvMaxStorageType];
-
-   /* BlockAddress offset of has table for FIXME: subkeys/values? (stable & volatile) */
-   HCELL_INDEX SubKeyLists[HvMaxStorageType];
-
-   CHILD_LIST ValueList;
-
-   /* BlockAddress offset of security cell */
-   HCELL_INDEX SecurityKeyOffset;
-
-   /* BlockAddress offset of registry key class */
-   HCELL_INDEX ClassNameOffset;
-
-   ULONG MaxNameLen;
-   ULONG MaxClassLen;
-   ULONG MaxValueNameLen;
-   ULONG MaxValueDataLen;
-   ULONG WorkVar;
-
-   /* Size in bytes of key name */
-   USHORT NameSize;
-
-   /* Size of class name in bytes */
-   USHORT ClassSize;
-
-   /* Name of key (not zero terminated) */
-   UCHAR Name[0];
-} CM_KEY_NODE, *PCM_KEY_NODE;
-
-/* CM_KEY_NODE.Flags constants */
-#define  REG_KEY_VOLATILE_CELL             0x01
-#define  REG_KEY_ROOT_CELL                 0x0C
-#define  REG_KEY_LINK_CELL                 0x10
-#define  REG_KEY_NAME_PACKED               0x20
-
-/*
- * Hash record
- *
- * HashValue:
- *     packed name: four letters of value's name
- *     otherwise: Zero!
- */
-typedef struct _HASH_RECORD
-{
-  HCELL_INDEX  KeyOffset;
-  ULONG  HashValue;
-} HASH_RECORD, *PHASH_RECORD;
-
-typedef struct _HASH_TABLE_CELL
-{
-  USHORT  Id;
-  USHORT  HashTableSize;
-  HASH_RECORD  Table[0];
-} HASH_TABLE_CELL, *PHASH_TABLE_CELL;
-
-typedef struct _VALUE_LIST_CELL
-{
-  HCELL_INDEX  ValueOffset[0];
-} VALUE_LIST_CELL, *PVALUE_LIST_CELL;
-
-typedef struct _CM_KEY_VALUE
-{
-  USHORT Id;   // "kv"
-  USHORT NameSize;     // length of Name
-  ULONG  DataSize;     // length of datas in the cell pointed by DataOffset
-  HCELL_INDEX  DataOffset;// datas are here if high bit of DataSize is set
-  ULONG  DataType;
-  USHORT Flags;
-  USHORT Unused1;
-  UCHAR  Name[0]; /* warning : not zero terminated */
-} CM_KEY_VALUE, *PCM_KEY_VALUE;
-
-/* CM_KEY_VALUE.Flags constants */
-#define REG_VALUE_NAME_PACKED             0x0001
-
-/* CM_KEY_VALUE.DataSize mask constants */
-#define REG_DATA_SIZE_MASK                 0x7FFFFFFF
-#define REG_DATA_IN_OFFSET                 0x80000000
-
-typedef struct _CM_KEY_SECURITY
-{
-    USHORT Signature; // "sk"
-    USHORT Reserved;
-    HCELL_INDEX Flink;
-    HCELL_INDEX Blink;
-    ULONG ReferenceCount;
-    ULONG DescriptorLength;
-    //SECURITY_DESCRIPTOR_RELATIVE Descriptor;
-    UCHAR Data[0];
-} CM_KEY_SECURITY, *PCM_KEY_SECURITY;
-
-#include <poppack.h>
-
-#endif
-
-#endif /* CMLIB_CMDATA_H */
+/*\r
+ * PROJECT:   registry manipulation library\r
+ * LICENSE:   GPL - See COPYING in the top level directory\r
+ * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>\r
+ *            Copyright 2001 - 2005 Eric Kohl\r
+ */\r
+\r
+#ifndef CMLIB_CMDATA_H\r
+#define CMLIB_CMDATA_H\r
+\r
+#define  REG_INIT_BLOCK_LIST_SIZE      32\r
+#define  REG_INIT_HASH_TABLE_SIZE      3\r
+#define  REG_EXTEND_HASH_TABLE_SIZE    4\r
+#define  REG_VALUE_LIST_CELL_MULTIPLE  4\r
+\r
+#define  REG_KEY_CELL_ID               0x6b6e\r
+#define  REG_HASH_TABLE_CELL_ID        0x666c\r
+#define  REG_VALUE_CELL_ID             0x6b76\r
+#define  REG_SECURITY_CELL_ID          0x6b73\r
+\r
+#ifndef _CM_\r
+\r
+#include <pshpack1.h>\r
+\r
+typedef struct _CM_VIEW_OF_FILE\r
+{\r
+    LIST_ENTRY LRUViewList;\r
+    LIST_ENTRY PinViewList;\r
+    ULONG FileOffset;\r
+    ULONG Size;\r
+    PULONG ViewAddress;\r
+    PVOID Bcb;\r
+    ULONG UseCount;\r
+} CM_VIEW_OF_FILE, *PCM_VIEW_OF_FILE;\r
+\r
+typedef struct _CHILD_LIST\r
+{\r
+    ULONG Count;\r
+    HCELL_INDEX List;\r
+} CHILD_LIST, *PCHILD_LIST;\r
+\r
+typedef struct _CM_KEY_NODE\r
+{\r
+   /* Key cell identifier "kn" (0x6b6e) */\r
+   USHORT Id;\r
+\r
+   /* Flags */\r
+   USHORT Flags;\r
+\r
+   /* Time of last flush */\r
+   LARGE_INTEGER LastWriteTime;\r
+\r
+   ULONG Spare;\r
+\r
+   /* BlockAddress offset of parent key cell */\r
+   HCELL_INDEX Parent;\r
+\r
+   /* Count of sub keys for the key in this key cell (stable & volatile) */\r
+   ULONG SubKeyCounts[HvMaxStorageType];\r
+\r
+   /* BlockAddress offset of has table for FIXME: subkeys/values? (stable & volatile) */\r
+   HCELL_INDEX SubKeyLists[HvMaxStorageType];\r
+\r
+   CHILD_LIST ValueList;\r
+\r
+   /* BlockAddress offset of security cell */\r
+   HCELL_INDEX SecurityKeyOffset;\r
+\r
+   /* BlockAddress offset of registry key class */\r
+   HCELL_INDEX ClassNameOffset;\r
+\r
+   ULONG MaxNameLen;\r
+   ULONG MaxClassLen;\r
+   ULONG MaxValueNameLen;\r
+   ULONG MaxValueDataLen;\r
+   ULONG WorkVar;\r
+\r
+   /* Size in bytes of key name */\r
+   USHORT NameSize;\r
+\r
+   /* Size of class name in bytes */\r
+   USHORT ClassSize;\r
+\r
+   /* Name of key (not zero terminated) */\r
+   UCHAR Name[0];\r
+} CM_KEY_NODE, *PCM_KEY_NODE;\r
+\r
+/* CM_KEY_NODE.Flags constants */\r
+#define  REG_KEY_VOLATILE_CELL             0x01\r
+#define  REG_KEY_ROOT_CELL                 0x0C\r
+#define  REG_KEY_LINK_CELL                 0x10\r
+#define  REG_KEY_NAME_PACKED               0x20\r
+\r
+/*\r
+ * Hash record\r
+ *\r
+ * HashValue:\r
+ *     packed name: four letters of value's name\r
+ *     otherwise: Zero!\r
+ */\r
+typedef struct _HASH_RECORD\r
+{\r
+  HCELL_INDEX  KeyOffset;\r
+  ULONG  HashValue;\r
+} HASH_RECORD, *PHASH_RECORD;\r
+\r
+typedef struct _HASH_TABLE_CELL\r
+{\r
+  USHORT  Id;\r
+  USHORT  HashTableSize;\r
+  HASH_RECORD  Table[0];\r
+} HASH_TABLE_CELL, *PHASH_TABLE_CELL;\r
+\r
+typedef struct _VALUE_LIST_CELL\r
+{\r
+  HCELL_INDEX  ValueOffset[0];\r
+} VALUE_LIST_CELL, *PVALUE_LIST_CELL;\r
+\r
+typedef struct _CM_KEY_VALUE\r
+{\r
+  USHORT Id;   // "kv"\r
+  USHORT NameSize;     // length of Name\r
+  ULONG  DataSize;     // length of datas in the cell pointed by DataOffset\r
+  HCELL_INDEX  DataOffset;// datas are here if high bit of DataSize is set\r
+  ULONG  DataType;\r
+  USHORT Flags;\r
+  USHORT Unused1;\r
+  UCHAR  Name[0]; /* warning : not zero terminated */\r
+} CM_KEY_VALUE, *PCM_KEY_VALUE;\r
+\r
+/* CM_KEY_VALUE.Flags constants */\r
+#define REG_VALUE_NAME_PACKED             0x0001\r
+\r
+/* CM_KEY_VALUE.DataSize mask constants */\r
+#define REG_DATA_SIZE_MASK                 0x7FFFFFFF\r
+#define REG_DATA_IN_OFFSET                 0x80000000\r
+\r
+typedef struct _CM_KEY_SECURITY\r
+{\r
+    USHORT Signature; // "sk"\r
+    USHORT Reserved;\r
+    HCELL_INDEX Flink;\r
+    HCELL_INDEX Blink;\r
+    ULONG ReferenceCount;\r
+    ULONG DescriptorLength;\r
+    //SECURITY_DESCRIPTOR_RELATIVE Descriptor;\r
+    UCHAR Data[0];\r
+} CM_KEY_SECURITY, *PCM_KEY_SECURITY;\r
+\r
+#include <poppack.h>\r
+\r
+#endif\r
+\r
+#endif /* CMLIB_CMDATA_H */\r
index c401396..ac4a413 100644 (file)
@@ -1,82 +1,82 @@
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#include "cmlib.h"
-
-BOOLEAN CMAPI
-CmCreateRootNode(
-   PHHIVE Hive,
-   PCWSTR Name)
-{
-   PCM_KEY_NODE KeyCell;
-   HCELL_INDEX RootCellIndex;
-   SIZE_T NameSize;
-
-   NameSize = wcslen(Name) * sizeof(WCHAR);
-   RootCellIndex = HvAllocateCell(Hive, sizeof(CM_KEY_NODE) + NameSize, HvStable);
-   if (RootCellIndex == HCELL_NULL)
-      return FALSE;
-
-   Hive->HiveHeader->RootCell = RootCellIndex;
-   Hive->HiveHeader->Checksum = HvpHiveHeaderChecksum(Hive->HiveHeader);
-
-   KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, RootCellIndex);
-   KeyCell->Id = REG_KEY_CELL_ID;
-   KeyCell->Flags = REG_KEY_ROOT_CELL;
-   KeyCell->LastWriteTime.QuadPart = 0;
-   KeyCell->Parent = HCELL_NULL;
-   KeyCell->SubKeyCounts[0] = 0;
-   KeyCell->SubKeyCounts[1] = 0;
-   KeyCell->SubKeyLists[0] = HCELL_NULL;
-   KeyCell->SubKeyLists[1] = HCELL_NULL;
-   KeyCell->ValueList.Count = 0;
-   KeyCell->ValueList.List = HCELL_NULL;
-   KeyCell->SecurityKeyOffset = HCELL_NULL;
-   KeyCell->ClassNameOffset = HCELL_NULL; 
-   KeyCell->NameSize = (USHORT)NameSize;
-   KeyCell->ClassSize = 0;
-   memcpy(KeyCell->Name, Name, NameSize);
-
-   return TRUE;
-}
-
-static VOID CMAPI
-CmpPrepareKey(
-   PHHIVE RegistryHive,
-   PCM_KEY_NODE KeyCell)
-{
-   PCM_KEY_NODE SubKeyCell;
-   PHASH_TABLE_CELL HashCell;
-   ULONG i;
-
-   ASSERT(KeyCell->Id == REG_KEY_CELL_ID);
-
-   KeyCell->SubKeyLists[HvVolatile] = HCELL_NULL;
-   KeyCell->SubKeyCounts[HvVolatile] = 0;
-
-   /* Enumerate and add subkeys */
-   if (KeyCell->SubKeyCounts[HvStable] > 0)
-   {
-      HashCell = HvGetCell(RegistryHive, KeyCell->SubKeyLists[HvStable]);
-
-      for (i = 0; i < KeyCell->SubKeyCounts[HvStable]; i++)
-      {
-         SubKeyCell = HvGetCell(RegistryHive, HashCell->Table[i].KeyOffset);
-         CmpPrepareKey(RegistryHive, SubKeyCell);
-      }
-   }
-}
-
-VOID CMAPI
-CmPrepareHive(
-   PHHIVE RegistryHive)
-{ 
-   PCM_KEY_NODE RootCell;
-
-   RootCell = HvGetCell(RegistryHive, RegistryHive->HiveHeader->RootCell);
-   CmpPrepareKey(RegistryHive, RootCell);
-}
+/*\r
+ * PROJECT:   registry manipulation library\r
+ * LICENSE:   GPL - See COPYING in the top level directory\r
+ * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>\r
+ *            Copyright 2001 - 2005 Eric Kohl\r
+ */\r
+\r
+#include "cmlib.h"\r
+\r
+BOOLEAN CMAPI\r
+CmCreateRootNode(\r
+   PHHIVE Hive,\r
+   PCWSTR Name)\r
+{\r
+   PCM_KEY_NODE KeyCell;\r
+   HCELL_INDEX RootCellIndex;\r
+   SIZE_T NameSize;\r
+\r
+   NameSize = wcslen(Name) * sizeof(WCHAR);\r
+   RootCellIndex = HvAllocateCell(Hive, sizeof(CM_KEY_NODE) + NameSize, HvStable);\r
+   if (RootCellIndex == HCELL_NULL)\r
+      return FALSE;\r
+\r
+   Hive->HiveHeader->RootCell = RootCellIndex;\r
+   Hive->HiveHeader->Checksum = HvpHiveHeaderChecksum(Hive->HiveHeader);\r
+\r
+   KeyCell = (PCM_KEY_NODE)HvGetCell(Hive, RootCellIndex);\r
+   KeyCell->Id = REG_KEY_CELL_ID;\r
+   KeyCell->Flags = REG_KEY_ROOT_CELL;\r
+   KeyCell->LastWriteTime.QuadPart = 0;\r
+   KeyCell->Parent = HCELL_NULL;\r
+   KeyCell->SubKeyCounts[0] = 0;\r
+   KeyCell->SubKeyCounts[1] = 0;\r
+   KeyCell->SubKeyLists[0] = HCELL_NULL;\r
+   KeyCell->SubKeyLists[1] = HCELL_NULL;\r
+   KeyCell->ValueList.Count = 0;\r
+   KeyCell->ValueList.List = HCELL_NULL;\r
+   KeyCell->SecurityKeyOffset = HCELL_NULL;\r
+   KeyCell->ClassNameOffset = HCELL_NULL; \r
+   KeyCell->NameSize = (USHORT)NameSize;\r
+   KeyCell->ClassSize = 0;\r
+   memcpy(KeyCell->Name, Name, NameSize);\r
+\r
+   return TRUE;\r
+}\r
+\r
+static VOID CMAPI\r
+CmpPrepareKey(\r
+   PHHIVE RegistryHive,\r
+   PCM_KEY_NODE KeyCell)\r
+{\r
+   PCM_KEY_NODE SubKeyCell;\r
+   PHASH_TABLE_CELL HashCell;\r
+   ULONG i;\r
+\r
+   ASSERT(KeyCell->Id == REG_KEY_CELL_ID);\r
+\r
+   KeyCell->SubKeyLists[HvVolatile] = HCELL_NULL;\r
+   KeyCell->SubKeyCounts[HvVolatile] = 0;\r
+\r
+   /* Enumerate and add subkeys */\r
+   if (KeyCell->SubKeyCounts[HvStable] > 0)\r
+   {\r
+      HashCell = HvGetCell(RegistryHive, KeyCell->SubKeyLists[HvStable]);\r
+\r
+      for (i = 0; i < KeyCell->SubKeyCounts[HvStable]; i++)\r
+      {\r
+         SubKeyCell = HvGetCell(RegistryHive, HashCell->Table[i].KeyOffset);\r
+         CmpPrepareKey(RegistryHive, SubKeyCell);\r
+      }\r
+   }\r
+}\r
+\r
+VOID CMAPI\r
+CmPrepareHive(\r
+   PHHIVE RegistryHive)\r
+{ \r
+   PCM_KEY_NODE RootCell;\r
+\r
+   RootCell = HvGetCell(RegistryHive, RegistryHive->HiveHeader->RootCell);\r
+   CmpPrepareKey(RegistryHive, RootCell);\r
+}\r
index f691c45..7e590c2 100644 (file)
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#ifndef CMLIB_H
-#define CMLIB_H
-
-#define WIN32_NO_STATUS
-#include <ntddk.h>
-#include "hivedata.h"
-#include "cmdata.h"
-
-#ifndef ROUND_UP
-#define ROUND_UP(a,b)        ((((a)+(b)-1)/(b))*(b))
-#define ROUND_DOWN(a,b)      (((a)/(b))*(b))
-#endif
-
-#define CMAPI NTAPI
-
-struct _HHIVE;
-
-typedef PVOID (CMAPI *PGET_CELL_ROUTINE)(
-   struct _HHIVE *Hive,
-   HCELL_INDEX Cell);
-
-typedef VOID (CMAPI *PRELEASE_CELL_ROUTINE)(
-   struct _HHIVE *Hive,
-   HCELL_INDEX Cell);
-
-typedef PVOID (CMAPI *PALLOCATE_ROUTINE)(
-   SIZE_T Size,
-   BOOLEAN Paged);
-
-typedef VOID (CMAPI *PFREE_ROUTINE)(
-   PVOID Ptr);
-
-typedef BOOLEAN (CMAPI *PFILE_READ_ROUTINE)(
-   struct _HHIVE *RegistryHive,
-   ULONG FileType,
-   ULONGLONG FileOffset,
-   PVOID Buffer,
-   SIZE_T BufferLength);
-
-typedef BOOLEAN (CMAPI *PFILE_WRITE_ROUTINE)(
-   struct _HHIVE *RegistryHive,
-   ULONG FileType,
-   ULONGLONG FileOffset,
-   PVOID Buffer,
-   SIZE_T BufferLength);
-
-typedef BOOLEAN (CMAPI *PFILE_SET_SIZE_ROUTINE)(
-   struct _HHIVE *RegistryHive,
-   ULONG FileType,
-   ULONGLONG FileSize);
-
-typedef BOOLEAN (CMAPI *PFILE_FLUSH_ROUTINE)(
-   struct _HHIVE *RegistryHive,
-   ULONG FileType);
-
-typedef struct _HMAP_ENTRY
-{
-    ULONG_PTR Bin;
-    ULONG_PTR Block;
-    struct _CM_VIEW_OF_FILE *CmHive;
-    ULONG MemAlloc;
-} HMAP_ENTRY, *PHMAP_ENTRY;
-
-typedef struct _HMAP_TABLE
-{
-    HMAP_ENTRY Table[512];
-} HMAP_TABLE, *PHMAP_TABLE;
-
-typedef struct _HMAP_DIRECTORY
-{
-    PHMAP_TABLE Directory[2048];
-} HMAP_DIRECTORY, *PHMAP_DIRECTORY;
-
-typedef struct _DUAL
-{
-    ULONG Length;
-    PHMAP_DIRECTORY Map;
-    PHMAP_ENTRY BlockList; // PHMAP_TABLE SmallDir;
-    ULONG Guard;
-    HCELL_INDEX FreeDisplay[24]; //FREE_DISPLAY FreeDisplay[24];
-    ULONG FreeSummary;
-    LIST_ENTRY FreeBins;
-} DUAL, *PDUAL;
-
-typedef struct _HHIVE
-{
-    ULONG Signature;
-    PGET_CELL_ROUTINE GetCellRoutine;
-    PRELEASE_CELL_ROUTINE ReleaseCellRoutine;
-    PALLOCATE_ROUTINE Allocate;
-    PFREE_ROUTINE Free;
-    PFILE_READ_ROUTINE FileRead;
-    PFILE_WRITE_ROUTINE FileWrite;
-    PFILE_SET_SIZE_ROUTINE FileSetSize;
-    PFILE_FLUSH_ROUTINE FileFlush;
-    PHBASE_BLOCK HiveHeader;
-    RTL_BITMAP DirtyVector;
-    ULONG DirtyCount;
-    ULONG DirtyAlloc;
-    ULONG BaseBlockAlloc;
-    ULONG Cluster;
-    BOOLEAN Flat;
-    BOOLEAN ReadOnly;
-    BOOLEAN Log;
-    BOOLEAN DirtyFlag;
-    ULONG HvBinHeadersUse;
-    ULONG HvFreeCellsUse;
-    ULONG HvUsedcellsUse;
-    ULONG CmUsedCellsUse;
-    ULONG HiveFlags;
-    ULONG LogSize;
-    ULONG RefreshCount;
-    ULONG StorageTypeCount;
-    ULONG Version;
-    DUAL Storage[HvMaxStorageType];
-} HHIVE, *PHHIVE;
-
-#ifndef _CM_
-typedef struct _EREGISTRY_HIVE
-{
-  HHIVE Hive;
-  LIST_ENTRY  HiveList;
-  UNICODE_STRING  HiveFileName;
-  UNICODE_STRING  LogFileName;
-  PCM_KEY_SECURITY  RootSecurityCell;
-  ULONG  Flags;
-  HANDLE  HiveHandle;
-  HANDLE  LogHandle;
-} EREGISTRY_HIVE, *PEREGISTRY_HIVE;
-#endif
-
-/*
- * Public functions.
- */
-
-#define HV_OPERATION_CREATE_HIVE    0
-#define HV_OPERATION_MEMORY         1
-#define HV_OPERATION_MEMORY_INPLACE 3
-
-NTSTATUS CMAPI
-HvInitialize(
-   PHHIVE RegistryHive,
-   ULONG Operation,
-   ULONG_PTR HiveData OPTIONAL,
-   ULONG Cluster OPTIONAL,
-   ULONG Flags,
-   ULONG FileType,
-   PALLOCATE_ROUTINE Allocate,
-   PFREE_ROUTINE Free,
-   PFILE_READ_ROUTINE FileRead,
-   PFILE_WRITE_ROUTINE FileWrite,
-   PFILE_SET_SIZE_ROUTINE FileSetSize,
-   PFILE_FLUSH_ROUTINE FileFlush,
-   IN PUNICODE_STRING FileName);
-
-VOID CMAPI 
-HvFree(
-   PHHIVE RegistryHive);
-
-PVOID CMAPI
-HvGetCell(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellOffset);
-
-#define HvReleaseCell(h, c)     \
-    if (h->ReleaseCellRoutine) h->ReleaseCellRoutine(h, c)
-
-LONG CMAPI
-HvGetCellSize(
-   PHHIVE RegistryHive,
-   PVOID Cell);
-
-HCELL_INDEX CMAPI
-HvAllocateCell(
-   PHHIVE RegistryHive,
-   SIZE_T Size,
-   HV_STORAGE_TYPE Storage);
-
-HCELL_INDEX CMAPI
-HvReallocateCell(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellOffset,
-   ULONG Size);
-
-VOID CMAPI
-HvFreeCell(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellOffset);
-
-VOID CMAPI
-HvMarkCellDirty(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellOffset);
-
-BOOLEAN CMAPI
-HvSyncHive(
-   PHHIVE RegistryHive);
-
-BOOLEAN CMAPI
-HvWriteHive(
-   PHHIVE RegistryHive);
-
-BOOLEAN CMAPI
-CmCreateRootNode(
-   PHHIVE Hive,
-   PCWSTR Name);
-
-VOID CMAPI
-CmPrepareHive(
-   PHHIVE RegistryHive);
-
-/*
- * Private functions.
- */
-
-PHBIN CMAPI
-HvpAddBin(
-   PHHIVE RegistryHive,
-   ULONG Size,
-   HV_STORAGE_TYPE Storage);
-
-NTSTATUS CMAPI
-HvpCreateHiveFreeCellList(
-   PHHIVE Hive);
-
-ULONG CMAPI
-HvpHiveHeaderChecksum(
-   PHBASE_BLOCK HiveHeader);
-
-#endif /* CMLIB_H */
+/*\r
+ * PROJECT:   registry manipulation library\r
+ * LICENSE:   GPL - See COPYING in the top level directory\r
+ * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>\r
+ *            Copyright 2001 - 2005 Eric Kohl\r
+ */\r
+\r
+#ifndef CMLIB_H\r
+#define CMLIB_H\r
+\r
+#define WIN32_NO_STATUS\r
+#include <ntddk.h>\r
+#include "hivedata.h"\r
+#include "cmdata.h"\r
+\r
+#ifndef ROUND_UP\r
+#define ROUND_UP(a,b)        ((((a)+(b)-1)/(b))*(b))\r
+#define ROUND_DOWN(a,b)      (((a)/(b))*(b))\r
+#endif\r
+\r
+#define CMAPI NTAPI\r
+\r
+struct _HHIVE;\r
+\r
+typedef PVOID (CMAPI *PGET_CELL_ROUTINE)(\r
+   struct _HHIVE *Hive,\r
+   HCELL_INDEX Cell);\r
+\r
+typedef VOID (CMAPI *PRELEASE_CELL_ROUTINE)(\r
+   struct _HHIVE *Hive,\r
+   HCELL_INDEX Cell);\r
+\r
+typedef PVOID (CMAPI *PALLOCATE_ROUTINE)(\r
+   SIZE_T Size,\r
+   BOOLEAN Paged);\r
+\r
+typedef VOID (CMAPI *PFREE_ROUTINE)(\r
+   PVOID Ptr);\r
+\r
+typedef BOOLEAN (CMAPI *PFILE_READ_ROUTINE)(\r
+   struct _HHIVE *RegistryHive,\r
+   ULONG FileType,\r
+   ULONGLONG FileOffset,\r
+   PVOID Buffer,\r
+   SIZE_T BufferLength);\r
+\r
+typedef BOOLEAN (CMAPI *PFILE_WRITE_ROUTINE)(\r
+   struct _HHIVE *RegistryHive,\r
+   ULONG FileType,\r
+   ULONGLONG FileOffset,\r
+   PVOID Buffer,\r
+   SIZE_T BufferLength);\r
+\r
+typedef BOOLEAN (CMAPI *PFILE_SET_SIZE_ROUTINE)(\r
+   struct _HHIVE *RegistryHive,\r
+   ULONG FileType,\r
+   ULONGLONG FileSize);\r
+\r
+typedef BOOLEAN (CMAPI *PFILE_FLUSH_ROUTINE)(\r
+   struct _HHIVE *RegistryHive,\r
+   ULONG FileType);\r
+\r
+typedef struct _HMAP_ENTRY\r
+{\r
+    ULONG_PTR Bin;\r
+    ULONG_PTR Block;\r
+    struct _CM_VIEW_OF_FILE *CmHive;\r
+    ULONG MemAlloc;\r
+} HMAP_ENTRY, *PHMAP_ENTRY;\r
+\r
+typedef struct _HMAP_TABLE\r
+{\r
+    HMAP_ENTRY Table[512];\r
+} HMAP_TABLE, *PHMAP_TABLE;\r
+\r
+typedef struct _HMAP_DIRECTORY\r
+{\r
+    PHMAP_TABLE Directory[2048];\r
+} HMAP_DIRECTORY, *PHMAP_DIRECTORY;\r
+\r
+typedef struct _DUAL\r
+{\r
+    ULONG Length;\r
+    PHMAP_DIRECTORY Map;\r
+    PHMAP_ENTRY BlockList; // PHMAP_TABLE SmallDir;\r
+    ULONG Guard;\r
+    HCELL_INDEX FreeDisplay[24]; //FREE_DISPLAY FreeDisplay[24];\r
+    ULONG FreeSummary;\r
+    LIST_ENTRY FreeBins;\r
+} DUAL, *PDUAL;\r
+\r
+typedef struct _HHIVE\r
+{\r
+    ULONG Signature;\r
+    PGET_CELL_ROUTINE GetCellRoutine;\r
+    PRELEASE_CELL_ROUTINE ReleaseCellRoutine;\r
+    PALLOCATE_ROUTINE Allocate;\r
+    PFREE_ROUTINE Free;\r
+    PFILE_READ_ROUTINE FileRead;\r
+    PFILE_WRITE_ROUTINE FileWrite;\r
+    PFILE_SET_SIZE_ROUTINE FileSetSize;\r
+    PFILE_FLUSH_ROUTINE FileFlush;\r
+    PHBASE_BLOCK HiveHeader;\r
+    RTL_BITMAP DirtyVector;\r
+    ULONG DirtyCount;\r
+    ULONG DirtyAlloc;\r
+    ULONG BaseBlockAlloc;\r
+    ULONG Cluster;\r
+    BOOLEAN Flat;\r
+    BOOLEAN ReadOnly;\r
+    BOOLEAN Log;\r
+    BOOLEAN DirtyFlag;\r
+    ULONG HvBinHeadersUse;\r
+    ULONG HvFreeCellsUse;\r
+    ULONG HvUsedcellsUse;\r
+    ULONG CmUsedCellsUse;\r
+    ULONG HiveFlags;\r
+    ULONG LogSize;\r
+    ULONG RefreshCount;\r
+    ULONG StorageTypeCount;\r
+    ULONG Version;\r
+    DUAL Storage[HvMaxStorageType];\r
+} HHIVE, *PHHIVE;\r
+\r
+#ifndef _CM_\r
+typedef struct _EREGISTRY_HIVE\r
+{\r
+  HHIVE Hive;\r
+  LIST_ENTRY  HiveList;\r
+  UNICODE_STRING  HiveFileName;\r
+  UNICODE_STRING  LogFileName;\r
+  PCM_KEY_SECURITY  RootSecurityCell;\r
+  ULONG  Flags;\r
+  HANDLE  HiveHandle;\r
+  HANDLE  LogHandle;\r
+} EREGISTRY_HIVE, *PEREGISTRY_HIVE;\r
+#endif\r
+\r
+/*\r
+ * Public functions.\r
+ */\r
+\r
+#define HV_OPERATION_CREATE_HIVE    0\r
+#define HV_OPERATION_MEMORY         1\r
+#define HV_OPERATION_MEMORY_INPLACE 3\r
+\r
+NTSTATUS CMAPI\r
+HvInitialize(\r
+   PHHIVE RegistryHive,\r
+   ULONG Operation,\r
+   ULONG_PTR HiveData OPTIONAL,\r
+   ULONG Cluster OPTIONAL,\r
+   ULONG Flags,\r
+   ULONG FileType,\r
+   PALLOCATE_ROUTINE Allocate,\r
+   PFREE_ROUTINE Free,\r
+   PFILE_READ_ROUTINE FileRead,\r
+   PFILE_WRITE_ROUTINE FileWrite,\r
+   PFILE_SET_SIZE_ROUTINE FileSetSize,\r
+   PFILE_FLUSH_ROUTINE FileFlush,\r
+   IN PUNICODE_STRING FileName);\r
+\r
+VOID CMAPI \r
+HvFree(\r
+   PHHIVE RegistryHive);\r
+\r
+PVOID CMAPI\r
+HvGetCell(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellOffset);\r
+\r
+#define HvReleaseCell(h, c)     \\r
+    if (h->ReleaseCellRoutine) h->ReleaseCellRoutine(h, c)\r
+\r
+LONG CMAPI\r
+HvGetCellSize(\r
+   PHHIVE RegistryHive,\r
+   PVOID Cell);\r
+\r
+HCELL_INDEX CMAPI\r
+HvAllocateCell(\r
+   PHHIVE RegistryHive,\r
+   SIZE_T Size,\r
+   HV_STORAGE_TYPE Storage);\r
+\r
+HCELL_INDEX CMAPI\r
+HvReallocateCell(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellOffset,\r
+   ULONG Size);\r
+\r
+VOID CMAPI\r
+HvFreeCell(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellOffset);\r
+\r
+VOID CMAPI\r
+HvMarkCellDirty(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellOffset);\r
+\r
+BOOLEAN CMAPI\r
+HvSyncHive(\r
+   PHHIVE RegistryHive);\r
+\r
+BOOLEAN CMAPI\r
+HvWriteHive(\r
+   PHHIVE RegistryHive);\r
+\r
+BOOLEAN CMAPI\r
+CmCreateRootNode(\r
+   PHHIVE Hive,\r
+   PCWSTR Name);\r
+\r
+VOID CMAPI\r
+CmPrepareHive(\r
+   PHHIVE RegistryHive);\r
+\r
+/*\r
+ * Private functions.\r
+ */\r
+\r
+PHBIN CMAPI\r
+HvpAddBin(\r
+   PHHIVE RegistryHive,\r
+   ULONG Size,\r
+   HV_STORAGE_TYPE Storage);\r
+\r
+NTSTATUS CMAPI\r
+HvpCreateHiveFreeCellList(\r
+   PHHIVE Hive);\r
+\r
+ULONG CMAPI\r
+HvpHiveHeaderChecksum(\r
+   PHBASE_BLOCK HiveHeader);\r
+\r
+#endif /* CMLIB_H */\r
index bc9aae4..e35e3cc 100644 (file)
@@ -1,72 +1,72 @@
-CMLIB_BASE = $(LIB_BASE_)cmlib
-CMLIB_BASE_ = $(CMLIB_BASE)$(SEP)
-CMLIB_INT = $(INTERMEDIATE_)$(CMLIB_BASE)_host
-CMLIB_INT_ = $(INTERMEDIATE_)$(CMLIB_BASE)_host$(SEP)
-CMLIB_OUT = $(OUTPUT_)$(CMLIB_BASE)_host
-CMLIB_OUT_ = $(OUTPUT_)$(CMLIB_BASE)_host$(SEP)
-
-$(CMLIB_INT): | $(LIB_INT)
-       $(ECHO_MKDIR)
-       ${mkdir} $@
-
-ifneq ($(INTERMEDIATE),$(OUTPUT))
-$(CMLIB_OUT): | $(OUTPUT_)$(LIB_BASE)
-       $(ECHO_MKDIR)
-       ${mkdir} $@
-endif
-
-CMLIB_HOST_TARGET = \
-       $(CMLIB_OUT)$(SEP)cmlib.a
-
-CMLIB_HOST_SOURCES = $(addprefix $(CMLIB_BASE_), \
-       cminit.c \
-       hivebin.c \
-       hivecell.c \
-       hiveinit.c \
-       hivesum.c \
-       hivewrt.c \
-       )
-
-CMLIB_HOST_OBJECTS = \
-       $(subst $(CMLIB_BASE), $(CMLIB_INT), $(CMLIB_HOST_SOURCES:.c=.o))
-
-CMLIB_HOST_CFLAGS = -O3 -Wall -Wwrite-strings -Wpointer-arith \
-  -D_X86_ -D__i386__ -D_REACTOS_ -D_NTOSKRNL_\
-  -DCMLIB_HOST -D_M_IX86 -I$(CMLIB_BASE) -Iinclude/reactos -Iinclude/psdk -Iinclude/ddk -Iinclude/crt \
-  -D__NO_CTYPE_INLINES
-
-$(CMLIB_HOST_TARGET): $(CMLIB_HOST_OBJECTS) | $(CMLIB_OUT)
-       $(ECHO_AR)
-       $(host_ar) -r $@ $(CMLIB_HOST_OBJECTS)
-
-$(CMLIB_INT_)cminit.o: $(CMLIB_BASE_)cminit.c | $(CMLIB_INT)
-       $(ECHO_CC)
-       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@
-
-$(CMLIB_INT_)hivebin.o: $(CMLIB_BASE_)hivebin.c | $(CMLIB_INT)
-       $(ECHO_CC)
-       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@
-
-$(CMLIB_INT_)hivecell.o: $(CMLIB_BASE_)hivecell.c | $(CMLIB_INT)
-       $(ECHO_CC)
-       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@
-
-$(CMLIB_INT_)hiveinit.o: $(CMLIB_BASE_)hiveinit.c | $(CMLIB_INT)
-       $(ECHO_CC)
-       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@
-
-$(CMLIB_INT_)hivesum.o: $(CMLIB_BASE_)hivesum.c | $(CMLIB_INT)
-       $(ECHO_CC)
-       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@
-
-$(CMLIB_INT_)hivewrt.o: $(CMLIB_BASE_)hivewrt.c | $(CMLIB_INT)
-       $(ECHO_CC)
-       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@
-
-.PHONY: cmlib_host
-cmlib_host: $(CMLIB_HOST_TARGET)
-
-.PHONY: cmlib_host_clean
-cmlib_host_clean:
-       -@$(rm) $(CMLIB_HOST_TARGET) $(CMLIB_HOST_OBJECTS) 2>$(NUL)
-clean: cmlib_host_clean
+CMLIB_BASE = $(LIB_BASE_)cmlib\r
+CMLIB_BASE_ = $(CMLIB_BASE)$(SEP)\r
+CMLIB_INT = $(INTERMEDIATE_)$(CMLIB_BASE)_host\r
+CMLIB_INT_ = $(INTERMEDIATE_)$(CMLIB_BASE)_host$(SEP)\r
+CMLIB_OUT = $(OUTPUT_)$(CMLIB_BASE)_host\r
+CMLIB_OUT_ = $(OUTPUT_)$(CMLIB_BASE)_host$(SEP)\r
+\r
+$(CMLIB_INT): | $(LIB_INT)\r
+       $(ECHO_MKDIR)\r
+       ${mkdir} $@\r
+\r
+ifneq ($(INTERMEDIATE),$(OUTPUT))\r
+$(CMLIB_OUT): | $(OUTPUT_)$(LIB_BASE)\r
+       $(ECHO_MKDIR)\r
+       ${mkdir} $@\r
+endif\r
+\r
+CMLIB_HOST_TARGET = \\r
+       $(CMLIB_OUT)$(SEP)cmlib.a\r
+\r
+CMLIB_HOST_SOURCES = $(addprefix $(CMLIB_BASE_), \\r
+       cminit.c \\r
+       hivebin.c \\r
+       hivecell.c \\r
+       hiveinit.c \\r
+       hivesum.c \\r
+       hivewrt.c \\r
+       )\r
+\r
+CMLIB_HOST_OBJECTS = \\r
+       $(subst $(CMLIB_BASE), $(CMLIB_INT), $(CMLIB_HOST_SOURCES:.c=.o))\r
+\r
+CMLIB_HOST_CFLAGS = -O3 -Wall -Wwrite-strings -Wpointer-arith \\r
+  -D_X86_ -D__i386__ -D_REACTOS_ -D_NTOSKRNL_ -D_NTSYSTEM_ \\r
+  -DCMLIB_HOST -D_M_IX86 -I$(CMLIB_BASE) -Iinclude/reactos -Iinclude/psdk -Iinclude/ddk -Iinclude/crt \\r
+  -D__NO_CTYPE_INLINES\r
+\r
+$(CMLIB_HOST_TARGET): $(CMLIB_HOST_OBJECTS) | $(CMLIB_OUT)\r
+       $(ECHO_AR)\r
+       $(host_ar) -r $@ $(CMLIB_HOST_OBJECTS)\r
+\r
+$(CMLIB_INT_)cminit.o: $(CMLIB_BASE_)cminit.c | $(CMLIB_INT)\r
+       $(ECHO_CC)\r
+       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@\r
+\r
+$(CMLIB_INT_)hivebin.o: $(CMLIB_BASE_)hivebin.c | $(CMLIB_INT)\r
+       $(ECHO_CC)\r
+       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@\r
+\r
+$(CMLIB_INT_)hivecell.o: $(CMLIB_BASE_)hivecell.c | $(CMLIB_INT)\r
+       $(ECHO_CC)\r
+       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@\r
+\r
+$(CMLIB_INT_)hiveinit.o: $(CMLIB_BASE_)hiveinit.c | $(CMLIB_INT)\r
+       $(ECHO_CC)\r
+       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@\r
+\r
+$(CMLIB_INT_)hivesum.o: $(CMLIB_BASE_)hivesum.c | $(CMLIB_INT)\r
+       $(ECHO_CC)\r
+       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@\r
+\r
+$(CMLIB_INT_)hivewrt.o: $(CMLIB_BASE_)hivewrt.c | $(CMLIB_INT)\r
+       $(ECHO_CC)\r
+       ${host_gcc} $(CMLIB_HOST_CFLAGS) -c $< -o $@\r
+\r
+.PHONY: cmlib_host\r
+cmlib_host: $(CMLIB_HOST_TARGET)\r
+\r
+.PHONY: cmlib_host_clean\r
+cmlib_host_clean:\r
+       -@$(rm) $(CMLIB_HOST_TARGET) $(CMLIB_HOST_OBJECTS) 2>$(NUL)\r
+clean: cmlib_host_clean\r
index f973ef1..5a70b8d 100644 (file)
@@ -1,98 +1,98 @@
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2005 Hartmut Birr
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#include "cmlib.h"
-
-PHBIN CMAPI
-HvpAddBin(
-   PHHIVE RegistryHive,
-   ULONG Size,
-   HV_STORAGE_TYPE Storage)
-{
-   PHMAP_ENTRY BlockList;
-   PHBIN Bin;
-   SIZE_T BinSize;
-   ULONG i;
-   ULONG BitmapSize;
-   ULONG BlockCount;
-   ULONG OldBlockListSize;
-   PHCELL Block;
-
-   BinSize = ROUND_UP(Size + sizeof(HBIN), HV_BLOCK_SIZE);
-   BlockCount = (ULONG)(BinSize / HV_BLOCK_SIZE);
-
-   Bin = RegistryHive->Allocate(BinSize, TRUE);
-   if (Bin == NULL)
-      return NULL;
-   RtlZeroMemory(Bin, BinSize);
-
-   Bin->Signature = HV_BIN_SIGNATURE;
-   Bin->FileOffset = RegistryHive->Storage[Storage].Length *
-                    HV_BLOCK_SIZE;
-   Bin->Size = (ULONG)BinSize;
-
-   /* Allocate new block list */
-   OldBlockListSize = RegistryHive->Storage[Storage].Length;
-   BlockList = RegistryHive->Allocate(sizeof(HMAP_ENTRY) *
-                                      (OldBlockListSize + BlockCount), TRUE);
-   if (BlockList == NULL)
-   {
-      RegistryHive->Free(Bin);
-      return NULL;
-   }
-
-   if (OldBlockListSize > 0)
-   {
-      RtlCopyMemory(BlockList, RegistryHive->Storage[Storage].BlockList,
-                    OldBlockListSize * sizeof(HMAP_ENTRY));
-      RegistryHive->Free(RegistryHive->Storage[Storage].BlockList);
-   }
-
-   RegistryHive->Storage[Storage].BlockList = BlockList;
-   RegistryHive->Storage[Storage].Length += BlockCount;
-  
-   for (i = 0; i < BlockCount; i++)
-   {
-      RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].Block =
-         ((ULONG_PTR)Bin + (i * HV_BLOCK_SIZE));
-      RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].Bin = (ULONG_PTR)Bin;
-   }
-
-   /* Initialize a free block in this heap. */
-   Block = (PHCELL)(Bin + 1);
-   Block->Size = (LONG)(BinSize - sizeof(HBIN));
-
-   if (Storage == HvStable)
-   {
-      /* Calculate bitmap size in bytes (always a multiple of 32 bits). */
-      BitmapSize = ROUND_UP(RegistryHive->Storage[HvStable].Length,
-                            sizeof(ULONG) * 8) / 8;
-
-      /* Grow bitmap if necessary. */
-      if (BitmapSize > RegistryHive->DirtyVector.SizeOfBitMap / 8)
-      {
-         PULONG BitmapBuffer;
-
-         BitmapBuffer = RegistryHive->Allocate(BitmapSize, TRUE);
-         RtlZeroMemory(BitmapBuffer, BitmapSize);
-         RtlCopyMemory(BitmapBuffer,
-                   RegistryHive->DirtyVector.Buffer,
-                   RegistryHive->DirtyVector.SizeOfBitMap / 8);
-         RegistryHive->Free(RegistryHive->DirtyVector.Buffer);
-         RtlInitializeBitMap(&RegistryHive->DirtyVector, BitmapBuffer,
-                             BitmapSize * 8);
-      }
-
-      /* Mark new bin dirty. */
-      RtlSetBits(&RegistryHive->DirtyVector,
-                 Bin->FileOffset / HV_BLOCK_SIZE,
-                 BlockCount);
-   }
-
-   return Bin;
-}
+/*\r
+ * PROJECT:   registry manipulation library\r
+ * LICENSE:   GPL - See COPYING in the top level directory\r
+ * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>\r
+ *            Copyright 2005 Hartmut Birr\r
+ *            Copyright 2001 - 2005 Eric Kohl\r
+ */\r
+\r
+#include "cmlib.h"\r
+\r
+PHBIN CMAPI\r
+HvpAddBin(\r
+   PHHIVE RegistryHive,\r
+   ULONG Size,\r
+   HV_STORAGE_TYPE Storage)\r
+{\r
+   PHMAP_ENTRY BlockList;\r
+   PHBIN Bin;\r
+   SIZE_T BinSize;\r
+   ULONG i;\r
+   ULONG BitmapSize;\r
+   ULONG BlockCount;\r
+   ULONG OldBlockListSize;\r
+   PHCELL Block;\r
+\r
+   BinSize = ROUND_UP(Size + sizeof(HBIN), HV_BLOCK_SIZE);\r
+   BlockCount = (ULONG)(BinSize / HV_BLOCK_SIZE);\r
+\r
+   Bin = RegistryHive->Allocate(BinSize, TRUE);\r
+   if (Bin == NULL)\r
+      return NULL;\r
+   RtlZeroMemory(Bin, BinSize);\r
+\r
+   Bin->Signature = HV_BIN_SIGNATURE;\r
+   Bin->FileOffset = RegistryHive->Storage[Storage].Length *\r
+                    HV_BLOCK_SIZE;\r
+   Bin->Size = (ULONG)BinSize;\r
+\r
+   /* Allocate new block list */\r
+   OldBlockListSize = RegistryHive->Storage[Storage].Length;\r
+   BlockList = RegistryHive->Allocate(sizeof(HMAP_ENTRY) *\r
+                                      (OldBlockListSize + BlockCount), TRUE);\r
+   if (BlockList == NULL)\r
+   {\r
+      RegistryHive->Free(Bin);\r
+      return NULL;\r
+   }\r
+\r
+   if (OldBlockListSize > 0)\r
+   {\r
+      RtlCopyMemory(BlockList, RegistryHive->Storage[Storage].BlockList,\r
+                    OldBlockListSize * sizeof(HMAP_ENTRY));\r
+      RegistryHive->Free(RegistryHive->Storage[Storage].BlockList);\r
+   }\r
+\r
+   RegistryHive->Storage[Storage].BlockList = BlockList;\r
+   RegistryHive->Storage[Storage].Length += BlockCount;\r
+  \r
+   for (i = 0; i < BlockCount; i++)\r
+   {\r
+      RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].Block =\r
+         ((ULONG_PTR)Bin + (i * HV_BLOCK_SIZE));\r
+      RegistryHive->Storage[Storage].BlockList[OldBlockListSize + i].Bin = (ULONG_PTR)Bin;\r
+   }\r
+\r
+   /* Initialize a free block in this heap. */\r
+   Block = (PHCELL)(Bin + 1);\r
+   Block->Size = (LONG)(BinSize - sizeof(HBIN));\r
+\r
+   if (Storage == HvStable)\r
+   {\r
+      /* Calculate bitmap size in bytes (always a multiple of 32 bits). */\r
+      BitmapSize = ROUND_UP(RegistryHive->Storage[HvStable].Length,\r
+                            sizeof(ULONG) * 8) / 8;\r
+\r
+      /* Grow bitmap if necessary. */\r
+      if (BitmapSize > RegistryHive->DirtyVector.SizeOfBitMap / 8)\r
+      {\r
+         PULONG BitmapBuffer;\r
+\r
+         BitmapBuffer = RegistryHive->Allocate(BitmapSize, TRUE);\r
+         RtlZeroMemory(BitmapBuffer, BitmapSize);\r
+         RtlCopyMemory(BitmapBuffer,\r
+                   RegistryHive->DirtyVector.Buffer,\r
+                   RegistryHive->DirtyVector.SizeOfBitMap / 8);\r
+         RegistryHive->Free(RegistryHive->DirtyVector.Buffer);\r
+         RtlInitializeBitMap(&RegistryHive->DirtyVector, BitmapBuffer,\r
+                             BitmapSize * 8);\r
+      }\r
+\r
+      /* Mark new bin dirty. */\r
+      RtlSetBits(&RegistryHive->DirtyVector,\r
+                 Bin->FileOffset / HV_BLOCK_SIZE,\r
+                 BlockCount);\r
+   }\r
+\r
+   return Bin;\r
+}\r
index 1e84baf..d829bc8 100644 (file)
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#include "cmlib.h"
-#define NDEBUG
-#include <debug.h>
-
-static PHCELL __inline CMAPI
-HvpGetCellHeader(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellIndex)
-{
-   PVOID Block;
-
-   ASSERT(CellIndex != HCELL_NULL);
-   if (!RegistryHive->Flat)
-   {
-      ULONG CellType;
-      ULONG CellBlock;
-      ULONG CellOffset;
-
-      CellType = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;
-      CellBlock = (CellIndex & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;
-      CellOffset = (CellIndex & HCELL_OFFSET_MASK) >> HCELL_OFFSET_SHIFT;
-      ASSERT(CellBlock < RegistryHive->Storage[CellType].Length);
-      Block = (PVOID)RegistryHive->Storage[CellType].BlockList[CellBlock].Block;
-      ASSERT(Block != NULL);
-      return (PVOID)((ULONG_PTR)Block + CellOffset);
-   }
-   else
-   {
-      ASSERT((CellIndex & HCELL_TYPE_MASK) == HvStable);
-      return (PVOID)((ULONG_PTR)RegistryHive->HiveHeader + HV_BLOCK_SIZE +
-                     CellIndex);
-   }
-}
-
-PVOID CMAPI
-HvGetCell(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellIndex)
-{
-   return (PVOID)(HvpGetCellHeader(RegistryHive, CellIndex) + 1);
-}
-
-static LONG __inline CMAPI
-HvpGetCellFullSize(
-   PHHIVE RegistryHive,
-   PVOID Cell)
-{
-   return ((PHCELL)Cell - 1)->Size;
-}
-
-LONG CMAPI
-HvGetCellSize(
-   PHHIVE RegistryHive,
-   PVOID Cell)
-{
-   PHCELL CellHeader;
-
-   CellHeader = (PHCELL)Cell - 1;
-   if (CellHeader->Size < 0)
-      return CellHeader->Size + sizeof(HCELL);
-   else
-      return CellHeader->Size - sizeof(HCELL);
-}
-
-VOID CMAPI
-HvMarkCellDirty(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellIndex)
-{
-   LONG CellSize;
-   ULONG CellBlock;
-   ULONG CellLastBlock;
-
-   ASSERT(RegistryHive->ReadOnly == FALSE);
-
-   if ((CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT != HvStable)
-      return;
-
-   CellBlock = (CellIndex & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;
-   CellLastBlock = ((CellIndex + HV_BLOCK_SIZE - 1) & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;
-
-   CellSize = HvpGetCellFullSize(RegistryHive, HvGetCell(RegistryHive, CellIndex));
-   if (CellSize < 0)
-      CellSize = -CellSize;
-
-   RtlSetBits(&RegistryHive->DirtyVector,
-              CellBlock, CellLastBlock - CellBlock);
-}
-
-static ULONG __inline CMAPI
-HvpComputeFreeListIndex(
-   ULONG Size)
-{
-   ULONG Index;
-   static CCHAR FindFirstSet[256] = {
-      0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
-      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
-
-   Index = (Size >> 3) - 1;
-   if (Index >= 16)
-   {
-      if (Index > 255)
-         Index = 23;
-      else
-         Index = FindFirstSet[Index] + 7;
-   }
-
-   return Index;
-}
-
-static NTSTATUS CMAPI
-HvpAddFree(
-   PHHIVE RegistryHive,
-   PHCELL FreeBlock,
-   HCELL_INDEX FreeIndex)
-{
-   PHCELL_INDEX FreeBlockData;
-   HV_STORAGE_TYPE Storage;
-   ULONG Index;
-
-   ASSERT(RegistryHive != NULL);
-   ASSERT(FreeBlock != NULL);
-
-   Storage = (FreeIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;
-   Index = HvpComputeFreeListIndex((ULONG)FreeBlock->Size);
-
-   FreeBlockData = (PHCELL_INDEX)(FreeBlock + 1);
-   *FreeBlockData = RegistryHive->Storage[Storage].FreeDisplay[Index];
-   RegistryHive->Storage[Storage].FreeDisplay[Index] = FreeIndex;
-
-   /* FIXME: Eventually get rid of free bins. */
-
-   return STATUS_SUCCESS;
-}
-
-static VOID CMAPI
-HvpRemoveFree(
-   PHHIVE RegistryHive,
-   PHCELL CellBlock,
-   HCELL_INDEX CellIndex)
-{
-   PHCELL_INDEX FreeCellData;
-   PHCELL_INDEX pFreeCellOffset;
-   HV_STORAGE_TYPE Storage;
-   ULONG Index;
-
-   ASSERT(RegistryHive->ReadOnly == FALSE);
-
-   Storage = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;
-   Index = HvpComputeFreeListIndex((ULONG)CellBlock->Size);
-
-   pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[Index];
-   while (*pFreeCellOffset != HCELL_NULL)
-   {
-      FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);
-      if (*pFreeCellOffset == CellIndex)
-      {
-         *pFreeCellOffset = *FreeCellData;
-         return;
-      }
-      pFreeCellOffset = FreeCellData;
-   }
-
-   ASSERT(FALSE);
-}
-
-static HCELL_INDEX CMAPI
-HvpFindFree(
-   PHHIVE RegistryHive,
-   ULONG Size,
-   HV_STORAGE_TYPE Storage)
-{
-   PHCELL_INDEX FreeCellData;
-   HCELL_INDEX FreeCellOffset;
-   PHCELL_INDEX pFreeCellOffset;
-   ULONG Index;
-
-   for (Index = HvpComputeFreeListIndex(Size); Index < 24; Index++)
-   {
-      pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[Index];
-      while (*pFreeCellOffset != HCELL_NULL)
-      {
-         FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);
-         if ((ULONG)HvpGetCellFullSize(RegistryHive, FreeCellData) >= Size)
-         {
-            FreeCellOffset = *pFreeCellOffset;
-            *pFreeCellOffset = *FreeCellData;
-            return FreeCellOffset;
-         }
-         pFreeCellOffset = FreeCellData;
-      }
-   }
-
-   return HCELL_NULL;
-}
-
-NTSTATUS CMAPI
-HvpCreateHiveFreeCellList(
-   PHHIVE Hive)
-{
-   HCELL_INDEX BlockOffset;
-   PHCELL FreeBlock;
-   ULONG BlockIndex;
-   ULONG FreeOffset;
-   PHBIN Bin;
-   NTSTATUS Status;
-   ULONG Index;
-
-   /* Initialize the free cell list */
-   for (Index = 0; Index < 24; Index++)
-   {
-      Hive->Storage[HvStable].FreeDisplay[Index] = HCELL_NULL;
-      Hive->Storage[HvVolatile].FreeDisplay[Index] = HCELL_NULL;
-   }
-
-   BlockOffset = 0;
-   BlockIndex = 0;
-   while (BlockIndex < Hive->Storage[HvStable].Length)
-   {
-      Bin = (PHBIN)Hive->Storage[HvStable].BlockList[BlockIndex].Bin;
-
-      /* Search free blocks and add to list */
-      FreeOffset = sizeof(HBIN);
-      while (FreeOffset < Bin->Size)
-      {
-         FreeBlock = (PHCELL)((ULONG_PTR)Bin + FreeOffset);
-         if (FreeBlock->Size > 0)
-         {
-            Status = HvpAddFree(Hive, FreeBlock, Bin->FileOffset + FreeOffset);
-            if (!NT_SUCCESS(Status))
-               return Status;
-
-            FreeOffset += FreeBlock->Size;
-         }
-         else
-         {
-            FreeOffset -= FreeBlock->Size;
-         }
-      }
-
-      BlockIndex += Bin->Size / HV_BLOCK_SIZE;
-      BlockOffset += Bin->Size;
-   }
-
-   return STATUS_SUCCESS;
-}
-
-HCELL_INDEX CMAPI
-HvAllocateCell(
-   PHHIVE RegistryHive,
-   ULONG Size,
-   HV_STORAGE_TYPE Storage)
-{
-   PHCELL FreeCell;
-   HCELL_INDEX FreeCellOffset;
-   PHCELL NewCell;
-   PHBIN Bin;
-
-   ASSERT(RegistryHive->ReadOnly == FALSE);
-
-   /* Round to 16 bytes multiple. */
-   Size = ROUND_UP(Size + sizeof(HCELL), 16);
-
-   /* First search in free blocks. */
-   FreeCellOffset = HvpFindFree(RegistryHive, Size, Storage);
-
-   /* If no free cell was found we need to extend the hive file. */
-   if (FreeCellOffset == HCELL_NULL)
-   {
-      Bin = HvpAddBin(RegistryHive, Size, Storage);
-      if (Bin == NULL)
-         return HCELL_NULL;
-      FreeCellOffset = Bin->FileOffset + sizeof(HBIN);
-      FreeCellOffset |= Storage << HCELL_TYPE_SHIFT;
-   }
-
-   FreeCell = HvpGetCellHeader(RegistryHive, FreeCellOffset);
-
-   /* Split the block in two parts */
-   /* FIXME: There is some minimal cell size that we must respect. */
-   if ((ULONG)FreeCell->Size > Size + sizeof(HCELL_INDEX))
-   {
-      NewCell = (PHCELL)((ULONG_PTR)FreeCell + Size);
-      NewCell->Size = FreeCell->Size - Size;
-      FreeCell->Size = Size;
-      HvpAddFree(RegistryHive, NewCell, FreeCellOffset + Size);
-      if (Storage == HvStable)
-         HvMarkCellDirty(RegistryHive, FreeCellOffset + Size);
-   }
-
-   if (Storage == HvStable)
-      HvMarkCellDirty(RegistryHive, FreeCellOffset);
-   FreeCell->Size = -FreeCell->Size;
-   RtlZeroMemory(FreeCell + 1, Size - sizeof(HCELL));
-
-   return FreeCellOffset;
-}
-
-HCELL_INDEX CMAPI
-HvReallocateCell(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellIndex,
-   ULONG Size)
-{
-   PVOID OldCell;
-   PVOID NewCell;
-   LONG OldCellSize;
-   HCELL_INDEX NewCellIndex;
-   HV_STORAGE_TYPE Storage;
-
-   ASSERT(CellIndex != HCELL_NULL);
-
-   Storage = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;
-
-   OldCell = HvGetCell(RegistryHive, CellIndex);
-   OldCellSize = HvGetCellSize(RegistryHive, OldCell);
-   ASSERT(OldCellSize < 0);
-  
-   /*
-    * If new data size is larger than the current, destroy current
-    * data block and allocate a new one.
-    *
-    * FIXME: Merge with adjacent free cell if possible.
-    * FIXME: Implement shrinking.
-    */
-   if (Size > (ULONG)-OldCellSize)
-   {
-      NewCellIndex = HvAllocateCell(RegistryHive, Size, Storage);
-      if (NewCellIndex == HCELL_NULL)
-         return HCELL_NULL;
-
-      NewCell = HvGetCell(RegistryHive, NewCellIndex);
-      RtlCopyMemory(NewCell, OldCell, (SIZE_T)-OldCellSize);
-      
-      HvFreeCell(RegistryHive, CellIndex);
-
-      return NewCellIndex;
-   }
-
-   return CellIndex;
-}
-
-VOID CMAPI
-HvFreeCell(
-   PHHIVE RegistryHive,
-   HCELL_INDEX CellIndex)
-{
-   PHCELL Free;
-   PHCELL Neighbor;
-   PHBIN Bin;
-   ULONG CellType;
-   ULONG CellBlock;
-
-   ASSERT(RegistryHive->ReadOnly == FALSE);
-   
-   Free = HvpGetCellHeader(RegistryHive, CellIndex);
-
-   ASSERT(Free->Size < 0);   
-   
-   Free->Size = -Free->Size;
-
-   CellType = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;
-   CellBlock = (CellIndex & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;
-
-   /* FIXME: Merge free blocks */
-   Bin = (PHBIN)RegistryHive->Storage[CellType].BlockList[CellBlock].Bin;
-
-   if ((CellIndex & ~HCELL_TYPE_MASK) + Free->Size <
-       Bin->FileOffset + Bin->Size)
-   {
-      Neighbor = (PHCELL)((ULONG_PTR)Free + Free->Size);
-      if (Neighbor->Size > 0)
-      {
-         HvpRemoveFree(RegistryHive, Neighbor,
-                       ((HCELL_INDEX)((ULONG_PTR)Neighbor - (ULONG_PTR)Bin +
-                       Bin->FileOffset)) | (CellIndex & HCELL_TYPE_MASK));
-         Free->Size += Neighbor->Size;
-      }
-   }
-
-   Neighbor = (PHCELL)(Bin + 1);
-   while (Neighbor < Free)
-   {
-      if (Neighbor->Size > 0)
-      {
-         if ((ULONG_PTR)Neighbor + Neighbor->Size == (ULONG_PTR)Free)
-         {
-            Neighbor->Size += Free->Size;
-            if (CellType == HvStable)
-               HvMarkCellDirty(RegistryHive,
-                               (HCELL_INDEX)((ULONG_PTR)Neighbor - (ULONG_PTR)Bin +
-                               Bin->FileOffset));
-            return;
-         }
-         Neighbor = (PHCELL)((ULONG_PTR)Neighbor + Neighbor->Size);
-      }
-      else
-      {
-         Neighbor = (PHCELL)((ULONG_PTR)Neighbor - Neighbor->Size);
-      }
-   }
-
-   /* Add block to the list of free blocks */
-   HvpAddFree(RegistryHive, Free, CellIndex);
-
-   if (CellType == HvStable)
-      HvMarkCellDirty(RegistryHive, CellIndex);
-}
+/*\r
+ * PROJECT:   registry manipulation library\r
+ * LICENSE:   GPL - See COPYING in the top level directory\r
+ * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>\r
+ *            Copyright 2001 - 2005 Eric Kohl\r
+ */\r
+\r
+#include "cmlib.h"\r
+#define NDEBUG\r
+#include <debug.h>\r
+\r
+static PHCELL __inline CMAPI\r
+HvpGetCellHeader(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellIndex)\r
+{\r
+   PVOID Block;\r
+\r
+   ASSERT(CellIndex != HCELL_NULL);\r
+   if (!RegistryHive->Flat)\r
+   {\r
+      ULONG CellType;\r
+      ULONG CellBlock;\r
+      ULONG CellOffset;\r
+\r
+      CellType = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;\r
+      CellBlock = (CellIndex & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;\r
+      CellOffset = (CellIndex & HCELL_OFFSET_MASK) >> HCELL_OFFSET_SHIFT;\r
+      ASSERT(CellBlock < RegistryHive->Storage[CellType].Length);\r
+      Block = (PVOID)RegistryHive->Storage[CellType].BlockList[CellBlock].Block;\r
+      ASSERT(Block != NULL);\r
+      return (PVOID)((ULONG_PTR)Block + CellOffset);\r
+   }\r
+   else\r
+   {\r
+      ASSERT((CellIndex & HCELL_TYPE_MASK) == HvStable);\r
+      return (PVOID)((ULONG_PTR)RegistryHive->HiveHeader + HV_BLOCK_SIZE +\r
+                     CellIndex);\r
+   }\r
+}\r
+\r
+PVOID CMAPI\r
+HvGetCell(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellIndex)\r
+{\r
+   return (PVOID)(HvpGetCellHeader(RegistryHive, CellIndex) + 1);\r
+}\r
+\r
+static LONG __inline CMAPI\r
+HvpGetCellFullSize(\r
+   PHHIVE RegistryHive,\r
+   PVOID Cell)\r
+{\r
+   return ((PHCELL)Cell - 1)->Size;\r
+}\r
+\r
+LONG CMAPI\r
+HvGetCellSize(\r
+   PHHIVE RegistryHive,\r
+   PVOID Cell)\r
+{\r
+   PHCELL CellHeader;\r
+\r
+   CellHeader = (PHCELL)Cell - 1;\r
+   if (CellHeader->Size < 0)\r
+      return CellHeader->Size + sizeof(HCELL);\r
+   else\r
+      return CellHeader->Size - sizeof(HCELL);\r
+}\r
+\r
+VOID CMAPI\r
+HvMarkCellDirty(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellIndex)\r
+{\r
+   LONG CellSize;\r
+   ULONG CellBlock;\r
+   ULONG CellLastBlock;\r
+\r
+   ASSERT(RegistryHive->ReadOnly == FALSE);\r
+\r
+   if ((CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT != HvStable)\r
+      return;\r
+\r
+   CellBlock = (CellIndex & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;\r
+   CellLastBlock = ((CellIndex + HV_BLOCK_SIZE - 1) & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;\r
+\r
+   CellSize = HvpGetCellFullSize(RegistryHive, HvGetCell(RegistryHive, CellIndex));\r
+   if (CellSize < 0)\r
+      CellSize = -CellSize;\r
+\r
+   RtlSetBits(&RegistryHive->DirtyVector,\r
+              CellBlock, CellLastBlock - CellBlock);\r
+}\r
+\r
+static ULONG __inline CMAPI\r
+HvpComputeFreeListIndex(\r
+   ULONG Size)\r
+{\r
+   ULONG Index;\r
+   static CCHAR FindFirstSet[256] = {\r
+      0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,\r
+      4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,\r
+      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\r
+      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,\r
+      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,\r
+      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,\r
+      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,\r
+      6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,\r
+      7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};\r
+\r
+   Index = (Size >> 3) - 1;\r
+   if (Index >= 16)\r
+   {\r
+      if (Index > 255)\r
+         Index = 23;\r
+      else\r
+         Index = FindFirstSet[Index] + 7;\r
+   }\r
+\r
+   return Index;\r
+}\r
+\r
+static NTSTATUS CMAPI\r
+HvpAddFree(\r
+   PHHIVE RegistryHive,\r
+   PHCELL FreeBlock,\r
+   HCELL_INDEX FreeIndex)\r
+{\r
+   PHCELL_INDEX FreeBlockData;\r
+   HV_STORAGE_TYPE Storage;\r
+   ULONG Index;\r
+\r
+   ASSERT(RegistryHive != NULL);\r
+   ASSERT(FreeBlock != NULL);\r
+\r
+   Storage = (FreeIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;\r
+   Index = HvpComputeFreeListIndex((ULONG)FreeBlock->Size);\r
+\r
+   FreeBlockData = (PHCELL_INDEX)(FreeBlock + 1);\r
+   *FreeBlockData = RegistryHive->Storage[Storage].FreeDisplay[Index];\r
+   RegistryHive->Storage[Storage].FreeDisplay[Index] = FreeIndex;\r
+\r
+   /* FIXME: Eventually get rid of free bins. */\r
+\r
+   return STATUS_SUCCESS;\r
+}\r
+\r
+static VOID CMAPI\r
+HvpRemoveFree(\r
+   PHHIVE RegistryHive,\r
+   PHCELL CellBlock,\r
+   HCELL_INDEX CellIndex)\r
+{\r
+   PHCELL_INDEX FreeCellData;\r
+   PHCELL_INDEX pFreeCellOffset;\r
+   HV_STORAGE_TYPE Storage;\r
+   ULONG Index;\r
+\r
+   ASSERT(RegistryHive->ReadOnly == FALSE);\r
+\r
+   Storage = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;\r
+   Index = HvpComputeFreeListIndex((ULONG)CellBlock->Size);\r
+\r
+   pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[Index];\r
+   while (*pFreeCellOffset != HCELL_NULL)\r
+   {\r
+      FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);\r
+      if (*pFreeCellOffset == CellIndex)\r
+      {\r
+         *pFreeCellOffset = *FreeCellData;\r
+         return;\r
+      }\r
+      pFreeCellOffset = FreeCellData;\r
+   }\r
+\r
+   ASSERT(FALSE);\r
+}\r
+\r
+static HCELL_INDEX CMAPI\r
+HvpFindFree(\r
+   PHHIVE RegistryHive,\r
+   ULONG Size,\r
+   HV_STORAGE_TYPE Storage)\r
+{\r
+   PHCELL_INDEX FreeCellData;\r
+   HCELL_INDEX FreeCellOffset;\r
+   PHCELL_INDEX pFreeCellOffset;\r
+   ULONG Index;\r
+\r
+   for (Index = HvpComputeFreeListIndex(Size); Index < 24; Index++)\r
+   {\r
+      pFreeCellOffset = &RegistryHive->Storage[Storage].FreeDisplay[Index];\r
+      while (*pFreeCellOffset != HCELL_NULL)\r
+      {\r
+         FreeCellData = (PHCELL_INDEX)HvGetCell(RegistryHive, *pFreeCellOffset);\r
+         if ((ULONG)HvpGetCellFullSize(RegistryHive, FreeCellData) >= Size)\r
+         {\r
+            FreeCellOffset = *pFreeCellOffset;\r
+            *pFreeCellOffset = *FreeCellData;\r
+            return FreeCellOffset;\r
+         }\r
+         pFreeCellOffset = FreeCellData;\r
+      }\r
+   }\r
+\r
+   return HCELL_NULL;\r
+}\r
+\r
+NTSTATUS CMAPI\r
+HvpCreateHiveFreeCellList(\r
+   PHHIVE Hive)\r
+{\r
+   HCELL_INDEX BlockOffset;\r
+   PHCELL FreeBlock;\r
+   ULONG BlockIndex;\r
+   ULONG FreeOffset;\r
+   PHBIN Bin;\r
+   NTSTATUS Status;\r
+   ULONG Index;\r
+\r
+   /* Initialize the free cell list */\r
+   for (Index = 0; Index < 24; Index++)\r
+   {\r
+      Hive->Storage[HvStable].FreeDisplay[Index] = HCELL_NULL;\r
+      Hive->Storage[HvVolatile].FreeDisplay[Index] = HCELL_NULL;\r
+   }\r
+\r
+   BlockOffset = 0;\r
+   BlockIndex = 0;\r
+   while (BlockIndex < Hive->Storage[HvStable].Length)\r
+   {\r
+      Bin = (PHBIN)Hive->Storage[HvStable].BlockList[BlockIndex].Bin;\r
+\r
+      /* Search free blocks and add to list */\r
+      FreeOffset = sizeof(HBIN);\r
+      while (FreeOffset < Bin->Size)\r
+      {\r
+         FreeBlock = (PHCELL)((ULONG_PTR)Bin + FreeOffset);\r
+         if (FreeBlock->Size > 0)\r
+         {\r
+            Status = HvpAddFree(Hive, FreeBlock, Bin->FileOffset + FreeOffset);\r
+            if (!NT_SUCCESS(Status))\r
+               return Status;\r
+\r
+            FreeOffset += FreeBlock->Size;\r
+         }\r
+         else\r
+         {\r
+            FreeOffset -= FreeBlock->Size;\r
+         }\r
+      }\r
+\r
+      BlockIndex += Bin->Size / HV_BLOCK_SIZE;\r
+      BlockOffset += Bin->Size;\r
+   }\r
+\r
+   return STATUS_SUCCESS;\r
+}\r
+\r
+HCELL_INDEX CMAPI\r
+HvAllocateCell(\r
+   PHHIVE RegistryHive,\r
+   ULONG Size,\r
+   HV_STORAGE_TYPE Storage)\r
+{\r
+   PHCELL FreeCell;\r
+   HCELL_INDEX FreeCellOffset;\r
+   PHCELL NewCell;\r
+   PHBIN Bin;\r
+\r
+   ASSERT(RegistryHive->ReadOnly == FALSE);\r
+\r
+   /* Round to 16 bytes multiple. */\r
+   Size = ROUND_UP(Size + sizeof(HCELL), 16);\r
+\r
+   /* First search in free blocks. */\r
+   FreeCellOffset = HvpFindFree(RegistryHive, Size, Storage);\r
+\r
+   /* If no free cell was found we need to extend the hive file. */\r
+   if (FreeCellOffset == HCELL_NULL)\r
+   {\r
+      Bin = HvpAddBin(RegistryHive, Size, Storage);\r
+      if (Bin == NULL)\r
+         return HCELL_NULL;\r
+      FreeCellOffset = Bin->FileOffset + sizeof(HBIN);\r
+      FreeCellOffset |= Storage << HCELL_TYPE_SHIFT;\r
+   }\r
+\r
+   FreeCell = HvpGetCellHeader(RegistryHive, FreeCellOffset);\r
+\r
+   /* Split the block in two parts */\r
+   /* FIXME: There is some minimal cell size that we must respect. */\r
+   if ((ULONG)FreeCell->Size > Size + sizeof(HCELL_INDEX))\r
+   {\r
+      NewCell = (PHCELL)((ULONG_PTR)FreeCell + Size);\r
+      NewCell->Size = FreeCell->Size - Size;\r
+      FreeCell->Size = Size;\r
+      HvpAddFree(RegistryHive, NewCell, FreeCellOffset + Size);\r
+      if (Storage == HvStable)\r
+         HvMarkCellDirty(RegistryHive, FreeCellOffset + Size);\r
+   }\r
+\r
+   if (Storage == HvStable)\r
+      HvMarkCellDirty(RegistryHive, FreeCellOffset);\r
+   FreeCell->Size = -FreeCell->Size;\r
+   RtlZeroMemory(FreeCell + 1, Size - sizeof(HCELL));\r
+\r
+   return FreeCellOffset;\r
+}\r
+\r
+HCELL_INDEX CMAPI\r
+HvReallocateCell(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellIndex,\r
+   ULONG Size)\r
+{\r
+   PVOID OldCell;\r
+   PVOID NewCell;\r
+   LONG OldCellSize;\r
+   HCELL_INDEX NewCellIndex;\r
+   HV_STORAGE_TYPE Storage;\r
+\r
+   ASSERT(CellIndex != HCELL_NULL);\r
+\r
+   Storage = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;\r
+\r
+   OldCell = HvGetCell(RegistryHive, CellIndex);\r
+   OldCellSize = HvGetCellSize(RegistryHive, OldCell);\r
+   ASSERT(OldCellSize < 0);\r
+  \r
+   /*\r
+    * If new data size is larger than the current, destroy current\r
+    * data block and allocate a new one.\r
+    *\r
+    * FIXME: Merge with adjacent free cell if possible.\r
+    * FIXME: Implement shrinking.\r
+    */\r
+   if (Size > (ULONG)-OldCellSize)\r
+   {\r
+      NewCellIndex = HvAllocateCell(RegistryHive, Size, Storage);\r
+      if (NewCellIndex == HCELL_NULL)\r
+         return HCELL_NULL;\r
+\r
+      NewCell = HvGetCell(RegistryHive, NewCellIndex);\r
+      RtlCopyMemory(NewCell, OldCell, (SIZE_T)-OldCellSize);\r
+      \r
+      HvFreeCell(RegistryHive, CellIndex);\r
+\r
+      return NewCellIndex;\r
+   }\r
+\r
+   return CellIndex;\r
+}\r
+\r
+VOID CMAPI\r
+HvFreeCell(\r
+   PHHIVE RegistryHive,\r
+   HCELL_INDEX CellIndex)\r
+{\r
+   PHCELL Free;\r
+   PHCELL Neighbor;\r
+   PHBIN Bin;\r
+   ULONG CellType;\r
+   ULONG CellBlock;\r
+\r
+   ASSERT(RegistryHive->ReadOnly == FALSE);\r
+   \r
+   Free = HvpGetCellHeader(RegistryHive, CellIndex);\r
+\r
+   ASSERT(Free->Size < 0);   \r
+   \r
+   Free->Size = -Free->Size;\r
+\r
+   CellType = (CellIndex & HCELL_TYPE_MASK) >> HCELL_TYPE_SHIFT;\r
+   CellBlock = (CellIndex & HCELL_BLOCK_MASK) >> HCELL_BLOCK_SHIFT;\r
+\r
+   /* FIXME: Merge free blocks */\r
+   Bin = (PHBIN)RegistryHive->Storage[CellType].BlockList[CellBlock].Bin;\r
+\r
+   if ((CellIndex & ~HCELL_TYPE_MASK) + Free->Size <\r
+       Bin->FileOffset + Bin->Size)\r
+   {\r
+      Neighbor = (PHCELL)((ULONG_PTR)Free + Free->Size);\r
+      if (Neighbor->Size > 0)\r
+      {\r
+         HvpRemoveFree(RegistryHive, Neighbor,\r
+                       ((HCELL_INDEX)((ULONG_PTR)Neighbor - (ULONG_PTR)Bin +\r
+                       Bin->FileOffset)) | (CellIndex & HCELL_TYPE_MASK));\r
+         Free->Size += Neighbor->Size;\r
+      }\r
+   }\r
+\r
+   Neighbor = (PHCELL)(Bin + 1);\r
+   while (Neighbor < Free)\r
+   {\r
+      if (Neighbor->Size > 0)\r
+      {\r
+         if ((ULONG_PTR)Neighbor + Neighbor->Size == (ULONG_PTR)Free)\r
+         {\r
+            Neighbor->Size += Free->Size;\r
+            if (CellType == HvStable)\r
+               HvMarkCellDirty(RegistryHive,\r
+                               (HCELL_INDEX)((ULONG_PTR)Neighbor - (ULONG_PTR)Bin +\r
+                               Bin->FileOffset));\r
+            return;\r
+         }\r
+         Neighbor = (PHCELL)((ULONG_PTR)Neighbor + Neighbor->Size);\r
+      }\r
+      else\r
+      {\r
+         Neighbor = (PHCELL)((ULONG_PTR)Neighbor - Neighbor->Size);\r
+      }\r
+   }\r
+\r
+   /* Add block to the list of free blocks */\r
+   HvpAddFree(RegistryHive, Free, CellIndex);\r
+\r
+   if (CellType == HvStable)\r
+      HvMarkCellDirty(RegistryHive, CellIndex);\r
+}\r
index 3857158..751c024 100644 (file)
@@ -30,7 +30,6 @@
  * the other bits specify index into the hive file. The value HCELL_NULL\r
  * (-1) is reserved for marking invalid cells.\r
  */\r
-\r
 typedef ULONG HCELL_INDEX, *PHCELL_INDEX;\r
 \r
 #define HCELL_NULL                     ((HCELL_INDEX)-1)\r
index 56997b6..4b44e5c 100644 (file)
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#include "cmlib.h"
-#define NDEBUG
-#include <debug.h>
-
-/**
- * @name HvpVerifyHiveHeader
- *
- * Internal function to verify that a hive header has valid format.
- */
-
-BOOLEAN CMAPI
-HvpVerifyHiveHeader(
-   PHBASE_BLOCK HiveHeader)
-{
-   if (HiveHeader->Signature != HV_SIGNATURE ||
-       HiveHeader->Major != HV_MAJOR_VER ||
-       HiveHeader->Minor < HV_MINOR_VER ||
-       HiveHeader->Type != HV_TYPE_PRIMARY ||
-       HiveHeader->Format != HV_FORMAT_MEMORY ||
-       HiveHeader->Cluster != 1 ||
-       HiveHeader->Sequence1 != HiveHeader->Sequence2 ||
-       HvpHiveHeaderChecksum(HiveHeader) != HiveHeader->Checksum)
-   {
-      DPRINT1("Verify Hive Header failed: \n");
-      DPRINT1("    Signature: 0x%x and not 0x%x, Major: 0x%x and not 0x%x\n",
-          HiveHeader->Signature, HV_SIGNATURE, HiveHeader->Major, HV_MAJOR_VER);
-      DPRINT1("    Minor: 0x%x is not >= 0x%x, Type: 0x%x and not 0x%x\n",
-          HiveHeader->Minor, HV_MINOR_VER, HiveHeader->Type, HV_TYPE_PRIMARY);
-      DPRINT1("    Format: 0x%x and not 0x%x, Cluster: 0x%x and not 1\n",
-          HiveHeader->Format, HV_FORMAT_MEMORY, HiveHeader->Cluster);
-      DPRINT1("    Sequence: 0x%x and not 0x%x, Checksum: 0x%x and not 0x%x\n",
-          HiveHeader->Sequence1, HiveHeader->Sequence2,
-          HvpHiveHeaderChecksum(HiveHeader), HiveHeader->Checksum);
-      return FALSE;
-   }
-
-   return TRUE;
-}
-
-/**
- * @name HvpFreeHiveBins
- *
- * Internal function to free all bin storage associated with hive
- * descriptor.
- */
-
-VOID CMAPI
-HvpFreeHiveBins(
-   PHHIVE Hive)
-{              
-   ULONG i;
-   PHBIN Bin;
-   ULONG Storage;
-
-   for (Storage = HvStable; Storage < HvMaxStorageType; Storage++)
-   {
-      Bin = NULL;
-      for (i = 0; i < Hive->Storage[Storage].Length; i++)
-      {
-         if (Hive->Storage[Storage].BlockList[i].Bin == (ULONG_PTR)NULL)
-            continue;
-         if (Hive->Storage[Storage].BlockList[i].Bin != (ULONG_PTR)Bin)
-         {
-            Bin = (PHBIN)Hive->Storage[Storage].BlockList[i].Bin;
-            Hive->Free((PHBIN)Hive->Storage[Storage].BlockList[i].Bin);
-         }
-         Hive->Storage[Storage].BlockList[i].Bin = (ULONG_PTR)NULL;
-         Hive->Storage[Storage].BlockList[i].Block = (ULONG_PTR)NULL;
-      }
-
-      if (Hive->Storage[Storage].Length)
-         Hive->Free(Hive->Storage[Storage].BlockList);
-   }
-}
-
-/**
- * @name HvpCreateHive
- *
- * Internal helper function to initalize hive descriptor structure for
- * newly created hive.
- *
- * @see HvInitialize
- */
-
-NTSTATUS CMAPI
-HvpCreateHive(
-   PHHIVE RegistryHive)
-{
-   PHBASE_BLOCK HiveHeader;
-   ULONG Index;
-
-   HiveHeader = RegistryHive->Allocate(sizeof(HBASE_BLOCK), FALSE);
-   if (HiveHeader == NULL)
-      return STATUS_NO_MEMORY;
-   RtlZeroMemory(HiveHeader, sizeof(HBASE_BLOCK));
-   HiveHeader->Signature = HV_SIGNATURE;
-   HiveHeader->Major = HV_MAJOR_VER;
-   HiveHeader->Minor = HV_MINOR_VER;
-   HiveHeader->Type = HV_TYPE_PRIMARY;
-   HiveHeader->Format = HV_FORMAT_MEMORY;
-   HiveHeader->Cluster = 1;
-   HiveHeader->RootCell = HCELL_NULL;
-   HiveHeader->Length = HV_BLOCK_SIZE;
-   HiveHeader->Sequence1 = 1;
-   HiveHeader->Sequence2 = 1;
-   /* FIXME: Fill in the file name */
-   HiveHeader->Checksum = HvpHiveHeaderChecksum(HiveHeader);
-
-   RegistryHive->HiveHeader = HiveHeader;
-   for (Index = 0; Index < 24; Index++)
-   {
-      RegistryHive->Storage[HvStable].FreeDisplay[Index] = HCELL_NULL;
-      RegistryHive->Storage[HvVolatile].FreeDisplay[Index] = HCELL_NULL;
-   }
-   RtlInitializeBitMap(&RegistryHive->DirtyVector, NULL, 0);
-
-   return STATUS_SUCCESS;
-}
-
-/**
- * @name HvpInitializeMemoryHive
- *
- * Internal helper function to initalize hive descriptor structure for
- * a hive stored in memory. The data of the hive are copied and it is
- * prepared for read/write access.
- *
- * @see HvInitialize
- */
-
-NTSTATUS CMAPI
-HvpInitializeMemoryHive(
-   PHHIVE Hive,
-   ULONG_PTR ChunkBase)
-{
-   SIZE_T BlockIndex;
-   PHBIN Bin, NewBin;
-   ULONG i;
-   ULONG BitmapSize;
-   PULONG BitmapBuffer;
-   SIZE_T ChunkSize;
-
-   //
-   // This hack is similar in magnitude to the US's National Debt
-   //
-   ChunkSize = ((PHBASE_BLOCK)ChunkBase)->Length;
-   ((PHBASE_BLOCK)ChunkBase)->Length = HV_BLOCK_SIZE;
-   DPRINT("ChunkSize: %lx\n", ChunkSize);
-
-   if (ChunkSize < sizeof(HBASE_BLOCK) ||
-       !HvpVerifyHiveHeader((PHBASE_BLOCK)ChunkBase))
-   {
-      DPRINT1("Registry is corrupt: ChunkSize %d < sizeof(HBASE_BLOCK) %d, "
-          "or HvpVerifyHiveHeader() failed\n", ChunkSize, sizeof(HBASE_BLOCK));
-      return STATUS_REGISTRY_CORRUPT;
-   }
-
-   Hive->HiveHeader = Hive->Allocate(sizeof(HBASE_BLOCK), FALSE);
-   if (Hive->HiveHeader == NULL)
-   {
-      return STATUS_NO_MEMORY;
-   }
-   RtlCopyMemory(Hive->HiveHeader, (PVOID)ChunkBase, sizeof(HBASE_BLOCK));
-
-   /*
-    * Build a block list from the in-memory chunk and copy the data as
-    * we go.
-    */
-   
-   Hive->Storage[HvStable].Length = (ULONG)(ChunkSize / HV_BLOCK_SIZE) - 1;
-   Hive->Storage[HvStable].BlockList =
-      Hive->Allocate(Hive->Storage[HvStable].Length *
-                     sizeof(HMAP_ENTRY), FALSE);
-   if (Hive->Storage[HvStable].BlockList == NULL)
-   {
-      DPRINT1("Allocating block list failed\n");
-      Hive->Free(Hive->HiveHeader);
-      return STATUS_NO_MEMORY;
-   }
-
-   for (BlockIndex = 0; BlockIndex < Hive->Storage[HvStable].Length; )
-   {
-      Bin = (PHBIN)((ULONG_PTR)ChunkBase + (BlockIndex + 1) * HV_BLOCK_SIZE);
-      if (Bin->Signature != HV_BIN_SIGNATURE ||
-          (Bin->Size % HV_BLOCK_SIZE) != 0)
-      {
-         Hive->Free(Hive->HiveHeader);
-         Hive->Free(Hive->Storage[HvStable].BlockList);
-         return STATUS_REGISTRY_CORRUPT;
-      }
-
-      NewBin = Hive->Allocate(Bin->Size, TRUE);
-      if (NewBin == NULL)
-      {
-         Hive->Free(Hive->HiveHeader);
-         Hive->Free(Hive->Storage[HvStable].BlockList);
-         return STATUS_NO_MEMORY;
-      }
-
-      Hive->Storage[HvStable].BlockList[BlockIndex].Bin = (ULONG_PTR)NewBin;
-      Hive->Storage[HvStable].BlockList[BlockIndex].Block = (ULONG_PTR)NewBin;
-
-      RtlCopyMemory(NewBin, Bin, Bin->Size);
-
-      if (Bin->Size > HV_BLOCK_SIZE)
-      {
-         for (i = 1; i < Bin->Size / HV_BLOCK_SIZE; i++)
-         {
-            Hive->Storage[HvStable].BlockList[BlockIndex + i].Bin = (ULONG_PTR)NewBin;
-            Hive->Storage[HvStable].BlockList[BlockIndex + i].Block =
-               ((ULONG_PTR)NewBin + (i * HV_BLOCK_SIZE));
-         }
-      }
-
-      BlockIndex += Bin->Size / HV_BLOCK_SIZE;
-   }
-
-   if (HvpCreateHiveFreeCellList(Hive))
-   {
-      HvpFreeHiveBins(Hive);
-      Hive->Free(Hive->HiveHeader);
-      return STATUS_NO_MEMORY;
-   }
-
-   BitmapSize = ROUND_UP(Hive->Storage[HvStable].Length,
-                         sizeof(ULONG) * 8) / 8;
-   BitmapBuffer = (PULONG)Hive->Allocate(BitmapSize, TRUE);
-   if (BitmapBuffer == NULL)
-   {
-      HvpFreeHiveBins(Hive);
-      Hive->Free(Hive->HiveHeader);
-      return STATUS_NO_MEMORY;
-   }
-
-   RtlInitializeBitMap(&Hive->DirtyVector, BitmapBuffer, BitmapSize * 8);
-   RtlClearAllBits(&Hive->DirtyVector);
-
-   return STATUS_SUCCESS;
-}
-
-/**
- * @name HvpInitializeMemoryInplaceHive
- *
- * Internal helper function to initalize hive descriptor structure for
- * a hive stored in memory. The in-memory data of the hive are directly
- * used and it is read-only accessible.
- *
- * @see HvInitialize
- */
-
-NTSTATUS CMAPI
-HvpInitializeMemoryInplaceHive(
-   PHHIVE Hive,
-   ULONG_PTR ChunkBase)
-{
-   if (!HvpVerifyHiveHeader((PHBASE_BLOCK)ChunkBase))
-   {
-      return STATUS_REGISTRY_CORRUPT;
-   }
-
-   Hive->HiveHeader = (PHBASE_BLOCK)ChunkBase;
-   Hive->ReadOnly = TRUE;
-   Hive->Flat = TRUE;
-
-   return STATUS_SUCCESS;
-}
-
-/**
- * @name HvInitialize
- *
- * Allocate a new hive descriptor structure and intialize it.
- *
- * @param RegistryHive
- *        Output variable to store pointer to the hive descriptor.
- * @param Operation
- *        - HV_OPERATION_CREATE_HIVE
- *          Create a new hive for read/write access.
- *        - HV_OPERATION_MEMORY
- *          Load and copy in-memory hive for read/write access. The
- *          pointer to data passed to this routine can be freed after
- *          the function is executed.
- *        - HV_OPERATION_MEMORY_INPLACE
- *          Load an in-memory hive for read-only access. The pointer
- *          to data passed to this routine MUSTN'T be freed until
- *          HvFree is called.
- * @param ChunkBase
- *        Pointer to hive data.
- * @param ChunkSize
- *        Size of passed hive data.
- *
- * @return
- *    STATUS_NO_MEMORY - A memory allocation failed.
- *    STATUS_REGISTRY_CORRUPT - Registry corruption was detected.
- *    STATUS_SUCCESS
- *        
- * @see HvFree
- */
-
-NTSTATUS CMAPI
-HvInitialize(
-   PHHIVE RegistryHive,
-   ULONG Operation,
-   ULONG HiveType,
-   ULONG HiveFlags,
-   ULONG_PTR HiveData OPTIONAL,
-   ULONG Cluster OPTIONAL,
-   PALLOCATE_ROUTINE Allocate,
-   PFREE_ROUTINE Free,
-   PFILE_READ_ROUTINE FileRead,
-   PFILE_WRITE_ROUTINE FileWrite,
-   PFILE_SET_SIZE_ROUTINE FileSetSize,
-   PFILE_FLUSH_ROUTINE FileFlush,
-   IN PUNICODE_STRING FileName)
-{
-   NTSTATUS Status;
-   PHHIVE Hive = RegistryHive;
-
-   /*
-    * Create a new hive structure that will hold all the maintenance data.
-    */
-
-   RtlZeroMemory(Hive, sizeof(HHIVE));
-
-   Hive->Allocate = Allocate;
-   Hive->Free = Free;
-   Hive->FileRead = FileRead;
-   Hive->FileWrite = FileWrite;
-   Hive->FileSetSize = FileSetSize;
-   Hive->FileFlush = FileFlush;
-
-   switch (Operation)
-   {
-      case HV_OPERATION_CREATE_HIVE:
-         Status = HvpCreateHive(Hive);
-         break;
-
-      case HV_OPERATION_MEMORY:
-         Status = HvpInitializeMemoryHive(Hive, HiveData);
-         break;
-
-      case HV_OPERATION_MEMORY_INPLACE:
-         Status = HvpInitializeMemoryInplaceHive(Hive, HiveData);
-         break;
-
-      default:
-         /* FIXME: A better return status value is needed */
-         Status = STATUS_NOT_IMPLEMENTED;
-         ASSERT(FALSE);
-   }
-
-   if (!NT_SUCCESS(Status))
-   {
-      Hive->Free(Hive);
-      return Status;
-   }
-
-   return Status;
-}
-
-/**
- * @name HvFree
- *
- * Free all stroage and handles associated with hive descriptor.
- */
-
-VOID CMAPI 
-HvFree(
-   PHHIVE RegistryHive)
-{
-   if (!RegistryHive->ReadOnly)
-   {
-      /* Release hive bitmap */
-      if (RegistryHive->DirtyVector.Buffer)
-      {
-         RegistryHive->Free(RegistryHive->DirtyVector.Buffer);
-      }
-
-      HvpFreeHiveBins(RegistryHive);
-   }
-
-   RegistryHive->Free(RegistryHive);
-}
-
-/* EOF */
+/*\r
+ * PROJECT:   registry manipulation library\r
+ * LICENSE:   GPL - See COPYING in the top level directory\r
+ * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>\r
+ *            Copyright 2001 - 2005 Eric Kohl\r
+ */\r
+\r
+#include "cmlib.h"\r
+#define NDEBUG\r
+#include <debug.h>\r
+\r
+/**\r
+ * @name HvpVerifyHiveHeader\r
+ *\r
+ * Internal function to verify that a hive header has valid format.\r
+ */\r
+\r
+BOOLEAN CMAPI\r
+HvpVerifyHiveHeader(\r
+   PHBASE_BLOCK HiveHeader)\r
+{\r
+   if (HiveHeader->Signature != HV_SIGNATURE ||\r
+       HiveHeader->Major != HV_MAJOR_VER ||\r
+       HiveHeader->Minor < HV_MINOR_VER ||\r
+       HiveHeader->Type != HV_TYPE_PRIMARY ||\r
+       HiveHeader->Format != HV_FORMAT_MEMORY ||\r
+       HiveHeader->Cluster != 1 ||\r
+       HiveHeader->Sequence1 != HiveHeader->Sequence2 ||\r
+       HvpHiveHeaderChecksum(HiveHeader) != HiveHeader->Checksum)\r
+   {\r
+      DPRINT1("Verify Hive Header failed: \n");\r
+      DPRINT1("    Signature: 0x%x and not 0x%x, Major: 0x%x and not 0x%x\n",\r
+          HiveHeader->Signature, HV_SIGNATURE, HiveHeader->Major, HV_MAJOR_VER);\r
+      DPRINT1("    Minor: 0x%x is not >= 0x%x, Type: 0x%x and not 0x%x\n",\r
+          HiveHeader->Minor, HV_MINOR_VER, HiveHeader->Type, HV_TYPE_PRIMARY);\r
+      DPRINT1("    Format: 0x%x and not 0x%x, Cluster: 0x%x and not 1\n",\r
+          HiveHeader->Format, HV_FORMAT_MEMORY, HiveHeader->Cluster);\r
+      DPRINT1("    Sequence: 0x%x and not 0x%x, Checksum: 0x%x and not 0x%x\n",\r
+          HiveHeader->Sequence1, HiveHeader->Sequence2,\r
+          HvpHiveHeaderChecksum(HiveHeader), HiveHeader->Checksum);\r
+      return FALSE;\r
+   }\r
+\r
+   return TRUE;\r
+}\r
+\r
+/**\r
+ * @name HvpFreeHiveBins\r
+ *\r
+ * Internal function to free all bin storage associated with hive\r
+ * descriptor.\r
+ */\r
+\r
+VOID CMAPI\r
+HvpFreeHiveBins(\r
+   PHHIVE Hive)\r
+{              \r
+   ULONG i;\r
+   PHBIN Bin;\r
+   ULONG Storage;\r
+\r
+   for (Storage = HvStable; Storage < HvMaxStorageType; Storage++)\r
+   {\r
+      Bin = NULL;\r
+      for (i = 0; i < Hive->Storage[Storage].Length; i++)\r
+      {\r
+         if (Hive->Storage[Storage].BlockList[i].Bin == (ULONG_PTR)NULL)\r
+            continue;\r
+         if (Hive->Storage[Storage].BlockList[i].Bin != (ULONG_PTR)Bin)\r
+         {\r
+            Bin = (PHBIN)Hive->Storage[Storage].BlockList[i].Bin;\r
+            Hive->Free((PHBIN)Hive->Storage[Storage].BlockList[i].Bin);\r
+         }\r
+         Hive->Storage[Storage].BlockList[i].Bin = (ULONG_PTR)NULL;\r
+         Hive->Storage[Storage].BlockList[i].Block = (ULONG_PTR)NULL;\r
+      }\r
+\r
+      if (Hive->Storage[Storage].Length)\r
+         Hive->Free(Hive->Storage[Storage].BlockList);\r
+   }\r
+}\r
+\r
+/**\r
+ * @name HvpCreateHive\r
+ *\r
+ * Internal helper function to initalize hive descriptor structure for\r
+ * newly created hive.\r
+ *\r
+ * @see HvInitialize\r
+ */\r
+\r
+NTSTATUS CMAPI\r
+HvpCreateHive(\r
+   PHHIVE RegistryHive)\r
+{\r
+   PHBASE_BLOCK HiveHeader;\r
+   ULONG Index;\r
+\r
+   HiveHeader = RegistryHive->Allocate(sizeof(HBASE_BLOCK), FALSE);\r
+   if (HiveHeader == NULL)\r
+      return STATUS_NO_MEMORY;\r
+   RtlZeroMemory(HiveHeader, sizeof(HBASE_BLOCK));\r
+   HiveHeader->Signature = HV_SIGNATURE;\r
+   HiveHeader->Major = HV_MAJOR_VER;\r
+   HiveHeader->Minor = HV_MINOR_VER;\r
+   HiveHeader->Type = HV_TYPE_PRIMARY;\r
+   HiveHeader->Format = HV_FORMAT_MEMORY;\r
+   HiveHeader->Cluster = 1;\r
+   HiveHeader->RootCell = HCELL_NULL;\r
+   HiveHeader->Length = HV_BLOCK_SIZE;\r
+   HiveHeader->Sequence1 = 1;\r
+   HiveHeader->Sequence2 = 1;\r
+   /* FIXME: Fill in the file name */\r
+   HiveHeader->Checksum = HvpHiveHeaderChecksum(HiveHeader);\r
+\r
+   RegistryHive->HiveHeader = HiveHeader;\r
+   for (Index = 0; Index < 24; Index++)\r
+   {\r
+      RegistryHive->Storage[HvStable].FreeDisplay[Index] = HCELL_NULL;\r
+      RegistryHive->Storage[HvVolatile].FreeDisplay[Index] = HCELL_NULL;\r
+   }\r
+   RtlInitializeBitMap(&RegistryHive->DirtyVector, NULL, 0);\r
+\r
+   return STATUS_SUCCESS;\r
+}\r
+\r
+/**\r
+ * @name HvpInitializeMemoryHive\r
+ *\r
+ * Internal helper function to initalize hive descriptor structure for\r
+ * a hive stored in memory. The data of the hive are copied and it is\r
+ * prepared for read/write access.\r
+ *\r
+ * @see HvInitialize\r
+ */\r
+\r
+NTSTATUS CMAPI\r
+HvpInitializeMemoryHive(\r
+   PHHIVE Hive,\r
+   ULONG_PTR ChunkBase)\r
+{\r
+   SIZE_T BlockIndex;\r
+   PHBIN Bin, NewBin;\r
+   ULONG i;\r
+   ULONG BitmapSize;\r
+   PULONG BitmapBuffer;\r
+   SIZE_T ChunkSize;\r
+\r
+   //\r
+   // This hack is similar in magnitude to the US's National Debt\r
+   //\r
+   ChunkSize = ((PHBASE_BLOCK)ChunkBase)->Length;\r
+   ((PHBASE_BLOCK)ChunkBase)->Length = HV_BLOCK_SIZE;\r
+   DPRINT("ChunkSize: %lx\n", ChunkSize);\r
+\r
+   if (ChunkSize < sizeof(HBASE_BLOCK) ||\r
+       !HvpVerifyHiveHeader((PHBASE_BLOCK)ChunkBase))\r
+   {\r
+      DPRINT1("Registry is corrupt: ChunkSize %d < sizeof(HBASE_BLOCK) %d, "\r
+          "or HvpVerifyHiveHeader() failed\n", ChunkSize, sizeof(HBASE_BLOCK));\r
+      return STATUS_REGISTRY_CORRUPT;\r
+   }\r
+\r
+   Hive->HiveHeader = Hive->Allocate(sizeof(HBASE_BLOCK), FALSE);\r
+   if (Hive->HiveHeader == NULL)\r
+   {\r
+      return STATUS_NO_MEMORY;\r
+   }\r
+   RtlCopyMemory(Hive->HiveHeader, (PVOID)ChunkBase, sizeof(HBASE_BLOCK));\r
+\r
+   /*\r
+    * Build a block list from the in-memory chunk and copy the data as\r
+    * we go.\r
+    */\r
+   \r
+   Hive->Storage[HvStable].Length = (ULONG)(ChunkSize / HV_BLOCK_SIZE) - 1;\r
+   Hive->Storage[HvStable].BlockList =\r
+      Hive->Allocate(Hive->Storage[HvStable].Length *\r
+                     sizeof(HMAP_ENTRY), FALSE);\r
+   if (Hive->Storage[HvStable].BlockList == NULL)\r
+   {\r
+      DPRINT1("Allocating block list failed\n");\r
+      Hive->Free(Hive->HiveHeader);\r
+      return STATUS_NO_MEMORY;\r
+   }\r
+\r
+   for (BlockIndex = 0; BlockIndex < Hive->Storage[HvStable].Length; )\r
+   {\r
+      Bin = (PHBIN)((ULONG_PTR)ChunkBase + (BlockIndex + 1) * HV_BLOCK_SIZE);\r
+      if (Bin->Signature != HV_BIN_SIGNATURE ||\r
+          (Bin->Size % HV_BLOCK_SIZE) != 0)\r
+      {\r
+         Hive->Free(Hive->HiveHeader);\r
+         Hive->Free(Hive->Storage[HvStable].BlockList);\r
+         return STATUS_REGISTRY_CORRUPT;\r
+      }\r
+\r
+      NewBin = Hive->Allocate(Bin->Size, TRUE);\r
+      if (NewBin == NULL)\r
+      {\r
+         Hive->Free(Hive->HiveHeader);\r
+         Hive->Free(Hive->Storage[HvStable].BlockList);\r
+         return STATUS_NO_MEMORY;\r
+      }\r
+\r
+      Hive->Storage[HvStable].BlockList[BlockIndex].Bin = (ULONG_PTR)NewBin;\r
+      Hive->Storage[HvStable].BlockList[BlockIndex].Block = (ULONG_PTR)NewBin;\r
+\r
+      RtlCopyMemory(NewBin, Bin, Bin->Size);\r
+\r
+      if (Bin->Size > HV_BLOCK_SIZE)\r
+      {\r
+         for (i = 1; i < Bin->Size / HV_BLOCK_SIZE; i++)\r
+         {\r
+            Hive->Storage[HvStable].BlockList[BlockIndex + i].Bin = (ULONG_PTR)NewBin;\r
+            Hive->Storage[HvStable].BlockList[BlockIndex + i].Block =\r
+               ((ULONG_PTR)NewBin + (i * HV_BLOCK_SIZE));\r
+         }\r
+      }\r
+\r
+      BlockIndex += Bin->Size / HV_BLOCK_SIZE;\r
+   }\r
+\r
+   if (HvpCreateHiveFreeCellList(Hive))\r
+   {\r
+      HvpFreeHiveBins(Hive);\r
+      Hive->Free(Hive->HiveHeader);\r
+      return STATUS_NO_MEMORY;\r
+   }\r
+\r
+   BitmapSize = ROUND_UP(Hive->Storage[HvStable].Length,\r
+                         sizeof(ULONG) * 8) / 8;\r
+   BitmapBuffer = (PULONG)Hive->Allocate(BitmapSize, TRUE);\r
+   if (BitmapBuffer == NULL)\r
+   {\r
+      HvpFreeHiveBins(Hive);\r
+      Hive->Free(Hive->HiveHeader);\r
+      return STATUS_NO_MEMORY;\r
+   }\r
+\r
+   RtlInitializeBitMap(&Hive->DirtyVector, BitmapBuffer, BitmapSize * 8);\r
+   RtlClearAllBits(&Hive->DirtyVector);\r
+\r
+   return STATUS_SUCCESS;\r
+}\r
+\r
+/**\r
+ * @name HvpInitializeMemoryInplaceHive\r
+ *\r
+ * Internal helper function to initalize hive descriptor structure for\r
+ * a hive stored in memory. The in-memory data of the hive are directly\r
+ * used and it is read-only accessible.\r
+ *\r
+ * @see HvInitialize\r
+ */\r
+\r
+NTSTATUS CMAPI\r
+HvpInitializeMemoryInplaceHive(\r
+   PHHIVE Hive,\r
+   ULONG_PTR ChunkBase)\r
+{\r
+   if (!HvpVerifyHiveHeader((PHBASE_BLOCK)ChunkBase))\r
+   {\r
+      return STATUS_REGISTRY_CORRUPT;\r
+   }\r
+\r
+   Hive->HiveHeader = (PHBASE_BLOCK)ChunkBase;\r
+   Hive->ReadOnly = TRUE;\r
+   Hive->Flat = TRUE;\r
+\r
+   return STATUS_SUCCESS;\r
+}\r
+\r
+/**\r
+ * @name HvInitialize\r
+ *\r
+ * Allocate a new hive descriptor structure and intialize it.\r
+ *\r
+ * @param RegistryHive\r
+ *        Output variable to store pointer to the hive descriptor.\r
+ * @param Operation\r
+ *        - HV_OPERATION_CREATE_HIVE\r
+ *          Create a new hive for read/write access.\r
+ *        - HV_OPERATION_MEMORY\r
+ *          Load and copy in-memory hive for read/write access. The\r
+ *          pointer to data passed to this routine can be freed after\r
+ *          the function is executed.\r
+ *        - HV_OPERATION_MEMORY_INPLACE\r
+ *          Load an in-memory hive for read-only access. The pointer\r
+ *          to data passed to this routine MUSTN'T be freed until\r
+ *          HvFree is called.\r
+ * @param ChunkBase\r
+ *        Pointer to hive data.\r
+ * @param ChunkSize\r
+ *        Size of passed hive data.\r
+ *\r
+ * @return\r
+ *    STATUS_NO_MEMORY - A memory allocation failed.\r
+ *    STATUS_REGISTRY_CORRUPT - Registry corruption was detected.\r
+ *    STATUS_SUCCESS\r
+ *        \r
+ * @see HvFree\r
+ */\r
+\r
+NTSTATUS CMAPI\r
+HvInitialize(\r
+   PHHIVE RegistryHive,\r
+   ULONG Operation,\r
+   ULONG HiveType,\r
+   ULONG HiveFlags,\r
+   ULONG_PTR HiveData OPTIONAL,\r
+   ULONG Cluster OPTIONAL,\r
+   PALLOCATE_ROUTINE Allocate,\r
+   PFREE_ROUTINE Free,\r
+   PFILE_READ_ROUTINE FileRead,\r
+   PFILE_WRITE_ROUTINE FileWrite,\r
+   PFILE_SET_SIZE_ROUTINE FileSetSize,\r
+   PFILE_FLUSH_ROUTINE FileFlush,\r
+   IN PUNICODE_STRING FileName)\r
+{\r
+   NTSTATUS Status;\r
+   PHHIVE Hive = RegistryHive;\r
+\r
+   /*\r
+    * Create a new hive structure that will hold all the maintenance data.\r
+    */\r
+\r
+   RtlZeroMemory(Hive, sizeof(HHIVE));\r
+\r
+   Hive->Allocate = Allocate;\r
+   Hive->Free = Free;\r
+   Hive->FileRead = FileRead;\r
+   Hive->FileWrite = FileWrite;\r
+   Hive->FileSetSize = FileSetSize;\r
+   Hive->FileFlush = FileFlush;\r
+   Hive->StorageTypeCount = 2;\r
+\r
+   switch (Operation)\r
+   {\r
+      case HV_OPERATION_CREATE_HIVE:\r
+         Status = HvpCreateHive(Hive);\r
+         break;\r
+\r
+      case HV_OPERATION_MEMORY:\r
+         Status = HvpInitializeMemoryHive(Hive, HiveData);\r
+         break;\r
+\r
+      case HV_OPERATION_MEMORY_INPLACE:\r
+         Status = HvpInitializeMemoryInplaceHive(Hive, HiveData);\r
+         break;\r
+\r
+      default:\r
+         /* FIXME: A better return status value is needed */\r
+         Status = STATUS_NOT_IMPLEMENTED;\r
+         ASSERT(FALSE);\r
+   }\r
+\r
+   if (!NT_SUCCESS(Status))\r
+   {\r
+      Hive->Free(Hive);\r
+      return Status;\r
+   }\r
+\r
+   return Status;\r
+}\r
+\r
+/**\r
+ * @name HvFree\r
+ *\r
+ * Free all stroage and handles associated with hive descriptor.\r
+ */\r
+\r
+VOID CMAPI \r
+HvFree(\r
+   PHHIVE RegistryHive)\r
+{\r
+   if (!RegistryHive->ReadOnly)\r
+   {\r
+      /* Release hive bitmap */\r
+      if (RegistryHive->DirtyVector.Buffer)\r
+      {\r
+         RegistryHive->Free(RegistryHive->DirtyVector.Buffer);\r
+      }\r
+\r
+      HvpFreeHiveBins(RegistryHive);\r
+   }\r
+\r
+   RegistryHive->Free(RegistryHive);\r
+}\r
+\r
+/* EOF */\r
index 62fcfe7..e1d1c11 100644 (file)
-/*
- * PROJECT:   registry manipulation library
- * LICENSE:   GPL - See COPYING in the top level directory
- * COPYRIGHT: Copyright 2005 Filip Navara <navaraf@reactos.org>
- *            Copyright 2001 - 2005 Eric Kohl
- */
-
-#include "cmlib.h"
-#define NDEBUG
-#include <debug.h>
-
-static BOOLEAN CMAPI
-HvpWriteLog(
-   PHHIVE RegistryHive)
-{
-   ULONGLONG FileOffset;
-   SIZE_T BufferSize;
-   SIZE_T BitmapSize;
-   PUCHAR Buffer;
-   PUCHAR Ptr;
-   ULONG BlockIndex;
-   ULONG LastIndex;
-   PVOID BlockPtr;
-   BOOLEAN Success;
-   
-   ASSERT(RegistryHive->ReadOnly == FALSE);
-   
-   DPRINT("HvpWriteLog called\n");
-
-   if (RegistryHive->HiveHeader->Sequence1 !=
-       RegistryHive->HiveHeader->Sequence2)
-   {
-      return FALSE;
-   }
-
-   BitmapSize = RegistryHive->DirtyVector.SizeOfBitMap;
-   BufferSize = HV_LOG_HEADER_SIZE + sizeof(ULONG) + BitmapSize;
-   BufferSize = ROUND_UP(BufferSize, HV_BLOCK_SIZE);
-
-   DPRINT("Bitmap size %lu  buffer size: %lu\n", BitmapSize, BufferSize);
-
-   Buffer = RegistryHive->Allocate(BufferSize, TRUE);
-   if (Buffer == NULL)
-   {
-      return FALSE;
-   }
-
-   /* Update first update counter and checksum */
-   RegistryHive->HiveHeader->Type = HV_TYPE_LOG;
-   RegistryHive->HiveHeader->Sequence1++;
-   RegistryHive->HiveHeader->Checksum =
-      HvpHiveHeaderChecksum(RegistryHive->HiveHeader);
-
-   /* Copy hive header */
-   RtlCopyMemory(Buffer, RegistryHive->HiveHeader, HV_LOG_HEADER_SIZE);
-   Ptr = Buffer + HV_LOG_HEADER_SIZE;
-   RtlCopyMemory(Ptr, "DIRT", 4);
-   Ptr += 4;
-   RtlCopyMemory(Ptr, RegistryHive->DirtyVector.Buffer, BitmapSize);
-
-   /* Write hive block and block bitmap */
-   Success = RegistryHive->FileWrite(RegistryHive, HV_TYPE_LOG,
-                                     0, Buffer, BufferSize);
-   if (!Success)
-   {
-      return FALSE;
-   }
-
-   RegistryHive->Free(Buffer);
-
-   /* Write dirty blocks */
-   FileOffset = BufferSize;
-   BlockIndex = 0;
-   while (BlockIndex < RegistryHive->Storage[HvStable].Length)
-   {
-      LastIndex = BlockIndex;
-      BlockIndex = RtlFindSetBits(&RegistryHive->DirtyVector, 1, BlockIndex);
-      if (BlockIndex == ~0 || BlockIndex < LastIndex)
-      {
-         break;
-      }
-
-      BlockPtr = (PVOID)RegistryHive->Storage[HvStable].BlockList[BlockIndex].Block;
-
-      /* Write hive block */
-      Success = RegistryHive->FileWrite(RegistryHive, HV_TYPE_LOG,
-                                        FileOffset, BlockPtr,
-                                        HV_BLOCK_SIZE);
-      if (!Success)
-      {
-         return FALSE;
-      }
-
-      BlockIndex++;
-      FileOffset += HV_BLOCK_SIZE;
-    }
-
-   Success = RegistryHive->FileSetSize(RegistryHive, HV_TYPE_LOG, FileOffset);
-   if (!Success)
-   {
-      DPRINT("FileSetSize failed\n");
-      return FALSE;
-    }
-
-   /* Flush the log file */
-   Success = RegistryHive->FileFlush(RegistryHive, HV_TYPE_LOG);
-   if (!Success)
-   {
-      DPRINT("FileFlush failed\n");
-   }
-
-   /* Update first and second update counter and checksum. */
-   RegistryHive->HiveHeader->Sequence2++;
-   RegistryHive->HiveHeader->Checksum =
-      HvpHiveHeaderChecksum(RegistryHive->HiveHeader);
-
-   /* Write hive header again with updated sequence counter. */
-   Success = RegistryHive->FileWrite(RegistryHive, HV_TYPE_LOG,
-                                     0, RegistryHive->HiveHeader,
-                         &nbs