create rtl for stuff common to ntdll/ntoskrnl
[reactos.git] / reactos / ntoskrnl / rtl / nls.c
1 /* $Id: nls.c,v 1.23 2004/05/31 19:40:49 gdalsnes Exp $
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 <ddk/ntddk.h>
12
13 #include <internal/mm.h>
14 #include <internal/nls.h>
15
16 #define NDEBUG
17 #include <internal/debug.h>
18
19
20 /* GLOBALS *******************************************************************/
21
22
23 static PUSHORT NlsAnsiCodePageTable = NULL;
24 static ULONG NlsAnsiCodePageTableSize = 0;
25
26 static PUSHORT NlsOemCodePageTable = NULL;
27 static ULONG NlsOemCodePageTableSize = 0;
28
29 static PUSHORT NlsUnicodeCasemapTable = NULL;
30 static ULONG NlsUnicodeCasemapTableSize = 0;
31
32 PVOID NlsSectionObject = NULL;
33 static PVOID NlsSectionBase = NULL;
34 static ULONG NlsSectionViewSize = 0;
35
36 ULONG NlsAnsiTableOffset = 0;
37 ULONG NlsOemTableOffset = 0;
38 ULONG NlsUnicodeTableOffset = 0;
39
40
41 /* FUNCTIONS *****************************************************************/
42
43
44
45 VOID INIT_FUNCTION
46 RtlpImportAnsiCodePage(PUSHORT TableBase,
47 ULONG Size)
48 {
49 NlsAnsiCodePageTable = TableBase;
50 NlsAnsiCodePageTableSize = Size;
51 }
52
53
54 VOID INIT_FUNCTION
55 RtlpImportOemCodePage(PUSHORT TableBase,
56 ULONG Size)
57 {
58 NlsOemCodePageTable = TableBase;
59 NlsOemCodePageTableSize = Size;
60 }
61
62
63 VOID INIT_FUNCTION
64 RtlpImportUnicodeCasemap(PUSHORT TableBase,
65 ULONG Size)
66 {
67 NlsUnicodeCasemapTable = TableBase;
68 NlsUnicodeCasemapTableSize = Size;
69 }
70
71
72 VOID INIT_FUNCTION
73 RtlpCreateInitialNlsTables(VOID)
74 {
75 NLSTABLEINFO NlsTable;
76
77 if (NlsAnsiCodePageTable == NULL || NlsAnsiCodePageTableSize == 0 ||
78 NlsOemCodePageTable == NULL || NlsOemCodePageTableSize == 0 ||
79 NlsUnicodeCasemapTable == NULL || NlsUnicodeCasemapTableSize == 0)
80 {
81 KEBUGCHECKEX (0x32, STATUS_UNSUCCESSFUL, 1, 0, 0);
82 }
83
84 RtlInitNlsTables (NlsAnsiCodePageTable,
85 NlsOemCodePageTable,
86 NlsUnicodeCasemapTable,
87 &NlsTable);
88
89 RtlResetRtlTranslations (&NlsTable);
90 }
91
92
93 VOID INIT_FUNCTION
94 RtlpCreateNlsSection(VOID)
95 {
96 NLSTABLEINFO NlsTable;
97 LARGE_INTEGER SectionSize;
98 HANDLE SectionHandle;
99 NTSTATUS Status;
100
101 DPRINT("RtlpCreateNlsSection() called\n");
102
103 NlsSectionViewSize = ROUND_UP(NlsAnsiCodePageTableSize, PAGE_SIZE) +
104 ROUND_UP(NlsOemCodePageTableSize, PAGE_SIZE) +
105 ROUND_UP(NlsUnicodeCasemapTableSize, PAGE_SIZE);
106
107 DPRINT("NlsSectionViewSize %lx\n", NlsSectionViewSize);
108
109 SectionSize.QuadPart = (LONGLONG)NlsSectionViewSize;
110 Status = NtCreateSection(&SectionHandle,
111 SECTION_ALL_ACCESS,
112 NULL,
113 &SectionSize,
114 PAGE_READWRITE,
115 SEC_COMMIT,
116 NULL);
117 if (!NT_SUCCESS(Status))
118 {
119 DPRINT1("NtCreateSection() failed\n");
120 KEBUGCHECKEX(0x32, Status, 1, 1, 0);
121 }
122
123 Status = ObReferenceObjectByHandle(SectionHandle,
124 SECTION_ALL_ACCESS,
125 MmSectionObjectType,
126 KernelMode,
127 &NlsSectionObject,
128 NULL);
129 NtClose(SectionHandle);
130 if (!NT_SUCCESS(Status))
131 {
132 DPRINT1("ObReferenceObjectByHandle() failed\n");
133 KEBUGCHECKEX(0x32, Status, 1, 2, 0);
134 }
135
136 Status = MmMapViewInSystemSpace(NlsSectionObject,
137 &NlsSectionBase,
138 &NlsSectionViewSize);
139 if (!NT_SUCCESS(Status))
140 {
141 DPRINT1("MmMapViewInSystemSpace() failed\n");
142 KEBUGCHECKEX(0x32, Status, 1, 3, 0);
143 }
144
145 DPRINT("NlsSection: Base %p Size %lx\n",
146 NlsSectionBase,
147 NlsSectionViewSize);
148
149 NlsAnsiTableOffset = 0;
150 RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsAnsiTableOffset),
151 NlsAnsiCodePageTable,
152 NlsAnsiCodePageTableSize);
153
154 NlsOemTableOffset = NlsAnsiTableOffset + ROUND_UP(NlsAnsiCodePageTableSize, PAGE_SIZE);
155 RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsOemTableOffset),
156 NlsOemCodePageTable,
157 NlsOemCodePageTableSize);
158
159 NlsUnicodeTableOffset = NlsOemTableOffset + ROUND_UP(NlsOemCodePageTableSize, PAGE_SIZE);
160 RtlCopyMemory((PVOID)((ULONG)NlsSectionBase + NlsUnicodeTableOffset),
161 NlsUnicodeCasemapTable,
162 NlsUnicodeCasemapTableSize);
163
164 RtlInitNlsTables ((PVOID)((ULONG)NlsSectionBase + NlsAnsiTableOffset),
165 (PVOID)((ULONG)NlsSectionBase + NlsOemTableOffset),
166 (PVOID)((ULONG)NlsSectionBase + NlsUnicodeTableOffset),
167 &NlsTable);
168
169 RtlResetRtlTranslations (&NlsTable);
170 }