From: xiaosi on
It's strange that why to use loop instead of __stosb on none _M_AMD64 cpu.
On my AMD32 cpu, __stosb (114 clocks) is faster than this loop (195 clocks).

FORCEINLINE
PVOID
RtlSecureZeroMemory(
__in_bcount(cnt) PVOID ptr,
__in SIZE_T cnt
)
{
volatile char *vptr = (volatile char *)ptr;
#if defined(_M_AMD64)
__stosb((PBYTE )((DWORD64)vptr), 0, cnt);
#else
while (cnt) {
*vptr = 0;
vptr++;
cnt--;
}
#endif
return ptr;
}

"Alex Blekhman" <tkfx.REMOVE(a)yahoo.com> wrote:
> I found in the WinNT.h header the SecureZeroMemory macro, which
> expands to the RtlSecureZeroMemory function. It is implemented
> inline in the header file, so it doesn't have any external
> dependencies. Basically, it's a straightforward implementation of
> memset.
>
> HTH
> Alex
From: Vincent Fatica on
On Wed, 9 Sep 2009 15:25:55 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:

|When add /FORCE:MULTIPLE to linker option:
|LIBCMT.lib(_wctype.obj) : warning LNK4006: _iswlower already defined in ntdll.lib(ntdll.dll); second definition ignored
|LIBCMT.lib(_wctype.obj) : warning LNK4006: _iswdigit already defined in ntdll.lib(ntdll.dll); second definition ignored

Yes, I discovered that and tried it. It worked but the resulting scary warnings
made it seem rather heavy-handed.

I read about the purpose of ntdll.dll (as an interface to the native API). Then
I looked at the win7 version of ntdll.lib in the WDK. It contains *none* of the
CTR stuff (str*, wcs*, ...) that's in the winxp version. Do you suppose it's
incomplete ... or perhaps, has the philosophy changed?
--
- Vince
From: Vincent Fatica on
On Wed, 9 Sep 2009 10:48:28 +0300, "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com>
wrote:

|"Vincent Fatica" wrote:
|> |You can use the ZeroMemory macro, which results in a call to
|> ntdll.dll's RtlZeroMemory routine instead of pulling in the CRT.
|>
|> Tried that ... results in a call to _memset.
|
|I found in the WinNT.h header the SecureZeroMemory macro, which
|expands to the RtlSecureZeroMemory function. It is implemented
|inline in the header file, so it doesn't have any external
|dependencies. Basically, it's a straightforward implementation of
|memset.

Yes, I discovered that early on. It works, using 7 bytes more text than stosd
(if I recall correctly).
--
- Vince
From: Vincent Fatica on
On Wed, 9 Sep 2009 17:07:18 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:

|It's strange that why to use loop instead of __stosb on none _M_AMD64 cpu.
|On my AMD32 cpu, __stosb (114 clocks) is faster than this loop (195 clocks).

How do you time such things?
--
- Vince
From: xiaosi on
Those crt functions in ntdll.dll seems to be undocumented feature of Windows. I had never heard of this before the day that I
"dumpbined" it. Since it's undocumented, Windows does not promise to support this in the future.

"Vincent Fatica" <vince(a)blackholespam.net> wrote:
> On Wed, 9 Sep 2009 15:25:55 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:
>
> |When add /FORCE:MULTIPLE to linker option:
> |LIBCMT.lib(_wctype.obj) : warning LNK4006: _iswlower already defined in ntdll.lib(ntdll.dll); second definition ignored
> |LIBCMT.lib(_wctype.obj) : warning LNK4006: _iswdigit already defined in ntdll.lib(ntdll.dll); second definition ignored
>
> Yes, I discovered that and tried it. It worked but the resulting scary warnings
> made it seem rather heavy-handed.
>
> I read about the purpose of ntdll.dll (as an interface to the native API). Then
> I looked at the win7 version of ntdll.lib in the WDK. It contains *none* of the
> CTR stuff (str*, wcs*, ...) that's in the winxp version. Do you suppose it's
> incomplete ... or perhaps, has the philosophy changed?
> --
> - Vince