ntoskrnl: Use the MDL allocation routines for standard ioctl processing.
This commit is contained in:
parent
5fc369ff21
commit
1895a42509
|
@ -140,7 +140,6 @@ static HANDLE get_device_manager(void)
|
||||||
static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff, ULONG in_size,
|
static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff, ULONG in_size,
|
||||||
void *out_buff, ULONG *out_size )
|
void *out_buff, ULONG *out_size )
|
||||||
{
|
{
|
||||||
MDL mdl;
|
|
||||||
IRP *irp;
|
IRP *irp;
|
||||||
void *sys_buff = NULL;
|
void *sys_buff = NULL;
|
||||||
FILE_OBJECT file;
|
FILE_OBJECT file;
|
||||||
|
@ -150,7 +149,6 @@ static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff,
|
||||||
TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
|
TRACE( "ioctl %x device %p in_size %u out_size %u\n", code, device, in_size, *out_size );
|
||||||
|
|
||||||
/* so we can spot things that we should initialize */
|
/* so we can spot things that we should initialize */
|
||||||
memset( &mdl, 0x77, sizeof(mdl) );
|
|
||||||
memset( &file, 0x88, sizeof(file) );
|
memset( &file, 0x88, sizeof(file) );
|
||||||
|
|
||||||
if ((code & 3) == METHOD_BUFFERED)
|
if ((code & 3) == METHOD_BUFFERED)
|
||||||
|
@ -170,18 +168,13 @@ static NTSTATUS process_ioctl( DEVICE_OBJECT *device, ULONG code, void *in_buff,
|
||||||
irp->RequestorMode = UserMode;
|
irp->RequestorMode = UserMode;
|
||||||
irp->AssociatedIrp.SystemBuffer = ((code & 3) == METHOD_BUFFERED) ? sys_buff : in_buff;
|
irp->AssociatedIrp.SystemBuffer = ((code & 3) == METHOD_BUFFERED) ? sys_buff : in_buff;
|
||||||
irp->UserBuffer = out_buff;
|
irp->UserBuffer = out_buff;
|
||||||
irp->MdlAddress = &mdl;
|
|
||||||
irp->Tail.Overlay.OriginalFileObject = &file;
|
irp->Tail.Overlay.OriginalFileObject = &file;
|
||||||
|
|
||||||
mdl.Next = NULL;
|
|
||||||
mdl.Size = 0;
|
|
||||||
mdl.StartVa = out_buff;
|
|
||||||
mdl.ByteCount = *out_size;
|
|
||||||
mdl.ByteOffset = 0;
|
|
||||||
|
|
||||||
file.FsContext = NULL;
|
file.FsContext = NULL;
|
||||||
file.FsContext2 = NULL;
|
file.FsContext2 = NULL;
|
||||||
|
|
||||||
|
IoAllocateMdl( out_buff, *out_size, FALSE, FALSE, irp );
|
||||||
|
|
||||||
device->CurrentIrp = irp;
|
device->CurrentIrp = irp;
|
||||||
|
|
||||||
KeQueryTickCount( &count ); /* update the global KeTickCount */
|
KeQueryTickCount( &count ); /* update the global KeTickCount */
|
||||||
|
@ -385,8 +378,18 @@ PIRP WINAPI IoAllocateIrp( CCHAR stack_size, BOOLEAN charge_quota )
|
||||||
*/
|
*/
|
||||||
void WINAPI IoFreeIrp( IRP *irp )
|
void WINAPI IoFreeIrp( IRP *irp )
|
||||||
{
|
{
|
||||||
|
MDL *mdl;
|
||||||
|
|
||||||
TRACE( "%p\n", irp );
|
TRACE( "%p\n", irp );
|
||||||
|
|
||||||
|
mdl = irp->MdlAddress;
|
||||||
|
while (mdl)
|
||||||
|
{
|
||||||
|
MDL *next = mdl->Next;
|
||||||
|
IoFreeMdl( mdl );
|
||||||
|
mdl = next;
|
||||||
|
}
|
||||||
|
|
||||||
ExFreePool( irp );
|
ExFreePool( irp );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,24 +407,21 @@ PVOID WINAPI IoAllocateErrorLogEntry( PVOID IoObject, UCHAR EntrySize )
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* IoAllocateMdl (NTOSKRNL.EXE.@)
|
* IoAllocateMdl (NTOSKRNL.EXE.@)
|
||||||
*/
|
*/
|
||||||
PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN SecondaryBuffer, BOOLEAN ChargeQuota, PIRP Irp )
|
PMDL WINAPI IoAllocateMdl( PVOID va, ULONG length, BOOLEAN secondary, BOOLEAN charge_quota, IRP *irp )
|
||||||
{
|
{
|
||||||
PMDL mdl;
|
PMDL mdl;
|
||||||
ULONG_PTR address = (ULONG_PTR)VirtualAddress;
|
ULONG_PTR address = (ULONG_PTR)va;
|
||||||
ULONG_PTR page_address;
|
ULONG_PTR page_address;
|
||||||
SIZE_T nb_pages, mdl_size;
|
SIZE_T nb_pages, mdl_size;
|
||||||
|
|
||||||
TRACE("(%p, %u, %i, %i, %p)\n", VirtualAddress, Length, SecondaryBuffer, ChargeQuota, Irp);
|
TRACE("(%p, %u, %i, %i, %p)\n", va, length, secondary, charge_quota, irp);
|
||||||
|
|
||||||
if (Irp)
|
if (charge_quota)
|
||||||
FIXME("Attaching the MDL to an IRP is not yet supported\n");
|
|
||||||
|
|
||||||
if (ChargeQuota)
|
|
||||||
FIXME("Charge quota is not yet supported\n");
|
FIXME("Charge quota is not yet supported\n");
|
||||||
|
|
||||||
/* FIXME: We suppose that page size is 4096 */
|
/* FIXME: We suppose that page size is 4096 */
|
||||||
page_address = address & ~(4096 - 1);
|
page_address = address & ~(4096 - 1);
|
||||||
nb_pages = (((address + Length - 1) & ~(4096 - 1)) - page_address) / 4096 + 1;
|
nb_pages = (((address + length - 1) & ~(4096 - 1)) - page_address) / 4096 + 1;
|
||||||
|
|
||||||
mdl_size = sizeof(MDL) + nb_pages * sizeof(PVOID);
|
mdl_size = sizeof(MDL) + nb_pages * sizeof(PVOID);
|
||||||
|
|
||||||
|
@ -430,11 +430,24 @@ PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN Secondary
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
mdl->Size = mdl_size;
|
mdl->Size = mdl_size;
|
||||||
mdl->Process = IoGetCurrentProcess();
|
mdl->Process = NULL; /* FIXME: IoGetCurrentProcess */
|
||||||
mdl->StartVa = (PVOID)page_address;
|
mdl->StartVa = (PVOID)page_address;
|
||||||
mdl->ByteCount = Length;
|
mdl->ByteCount = length;
|
||||||
mdl->ByteOffset = address - page_address;
|
mdl->ByteOffset = address - page_address;
|
||||||
|
|
||||||
|
if (!irp) return mdl;
|
||||||
|
|
||||||
|
if (secondary) /* add it at the end */
|
||||||
|
{
|
||||||
|
MDL **pmdl = &irp->MdlAddress;
|
||||||
|
while (*pmdl) pmdl = &(*pmdl)->Next;
|
||||||
|
*pmdl = mdl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mdl->Next = irp->MdlAddress;
|
||||||
|
irp->MdlAddress = mdl;
|
||||||
|
}
|
||||||
return mdl;
|
return mdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,10 +455,9 @@ PMDL WINAPI IoAllocateMdl( PVOID VirtualAddress, ULONG Length, BOOLEAN Secondary
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* IoFreeMdl (NTOSKRNL.EXE.@)
|
* IoFreeMdl (NTOSKRNL.EXE.@)
|
||||||
*/
|
*/
|
||||||
VOID WINAPI IoFreeMdl(PMDL mdl)
|
void WINAPI IoFreeMdl(PMDL mdl)
|
||||||
{
|
{
|
||||||
FIXME("partial stub: %p\n", mdl);
|
TRACE("%p\n", mdl);
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, mdl);
|
HeapFree(GetProcessHeap(), 0, mdl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1199,6 +1199,7 @@ void WINAPI ExFreePoolWithTag(PVOID,ULONG);
|
||||||
NTSTATUS WINAPI IoAllocateDriverObjectExtension(PDRIVER_OBJECT,PVOID,ULONG,PVOID*);
|
NTSTATUS WINAPI IoAllocateDriverObjectExtension(PDRIVER_OBJECT,PVOID,ULONG,PVOID*);
|
||||||
PVOID WINAPI IoAllocateErrorLogEntry(PVOID,UCHAR);
|
PVOID WINAPI IoAllocateErrorLogEntry(PVOID,UCHAR);
|
||||||
PIRP WINAPI IoAllocateIrp(CCHAR,BOOLEAN);
|
PIRP WINAPI IoAllocateIrp(CCHAR,BOOLEAN);
|
||||||
|
PMDL WINAPI IoAllocateMdl(PVOID,ULONG,BOOLEAN,BOOLEAN,IRP*);
|
||||||
PIRP WINAPI IoBuildDeviceIoControlRequest(ULONG,DEVICE_OBJECT*,PVOID,ULONG,PVOID,ULONG,BOOLEAN,PKEVENT,IO_STATUS_BLOCK*);
|
PIRP WINAPI IoBuildDeviceIoControlRequest(ULONG,DEVICE_OBJECT*,PVOID,ULONG,PVOID,ULONG,BOOLEAN,PKEVENT,IO_STATUS_BLOCK*);
|
||||||
NTSTATUS WINAPI IoCallDriver(DEVICE_OBJECT*,IRP*);
|
NTSTATUS WINAPI IoCallDriver(DEVICE_OBJECT*,IRP*);
|
||||||
VOID WINAPI IoCompleteRequest(IRP*,UCHAR);
|
VOID WINAPI IoCompleteRequest(IRP*,UCHAR);
|
||||||
|
@ -1209,6 +1210,7 @@ void WINAPI IoDeleteDevice(DEVICE_OBJECT*);
|
||||||
void WINAPI IoDeleteDriver(DRIVER_OBJECT*);
|
void WINAPI IoDeleteDriver(DRIVER_OBJECT*);
|
||||||
NTSTATUS WINAPI IoDeleteSymbolicLink(UNICODE_STRING*);
|
NTSTATUS WINAPI IoDeleteSymbolicLink(UNICODE_STRING*);
|
||||||
void WINAPI IoFreeIrp(IRP*);
|
void WINAPI IoFreeIrp(IRP*);
|
||||||
|
void WINAPI IoFreeMdl(MDL*);
|
||||||
PEPROCESS WINAPI IoGetCurrentProcess(void);
|
PEPROCESS WINAPI IoGetCurrentProcess(void);
|
||||||
NTSTATUS WINAPI IoGetDeviceInterfaces(const GUID*,PDEVICE_OBJECT,ULONG,PWSTR*);
|
NTSTATUS WINAPI IoGetDeviceInterfaces(const GUID*,PDEVICE_OBJECT,ULONG,PWSTR*);
|
||||||
NTSTATUS WINAPI IoGetDeviceObjectPointer(UNICODE_STRING*,ACCESS_MASK,PFILE_OBJECT*,PDEVICE_OBJECT*);
|
NTSTATUS WINAPI IoGetDeviceObjectPointer(UNICODE_STRING*,ACCESS_MASK,PFILE_OBJECT*,PDEVICE_OBJECT*);
|
||||||
|
|
Loading…
Reference in New Issue