Click here to Skip to main content
15,886,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: What's the workspace coordinates in WINDOWS ? Pin
Charles Oppermann5-Aug-11 4:24
Charles Oppermann5-Aug-11 4:24 
GeneralRe: What's the workspace coordinates in WINDOWS ? Pin
Cold_Fearing_Bird5-Aug-11 4:37
Cold_Fearing_Bird5-Aug-11 4:37 
GeneralRe: What's the workspace coordinates in WINDOWS ? Pin
Charles Oppermann5-Aug-11 6:23
Charles Oppermann5-Aug-11 6:23 
QuestionFlickering problem in list control Pin
MKC0025-Aug-11 0:46
MKC0025-Aug-11 0:46 
AnswerRe: Flickering problem in list control Pin
Chris Meech5-Aug-11 2:15
Chris Meech5-Aug-11 2:15 
AnswerRe: Flickering problem in list control Pin
Richard MacCutchan5-Aug-11 3:38
mveRichard MacCutchan5-Aug-11 3:38 
AnswerRe: Flickering problem in list control Pin
Rolf Kristensen9-Aug-11 10:34
Rolf Kristensen9-Aug-11 10:34 
QuestionWDM kernel driver: ZwClose in timed procedure causes bluescreen Pin
J. Ruffing4-Aug-11 22:49
J. Ruffing4-Aug-11 22:49 
I'm developing a driver based on the SWTuner sample from the WinDDK. The driver receives MPEG-TS data from an application, and for debugging purposes I want the driver to dump the data to file.

My problem with closing the file handle: Calling ZwClose in a procedure timed with KeSetTimer causes a bluescreen with the message INVALID_PROCESS_ATTACH_ATTEMPT.

In more detail:

The driver receives a request from the application to open the file (works fine) and then writes the incomming buffers to file (also works fine). The problem is with closing the file handle: To avoid a locked file, a KTIMER is set to 10 seconds every time the the file handle is opened or written to (see method ResetTimeoutTimer). The procedure assigned to the timer is supposed to close the file handle (see method TimeoutTimerDPC).

Problem: The procedure TimeoutTimerDPC gets called 10 seconds after the last write, so this part works. With ZwClose commented out, the procedure works fine (pDevice can be accessed, debug output is generated). But when TimeoutTimerDPC calls ZwClose(pDevice->m_FileHandle) , this results in a blue screen with INVALID_PROCESS_ATTACH_ATTEMPT.

Any ideas what I'm doing wrong here, and how to fix it?

C++
/*
 *  Members of CDevice that are used to store data concerning the dump to file:
 */
// --- CDevice members for test dump  ---
bool		m_test_dump_file_open;
HANDLE		m_FileHandle;
PRKDPC		m_FileTimeoutDpc;
KTIMER		m_FileTimeoutTimer;
// ------------


/*
 *  Handle_IOCTL_Open opens the file handle and initialises the DPC, 
 *  sets the timer for the first time
 */
CDevice::
Handle_IOCTL_Open(CDevice * pDevice,
                  PIRP Irp, 
                  PIO_STACK_LOCATION pIoStackIrp,
                  UINT *pdwDataWritten)
{
  PAGED_CODE();

  //--- filename
  UNICODE_STRING FileName;
  RtlZeroMemory(&FileName, sizeof(FileName));
  RtlInitUnicodeString(&FileName,  
                       L"\\DosDevices\\C:\\media\\pbda_driver_dump.ts");  
  //---
  OBJECT_ATTRIBUTES FileObject;
  IO_STATUS_BLOCK IoStatus;  
  NTSTATUS Status;

  // initialize file object
  InitializeObjectAttributes(&FileObject,
            &FileName,
            OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
            NULL,
            NULL);

  // init file handle
  Status = ZwCreateFile(&(pDevice->m_FileHandle),
            FILE_APPEND_DATA | SYNCHRONIZE, 
            &FileObject,
            &IoStatus,
            NULL,
            FILE_ATTRIBUTE_NORMAL,
            FILE_SHARE_WRITE,
            FILE_SUPERSEDE, 
            FILE_SYNCHRONOUS_IO_NONALERT,        
            NULL,
            0);

  // --- Initialize TIMER
  PAGED_CODE();

  // init timer
  KeInitializeTimer (&(pDevice->m_FileTimeoutTimer));

  // allocate memory for DPC
  pDevice->m_FileTimeoutDpc = new(NonPagedPool,MS_SAMPLE_TUNER_POOL_TAG) KDPC;

  // init dpc
  KeInitializeDpc (pDevice->m_FileTimeoutDpc, 
		   reinterpret_cast <PKDEFERRED_ROUTINE> CDevice::TimeoutTimerDPC),	 
                   pDevice );

  // set timer
  ResetTimeoutTimer(pDevice);
 
  return Status;
}

