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
;
35 int getpagesize (void);
39 # define MAP_ANONYMOUS MAP_ANON
44 do_test (size_t align
, size_t len
)
49 if (align
+ len
>= bufsize
)
56 memset (buf
, c1
, bufsize
);
59 MEMSET (buf
+ align
, c2
, len
);
62 i
= (align
> 64 ? align
- 64 : 0);
63 for (; i
< align
; ++i
)
66 printf ("Garbage before: ofs %zd\n", i
);
70 for (; i
< align
+ len
; ++i
)
73 printf ("Wrong result: ofs %zd\n", i
);
77 for (j
= i
+ 64 < bufsize
? i
+ 64 : bufsize
; i
< j
; ++i
)
80 printf ("Garbage after: ofs %zd\n", i
);
90 page_size
= getpagesize ();
91 bufsize
= 2 * page_size
;
93 buf
= mmap (NULL
, bufsize
+ 2*page_size
, PROT_READ
| PROT_WRITE
,
94 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
95 if (buf
== MAP_FAILED
)
98 if (mprotect (buf
, page_size
, PROT_NONE
))
101 if (mprotect (buf
+ bufsize
, page_size
, PROT_NONE
))
104 for (i
= 0; i
< 18; ++i
)
108 do_test (bufsize
- len
, len
);
111 for (i
= 0; i
< 32; ++i
)
112 for (j
= 0; j
< 32; ++j
)
115 for (i
= 3; i
< 32; ++i
)
117 if ((i
& (i
- 1)) == 0)