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
;
35 int getpagesize (void);
38 do_test (size_t align1
, size_t align2
, size_t len
)
41 unsigned char *s1
, *s2
;
44 if (align1
+ len
>= bufsize
)
46 if (align2
+ len
>= bufsize
)
51 memset (buf1
, c1
, bufsize
);
52 memset (buf2
, c2
, bufsize
);
57 for (i
= 0, j
= 1; i
< len
; i
++, j
+= 23)
58 s1
[i
] = (j
== c1
? j
+ 1 : j
);
64 if (memcmp (s1
, s2
, len
) != 0)
66 printf ("Wrong result: dalign %zd salign %zd len %zd\n",
72 for (i
= (align2
> 64 ? align2
- 64 : 0); i
< align2
; ++i
)
75 printf ("Garbage before: ofs %zd\n", i
);
79 for (i
= align2
+ len
, j
= i
+64 < bufsize
? i
+64 : bufsize
; i
< j
; ++i
)
82 printf ("Garbage after: ofs %zd\n", i
);
90 # define MAP_ANONYMOUS MAP_ANON
98 page_size
= getpagesize ();
99 bufsize
= 2 * page_size
;
101 buf1
= mmap (NULL
, bufsize
+ 2*page_size
, PROT_READ
| PROT_WRITE
,
102 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
103 if (buf1
== MAP_FAILED
)
105 buf2
= mmap (NULL
, bufsize
+ 2*page_size
, PROT_READ
| PROT_WRITE
,
106 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
107 if (buf2
== MAP_FAILED
)
110 if (mprotect (buf1
, page_size
, PROT_NONE
))
113 if (mprotect (buf1
+ bufsize
, page_size
, PROT_NONE
))
116 if (mprotect (buf2
, page_size
, PROT_NONE
))
119 if (mprotect (buf2
+ bufsize
, page_size
, PROT_NONE
))
122 for (i
= 0; i
< 18; ++i
)
131 do_test (0, bufsize
- len
, len
);
132 do_test (bufsize
- len
, 0, len
);
133 do_test (i
, bufsize
- len
, len
);
134 do_test (bufsize
- len
, i
, len
);
137 for (i
= 0; i
< 32; ++i
)
143 for (j
= 0; j
< 32; ++j
)
145 do_test (i
, bufsize
- i
- j
, i
);
146 do_test (bufsize
- i
- j
, i
, i
);
150 for (i
= 3; i
< 32; ++i
)
152 if ((i
& (i
- 1)) == 0)
154 do_test (0, 0, 16 * i
);
155 do_test (i
, 0, 16 * i
);
156 do_test (0, i
, 16 * i
);
157 do_test (i
, i
, 16 * i
);