I have just created a system thread and as my driver unloads I call ZwClose(hHandle); Yet I am receiving Driver Unloaded without cancelling pending operations. I may have miss another line of code previously but am I unloading the thread correctly.
Also when a thread does unload, does it stop at its immediate execution?
Calling ZwCloseHandle() just releases a reference to the thread object - it does not affect the target thread’s state in any possible way.
All system threads run in context of so-called" system process" which is just a collection of all threads that have no UM representation. They have no relationship to any particular module’s lifetime/state whatsoever. Therefore, if thread has not yet been terminated by the time you unload a driver module and its EIP points to something that is supposed to be driver code, in actuality its EIP points to the middle of nowhere after driver module gets unloaded. This is why you get a bugcheck.
What you have to do here is to wait on thread object in DriverUnload()…
Calling ZwCloseHandle() just releases a reference to the thread object - it does
not affect the target thread’s state in any possible way.
All system threads run in context of so-called" system process" which is just a
collection of all threads that have no UM representation. They have no
relationship to any particular module’s lifetime/state whatsoever. Therefore,
if thread has not yet been terminated by the time you unload a driver module
and its EIP points to something that is supposed to be driver code, in actuality
its EIP points to the middle of nowhere after driver module gets unloaded. This
is why you get a bugcheck.
What you have to do here is to wait on thread object in DriverUnload()…
wrote in message news:xxxxx@ntdev… > Hi. > > I have just created a system thread and as my driver unloads I call ZwClose(hHandle); Yet I am receiving Driver Unloaded without cancelling pending operations. I may have miss another line of code previously but am I unloading the thread correctly. > > Also when a thread does unload, does it stop at its immediate execution? > > Thanks, >