2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Base API Server DLL
4 * FILE: subsystems/win/basesrv/vdm.c
5 * PURPOSE: Virtual DOS Machines (VDM) Support
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 /* INCLUDES *******************************************************************/
16 /* GLOBALS ********************************************************************/
18 BOOLEAN BaseSrvKernel32DelayLoadComplete
;
19 HANDLE BaseSrvKernel32DllHandle
;
20 UNICODE_STRING BaseSrvKernel32DllPath
;
22 POPEN_DATA_FILE pOpenDataFile
;
23 PVOID
/*PGET_DEFAULT_SORTKEY_SIZE */ pGetDefaultSortkeySize
;
24 PVOID
/*PGET_LINGUIST_LANG_SIZE*/ pGetLinguistLangSize
;
25 PVOID
/*PNLS_CONVERT_INTEGER_TO_STRING*/ pNlsConvertIntegerToString
;
26 PVOID
/*PVALIDATE_LCTYPE*/ pValidateLCType
;
27 PVALIDATE_LOCALE pValidateLocale
;
28 PGET_NLS_SECTION_NAME pGetNlsSectionName
;
29 PVOID
/*PGET_USER_DEFAULT_LANGID*/ pGetUserDefaultLangID
;
30 PGET_CP_FILE_NAME_FROM_REGISTRY pGetCPFileNameFromRegistry
;
31 PCREATE_NLS_SECURTY_DESCRIPTOR pCreateNlsSecurityDescriptor
;
33 BASESRV_KERNEL_IMPORTS BaseSrvKernel32Imports
[10] =
35 { "OpenDataFile", (PVOID
*) &pOpenDataFile
},
36 { "GetDefaultSortkeySize", (PVOID
*) &pGetDefaultSortkeySize
},
37 { "GetLinguistLangSize", (PVOID
*) &pGetLinguistLangSize
},
38 { "NlsConvertIntegerToString", (PVOID
*) &pNlsConvertIntegerToString
},
39 { "ValidateLCType", (PVOID
*) &pValidateLCType
},
40 { "ValidateLocale", (PVOID
*) &pValidateLocale
},
41 { "GetNlsSectionName", (PVOID
*) &pGetNlsSectionName
},
42 { "GetUserDefaultLangID", (PVOID
*) &pGetUserDefaultLangID
},
43 { "GetCPFileNameFromRegistry", (PVOID
*) &pGetCPFileNameFromRegistry
},
44 { "CreateNlsSecurityDescriptor", (PVOID
*) &pCreateNlsSecurityDescriptor
},
47 /* FUNCTIONS *****************************************************************/
51 BaseSrvDelayLoadKernel32(VOID
)
55 ANSI_STRING ProcedureName
;
57 /* Only do this once */
58 if (BaseSrvKernel32DelayLoadComplete
) return STATUS_SUCCESS
;
60 /* Loop all imports */
61 for (i
= 0; i
< RTL_NUMBER_OF(BaseSrvKernel32Imports
); i
++)
63 /* Only look them up once */
64 if (!*BaseSrvKernel32Imports
[i
].FunctionPointer
)
66 /* If we haven't loaded the DLL yet, do it now */
67 if (!BaseSrvKernel32DllHandle
)
69 Status
= LdrLoadDll(0,
71 &BaseSrvKernel32DllPath
,
72 &BaseSrvKernel32DllHandle
);
73 if (!NT_SUCCESS(Status
))
75 DPRINT1("Failed to load %wZ\n", &BaseSrvKernel32DllPath
);
80 /* Get the address of the routine being looked up*/
81 RtlInitAnsiString(&ProcedureName
, BaseSrvKernel32Imports
[i
].FunctionName
);
82 Status
= LdrGetProcedureAddress(BaseSrvKernel32DllHandle
,
85 BaseSrvKernel32Imports
[i
].FunctionPointer
);
86 DPRINT1("NLS: Found %Z at 0x%p\n",
88 BaseSrvKernel32Imports
[i
].FunctionPointer
);
89 if (!NT_SUCCESS(Status
)) break;
93 /* Did we find them all? */
94 if (i
== RTL_NUMBER_OF(BaseSrvKernel32Imports
))
97 BaseSrvKernel32DelayLoadComplete
= TRUE
;
98 return STATUS_SUCCESS
;
105 /* PUBLIC SERVER APIS *********************************************************/
107 CSR_API(BaseSrvNlsSetUserInfo
)
109 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
110 return STATUS_NOT_IMPLEMENTED
;
113 CSR_API(BaseSrvNlsSetMultipleUserInfo
)
115 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
116 return STATUS_NOT_IMPLEMENTED
;
119 CSR_API(BaseSrvNlsCreateSection
)
122 HANDLE SectionHandle
, ProcessHandle
, FileHandle
;
124 UNICODE_STRING NlsSectionName
;
126 UCHAR SecurityDescriptor
[52];
127 OBJECT_ATTRIBUTES ObjectAttributes
;
128 PBASE_NLS_CREATE_SECTION NlsMsg
= &((PBASE_API_MESSAGE
)ApiMessage
)->Data
.NlsCreateSection
;
130 /* Load kernel32 first and import the NLS routines */
131 Status
= BaseSrvDelayLoadKernel32();
132 if (!NT_SUCCESS(Status
)) return Status
;
135 NlsMsg
->SectionHandle
= NULL
;
137 /* Check and validate the locale ID, if one is present */
138 LocaleId
= NlsMsg
->LocaleId
;
139 DPRINT1("NLS: Create Section with LCID: %lx for Type: %d\n", LocaleId
, NlsMsg
->Type
);
142 if (!pValidateLocale(LocaleId
)) return STATUS_INVALID_PARAMETER
;
145 /* Check which NLS section is being created */
146 switch (NlsMsg
->Type
)
148 /* For each one, set the correct filename and object name */
150 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionUnicode");
151 NlsFileName
= L
"unicode.nls";
154 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionLocale");
155 NlsFileName
= L
"locale.nls";
158 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionCType");
159 NlsFileName
= L
"ctype.nls";
162 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionSortkey");
163 NlsFileName
= L
"sortkey.nls";
166 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionSortTbls");
167 NlsFileName
= L
"sorttbls.nls";
170 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionCP437");
171 NlsFileName
= L
"c_437.nls";
174 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionCP1252");
175 NlsFileName
= L
"c_1252.nls";
178 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionLANG_EXCEPT");
179 NlsFileName
= L
"l_except.nls";
182 DPRINT1("This type not yet supported\n");
183 return STATUS_NOT_IMPLEMENTED
;
185 DPRINT1("This type not yet supported\n");
186 return STATUS_NOT_IMPLEMENTED
;
188 DPRINT1("This type not yet supported\n");
189 return STATUS_NOT_IMPLEMENTED
;
191 RtlInitUnicodeString(&NlsSectionName
, L
"\\NLS\\NlsSectionGeo");
192 NlsFileName
= L
"geo.nls";
195 DPRINT1("NLS: Invalid NLS type!\n");
196 return STATUS_INVALID_PARAMETER
;
199 /* Open the specified NLS file */
200 Status
= pOpenDataFile(&FileHandle
, NlsFileName
);
201 if (Status
!= STATUS_SUCCESS
)
203 DPRINT1("NLS: Failed to open file: %lx\n", Status
);
207 /* Create an SD for the section object */
208 Status
= pCreateNlsSecurityDescriptor(&SecurityDescriptor
,
209 sizeof(SecurityDescriptor
),
211 if (!NT_SUCCESS(Status
))
213 DPRINT1("NLS: CreateNlsSecurityDescriptor FAILED!: %lx\n", Status
);
218 /* Create the section object proper */
219 InitializeObjectAttributes(&ObjectAttributes
,
221 OBJ_CASE_INSENSITIVE
| OBJ_PERMANENT
| OBJ_OPENIF
,
223 &SecurityDescriptor
);
224 Status
= NtCreateSection(&SectionHandle
,
232 if (!NT_SUCCESS(Status
))
234 DPRINT1("NLS: Failed to create section! %lx\n", Status
);
238 /* Open a handle to the calling process */
239 InitializeObjectAttributes(&ObjectAttributes
, NULL
, 0, NULL
, NULL
);
240 Status
= NtOpenProcess(&ProcessHandle
,
243 &ApiMessage
->Header
.ClientId
);
244 if (!NT_SUCCESS(Status
))
246 DPRINT1("NLS: Failed to open process! %lx\n", Status
);
247 NtClose(SectionHandle
);
251 /* Duplicate the handle to the section object into it */
252 Status
= NtDuplicateObject(NtCurrentProcess(),
255 &NlsMsg
->SectionHandle
,
259 NtClose(ProcessHandle
);
263 CSR_API(BaseSrvNlsUpdateCacheCount
)
265 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
266 return STATUS_NOT_IMPLEMENTED
;
269 CSR_API(BaseSrvNlsGetUserInfo
)
271 DPRINT1("%s not yet implemented\n", __FUNCTION__
);
272 return STATUS_NOT_IMPLEMENTED
;