/*
 *  ResetTimeoutTimer [re]sets the timer to 10 seconds
 */
CDevice::
ResetTimeoutTimer(CDevice * pDevice)
{
  // lock
  KIRQL             MySpinIrql;
  KeAcquireSpinLock(&(pDevice->m_buffer_queue_lock), &MySpinIrql);

  // timer delay: 10 sec
  LARGE_INTEGER NextDeltaTime;
  NextDeltaTime.QuadPart = (-100000000); // 10s ; expressed in 100-nanosecond intervals		   		   
  // cancel current timer
  KeCancelTimer(&(pDevice->m_FileTimeoutTimer)); // this step might be unnecessary

  // set timer
  KeSetTimer (&(pDevice->m_FileTimeoutTimer), 
              NextDeltaTime, 
              pDevice->m_FileTimeoutDpc);

  // unlock
  KeReleaseSpinLock(&(pDevice->m_buffer_queue_lock), MySpinIrql);
}


/*
 *  TimeoutTimerDPC  gets called when the timer expires, 
 *  and is supposed to close the file handle
 */
//-----
void
CDevice::
TimeoutTimerDPC (
        IN PKDPC Dpc,
        IN CDevice *pDevice,
        IN PVOID SystemArg1,
        IN PVOID SystemArg2
        )
{
  UNREFERENCED_PARAMETER(Dpc);
  UNREFERENCED_PARAMETER(SystemArg1);
  UNREFERENCED_PARAMETER(SystemArg2);

  // lock
  KIRQL             MySpinIrql;
  KeAcquireSpinLock(&(pDevice->m_buffer_queue_lock), &MySpinIrql);
	
  NTSTATUS Status;
  // close file handler
  if(pDevice){
    Status = ZwClose(pDevice->m_FileHandle); // <--- this line causes bluescreen
  }
		
  // unlock
  KeReleaseSpinLock(&(pDevice->m_buffer_queue_lock), MySpinIrql);	 
		 
}

AnswerRe: WDM kernel driver: ZwClose in timed procedure causes bluescreen Pin
Ahmed Charfeddine8-Aug-11 0:24
Ahmed Charfeddine8-Aug-11 0:24 
QuestionWhat's the real difference between POPUP window and OVERLAPPED window Pin
Cold_Fearing_Bird3-Aug-11 23:50
Cold_Fearing_Bird3-Aug-11 23:50 
AnswerRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Richard MacCutchan4-Aug-11 1:27
mveRichard MacCutchan4-Aug-11 1:27 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Albert Holguin4-Aug-11 17:40
professionalAlbert Holguin4-Aug-11 17:40 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Cold_Fearing_Bird4-Aug-11 21:42
Cold_Fearing_Bird4-Aug-11 21:42 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Richard MacCutchan4-Aug-11 23:01
mveRichard MacCutchan4-Aug-11 23:01 
GeneralRe: What's the real difference between POPUP window and OVERLAPPED window Pin
Albert Holguin5-Aug-11 4:24
professionalAlbert Holguin5-Aug-11 4:24 
Questionproblem in writing a binary file using _tfopen_s function Pin
VCProgrammer3-Aug-11 20:48
VCProgrammer3-Aug-11 20:48 
AnswerRe: problem in writing a binary file using _tfopen_s function Pin
Code-o-mat3-Aug-11 21:04
Code-o-mat3-Aug-11 21:04 
RantRe: problem in writing a binary file using _tfopen_s function Pin
«_Superman_»4-Aug-11 3:41
professional«_Superman_»4-Aug-11 3:41 
Questionhandle fullscreen child view in c++ 2010? Pin
fracker_23213-Aug-11 20:46
fracker_23213-Aug-11 20:46 
AnswerRe: handle fullscreen child view in c++ 2010? Pin
Richard MacCutchan3-Aug-11 22:55
mveRichard MacCutchan3-Aug-11 22:55 
GeneralRe: handle fullscreen child view in c++ 2010? Pin
fracker_23214-Aug-11 1:28
fracker_23214-Aug-11 1:28 
AnswerRe: handle fullscreen child view in c++ 2010? Pin
Rolf Kristensen4-Aug-11 12:06
Rolf Kristensen4-Aug-11 12:06 
Questionpin_ptr on value struct is needed? [modified] Pin
Dusan Paulovic3-Aug-11 6:16
Dusan Paulovic3-Aug-11 6:16 
AnswerRe: pin_ptr on value struct is needed? Pin
Code-o-mat3-Aug-11 6:34
Code-o-mat3-Aug-11 6:34 
GeneralRe: pin_ptr on value struct is needed? Pin
Dusan Paulovic3-Aug-11 6:53
Dusan Paulovic3-Aug-11 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.