Alex Ionescu <ionucu@videotron.ca>
[reactos.git] / reactos / ntoskrnl / rtl / nls.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/rtl/nls.c
5 * PURPOSE: Bitmap functions
6 *
7 * PROGRAMMERS: Eric Kohl
8 */
9
10 #include <ntoskrnl.h>
11 #define NDEBUG
12 #include <internal/debug.h>
13
14
15 /* GLOBALS *******************************************************************/
16
17
18 static PUSHORT NlsAnsiCodePageTable = NULL;
19 static ULONG NlsAnsiCodePageTableSize = 0;
20
21 static PUSHORT NlsOemCodePageTable = NULL;
22 static ULONG NlsOemCodePageTableSize = 0;
23
24 static PUSHORT NlsUnicodeCasemapTable = NULL;
25 static ULONG NlsUnicodeCasemapTableSize = 0;
26
27 PSECTION_OBJECT NlsSectionObject = NULL;
28 static PVOID NlsSectionBase = NULL;
29 static ULONG NlsSectionViewSize = 0;
30
31 ULONG NlsAnsiTableOffset = 0;
32 ULONG NlsOemTableOffset = 0;
33 ULONG NlsUnicodeTableOffset = 0;
34
35
36 /* FUNCTIONS *****************************************************************/
37
38 VOID
39 INIT_FUNCTION
40 STDCALL
41 RtlpInitNls(VOID)
42 {
43 ULONG_PTR BaseAddress;
44
45 /* Import NLS Data */
46 BaseAddress = CachedModules[AnsiCodepage]->ModStart;
47 RtlpImportAnsiCodePage((PUSHORT)BaseAddress,
48 CachedModules[AnsiCodepage]->ModEnd - BaseAddress);
49
50 BaseAddress = CachedModules[OemCodepage]->ModStart;
51 RtlpImportOemCodePage((PUSHORT)BaseAddress,
52 CachedModules[OemCodepage]->ModEnd - BaseAddress);
53
54 BaseAddress = CachedModules[UnicodeCasemap]->ModStart;
55 RtlpImportUnicodeCasemap((PUSHORT)BaseAddress,
56 CachedModules[UnicodeCasemap]->ModEnd - BaseAddress);
57
58 /* Create initial NLS tables */
59 RtlpCreateInitialNlsTables();
60
61 /* Create the NLS section */
62 RtlpCreateNlsSection();
63 }
64
65 VOID INIT_FUNCTION
66 RtlpImportAnsiCodePage(PUSHORT TableBase,
67 ULONG Size)
68 {
69 NlsAnsiCodePageTable = TableBase;
70 NlsAnsiCodePageTableSize = Size;
71 }
72
73
74 VOID INIT_FUNCTION
75 RtlpImportOemCodePage(PUSHORT TableBase,
76 ULONG Size)
77 {
78 NlsOemCodePageTable = TableBase;
79 NlsOemCodePageTableSize = Size;
80 }
81
82
83 VOID INIT_FUNCTION
84 RtlpImportUnicodeCasemap(PUSHORT TableBase,
85 ULONG Size)
86 {
87 NlsUnicodeCasemapTable = TableBase;
88 NlsUnicodeCasemapTableSize = Size;
89 }
90
91
92 VOID INIT_FUNCTION
93 RtlpCreateInitialNlsTables(VOID)
94 {
95 NLSTABLEINFO NlsTable;
96
97 if (NlsAnsiCodePageTable == NULL || NlsAnsiCodePageTableSize == 0 ||
98 NlsOemCodePageTable == NULL || NlsOemCodePageTableSize == 0 ||
99 NlsUnicodeCasemapTable == NULL || NlsUnicodeCasemapTableSize == 0)
100 {
101 KEBUGCHECKEX (0x32, STATUS_UNSUCCESSFUL, 1, 0, 0);
102 }
103
104 RtlInitNlsTables (NlsAnsiCodePageTable,
105 NlsOemCodePageTable,
106 NlsUnicodeCasemapTable,
107 &NlsTable);
108
109 RtlResetRtlTranslations (&NlsTable);
110 }
111
112
113 VOID INIT_FUNCTION
114 RtlpCreateNlsSection(VOID)
115 {
116 NLSTABLEINFO NlsTable;
117 LARGE_INTEGER SectionSize;
118 NTSTATUS Status;
119
120 DPRINT("RtlpCreateNlsSection() called\n");
121
122 NlsSectionViewSize = ROUND_UP(NlsAnsiCodePageTableSize, PAGE_SIZE) +
123 ROUND_UP(NlsOemCodePageTableSize, PAGE_SIZE) +
124 ROUND_UP(NlsUnicodeCasemapTableSize, PAGE_SIZE);
125
126 DPRINT("NlsSectionViewSize %lx\n", NlsSectionViewSize);
127
128 SectionSize.QuadPart = (LONGLONG)NlsSectionViewSize;
129 Status = MmCreateSection(&NlsSectionObject,
130 SECTION_ALL_ACCESS,
131 NULL,
132 &SectionSize,
133 PAGE_READWRITE,
134 SEC_COMMIT,
135 NULL,
136 NULL);
137 if (!NT_SUCCESS(Status))
138 {
139 DPRINT1("MmCreateSection() failed\n");
140 KEBUGCHECKEX(0x32, Status, 1, 1, 0);
141 }
142
143 Status = MmMapViewInSystemSpace(NlsSectionObject,
144 &NlsSectionBase,
145 &NlsSectionViewSize);
146 if (!NT_SUCCESS(Status))
147 {
148 DPRINT1("MmMapViewInSystemSpace() failed\n");
149 KEBUGCHECKEX(0x32, Status, 1, 3, 0);
150 }
151
152 DPRINT("NlsSection: Base %p Size %lx\n",
153 NlsSectionBase,
154 NlsSectionViewSize);
155
156 NlsAnsiTableOffset = 0;
157 RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsAnsiTableOffset),
158 NlsAnsiCodePageTable,
159 NlsAnsiCodePageTableSize);
160
161 NlsOemTableOffset = NlsAnsiTableOffset + ROUND_UP(NlsAnsiCodePageTableSize, PAGE_SIZE);
162 RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsOemTableOffset),
163 NlsOemCodePageTable,
164 NlsOemCodePageTableSize);
165
166 NlsUnicodeTableOffset = NlsOemTableOffset + ROUND_UP(NlsOemCodePageTableSize, PAGE_SIZE);
167 RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsUnicodeTableOffset),
168 NlsUnicodeCasemapTable,
169 NlsUnicodeCasemapTableSize);
170
171 RtlInitNlsTables ((PVOID)((ULONG)NlsSectionBase + NlsAnsiTableOffset),
172 (PVOID)((ULONG)NlsSectionBase + NlsOemTableOffset),
173 (PVOID)((ULONG)NlsSectionBase + NlsUnicodeTableOffset),
174 &NlsTable);
175
176 RtlResetRtlTranslations (&NlsTable);
177 }