mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 19:52:56 +00:00
[KERNEL32] Reduce DefineDosDeviceA memory footprint
by using TEB static unicode string (which is already preallocated).
This commit is contained in:
parent
2ebda0e3d0
commit
1ed7f27466
1 changed files with 43 additions and 23 deletions
|
@ -30,41 +30,61 @@ DefineDosDeviceA(
|
||||||
LPCSTR lpTargetPath
|
LPCSTR lpTargetPath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UNICODE_STRING DeviceNameU = {0};
|
|
||||||
UNICODE_STRING TargetPathU = {0};
|
|
||||||
BOOL Result;
|
BOOL Result;
|
||||||
|
NTSTATUS Status;
|
||||||
|
ANSI_STRING AnsiString;
|
||||||
|
PWSTR TargetPathBuffer;
|
||||||
|
UNICODE_STRING TargetPathU;
|
||||||
|
PUNICODE_STRING DeviceNameU;
|
||||||
|
|
||||||
if (lpDeviceName &&
|
/* Convert DeviceName using static unicode string */
|
||||||
!RtlCreateUnicodeStringFromAsciiz(&DeviceNameU, lpDeviceName))
|
RtlInitAnsiString(&AnsiString, lpDeviceName);
|
||||||
|
DeviceNameU = &NtCurrentTeb()->StaticUnicodeString;
|
||||||
|
Status = RtlAnsiStringToUnicodeString(DeviceNameU, &AnsiString, FALSE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
/*
|
||||||
return 0;
|
* If the static unicode string is too small,
|
||||||
}
|
* it's because the name is too long...
|
||||||
|
* so, return appropriate status!
|
||||||
if (lpTargetPath &&
|
*/
|
||||||
!RtlCreateUnicodeStringFromAsciiz(&TargetPathU, lpTargetPath))
|
if (Status == STATUS_BUFFER_OVERFLOW)
|
||||||
{
|
|
||||||
if (DeviceNameU.Buffer)
|
|
||||||
{
|
{
|
||||||
RtlFreeUnicodeString(&DeviceNameU);
|
SetLastError(ERROR_FILENAME_EXCED_RANGE);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
return 0;
|
BaseSetLastNTError(Status);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result = DefineDosDeviceW(dwFlags,
|
/* Convert target path if existing */
|
||||||
DeviceNameU.Buffer,
|
if (lpTargetPath != NULL)
|
||||||
TargetPathU.Buffer);
|
{
|
||||||
|
RtlInitAnsiString(&AnsiString, lpTargetPath);
|
||||||
|
Status = RtlAnsiStringToUnicodeString(&TargetPathU, &AnsiString, TRUE);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
BaseSetLastNTError(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (TargetPathU.Buffer)
|
TargetPathBuffer = TargetPathU.Buffer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TargetPathBuffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call W */
|
||||||
|
Result = DefineDosDeviceW(dwFlags, DeviceNameU->Buffer, TargetPathBuffer);
|
||||||
|
|
||||||
|
/* Free target path if allocated */
|
||||||
|
if (TargetPathBuffer != NULL)
|
||||||
{
|
{
|
||||||
RtlFreeUnicodeString(&TargetPathU);
|
RtlFreeUnicodeString(&TargetPathU);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DeviceNameU.Buffer)
|
|
||||||
{
|
|
||||||
RtlFreeUnicodeString(&DeviceNameU);
|
|
||||||
}
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue