diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c
index 07b4d779be9..9152bedf7ef 100644
--- a/reactos/ntoskrnl/ex/init.c
+++ b/reactos/ntoskrnl/ex/init.c
@@ -45,9 +45,104 @@ ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset;
ULONG ExpUnicodeCaseTableDataOffset;
NLSTABLEINFO ExpNlsTableInfo;
ULONG ExpNlsTableSize;
+PVOID ExpNlsSectionPointer;
/* FUNCTIONS ****************************************************************/
+VOID
+NTAPI
+ExpInitNls(VOID)
+{
+ LARGE_INTEGER SectionSize;
+ NTSTATUS Status;
+ HANDLE NlsSection;
+ PVOID SectionBase = NULL;
+ ULONG ViewSize = 0;
+ LARGE_INTEGER SectionOffset = {{0}};
+
+ /* Set the section size */
+ SectionSize.QuadPart = ExpNlsTableSize;
+
+ /* Create the NLS Section */
+ Status = ZwCreateSection(&NlsSection,
+ SECTION_ALL_ACCESS,
+ NULL,
+ &SectionSize,
+ PAGE_READWRITE,
+ SEC_COMMIT,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Failed */
+ KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 1, 0, 0);
+ }
+
+ /* Get a pointer to the section */
+ Status = ObReferenceObjectByHandle(NlsSection,
+ SECTION_ALL_ACCESS,
+ MmSectionObjectType,
+ KernelMode,
+ &ExpNlsSectionPointer,
+ NULL);
+ ZwClose(NlsSection);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Failed */
+ KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 2, 0, 0);
+ }
+
+ /* Map the NLS Section in system space */
+ Status = MmMapViewInSystemSpace(ExpNlsSectionPointer,
+ &SectionBase,
+ &ExpNlsTableSize);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Failed */
+ KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 3, 0, 0);
+ }
+
+ /* Copy the codepage data in its new location. */
+ RtlMoveMemory(SectionBase, ExpNlsTableBase, ExpNlsTableSize);
+
+ /* Free the previously allocated buffer and set the new location */
+ ExFreePool(ExpNlsTableBase);
+ ExpNlsTableBase = SectionBase;
+
+ /* Initialize the NLS Tables */
+ RtlInitNlsTables((PVOID)((ULONG_PTR)ExpNlsTableBase +
+ ExpAnsiCodePageDataOffset),
+ (PVOID)((ULONG_PTR)ExpNlsTableBase +
+ ExpOemCodePageDataOffset),
+ (PVOID)((ULONG_PTR)ExpNlsTableBase +
+ ExpUnicodeCaseTableDataOffset),
+ &ExpNlsTableInfo);
+ RtlResetRtlTranslations(&ExpNlsTableInfo);
+
+ /* Reset the base to 0 */
+ SectionBase = NULL;
+
+ /* Map the section in the system process */
+ Status = MmMapViewOfSection(ExpNlsSectionPointer,
+ PsGetCurrentProcess(),
+ &SectionBase,
+ 0L,
+ 0L,
+ &SectionOffset,
+ &ViewSize,
+ ViewShare,
+ 0L,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Failed */
+ KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 5, 0, 0);
+ }
+
+ /* Copy the table into the system process and set this as the base */
+ RtlMoveMemory(SectionBase, ExpNlsTableBase, ExpNlsTableSize);
+ ExpNlsTableBase = SectionBase;
+}
+
static
VOID
INIT_FUNCTION
@@ -781,8 +876,8 @@ ExPhase2Init(PVOID Context)
/* Call KD Providers at Phase 2 */
KdInitSystem(2, KeLoaderBlock);
- /* Import and create NLS Data and Sections */
- RtlpInitNls();
+ /* Create NLS section */
+ ExpInitNls();
/* Import and Load Registry Hives */
CmInitHives(ExpInTextModeSetup);
diff --git a/reactos/ntoskrnl/include/internal/ex.h b/reactos/ntoskrnl/include/internal/ex.h
index caa6aab5659..a68f552fbb9 100644
--- a/reactos/ntoskrnl/include/internal/ex.h
+++ b/reactos/ntoskrnl/include/internal/ex.h
@@ -14,6 +14,9 @@ extern ULONG NtMinorVersion;
extern FAST_MUTEX ExpEnvironmentLock;
extern ERESOURCE ExpFirmwareTableResource;
extern LIST_ENTRY ExpFirmwareTableProviderListHead;
+ULONG ExpAnsiCodePageDataOffset, ExpOemCodePageDataOffset;
+ULONG ExpUnicodeCaseTableDataOffset;
+PVOID ExpNlsSectionPointer;
#define MAX_FAST_REFS 7
diff --git a/reactos/ntoskrnl/include/internal/rtl.h b/reactos/ntoskrnl/include/internal/rtl.h
index 7aa46a163db..45c506a58e9 100644
--- a/reactos/ntoskrnl/include/internal/rtl.h
+++ b/reactos/ntoskrnl/include/internal/rtl.h
@@ -1,48 +1,6 @@
#ifndef __NTOSKRNL_INCLUDE_INTERNAL_NLS_H
#define __NTOSKRNL_INCLUDE_INTERNAL_NLS_H
-extern PVOID NlsSectionObject;
-
-extern ULONG NlsAnsiTableOffset;
-extern ULONG NlsOemTableOffset;
-extern ULONG NlsUnicodeTableOffset;
-
-extern PUSHORT NlsUnicodeUpcaseTable;
-extern PUSHORT NlsUnicodeLowercaseTable;
-
-VOID
-NTAPI
-RtlpInitNls(VOID);
-
-VOID
-NTAPI
-RtlpImportAnsiCodePage(
- PUSHORT TableBase,
- ULONG Size
-);
-
-VOID
-NTAPI
-RtlpImportOemCodePage(
- PUSHORT TableBase,
- ULONG Size
-);
-
-VOID
-NTAPI
-RtlpImportUnicodeCasemap(
- PUSHORT TableBase,
- ULONG Size
-);
-
-VOID
-NTAPI
-RtlpCreateInitialNlsTables(VOID);
-
-VOID
-NTAPI
-RtlpCreateNlsSection(VOID);
-
NTSTATUS
NTAPI
RtlQueryAtomListInAtomTable(
diff --git a/reactos/ntoskrnl/ke/i386/kiinit.c b/reactos/ntoskrnl/ke/i386/kiinit.c
index 74d21b6500d..e9a831bad12 100644
--- a/reactos/ntoskrnl/ke/i386/kiinit.c
+++ b/reactos/ntoskrnl/ke/i386/kiinit.c
@@ -407,6 +407,25 @@ KiInitializeKernel(IN PKPROCESS InitProcess,
DPRINT1("SMP Boot support not yet present\n");
}
+ /* Setup the Idle Thread */
+ KeInitializeThread(InitProcess,
+ InitThread,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ IdleStack);
+ InitThread->NextProcessor = Number;
+ InitThread->Priority = HIGH_PRIORITY;
+ InitThread->State = Running;
+ InitThread->Affinity = 1 << Number;
+ InitThread->WaitIrql = DISPATCH_LEVEL;
+ InitProcess->ActiveProcessors = 1 << Number;
+
+ /* HACK for MmUpdatePageDir */
+ ((PETHREAD)InitThread)->ThreadsProcess = (PEPROCESS)InitProcess;
+
/* Initialize Kernel Memory Address Space */
MmInit1(FirstKrnlPhysAddr,
LastKrnlPhysAddr,
@@ -435,25 +454,6 @@ KiInitializeKernel(IN PKPROCESS InitProcess,
SharedUserData->ProcessorFeatures[PF_RDTSC_INSTRUCTION_AVAILABLE] =
(KeFeatureBits & KF_RDTSC);
- /* Setup the Idle Thread */
- KeInitializeThread(InitProcess,
- InitThread,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- IdleStack);
- InitThread->NextProcessor = Number;
- InitThread->Priority = HIGH_PRIORITY;
- InitThread->State = Running;
- InitThread->Affinity = 1 << Number;
- InitThread->WaitIrql = DISPATCH_LEVEL;
- InitProcess->ActiveProcessors = 1 << Number;
-
- /* HACK for MmUpdatePageDir */
- ((PETHREAD)InitThread)->ThreadsProcess = (PEPROCESS)InitProcess;
-
/* Set up the thread-related fields in the PRCB */
Prcb->CurrentThread = InitThread;
Prcb->NextThread = NULL;
diff --git a/reactos/ntoskrnl/mm/process.c b/reactos/ntoskrnl/mm/process.c
index 5be30d7e250..9d5d783e307 100644
--- a/reactos/ntoskrnl/mm/process.c
+++ b/reactos/ntoskrnl/mm/process.c
@@ -291,7 +291,7 @@ MmCreatePeb(PEPROCESS Process)
/* Map NLS Tables */
DPRINT("Mapping NLS\n");
- Status = MmMapViewOfSection(NlsSectionObject,
+ Status = MmMapViewOfSection(ExpNlsSectionPointer,
(PEPROCESS)Process,
&TableBase,
0,
@@ -322,9 +322,9 @@ MmCreatePeb(PEPROCESS Process)
Peb->Mutant = NULL;
/* NLS */
- Peb->AnsiCodePageData = (char*)TableBase + NlsAnsiTableOffset;
- Peb->OemCodePageData = (char*)TableBase + NlsOemTableOffset;
- Peb->UnicodeCaseTableData = (char*)TableBase + NlsUnicodeTableOffset;
+ Peb->AnsiCodePageData = (PCHAR)TableBase + ExpAnsiCodePageDataOffset;
+ Peb->OemCodePageData = (PCHAR)TableBase + ExpOemCodePageDataOffset;
+ Peb->UnicodeCaseTableData = (PCHAR)TableBase + ExpUnicodeCaseTableDataOffset;
/* Default Version Data (could get changed below) */
Peb->OSMajorVersion = NtMajorVersion;
diff --git a/reactos/ntoskrnl/ntoskrnl.rbuild b/reactos/ntoskrnl/ntoskrnl.rbuild
index f8ca060552e..544277c8a3a 100644
--- a/reactos/ntoskrnl/ntoskrnl.rbuild
+++ b/reactos/ntoskrnl/ntoskrnl.rbuild
@@ -315,7 +315,6 @@
libsupp.c
misc.c
- nls.c
regio.c
strtok.c
diff --git a/reactos/ntoskrnl/rtl/libsupp.c b/reactos/ntoskrnl/rtl/libsupp.c
index 6caf3670670..fafe20bf6e8 100644
--- a/reactos/ntoskrnl/rtl/libsupp.c
+++ b/reactos/ntoskrnl/rtl/libsupp.c
@@ -198,9 +198,6 @@ RtlpCaptureStackLimits(IN ULONG_PTR Ebp,
/* FIXME: Super native implementation */
- /* FIXME: ROS HACK */
- if (!Thread) return FALSE;
-
/* Start with defaults */
*StackBegin = Thread->StackLimit;
*StackEnd = (ULONG_PTR)Thread->StackBase;
diff --git a/reactos/ntoskrnl/rtl/nls.c b/reactos/ntoskrnl/rtl/nls.c
deleted file mode 100644
index 2f984c256bb..00000000000
--- a/reactos/ntoskrnl/rtl/nls.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS kernel
- * FILE: ntoskrnl/rtl/nls.c
- * PURPOSE: Bitmap functions
- *
- * PROGRAMMERS: Eric Kohl
- */
-
-#include
-#define NDEBUG
-#include
-
-#if defined (ALLOC_PRAGMA)
-#pragma alloc_text(INIT, RtlpInitNls)
-#pragma alloc_text(INIT, RtlpImportAnsiCodePage)
-#pragma alloc_text(INIT, RtlpImportOemCodePage)
-#pragma alloc_text(INIT, RtlpImportUnicodeCasemap)
-#pragma alloc_text(INIT, RtlpCreateInitialNlsTables)
-#pragma alloc_text(INIT, RtlpCreateNlsSection)
-#endif
-
-
-/* GLOBALS *******************************************************************/
-
-
-static PUSHORT NlsAnsiCodePageTable = NULL;
-static ULONG NlsAnsiCodePageTableSize = 0;
-
-static PUSHORT NlsOemCodePageTable = NULL;
-static ULONG NlsOemCodePageTableSize = 0;
-
-static PUSHORT NlsUnicodeCasemapTable = NULL;
-static ULONG NlsUnicodeCasemapTableSize = 0;
-
-PVOID NlsSectionObject = NULL;
-static PVOID NlsSectionBase = NULL;
-static ULONG NlsSectionViewSize = 0;
-
-ULONG NlsAnsiTableOffset = 0;
-ULONG NlsOemTableOffset = 0;
-ULONG NlsUnicodeTableOffset = 0;
-
-
-/* FUNCTIONS *****************************************************************/
-
-VOID
-INIT_FUNCTION
-STDCALL
-RtlpInitNls(VOID)
-{
- ULONG_PTR BaseAddress;
-
- /* Import NLS Data */
- BaseAddress = CachedModules[AnsiCodepage]->ModStart;
- RtlpImportAnsiCodePage((PUSHORT)BaseAddress,
- CachedModules[AnsiCodepage]->ModEnd - BaseAddress);
-
- BaseAddress = CachedModules[OemCodepage]->ModStart;
- RtlpImportOemCodePage((PUSHORT)BaseAddress,
- CachedModules[OemCodepage]->ModEnd - BaseAddress);
-
- BaseAddress = CachedModules[UnicodeCasemap]->ModStart;
- RtlpImportUnicodeCasemap((PUSHORT)BaseAddress,
- CachedModules[UnicodeCasemap]->ModEnd - BaseAddress);
-
- /* Create the NLS section */
- RtlpCreateNlsSection();
-}
-
-VOID
-INIT_FUNCTION
-NTAPI
-RtlpImportAnsiCodePage(PUSHORT TableBase,
- ULONG Size)
-{
- NlsAnsiCodePageTable = TableBase;
- NlsAnsiCodePageTableSize = Size;
-}
-
-
-VOID
-INIT_FUNCTION
-NTAPI
-RtlpImportOemCodePage(PUSHORT TableBase,
- ULONG Size)
-{
- NlsOemCodePageTable = TableBase;
- NlsOemCodePageTableSize = Size;
-}
-
-
-VOID
-NTAPI
-INIT_FUNCTION
-RtlpImportUnicodeCasemap(PUSHORT TableBase,
- ULONG Size)
-{
- NlsUnicodeCasemapTable = TableBase;
- NlsUnicodeCasemapTableSize = Size;
-}
-
-VOID
-NTAPI
-INIT_FUNCTION
-RtlpCreateNlsSection(VOID)
-{
- NLSTABLEINFO NlsTable;
- LARGE_INTEGER SectionSize;
- NTSTATUS Status;
-
- DPRINT("RtlpCreateNlsSection() called\n");
-
- NlsSectionViewSize = ROUND_UP(NlsAnsiCodePageTableSize, PAGE_SIZE) +
- ROUND_UP(NlsOemCodePageTableSize, PAGE_SIZE) +
- ROUND_UP(NlsUnicodeCasemapTableSize, PAGE_SIZE);
-
- DPRINT("NlsSectionViewSize %lx\n", NlsSectionViewSize);
-
- SectionSize.QuadPart = (LONGLONG)NlsSectionViewSize;
- Status = MmCreateSection(&NlsSectionObject,
- SECTION_ALL_ACCESS,
- NULL,
- &SectionSize,
- PAGE_READWRITE,
- SEC_COMMIT,
- NULL,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("MmCreateSection() failed\n");
- KEBUGCHECKEX(0x32, Status, 1, 1, 0);
- }
- Status = ObInsertObject(NlsSectionObject,
- NULL,
- SECTION_ALL_ACCESS,
- 0,
- NULL,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- ObDereferenceObject(NlsSectionObject);
- }
- Status = MmMapViewInSystemSpace(NlsSectionObject,
- &NlsSectionBase,
- &NlsSectionViewSize);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("MmMapViewInSystemSpace() failed\n");
- KEBUGCHECKEX(0x32, Status, 1, 3, 0);
- }
-
- DPRINT("NlsSection: Base %p Size %lx\n",
- NlsSectionBase,
- NlsSectionViewSize);
-
- NlsAnsiTableOffset = 0;
- RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsAnsiTableOffset),
- NlsAnsiCodePageTable,
- NlsAnsiCodePageTableSize);
-
- NlsOemTableOffset = NlsAnsiTableOffset + ROUND_UP(NlsAnsiCodePageTableSize, PAGE_SIZE);
- RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsOemTableOffset),
- NlsOemCodePageTable,
- NlsOemCodePageTableSize);
-
- NlsUnicodeTableOffset = NlsOemTableOffset + ROUND_UP(NlsOemCodePageTableSize, PAGE_SIZE);
- RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsUnicodeTableOffset),
- NlsUnicodeCasemapTable,
- NlsUnicodeCasemapTableSize);
-
- RtlInitNlsTables ((PVOID)((ULONG)NlsSectionBase + NlsAnsiTableOffset),
- (PVOID)((ULONG)NlsSectionBase + NlsOemTableOffset),
- (PVOID)((ULONG)NlsSectionBase + NlsUnicodeTableOffset),
- &NlsTable);
-
- RtlResetRtlTranslations (&NlsTable);
-}