Starting system thread to add callbacks

I have a 1394 NT4 middle-level driver laying on the top of the 1394 core
(basically, OHCI) driver. In DriverEntry, there is a call to the core
driver providing the core driver with the callbacks need to be called when a
device is added to / removed from the bus. This call to the core driver is
done from the routine running as a system thread. I am curious why it is
done via a system thread? Is it wrong to make this call directly from
DriverEntry?

The following is quoted code:

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{

// Start a thread that will init callbacks
status = PsCreateSystemThread (
&ThreadHandle,
THREAD_ALL_ACCESS,
NULL,
NULL,
NULL,
MF1394DriverL2InitCallbacks,
pDevExt);

}

void MF1394DriverL2InitCallbacks (PVOID Context)
{

IoSetCompletionRoutine(
pIrp,
MF1394SynchCompletionRoutine,
&Event,
TRUE,
TRUE,
TRUE
);

// Call the core driver
ntStatus = IoCallDriver(pDevExt->StackDeviceObject, pIrp);

if(ntStatus == STATUS_PENDING) {
ntStatus = KeWaitForSingleObject(&Event,
Executive,
KernelMode,
FALSE,
NULL );

}


}


Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Maybe the author believed a deadlock may happen if DriverEntry has
stopped until the IRP is completed and the core driver will call
the callbacks while handling the IRP. It depends on what the
DriverEntry is doing before and after creating the thread.
Or IRP handling takes too long to complete.

— Slava Abramov wrote:
> I have a 1394 NT4 middle-level driver laying on the top of the 1394 core
> (basically, OHCI) driver. In DriverEntry, there is a call to the core
> driver providing the core driver with the callbacks need to be called when a
> device is added to / removed from the bus. This call to the core driver is
> done from the routine running as a system thread. I am curious why it is
> done via a system thread? Is it wrong to make this call directly from
> DriverEntry?
>
> The following is quoted code:
>
> NTSTATUS
> DriverEntry(
> IN PDRIVER_OBJECT DriverObject,
> IN PUNICODE_STRING RegistryPath
> )
> {
> …
>
> // Start a thread that will init callbacks
> status = PsCreateSystemThread (
> &ThreadHandle,
> THREAD_ALL_ACCESS,
> NULL,
> NULL,
> NULL,
> MF1394DriverL2InitCallbacks,
> pDevExt);
> …
> }
>
> void MF1394DriverL2InitCallbacks (PVOID Context)
> {
> …
>
> IoSetCompletionRoutine(
> pIrp,
> MF1394SynchCompletionRoutine,
> &Event,
> TRUE,
> TRUE,
> TRUE
> );
>
> // Call the core driver
> ntStatus = IoCallDriver(pDevExt->StackDeviceObject, pIrp);
>
> if(ntStatus == STATUS_PENDING) {
> ntStatus = KeWaitForSingleObject(&Event,
> Executive,
> KernelMode,
> FALSE,
> NULL );
>
> }
>
> …
> }
>
>
>
>
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
>
> —
> You are currently subscribed to ntdev as: xxxxx@yahoo.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

DriverEntry is always executed by the system thread, safe to rely on it.
BTW - where have you found 1394 stack for NT4?

Max

----- Original Message -----
From: “Slava Abramov”
To: “NT Developers Interest List”
Sent: Thursday, December 06, 2001 6:53 PM
Subject: [ntdev] Starting system thread to add callbacks

> I have a 1394 NT4 middle-level driver laying on the top of the 1394 core
> (basically, OHCI) driver. In DriverEntry, there is a call to the core
> driver providing the core driver with the callbacks need to be called when a
> device is added to / removed from the bus. This call to the core driver is
> done from the routine running as a system thread. I am curious why it is
> done via a system thread? Is it wrong to make this call directly from
> DriverEntry?
>
> The following is quoted code:
>
> NTSTATUS
> DriverEntry(
> IN PDRIVER_OBJECT DriverObject,
> IN PUNICODE_STRING RegistryPath
> )
> {
> …
>
> // Start a thread that will init callbacks
> status = PsCreateSystemThread (
> &ThreadHandle,
> THREAD_ALL_ACCESS,
> NULL,
> NULL,
> NULL,
> MF1394DriverL2InitCallbacks,
> pDevExt);
> …
> }
>
> void MF1394DriverL2InitCallbacks (PVOID Context)
> {
> …
>
> IoSetCompletionRoutine(
> pIrp,
> MF1394SynchCompletionRoutine,
> &Event,
> TRUE,
> TRUE,
> TRUE
> );
>
> // Call the core driver
> ntStatus = IoCallDriver(pDevExt->StackDeviceObject, pIrp);
>
> if(ntStatus == STATUS_PENDING) {
> ntStatus = KeWaitForSingleObject(&Event,
> Executive,
> KernelMode,
> FALSE,
> NULL );
>
> }
>
> …
> }
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com