none
Question code about API function KeEnterCriticalRegion et KeLeaveCriticalRegion RRS feed

  • Question

  • I have a question:

    when b = false KeLeaveCriticalRegion is called immediately
    when b = true KeLeaveCriticalRegion is called after 'time = 30 sec', Is this suitable?
    If not, what can happen in extreme case ?

    If not , Can the system freeze ??????

    b is often equal to true.

    KeEnterCriticalRegion();
    						LockService(); ///ExAcquireResourceExclusiveLite(&pd->resservice, TRUE);
    						b = IsListEmpty(&pd->ListSendService);
    						
    						if (b==FALSE)
    						{
    							PLIST_ENTRY lm=pd->ListSendService.Flink;
    							...
    							...
    							UnLockService(); //	ExReleaseResourceLite(&pd->resservice);
    							
    							status=STATUS_SUCCESS;
    
    						}
    						else
    						{
    							
    							
    							status=STATUS_NO_MORE_ENTRIES;
    							UnLockService(); 
    							//KeClearEvent(&pd->eventrequestservice);
    							WaitObject(&pd->eventrequestservice,time);
    							KeClearEvent(&pd->eventrequestservice);
    						}
    						
    						KeLeaveCriticalRegion();

    NTSTATUS WaitObject(PKEVENT event,DWORD sec)
    {
    	LARGE_INTEGER dr;
    	NTSTATUS status;
    	RtlZeroMemory(&dr,sizeof (LARGE_INTEGER));
    	dr.QuadPart = sec;
    	dr.QuadPart = dr.QuadPart * (-10000000);
    	status=KeWaitForSingleObject(event, Executive, KernelMode, FALSE, &dr);	
    	KeClearEvent(event);
    	return status;
    }

    Thank



    • Edited by Sizy458 Sunday, August 18, 2019 10:01 PM
    Sunday, August 18, 2019 9:52 PM

All replies

  • Pair your critical region calls with your Lock/Unlock calls.   You are just making the system unresponsive with what you are doing.  I suspect that a number of the questions you are asking would be different if you ran Code Analysis with all checks (not just the default ones) enabled, and ran your driver with Driver Verifier.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Sunday, August 18, 2019 11:31 PM
  •   KeEnterCriticalRegion(); 
                           LockService(); 
    ///ExAcquireResourceExclusiveLite(&pd->resservice, TRUE);                   
         b = IsListEmpty(&pd->ListSendService); 
                                                   if (b==FALSE)                        { 
                               PLIST_ENTRY lm=pd->ListSendService.Flink;    
                            ...   
                             ...   
                             UnLockService(); //   
                         ExReleaseResourceLite(&pd->resservice);      
                          KeLeaveCriticalRegion(); 
             
                                                 status=STATUS_SUCCESS;  
                          }  
                          else        
                    {                                          
                                              status=STATUS_NO_MORE_ENTRIES;  
                              UnLockService();  
                               KeLeaveCriticalRegion();   
                             //KeClearEvent(&pd->eventrequestservice); 
                               
    WaitObject(&pd->eventrequestservice,time);  
                             
    
    
     KeClearEvent(&pd->eventrequestservice); 
                          
     }              
         //KeLeaveCriticalRegion();

    The code above ,

    it's good ?

    PS:Excuse me for the indentation of the code,
    not very practical

    • Edited by Sizy458 Friday, August 23, 2019 9:49 AM
    Friday, August 23, 2019 9:48 AM