[Wine-patches] [18/23] ntoskrnl.exe: Add support for FILE_AUTOGENERATED_DEVICE_NAME.
Alexander Morozov
=?iso-8859-1?q?amorozov_=CE=C1_etersoft=2Eru?=
Пн Янв 19 18:25:18 MSK 2009
For eterhack branch
----------- следующая часть -----------
From 46a54e2b1b76e0a9b4ceedf68da8ed393a013332 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Fri, 16 Jan 2009 13:57:36 +0300
Subject: [PATCH] ntoskrnl.exe: Add support for FILE_AUTOGENERATED_DEVICE_NAME.
---
dlls/ntoskrnl.exe/ntoskrnl.c | 49 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.c b/dlls/ntoskrnl.exe/ntoskrnl.c
index 6ac20cd..7072f96 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/ntoskrnl.c
@@ -285,6 +285,41 @@ static HANDLE get_device_manager(void)
return ret;
}
+static NTSTATUS get_autogenerated_device_name( UNICODE_STRING *name )
+{
+ static const WCHAR autogen_nameW[] = {'\\','D','e','v','i','c','e',
+ '\\','%','0','8','x',0};
+
+ NTSTATUS status;
+ WCHAR *nameW;
+ HANDLE handle;
+ OBJECT_ATTRIBUTES attr;
+ IO_STATUS_BLOCK io;
+ unsigned int k = 1;
+
+ if (!(nameW = RtlAllocateHeap( GetProcessHeap(), 0, 17 * sizeof(WCHAR) )))
+ return STATUS_NO_MEMORY;
+
+ attr.Length = sizeof(attr);
+ attr.RootDirectory = 0;
+ attr.Attributes = OBJ_CASE_INSENSITIVE;
+ attr.ObjectName = name;
+ attr.SecurityDescriptor = NULL;
+ attr.SecurityQualityOfService = NULL;
+
+ for (;;)
+ {
+ sprintfW( nameW, autogen_nameW, k );
+ RtlInitUnicodeString( name, nameW );
+ status = NtCreateFile( &handle, 0, &attr, &io, NULL, 0, 0,
+ FILE_OPEN, 0, NULL, 0 );
+ if (status != STATUS_SUCCESS) break;
+ NtClose( handle );
+ ++k;
+ }
+ return STATUS_SUCCESS;
+}
+
/* exception handler for emulation of privileged instructions */
static LONG CALLBACK vectored_handler( EXCEPTION_POINTERS *ptrs )
{
@@ -981,6 +1016,7 @@ NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
DEVICE_OBJECT *device;
HANDLE handle = 0;
HANDLE manager = get_device_manager();
+ UNICODE_STRING generated_name;
TRACE( "(%p, %u, %s, %u, %x, %u, %p)\n",
driver, ext_size, debugstr_us(name), type, characteristics, exclusive, ret_device );
@@ -988,6 +1024,17 @@ NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
if (!(device = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*device) + ext_size )))
return STATUS_NO_MEMORY;
+ if (characteristics & FILE_AUTOGENERATED_DEVICE_NAME)
+ {
+ status = get_autogenerated_device_name( &generated_name );
+ if (status != STATUS_SUCCESS)
+ {
+ HeapFree( GetProcessHeap(), 0, device );
+ return status;
+ }
+ name = &generated_name;
+ }
+
SERVER_START_REQ( create_device )
{
req->access = 0;
@@ -1019,6 +1066,8 @@ NTSTATUS WINAPI IoCreateDevice( DRIVER_OBJECT *driver, ULONG ext_size,
}
else HeapFree( GetProcessHeap(), 0, device );
+ if (characteristics & FILE_AUTOGENERATED_DEVICE_NAME)
+ RtlFreeUnicodeString( &generated_name );
return status;
}
--
1.6.0.2.GIT
Подробная информация о списке рассылки Wine-patches