2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/rtl/nls.c
5 * PURPOSE: Bitmap functions
7 * PROGRAMMERS: Eric Kohl
12 #include <internal/debug.h>
14 #if defined (ALLOC_PRAGMA)
15 #pragma alloc_text(INIT, RtlpInitNls)
16 #pragma alloc_text(INIT, RtlpImportAnsiCodePage)
17 #pragma alloc_text(INIT, RtlpImportOemCodePage)
18 #pragma alloc_text(INIT, RtlpImportUnicodeCasemap)
19 #pragma alloc_text(INIT, RtlpCreateInitialNlsTables)
20 #pragma alloc_text(INIT, RtlpCreateNlsSection)
24 /* GLOBALS *******************************************************************/
27 static PUSHORT NlsAnsiCodePageTable
= NULL
;
28 static ULONG NlsAnsiCodePageTableSize
= 0;
30 static PUSHORT NlsOemCodePageTable
= NULL
;
31 static ULONG NlsOemCodePageTableSize
= 0;
33 static PUSHORT NlsUnicodeCasemapTable
= NULL
;
34 static ULONG NlsUnicodeCasemapTableSize
= 0;
36 PSECTION_OBJECT NlsSectionObject
= NULL
;
37 static PVOID NlsSectionBase
= NULL
;
38 static ULONG NlsSectionViewSize
= 0;
40 ULONG NlsAnsiTableOffset
= 0;
41 ULONG NlsOemTableOffset
= 0;
42 ULONG NlsUnicodeTableOffset
= 0;
45 /* FUNCTIONS *****************************************************************/
52 ULONG_PTR BaseAddress
;
55 BaseAddress
= CachedModules
[AnsiCodepage
]->ModStart
;
56 RtlpImportAnsiCodePage((PUSHORT
)BaseAddress
,
57 CachedModules
[AnsiCodepage
]->ModEnd
- BaseAddress
);
59 BaseAddress
= CachedModules
[OemCodepage
]->ModStart
;
60 RtlpImportOemCodePage((PUSHORT
)BaseAddress
,
61 CachedModules
[OemCodepage
]->ModEnd
- BaseAddress
);
63 BaseAddress
= CachedModules
[UnicodeCasemap
]->ModStart
;
64 RtlpImportUnicodeCasemap((PUSHORT
)BaseAddress
,
65 CachedModules
[UnicodeCasemap
]->ModEnd
- BaseAddress
);
67 /* Create initial NLS tables */
68 RtlpCreateInitialNlsTables();
70 /* Create the NLS section */
71 RtlpCreateNlsSection();
77 RtlpImportAnsiCodePage(PUSHORT TableBase
,
80 NlsAnsiCodePageTable
= TableBase
;
81 NlsAnsiCodePageTableSize
= Size
;
88 RtlpImportOemCodePage(PUSHORT TableBase
,
91 NlsOemCodePageTable
= TableBase
;
92 NlsOemCodePageTableSize
= Size
;
99 RtlpImportUnicodeCasemap(PUSHORT TableBase
,
102 NlsUnicodeCasemapTable
= TableBase
;
103 NlsUnicodeCasemapTableSize
= Size
;
110 RtlpCreateInitialNlsTables(VOID
)
112 NLSTABLEINFO NlsTable
;
114 if (NlsAnsiCodePageTable
== NULL
|| NlsAnsiCodePageTableSize
== 0 ||
115 NlsOemCodePageTable
== NULL
|| NlsOemCodePageTableSize
== 0 ||
116 NlsUnicodeCasemapTable
== NULL
|| NlsUnicodeCasemapTableSize
== 0)
118 KEBUGCHECKEX (0x32, STATUS_UNSUCCESSFUL
, 1, 0, 0);
121 RtlInitNlsTables (NlsAnsiCodePageTable
,
123 NlsUnicodeCasemapTable
,
126 RtlResetRtlTranslations (&NlsTable
);
132 RtlpCreateNlsSection(VOID
)
134 NLSTABLEINFO NlsTable
;
135 LARGE_INTEGER SectionSize
;
138 DPRINT("RtlpCreateNlsSection() called\n");
140 NlsSectionViewSize
= ROUND_UP(NlsAnsiCodePageTableSize
, PAGE_SIZE
) +
141 ROUND_UP(NlsOemCodePageTableSize
, PAGE_SIZE
) +
142 ROUND_UP(NlsUnicodeCasemapTableSize
, PAGE_SIZE
);
144 DPRINT("NlsSectionViewSize %lx\n", NlsSectionViewSize
);
146 SectionSize
.QuadPart
= (LONGLONG
)NlsSectionViewSize
;
147 Status
= MmCreateSection(&NlsSectionObject
,
155 if (!NT_SUCCESS(Status
))
157 DPRINT1("MmCreateSection() failed\n");
158 KEBUGCHECKEX(0x32, Status
, 1, 1, 0);
160 Status
= ObInsertObject(NlsSectionObject
,
166 if (!NT_SUCCESS(Status
))
168 ObDereferenceObject(NlsSectionObject
);
170 Status
= MmMapViewInSystemSpace(NlsSectionObject
,
172 &NlsSectionViewSize
);
173 if (!NT_SUCCESS(Status
))
175 DPRINT1("MmMapViewInSystemSpace() failed\n");
176 KEBUGCHECKEX(0x32, Status
, 1, 3, 0);
179 DPRINT("NlsSection: Base %p Size %lx\n",
183 NlsAnsiTableOffset
= 0;
184 RtlCopyMemory((PVOID
)((ULONG
)NlsSectionBase
+ NlsAnsiTableOffset
),
185 NlsAnsiCodePageTable
,
186 NlsAnsiCodePageTableSize
);
188 NlsOemTableOffset
= NlsAnsiTableOffset
+ ROUND_UP(NlsAnsiCodePageTableSize
, PAGE_SIZE
);
189 RtlCopyMemory((PVOID
)((ULONG
)NlsSectionBase
+ NlsOemTableOffset
),
191 NlsOemCodePageTableSize
);
193 NlsUnicodeTableOffset
= NlsOemTableOffset
+ ROUND_UP(NlsOemCodePageTableSize
, PAGE_SIZE
);
194 RtlCopyMemory((PVOID
)((ULONG
)NlsSectionBase
+ NlsUnicodeTableOffset
),
195 NlsUnicodeCasemapTable
,
196 NlsUnicodeCasemapTableSize
);
198 RtlInitNlsTables ((PVOID
)((ULONG
)NlsSectionBase
+ NlsAnsiTableOffset
),
199 (PVOID
)((ULONG
)NlsSectionBase
+ NlsOemTableOffset
),
200 (PVOID
)((ULONG
)NlsSectionBase
+ NlsUnicodeTableOffset
),
203 RtlResetRtlTranslations (&NlsTable
);