How to add sleep() in DriverEntry() method?

Hi,

I want to add sleep() function inside DriverEntry() callback function. I have tried as
#include “dos.h”
sleep(10);

But it is showing error sleep(): Identifier is not found.

Any idea how to include sleep() function or any other way to wait the control inside the DriverEntry callback function.

Thanks.

Why do you think you need this? Depending on the version of Windows you are
blocking the system with your delay.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@yahoo.co.in
Sent: Friday, June 13, 2014 7:15 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to add sleep() in DriverEntry() method?

Hi,

I want to add sleep() function inside DriverEntry() callback function. I
have tried as #include “dos.h”
sleep(10);

But it is showing error sleep(): Identifier is not found.

Any idea how to include sleep() function or any other way to wait the
control inside the DriverEntry callback function.

Thanks.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

in principle KeDelayExecutionThread can be used.

Why do you think you need this?
good question ) this is logic error

You don’t want to do this.

What problem are you trying to solve?

Peter
OSR
@OSRDrivers

If you are trying to sleep in order to wait for another driver to load, it ain’t gonna happen. All of the DriverEntry routines are called synchronously by the same thread.

Thanks for reply !!!

I need device serial number that method Due to execution is very fast, so some time device is boot successfully and get the serial number but some time it’s fail to retrieve the serial number because devices is not booted properly, I think so.

I have added the routine KeDelayExecutionThread (time) and resolved the problem.

Thanks again for your help.

Why are you touching HW in driverentry()? This should be a pnp driver and then init shouldn’t need delays

d

Bent from my phone


From: xxxxx@yahoo.co.inmailto:xxxxx
Sent: ?6/?13/?2014 7:37 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] How to add sleep() in DriverEntry() method?

Thanks for reply !!!

I need device serial number that method Due to execution is very fast, so some time device is boot successfully and get the serial number but some time it’s fail to retrieve the serial number because devices is not booted properly, I think so.

I have added the routine KeDelayExecutionThread (time) and resolved the problem.

Thanks again for your help.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

xxxxx@yahoo.co.in wrote:

I need device serial number that method Due to execution is very fast, so some time device is boot successfully and get the serial number but some time it’s fail to retrieve the serial number because devices is not booted properly, I think so.

What kind of device is this, exactly? I would argue that you either
have a hardware design bug or a driver design flaw. For a PnP driver,
you aren’t allowed to do any hardware access at all until you get a
START_DEVICE request. Up until that point, you don’t have a device
object, which means you haven’t actually been asked to drive any
specific device, and you haven’t been assigned any resources.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

“I need device serial number that method Due to execution is very fast, so some
time device is boot successfully and get the serial number but some time it’s
fail to retrieve the serial number because devices is not booted properly”

That’s a hardware issue. Waiting isn’t going to help it. What does it look like in DeviceManager when it fails? How are you getting the serial number, is it USB? The hardware wont be there until your AddDevice handler gets called, so as Doron says, interact with the hardware there. If the device fails to enumerate your AddDevice wont be called.

Slight correction: you have a device object, that was created in
AddDevice. What you don’t have is access to the device itself. For
bus-connected devices, this means you don’t have the addresses of the
device’s registers (or, more rarely these days, its I/O ports) and for USB
devices you don’t have its endpoint address. So until the
IRP_MN_PNP:IRP_MN_START_DEVICE, you are unable to communicate with it.

For bus devices (PCI, PCIe) the boot sequence is definitely involved: the
PCI BIOS. For USB devices, they are not even visible until the USB Bus
Driver begins to operate, we’ll towards the end of the boot sequence.
I’ll vote +1 on the bad hardware/bad driver verdict.

By the way, my program has a bug. Can you tell me what is wrong? [Hint:
your question omits every important piece of information required to give
a useful analysis]
Joe

xxxxx@yahoo.co.in wrote:
> I need device serial number that method Due to execution is very fast,
> so some time device is boot successfully and get the serial number but
> some time it’s fail to retrieve the serial number because devices is not
> booted properly, I think so.

What kind of device is this, exactly? I would argue that you either
have a hardware design bug or a driver design flaw. For a PnP driver,
you aren’t allowed to do any hardware access at all until you get a
START_DEVICE request. Up until that point, you don’t have a device
object, which means you haven’t actually been asked to drive any
specific device, and you haven’t been assigned any resources.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

What I used to tell my students was “If you write a multithreaded program,
and you have to add Sleep() calls to get it to work, your fundamental
design is wrong. A bad design cannot be fixed by sprinkling Sleep()
calls around like Magic Pixie Dust. Your design is still wrong, you’ve
just hidden the flaw for a while”

Given the OP told us nothing useful, it is hard to guess what is wrong.
joe

Why are you touching HW in driverentry()? This should be a pnp driver and
then init shouldn’t need delays

d

Bent from my phone


From: xxxxx@yahoo.co.inmailto:xxxxx
> Sent: ý6/ý13/ý2014 7:37 AM
> To: Windows System Software Devs Interest Listmailto:xxxxx
> Subject: RE:[ntdev] How to add sleep() in DriverEntry() method?
>
> Thanks for reply !!!
>
> I need device serial number that method Due to execution is very fast, so
> some time device is boot successfully and get the serial number but some
> time it’s fail to retrieve the serial number because devices is not booted
> properly, I think so.
>
> I have added the routine KeDelayExecutionThread (time) and resolved the
> problem.
>
> Thanks again for your help.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

> Hi,

I want to add sleep() function inside DriverEntry() callback function. I
have tried as
#include “dos.h”
sleep(10);

Let me give you a hint: this would work fine for a DOS application. You,
however, are writing a Windows kernel component. Has it occurred to you
that a function for DOS applications might not work in the Windows kernel?

Also, note that “10” is not a meaningful number, since it is rounded up to
15. If you really want 10, this requires significant magic.

And, of course, if you do figure out how to do it, you do not want to do
it. And if you don’t understand why, you should not be in the kernel.
joe

But it is showing error sleep(): Identifier is not found.

Any idea how to include sleep() function or any other way to wait the
control inside the DriverEntry callback function.

Thanks.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>Why do you think you need this? Depending on the version of Windows you are blocking the system

with your delay.

Well, taking into consideration the OP’s apparent level of “understanding” of C basics explaining to him why one should not block in DriverEntry() seems to be already a waste of effort, don’t you think. I guess the only appropriate statement here would be “Where is Mr.Aseltine”…

Anton Bassov

anton bassov wrote:

I guess the only appropriate statement here would be
“Where is Mr.Aseltine”…

I must have missed this one earlier on, but fortunately Dr. Joe has resurrected the thread for us all…

#include “dos.h”
sleep(10);

The fact that someone tried to include “#dos.h”, in a Windows kernel component, in the year 2014, probably shouldn’t surprise me, but I have to admit it does.

The above statement is an uber strong candidate for “NTDEV Forum Motto”… Don’t you all think? It sums-up so many of my experiences answering questions here in a tasty bite-sized portion.

Peter
OSR
@OSRDrivers

“Dan Kyler Prize” contest gets more and more tough…

I just wonder what else we are about to see…

Anton Bassov