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