Re: Compiler Produces Incorrect Code
From: Matt Taylor (com.sisecure_at_mtaylor)
Date: 12/30/04
- Next message: Matt Taylor: "Re: Compiler Produces Incorrect Code"
- Previous message: francois: "IRP_MN_QUERY_PNP_DEVICE_STATE in BDA device driver"
- In reply to: cristalink: "Re: Compiler Produces Incorrect Code"
- Next in thread: Alexander Grigoriev: "Re: Compiler Produces Incorrect Code"
- Reply: Alexander Grigoriev: "Re: Compiler Produces Incorrect Code"
- Reply: cristalink: "Re: Compiler Produces Incorrect Code"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 30 Dec 2004 12:02:18 GMT
"cristalink" <cristalink@nospam.nospam> wrote in message
news:OJqmpLg7EHA.3836@tk2msftngp13.phx.gbl...
> eax may well be used as a parameter due to compiler optimizations, esp.
> because MyControlInternal is static. Where's the code for
MyControlInternal?
[...]
A bit lengthy, but here it is:
static NTSTATUS MyIoControlInternal(PDEVICE_OBJECT DeviceObject,
PFILE_OBJECT FileObject,
ULONG IoControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength,
IO_STATUS_BLOCK *pISB)
{
KEVENT ke;
PIRP Irp;
PIO_STACK_LOCATION IrpSp;
PVOID Buffer, TempInputBuffer, TempOutputBuffer;
NTSTATUS stat;
// NOTE: This can never overflow
if ((InputBufferLength + OutputBufferLength) > 0)
{
if ((Buffer = ExAllocatePool(NonPagedPool, InputBufferLength +
OutputBufferLength)) == NULL)
{
MyDebugLog("ExAllocatePoolWithTag failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
TempInputBuffer = Buffer;
TempOutputBuffer = (PVOID)((size_t) TempInputBuffer + InputBufferLength);
if (InputBufferLength > 0)
RtlCopyMemory(TempInputBuffer, InputBuffer, InputBufferLength);
}
else
{
Buffer = NULL;
}
KeInitializeEvent(&ke, NotificationEvent, FALSE);
Irp = IoBuildDeviceIoControlRequest(IoControlCode,
DeviceObject,
TempInputBuffer,
InputBufferLength,
TempOutputBuffer,
OutputBufferLength,
FALSE,
&ke,
pISB);
if (Irp == NULL)
{
if (Buffer != NULL)
ExFreePool(Buffer);
MyDebugLog("IoBuildDeviceIoControlRequest failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
IrpSp = IoGetCurrentIrpStackLocation(Irp) - 1;
IrpSp->FileObject = FileObject;
// NOTE: seems the event is not getting set for certain IOCTLs.
IoCompletion seems to fix it.
IoSetCompletionRoutine(Irp, MySetEventIoCompletion, &ke, TRUE, TRUE, TRUE);
stat = IoCallDriver(DeviceObject, Irp);
KeWaitForSingleObject(&ke, Executive, KernelMode, FALSE, NULL);
IoFreeIrp(Irp);
stat = pISB->Status;
if (Buffer != NULL)
{
if (OutputBufferLength > 0)
RtlCopyMemory(OutputBuffer, TempOutputBuffer, OutputBufferLength);
if (Buffer != NULL)
ExFreePool(Buffer);
}
return stat;
}
-Matt
- Next message: Matt Taylor: "Re: Compiler Produces Incorrect Code"
- Previous message: francois: "IRP_MN_QUERY_PNP_DEVICE_STATE in BDA device driver"
- In reply to: cristalink: "Re: Compiler Produces Incorrect Code"
- Next in thread: Alexander Grigoriev: "Re: Compiler Produces Incorrect Code"
- Reply: Alexander Grigoriev: "Re: Compiler Produces Incorrect Code"
- Reply: cristalink: "Re: Compiler Produces Incorrect Code"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|