2003-09-18 02:06:02 +02:00
|
|
|
/*
|
|
|
|
* Win32 VxD functions
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998 Ulrich Weigand
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-09-18 02:06:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
2005-05-06 18:22:54 +02:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
2003-09-18 02:06:02 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2005-06-06 22:00:14 +02:00
|
|
|
#include "winternl.h"
|
2005-08-22 16:08:39 +02:00
|
|
|
#include "winioctl.h"
|
2003-11-13 22:04:01 +01:00
|
|
|
#include "kernel_private.h"
|
2004-02-21 05:13:56 +01:00
|
|
|
#include "wine/library.h"
|
2004-02-20 06:22:20 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/server.h"
|
2003-09-18 02:06:02 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vxd);
|
|
|
|
|
2004-02-20 06:22:20 +01:00
|
|
|
typedef BOOL (WINAPI *DeviceIoProc)(DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
|
2004-02-21 05:13:56 +01:00
|
|
|
typedef DWORD (WINAPI *VxDCallProc)(DWORD, CONTEXT86 *);
|
2004-02-20 06:22:20 +01:00
|
|
|
|
|
|
|
struct vxd_module
|
|
|
|
{
|
2006-10-31 20:23:56 +01:00
|
|
|
LARGE_INTEGER index;
|
|
|
|
HANDLE handle;
|
|
|
|
HMODULE module;
|
|
|
|
DeviceIoProc proc;
|
2004-02-20 06:22:20 +01:00
|
|
|
};
|
|
|
|
|
2004-02-21 05:13:56 +01:00
|
|
|
struct vxdcall_service
|
|
|
|
{
|
|
|
|
WCHAR name[12];
|
|
|
|
DWORD service;
|
|
|
|
HMODULE module;
|
|
|
|
VxDCallProc proc;
|
|
|
|
};
|
|
|
|
|
2004-02-20 06:22:20 +01:00
|
|
|
#define MAX_VXD_MODULES 32
|
|
|
|
|
|
|
|
static struct vxd_module vxd_modules[MAX_VXD_MODULES];
|
|
|
|
|
2004-02-21 05:13:56 +01:00
|
|
|
static struct vxdcall_service vxd_services[] =
|
|
|
|
{
|
|
|
|
{ {'v','m','m','.','v','x','d',0}, 0x0001, NULL, NULL },
|
|
|
|
{ {'v','w','i','n','3','2','.','v','x','d',0}, 0x002a, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NB_VXD_SERVICES (sizeof(vxd_services)/sizeof(vxd_services[0]))
|
|
|
|
|
2004-02-20 06:22:20 +01:00
|
|
|
static CRITICAL_SECTION vxd_section;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &vxd_section,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
2005-09-09 12:19:44 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": vxd_section") }
|
2004-02-20 06:22:20 +01:00
|
|
|
};
|
|
|
|
static CRITICAL_SECTION vxd_section = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
|
|
/* create a file handle to represent a VxD, by opening a dummy file in the wineserver directory */
|
|
|
|
static HANDLE open_vxd_handle( LPCWSTR name )
|
|
|
|
{
|
|
|
|
const char *dir = wine_get_server_dir();
|
2004-04-14 06:31:55 +02:00
|
|
|
int len;
|
2004-02-20 06:22:20 +01:00
|
|
|
HANDLE ret;
|
2004-04-14 06:31:55 +02:00
|
|
|
NTSTATUS status;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
UNICODE_STRING nameW;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_UNIXCP, 0, dir, -1, NULL, 0 );
|
|
|
|
nameW.Length = (len + 1 + strlenW( name )) * sizeof(WCHAR);
|
|
|
|
nameW.MaximumLength = nameW.Length + sizeof(WCHAR);
|
|
|
|
if (!(nameW.Buffer = HeapAlloc( GetProcessHeap(), 0, nameW.Length )))
|
2004-02-20 06:22:20 +01:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-14 06:31:55 +02:00
|
|
|
MultiByteToWideChar( CP_UNIXCP, 0, dir, -1, nameW.Buffer, len );
|
|
|
|
nameW.Buffer[len-1] = '/';
|
|
|
|
strcpyW( nameW.Buffer + len, name );
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = 0;
|
|
|
|
attr.ObjectName = &nameW;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
|
|
|
status = NtCreateFile( &ret, 0, &attr, &io, NULL, 0,
|
|
|
|
FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF,
|
|
|
|
FILE_SYNCHRONOUS_IO_ALERT, NULL, 0 );
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
}
|
|
|
|
RtlFreeUnicodeString( &nameW );
|
2004-02-20 06:22:20 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve the DeviceIoControl function for a Vxd given a file handle */
|
|
|
|
static DeviceIoProc get_vxd_proc( HANDLE handle )
|
|
|
|
{
|
|
|
|
DeviceIoProc ret = NULL;
|
2006-10-31 20:23:56 +01:00
|
|
|
int status, i;
|
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_INTERNAL_INFORMATION info;
|
2004-02-20 06:22:20 +01:00
|
|
|
|
2006-10-31 20:23:56 +01:00
|
|
|
status = NtQueryInformationFile( handle, &io, &info, sizeof(info), FileInternalInformation );
|
2004-02-20 06:22:20 +01:00
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &vxd_section );
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_VXD_MODULES; i++)
|
|
|
|
{
|
|
|
|
if (!vxd_modules[i].module) break;
|
2006-10-31 20:23:56 +01:00
|
|
|
if (vxd_modules[i].index.QuadPart == info.IndexNumber.QuadPart)
|
2004-02-20 06:22:20 +01:00
|
|
|
{
|
|
|
|
if (!(ret = vxd_modules[i].proc)) SetLastError( ERROR_INVALID_FUNCTION );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME: Here we could go through the directory to find the VxD name and load it. */
|
|
|
|
/* Let's wait to find out if there are actually apps out there that try to share */
|
|
|
|
/* VxD handles between processes, before we go to the trouble of implementing it. */
|
|
|
|
ERR( "handle %p not found in module list, inherited from another process?\n", handle );
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlLeaveCriticalSection( &vxd_section );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* load a VxD and return a file handle to it */
|
|
|
|
HANDLE VXD_Open( LPCWSTR filenameW, DWORD access, SECURITY_ATTRIBUTES *sa )
|
|
|
|
{
|
|
|
|
static const WCHAR dotVxDW[] = {'.','v','x','d',0};
|
|
|
|
int i;
|
|
|
|
HANDLE handle;
|
|
|
|
HMODULE module;
|
|
|
|
WCHAR *p, name[16];
|
|
|
|
|
|
|
|
if (!(GetVersion() & 0x80000000)) /* there are no VxDs on NT */
|
|
|
|
{
|
2004-07-06 23:31:24 +02:00
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
2004-02-20 06:22:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* normalize the filename */
|
|
|
|
|
|
|
|
if (strlenW( filenameW ) >= sizeof(name)/sizeof(WCHAR) - 4 ||
|
|
|
|
strchrW( filenameW, '/' ) || strchrW( filenameW, '\\' ))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpyW( name, filenameW );
|
|
|
|
strlwrW( name );
|
|
|
|
p = strchrW( name, '.' );
|
|
|
|
if (!p) strcatW( name, dotVxDW );
|
2005-11-18 13:06:57 +01:00
|
|
|
else if (strcmpiW( p, dotVxDW )) /* existing extension has to be .vxd */
|
2004-02-20 06:22:20 +01:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to load the module first */
|
|
|
|
|
|
|
|
if (!(module = LoadLibraryW( name )))
|
|
|
|
{
|
|
|
|
FIXME( "Unknown/unsupported VxD %s. Try setting Windows version to 'nt40' or 'win31'.\n",
|
|
|
|
debugstr_w(name) );
|
2004-02-25 02:31:17 +01:00
|
|
|
SetLastError( ERROR_FILE_NOT_FOUND );
|
2004-02-20 06:22:20 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register the module in the global list if necessary */
|
|
|
|
|
|
|
|
RtlEnterCriticalSection( &vxd_section );
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_VXD_MODULES; i++)
|
|
|
|
{
|
|
|
|
if (vxd_modules[i].module == module)
|
|
|
|
{
|
|
|
|
handle = vxd_modules[i].handle;
|
|
|
|
goto done; /* already registered */
|
|
|
|
}
|
|
|
|
if (!vxd_modules[i].module) /* new one, register it */
|
|
|
|
{
|
2006-10-31 20:23:56 +01:00
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_INTERNAL_INFORMATION info;
|
2004-02-20 06:22:20 +01:00
|
|
|
|
|
|
|
/* get a file handle to the dummy file */
|
|
|
|
if (!(handle = open_vxd_handle( name )))
|
|
|
|
{
|
|
|
|
FreeLibrary( module );
|
|
|
|
goto done;
|
|
|
|
}
|
2006-10-31 20:23:56 +01:00
|
|
|
if (!NtQueryInformationFile( handle, &io, &info, sizeof(info), FileInternalInformation ))
|
|
|
|
vxd_modules[i].index = info.IndexNumber;
|
|
|
|
|
2004-02-20 06:22:20 +01:00
|
|
|
vxd_modules[i].module = module;
|
|
|
|
vxd_modules[i].handle = handle;
|
|
|
|
vxd_modules[i].proc = (DeviceIoProc)GetProcAddress( module, "DeviceIoControl" );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("too many open VxD modules, please report\n" );
|
|
|
|
FreeLibrary( module );
|
|
|
|
handle = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
RtlLeaveCriticalSection( &vxd_section );
|
|
|
|
if (!DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), &handle, 0,
|
|
|
|
(sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle),
|
|
|
|
DUP_HANDLE_SAME_ACCESS ))
|
|
|
|
handle = 0;
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-18 02:06:02 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* VxDCall0 (KERNEL32.1)
|
|
|
|
* VxDCall1 (KERNEL32.2)
|
|
|
|
* VxDCall2 (KERNEL32.3)
|
|
|
|
* VxDCall3 (KERNEL32.4)
|
|
|
|
* VxDCall4 (KERNEL32.5)
|
|
|
|
* VxDCall5 (KERNEL32.6)
|
|
|
|
* VxDCall6 (KERNEL32.7)
|
|
|
|
* VxDCall7 (KERNEL32.8)
|
|
|
|
* VxDCall8 (KERNEL32.9)
|
|
|
|
*/
|
2005-05-07 20:25:51 +02:00
|
|
|
void WINAPI __regs_VxDCall( DWORD service, CONTEXT86 *context )
|
2003-09-18 02:06:02 +02:00
|
|
|
{
|
2004-02-21 05:13:56 +01:00
|
|
|
int i;
|
|
|
|
VxDCallProc proc = NULL;
|
2003-09-18 02:06:02 +02:00
|
|
|
|
2004-02-21 05:13:56 +01:00
|
|
|
RtlEnterCriticalSection( &vxd_section );
|
|
|
|
for (i = 0; i < NB_VXD_SERVICES; i++)
|
2003-09-18 02:06:02 +02:00
|
|
|
{
|
2004-02-21 05:13:56 +01:00
|
|
|
if (HIWORD(service) != vxd_services[i].service) continue;
|
|
|
|
if (!vxd_services[i].module) /* need to load it */
|
|
|
|
{
|
|
|
|
if ((vxd_services[i].module = LoadLibraryW( vxd_services[i].name )))
|
|
|
|
vxd_services[i].proc = (VxDCallProc)GetProcAddress( vxd_services[i].module, "VxDCall" );
|
|
|
|
}
|
|
|
|
proc = vxd_services[i].proc;
|
2003-09-18 02:06:02 +02:00
|
|
|
break;
|
2004-02-21 05:13:56 +01:00
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection( &vxd_section );
|
|
|
|
|
|
|
|
if (proc) context->Eax = proc( service, context );
|
|
|
|
else
|
|
|
|
{
|
2006-10-12 22:56:29 +02:00
|
|
|
FIXME( "Unknown/unimplemented VxD (%08x)\n", service);
|
2004-02-21 05:13:56 +01:00
|
|
|
context->Eax = 0xffffffff; /* FIXME */
|
2003-09-18 02:06:02 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-07 20:25:51 +02:00
|
|
|
#ifdef DEFINE_REGS_ENTRYPOINT
|
2007-04-08 17:26:07 +02:00
|
|
|
DEFINE_REGS_ENTRYPOINT( VxDCall, 4, 4 )
|
2005-05-07 20:25:51 +02:00
|
|
|
#endif
|
2003-09-18 02:06:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenVxDHandle (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* This function is supposed to return the corresponding Ring 0
|
|
|
|
* ("kernel") handle for a Ring 3 handle in Win9x.
|
|
|
|
* Evidently, Wine will have problems with this. But we try anyway,
|
|
|
|
* maybe it helps...
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenVxDHandle(HANDLE hHandleRing3)
|
|
|
|
{
|
|
|
|
FIXME( "(%p), stub! (returning Ring 3 handle instead of Ring 0)\n", hHandleRing3);
|
|
|
|
return hHandleRing3;
|
|
|
|
}
|
2004-02-20 06:22:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* DeviceIoControl (KERNEL32.@)
|
|
|
|
* This is one of those big ugly nasty procedure which can do
|
|
|
|
* a million and one things when it comes to devices. It can also be
|
|
|
|
* used for VxD communication.
|
|
|
|
*
|
|
|
|
* A return value of FALSE indicates that something has gone wrong which
|
|
|
|
* GetLastError can decipher.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
|
|
|
|
LPVOID lpvInBuffer, DWORD cbInBuffer,
|
|
|
|
LPVOID lpvOutBuffer, DWORD cbOutBuffer,
|
|
|
|
LPDWORD lpcbBytesReturned,
|
|
|
|
LPOVERLAPPED lpOverlapped)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE( "(%p,%x,%p,%d,%p,%d,%p,%p)\n",
|
2004-02-20 06:22:20 +01:00
|
|
|
hDevice,dwIoControlCode,lpvInBuffer,cbInBuffer,
|
|
|
|
lpvOutBuffer,cbOutBuffer,lpcbBytesReturned,lpOverlapped );
|
|
|
|
|
|
|
|
/* Check if this is a user defined control code for a VxD */
|
|
|
|
|
|
|
|
if( HIWORD( dwIoControlCode ) == 0 )
|
|
|
|
{
|
|
|
|
DeviceIoProc proc = get_vxd_proc( hDevice );
|
|
|
|
if (proc) return proc( dwIoControlCode, lpvInBuffer, cbInBuffer,
|
|
|
|
lpvOutBuffer, cbOutBuffer, lpcbBytesReturned, lpOverlapped );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not a VxD, let ntdll handle it */
|
|
|
|
|
|
|
|
if (lpOverlapped)
|
|
|
|
{
|
2005-08-22 16:08:39 +02:00
|
|
|
if (HIWORD(dwIoControlCode) == FILE_DEVICE_FILE_SYSTEM)
|
|
|
|
status = NtFsControlFile(hDevice, lpOverlapped->hEvent,
|
|
|
|
NULL, NULL, (PIO_STATUS_BLOCK)lpOverlapped,
|
|
|
|
dwIoControlCode, lpvInBuffer, cbInBuffer,
|
|
|
|
lpvOutBuffer, cbOutBuffer);
|
|
|
|
else
|
|
|
|
status = NtDeviceIoControlFile(hDevice, lpOverlapped->hEvent,
|
|
|
|
NULL, NULL, (PIO_STATUS_BLOCK)lpOverlapped,
|
|
|
|
dwIoControlCode, lpvInBuffer, cbInBuffer,
|
|
|
|
lpvOutBuffer, cbOutBuffer);
|
2004-02-20 06:22:20 +01:00
|
|
|
if (lpcbBytesReturned) *lpcbBytesReturned = lpOverlapped->InternalHigh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
|
2005-08-22 16:08:39 +02:00
|
|
|
if (HIWORD(dwIoControlCode) == FILE_DEVICE_FILE_SYSTEM)
|
|
|
|
status = NtFsControlFile(hDevice, NULL, NULL, NULL, &iosb,
|
|
|
|
dwIoControlCode, lpvInBuffer, cbInBuffer,
|
|
|
|
lpvOutBuffer, cbOutBuffer);
|
|
|
|
else
|
|
|
|
status = NtDeviceIoControlFile(hDevice, NULL, NULL, NULL, &iosb,
|
|
|
|
dwIoControlCode, lpvInBuffer, cbInBuffer,
|
|
|
|
lpvOutBuffer, cbOutBuffer);
|
2004-02-20 06:22:20 +01:00
|
|
|
if (lpcbBytesReturned) *lpcbBytesReturned = iosb.Information;
|
|
|
|
}
|
|
|
|
if (status) SetLastError( RtlNtStatusToDosError(status) );
|
|
|
|
return !status;
|
|
|
|
}
|