1 /* This program is free software; you can redistribute it and/or modify
2 it under the terms of the GNU General Public License as published by
3 the Free Software Foundation; either version 2 of the License, or
4 (at your option) any later version.
6 This program is distributed in the hope that it will be useful, but
7 WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 General Public License for more details.
11 You should have received a copy of the GNU General Public License
12 along with this program; if not, write to the Free Software
13 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 /* Verify memcpy operation. */
24 #define BEG_TRANSACTION \
25 _ITM_beginTransaction (pr_instrumentedCode | pr_hasNoAbort \
26 | pr_hasNoIrrevocable)
27 #define END_TRANSACTION \
28 _ITM_commitTransaction ()
30 #define MEMCPY _ITM_memcpyRtWt
32 static unsigned char *buf1
, *buf2
;
33 static size_t bufsize
, page_size
;
37 do_test (size_t align1
, size_t align2
, size_t len
)
40 unsigned char *s1
, *s2
;
43 if (align1
+ len
>= bufsize
)
45 if (align2
+ len
>= bufsize
)
50 memset (buf1
, c1
, bufsize
);
51 memset (buf2
, c2
, bufsize
);
56 for (i
= 0, j
= 1; i
< len
; i
++, j
+= 23)
57 s1
[i
] = (j
== c1
? j
+ 1 : j
);
63 if (memcmp (s1
, s2
, len
) != 0)
65 printf ("Wrong result: dalign %zd salign %zd len %zd\n",
71 for (i
= (align2
> 64 ? align2
- 64 : 0); i
< align2
; ++i
)
74 printf ("Garbage before: ofs %zd\n", i
);
78 for (i
= align2
+ len
, j
= i
+64 < bufsize
? i
+64 : bufsize
; i
< j
; ++i
)
81 printf ("Garbage after: ofs %zd\n", i
);
89 # define MAP_ANONYMOUS MAP_ANON
97 page_size
= getpagesize ();
98 bufsize
= 2 * page_size
;
100 buf1
= mmap (NULL
, bufsize
+ 2*page_size
, PROT_READ
| PROT_WRITE
,
101 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
102 if (buf1
== MAP_FAILED
)
104 buf2
= mmap (NULL
, bufsize
+ 2*page_size
, PROT_READ
| PROT_WRITE
,
105 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
106 if (buf2
== MAP_FAILED
)
109 if (mprotect (buf1
, page_size
, PROT_NONE
))
112 if (mprotect (buf1
+ bufsize
, page_size
, PROT_NONE
))
115 if (mprotect (buf2
, page_size
, PROT_NONE
))
118 if (mprotect (buf2
+ bufsize
, page_size
, PROT_NONE
))
121 for (i
= 0; i
< 18; ++i
)
130 do_test (0, bufsize
- len
, len
);
131 do_test (bufsize
- len
, 0, len
);
132 do_test (i
, bufsize
- len
, len
);
133 do_test (bufsize
- len
, i
, len
);
136 for (i
= 0; i
< 32; ++i
)
142 for (j
= 0; j
< 32; ++j
)
144 do_test (i
, bufsize
- i
- j
, i
);
145 do_test (bufsize
- i
- j
, i
, i
);
149 for (i
= 3; i
< 32; ++i
)
151 if ((i
& (i
- 1)) == 0)
153 do_test (0, 0, 16 * i
);
154 do_test (i
, 0, 16 * i
);
155 do_test (0, i
, 16 * i
);
156 do_test (i
, i
, 16 * i
);