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 MEMSET _ITM_memsetW
32 static unsigned char *buf;
33 static size_t bufsize, page_size;
37 do_test (size_t align, size_t len)
42 if (align + len >= bufsize)
49 memset (buf, c1, bufsize);
52 MEMSET (buf + align, c2, len);
55 i = (align > 64 ? align - 64 : 0);
56 for (; i < align; ++i)
59 printf ("Garbage before: ofs %zd\n", i);
63 for (; i < align + len; ++i)
66 printf ("Wrong result: ofs %zd\n", i);
70 for (j = i + 64 < bufsize ? i + 64 : bufsize; i < j; ++i)
73 printf ("Garbage after: ofs %zd\n", i);
83 page_size = getpagesize ();
84 bufsize = 2 * page_size;
86 buf = mmap (NULL, bufsize + 2*page_size, PROT_READ | PROT_WRITE,
87 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
88 if (buf == MAP_FAILED)
91 if (mprotect (buf, page_size, PROT_NONE))
94 if (mprotect (buf + bufsize, page_size, PROT_NONE))
97 for (i = 0; i < 18; ++i)
101 do_test (bufsize - len, len);
104 for (i = 0; i < 32; ++i)
105 for (j = 0; j < 32; ++j)
108 for (i = 3; i < 32; ++i)
110 if ((i & (i - 1)) == 0)