There is a bug in __stosb (as well as the other __stos* functions), as
illustrated by this code (compile with -Os for 64bit):
#include <stdio.h>
#include <windows.h>
#ifndef _AMD64_
#error Must be compiled for 64 bit
#endif
int main(int argc, char* argv[])
{
struct
{
int a;
int b;
} c;
c.a = 1;
c.b = 2;
__stosb((PBYTE)&c, 0, sizeof(c));
printf("%u %u\n", c.a, c.b); // Should print 0 0
}
The attached patch resolves this issue.
dw
Index: winnt.h
===================================================================
--- winnt.h (revision 5863)
+++ winnt.h (working copy)
@@ -1580,42 +1580,18 @@
VOID __stosq(PDWORD64 Destination,DWORD64 Value,SIZE_T Count);
#ifndef __CRT__NO_INLINE
- __CRT_INLINE VOID __stosb(PBYTE Dest,BYTE Data,SIZE_T Count)
- {
- __asm__ __volatile__
- (
- "rep; stosb" :
- [Dest] "=D" (Dest), [Count] "=c" (Count) :
- "[Dest]" (Dest), "a" (Data), "[Count]" (Count)
- );
- }
- __CRT_INLINE VOID __stosw(PWORD Dest,WORD Data,SIZE_T Count)
- {
- __asm__ __volatile__
- (
- "rep; stosw" :
- [Dest] "=D" (Dest), [Count] "=c" (Count) :
- "[Dest]" (Dest), "a" (Data), "[Count]" (Count)
- );
- }
- __CRT_INLINE VOID __stosd(PDWORD Dest,DWORD Data,SIZE_T Count)
- {
- __asm__ __volatile__
- (
- "rep; stosl" :
- [Dest] "=D" (Dest), [Count] "=c" (Count) :
- "[Dest]" (Dest), "a" (Data), "[Count]" (Count)
- );
- }
- __CRT_INLINE VOID __stosq(PDWORD64 Dest,DWORD64 Data,SIZE_T Count)
- {
- __asm__ __volatile__
- (
- "rep; stosq" :
- [Dest] "=D" (Dest), [Count] "=c" (Count) :
- "[Dest]" (Dest), "a" (Data), "[Count]" (Count)
- );
- }
+#define __buildstos(x, y) __CRT_INLINE VOID x(y *Dest, y Data, SIZE_T Count) \
+{ \
+ __asm__ __volatile__ ("rep stos%z2" \
+ : /* no outputs */ \
+ : "D" (Dest), "c" (Count), "a" (Data) \
+ : "memory"); \
+}
+
+__buildstos(__stosb, BYTE)
+__buildstos(__stosw, WORD)
+__buildstos(__stosd, DWORD)
+__buildstos(__stosq, DWORD64)
#endif /* __CRT__NO_INLINE */
#define MultiplyHigh __mulh
------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public