Hi,
I have a question about KeSetEvent.
I called KeSetEvent at DISPATCH_LEVEL and KeWaitForSingleObject is in a
thread that runs at
PASSIVE_LEVEL. why it cause a page fault?
both routine are locked by MmLockPagableCodeSection. And all variables are
in non-paged pool memory.
thanks.
NTSTATUS DRV4ReadIoCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
{
PIO_STACK_LOCATION pStackLoc;
NTSTATUS status;
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"++. IRP %p", Irp);
if (Irp->PendingReturned) {
IoMarkIrpPending( Irp );
}
pStackLoc = IoGetCurrentIrpStackLocation(Irp);
if(pStackLoc->Parameters.Read.Length)
{
while(mine->g_WaitForWritingToFile == TRUE && mine->g_IsThreadRunning ==
TRUE);
mine->g_WaitForWritingToFile = TRUE;
RtlZeroMemory(mine->g_TstBuff,100);
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION". Readed Length
%x",pStackLoc->Parameters.Read.Length );
RtlCopyMemory(mine->g_TstBuff,Irp->AssociatedIrp.SystemBuffer,pStackLoc->Par
ameters.Read.Length);
mine->g_ReadedLength = pStackLoc->Parameters.Read.Length;
/*************************PROBLEM********************/
KeSetEvent(&mine->g_ThreadEvent,IO_NO_INCREMENT,FALSE);
/******************************************************/
// DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION". Readed String
%S",tstBuff );
}
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"–. IRP %p STATUS %x",
Irp, STATUS_CONTINUE_COMPLETION);
return STATUS_CONTINUE_COMPLETION;
}
VOID DRV4Thread(
IN PVOID StartContext
)
{
NTSTATUS status;
OBJECT_ATTRIBUTES fileObjectAttributes;
HANDLE fileHandle;
IO_STATUS_BLOCK fileIoStatusBlock;
UNICODE_STRING fileUnicodeString;
int sw = TRUE;
PAGED_CODE();
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"++.");
KeInitializeEvent(&mine->g_ThreadEvent,SynchronizationEvent,FALSE);
//KeInitializeEvent(&mine->g_WaitForWriteEvent,SynchronizationEvent,FALSE);
//KeSetEvent(&mine->g_WaitForWriteEvent,IO_NO_INCREMENT,FALSE);
RtlInitUnicodeString(&fileUnicodeString,L"\DosDevices\C:\tstdrv.txt");
InitializeObjectAttributes(
&fileObjectAttributes,
&fileUnicodeString,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,NULL
);
status = ZwOpenFile(
&fileHandle,
FILE_APPEND_DATA,
&fileObjectAttributes,
&fileIoStatusBlock,
FILE_SHARE_WRITE | FILE_SHARE_READ,
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT
);
if(status != STATUS_SUCCESS)
{
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"Failed to open file.
STATUS %x",status);
mine->g_WaitForWritingToFile = FALSE;
mine->g_IsThreadRunning = FALSE;
return;
}
//mine->g_WaitForWritingToFile = TRUE;
while(sw == TRUE)
{
status = KeWaitForSingleObject(
&mine->g_ThreadEvent,
Executive,
UserMode,
FALSE,
NULL
);
if(!mine->g_ShouldContinue){
sw = FALSE;
}
if(status == STATUS_SUCCESS)
{
status = ZwWriteFile(
fileHandle,
NULL,NULL,NULL,
&fileIoStatusBlock,
mine->g_TstBuff,
mine->g_ReadedLength,
NULL,NULL
);
if(fileIoStatusBlock.Status == STATUS_SUCCESS )
{
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION". ZwWriteFile
Written bytes : %x",fileIoStatusBlock.Information);
}
DRV4DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION". ZwWriteFile STATUS
%x",status);
}
mine->g_WaitForWritingToFile = FALSE;
//KeSetEvent(&mine->g_WaitForWriteEvent,IO_NO_INCREMENT,FALSE);
}
ZwClose(fileHandle);
mine->g_IsThreadRunning = FALSE;
DRV4DebugPrint(DBG_INIT, DBG_TRACE, FUNCTION"–.");
}