Discussion:
cast UINT64 to "double" in WDK
(too old to reply)
Vitalie Vrabie
2010-11-10 10:17:23 UTC
Permalink
i need a function that returns a "double" representing the current
timestamp in days since 12/30/1899 (delphi/cbuilder's TDateTime
format) in my NDIS IM driver.

it's a 109205 days difference between the kernel's epoch and the one
of TDateTime.

given that there's no c runtime in a driver (thus no cast from uint64
to double), i come with this routine:

double SysUtilsNow()
{
UINT64 SystemTime, b;
double st, db;

NdisGetCurrentSystemTime((PLARGE_INTEGER)&SystemTime);

SystemTime -= ((UINT64)109205 * (UINT64)86400 * (UINT64)10000000);

// cast SystemTime to "double" in st
st = 0.0;
for (b=1, db=1.0; b!=0; b+=b, db+=db)
{
if ((SystemTime&b) != 0)
{
st += db;
}
}

return st / (86400.0 * 10000000.0);
}

and i get:
error LNK2001: unresolved external symbol __fltused
(same as i got when i tried to simply cast)

any insight where the problem is?
Vitalie Vrabie
2010-11-10 13:10:29 UTC
Permalink
Post by Vitalie Vrabie
any insight where the problem is?
http://www.microsoft.com/whdc/driver/kernel/kmcode.mspx
particularly:
"On x86 systems, the floating point and multimedia units are not
available in kernel mode unless specifically requested. Trying to use
them improperly may or may not cause a floating-point fault at raised
IRQL (which will crash the system), but it could cause silent data
corruption in random processes. Improper use can also cause data
corruption in other processes; such problems are often difficult to
debug."

problem closed.
no floating-point in the driver.

instead - kernelmode timestamping in the usermode app...

Loading...