Prev: SetupDiOpenDeviceInfo - adding devices based on wildcard chars
Next: Service installation section in this INF is invalid
From: John Bond on 3 Mar 2010 14:44 The following code does not work (does not delay execution): __int64 WaitIn100nsUnit = - n100nsTimeCount; KeDelayExecutionThread(KernelMode, FALSE, (PLARGE_INTEGER)&WaitIn100nsUnit); while the following does work: LARGE_INTEGER WaitIn100nsUnit = RtlConvertLongToLargeInteger( -1 * n100nsTimeCount ); KeDelayExecutionThread(KernelMode, FALSE, &WaitIn100nsUnit); I am testing my driver on Windows 7. Thx in advance, John Bond
From: Maxim S. Shatskih on 3 Mar 2010 15:20 > __int64 WaitIn100nsUnit = - n100nsTimeCount; > KeDelayExecutionThread(KernelMode, FALSE, > (PLARGE_INTEGER)&WaitIn100nsUnit); > > while the following does work: > > LARGE_INTEGER WaitIn100nsUnit = RtlConvertLongToLargeInteger( -1 * > n100nsTimeCount ); > KeDelayExecutionThread(KernelMode, FALSE, &WaitIn100nsUnit); KdPrint(("%I64x\n", *(PLARGE_INTEGER)&WaitIn100nsUnit)); - will help a lot. Also a working thing: LARGE_INTEGER WaitIn100nsUnit; WaitIn100nsUnit.QuadPart = -(LONGLONG)n100nsTimeCount; KeDelayExecutionThread(KernelMode, FALSE, &WaitIn100nsUnit); Probably the bug in your code is that n100nsTimeCount is unsigned, so, the negate is also unsigned, and then the promotion is done from 32bit unsigned to 64bit signed. In this case, I expect it will not work correctly (the senior dword will remain zero). Search the archives of this list, I'm nearly sure it was discussed (with relation of the rules imposed by C standard too) - by me and Alberto Moreira among others. -- Maxim S. Shatskih Windows DDK MVP maxim(a)storagecraft.com http://www.storagecraft.com
From: Maxim S. Shatskih on 5 Mar 2010 03:58
> There must be more to the code than that, because those two sequences are > equivalent. No. One is signed64 = - unsigned32; In this case, "-" will be executed on unsigned type, and then the unsigned 32bit type will be promoted to signed 64bit one. The promotion will be unsigned - i.e. zero-fill of the senior word, not sign-extension. The correct operator is: signed64 = - (signed32)unsigned32; This will first force-cast to signed32, then execute "-" on a signed type, then promote signed32 to signed64, which is sign-extension. As for me, I use LARGE_INTEGER where the OS wants so, but no RtlXxx obsolete routines - instead, I use arith on .QuadPart. -- Maxim S. Shatskih Windows DDK MVP maxim(a)storagecraft.com http://www.storagecraft.com |